mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-02-02 17:59:47 +08:00
update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user