diff --git a/src/43-kfuncs/module/Makefile b/src/43-kfuncs/module/Makefile index ad10772..1245b52 100644 --- a/src/43-kfuncs/module/Makefile +++ b/src/43-kfuncs/module/Makefile @@ -3,6 +3,7 @@ obj-m += hello.o # hello.o is the target # Enable BTF generation KBUILD_CFLAGS += -g -O2 ccflags-y += -DCONFIG_BPF_SYSCALL +KBUILD_MODPOST_WARN=1 all: # Compile the module with BTF information make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules diff --git a/src/43-kfuncs/module/hello.c b/src/43-kfuncs/module/hello.c index c570b42..b0f5b33 100644 --- a/src/43-kfuncs/module/hello.c +++ b/src/43-kfuncs/module/hello.c @@ -17,19 +17,19 @@ __bpf_kfunc_start_defs(); __bpf_kfunc int bpf_strstr(const char *str, u32 str__sz, const char *substr, u32 substr__sz) { - // const char *fmt = "strstr: str=%s, str__sz=%u, substr=%s\n"; - // // bpf_trace_printk((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, (u64)str__sz, (u64)(void*)substr); - // // Edge case: if substr is empty, return 0 (assuming empty string is found at the start) - // const struct bpf_func_proto *proto = bpf_base_func_proto(BPF_FUNC_trace_printk, NULL); - // if (!proto) { - // pr_err("bpf_trace_printk: Failed to get prototype\n"); - // return -1; - // } - // if (proto->func) { - // proto->func((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, str__sz, (u64)(void*)substr); - // } else { - // pr_err("bpf_trace_printk: Failed to get function pointer\n"); - // } + const char *fmt = "strstr: str=%s, str__sz=%u, substr=%s\n"; + // bpf_trace_printk((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, (u64)str__sz, (u64)(void*)substr); + // Edge case: if substr is empty, return 0 (assuming empty string is found at the start) + const struct bpf_func_proto *proto = bpf_base_func_proto(BPF_FUNC_trace_printk, NULL); + if (!proto) { + pr_err("bpf_trace_printk: Failed to get prototype\n"); + return -1; + } + if (proto->func) { + proto->func((u64)(void*)fmt, (u64)sizeof(fmt), (u64)(void*)str, str__sz, (u64)(void*)substr); + } else { + pr_err("bpf_trace_printk: Failed to get function pointer\n"); + } if (substr__sz == 0) { return 0;