diff --git a/source/lib/internal/ebpf/libbpf/src/btf.c b/source/lib/internal/ebpf/libbpf/src/btf.c index d9c10830d749f0adefe37023c7210d55d5d28656..f7e46e10bf3edb5824a7e51c5d4f8f51a8dc9fcb 100644 --- a/source/lib/internal/ebpf/libbpf/src/btf.c +++ b/source/lib/internal/ebpf/libbpf/src/btf.c @@ -4598,11 +4598,24 @@ struct btf *libbpf_find_kernel_btf(void) { "/usr/lib/debug/lib/modules/%1$s/vmlinux" }, }; char path[PATH_MAX + 1]; + char *sysak_env_path; struct utsname buf; struct btf *btf; int i; uname(&buf); + sysak_env_path = getenv("SYSAK_WORK_PATH"); + if (sysak_env_path) { + snprintf(path, PATH_MAX, "%s/tools/vmlinux-%s", sysak_env_path, buf.release); + + btf = btf__parse(path, NULL); + pr_debug("loading kernel BTF '%s': %ld\n", + path, IS_ERR(btf) ? PTR_ERR(btf) : 0); + if (IS_ERR(btf)) + goto out; + + return btf; + } for (i = 0; i < ARRAY_SIZE(locations); i++) { snprintf(path, PATH_MAX, locations[i].path_fmt, buf.release); @@ -4623,6 +4636,7 @@ struct btf *libbpf_find_kernel_btf(void) return btf; } +out: pr_warn("failed to find valid kernel BTF\n"); return ERR_PTR(-ESRCH); } diff --git a/source/tools/combine/btf/btf.sh b/source/tools/combine/btf/btf.sh index 8b8a0b960f6aeea9fc8d08043f515059d37922a6..bc1e7cda3cb1c333eb4b05994ee83d179671e527 100644 --- a/source/tools/combine/btf/btf.sh +++ b/source/tools/combine/btf/btf.sh @@ -2,9 +2,8 @@ # author: Shuyi Cheng # email: chengshuyi@linux.alibaba.com -TOOLS_ROOT=$(dirname "$0") -zip_path=${TOOLS_ROOT}/BTF/btf.7z -btf_dir=${TOOLS_ROOT}/BTF +zip_path=${SYSAK_WORK_PATH}/tools/BTF/btf.7z +btf_dir=${SYSAK_WORK_PATH}/tools btf_path=${btf_dir}/vmlinux-$(uname -r) usage() { @@ -14,7 +13,7 @@ usage() { } extract_btf() { - ${TOOLS_ROOT}/BTF/7za e ${zip_path} -o${btf_dir} vmlinux-btf/vmlinux-$(uname -r) + ${SYSAK_WORK_PATH}/tools/BTF/7za e ${zip_path} -o${btf_dir} vmlinux-btf/vmlinux-$(uname -r) } while getopts 'd:h' OPT; do diff --git a/source/tools/test/bpf_test/bpf/bpftest1.bpf.c b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c index 4186d9095459934044e39400f3b8980a2fd8bf2c..09e41de5eaf6ae00dd825fd9a947af8af192730f 100644 --- a/source/tools/test/bpf_test/bpf/bpftest1.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c @@ -4,14 +4,13 @@ #include #include "../bpftest.h" - - SEC("kprobe/tcp_v4_connect") -int BPF_KPROBE(kprobe_tcp_v4_connect,struct sock *sk, struct sockaddr *uaddr, int addr_len) +int BPF_KPROBE(kprobe_tcp_v4_connect, struct sock *sk, struct sockaddr *uaddr, int addr_len) { u64 tgid = bpf_get_current_pid_tgid(); + int tmp; + BPF_CORE_READ_INTO(&tmp, sk, sk_rcvbuf); return 0; } - char LICENSE[] SEC("license") = "GPL"; \ No newline at end of file diff --git a/source/tools/test/bpf_test/bpf/bpftest2.bpf.c b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c index 4186d9095459934044e39400f3b8980a2fd8bf2c..d55617640c6fc73c08c8e5a57e421aba0038f1fa 100644 --- a/source/tools/test/bpf_test/bpf/bpftest2.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c @@ -10,6 +10,8 @@ SEC("kprobe/tcp_v4_connect") int BPF_KPROBE(kprobe_tcp_v4_connect,struct sock *sk, struct sockaddr *uaddr, int addr_len) { u64 tgid = bpf_get_current_pid_tgid(); + int tmp; + BPF_CORE_READ_INTO(&tmp, sk, sk_rcvbuf); return 0; } diff --git a/source/tools/test/bpf_test/bpftest.c b/source/tools/test/bpf_test/bpftest.c index 6d3420e7f9bf49ed04bd9f273fc27194e51551aa..f50d8d4cf73e7f84ba513b7df9e56a36de358832 100644 --- a/source/tools/test/bpf_test/bpftest.c +++ b/source/tools/test/bpf_test/bpftest.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) goto cleanup; printf("bpftest2 program load done, test finished. exit.\n"); - while(1){} + // while(1){} cleanup: // destory the bpf program bpftest1_bpf__destroy(bpftest1);