diff --git a/src/features/struct_ops/module/bpf_testmod.h b/src/features/struct_ops/module/bpf_testmod.h index 5310641..bfffd40 100644 --- a/src/features/struct_ops/module/bpf_testmod.h +++ b/src/features/struct_ops/module/bpf_testmod.h @@ -5,7 +5,7 @@ struct bpf_testmod_ops { int (*test_1)(void); int (*test_2)(int a, int b); - void (*test_3)(const char *buf, int len); + int (*test_3)(const char *buf, int len); }; #endif /* _BPF_TESTMOD_H */ \ No newline at end of file diff --git a/src/features/struct_ops/module/hello.c b/src/features/struct_ops/module/hello.c index 8f23d54..03caa8e 100644 --- a/src/features/struct_ops/module/hello.c +++ b/src/features/struct_ops/module/hello.c @@ -6,12 +6,13 @@ #include #include #include +#include /* Define our custom struct_ops operations */ struct bpf_testmod_ops { int (*test_1)(void); int (*test_2)(int a, int b); - void (*test_3)(const char *buf, int len); + int (*test_3)(const char *buf, int len); }; /* Global instance that BPF programs will implement */ @@ -31,8 +32,9 @@ static int bpf_testmod_ops__test_2(int a, int b) return 0; } -static void bpf_testmod_ops__test_3(const char *buf, int len) +static int bpf_testmod_ops__test_3(const char *buf, int len) { + return 0; } /* CFI stubs structure */ @@ -58,8 +60,18 @@ static bool bpf_testmod_ops_is_valid_access(int off, int size, return true; } +/* Allow specific BPF helpers to be used in struct_ops programs */ +static const struct bpf_func_proto * +bpf_testmod_ops_get_func_proto(enum bpf_func_id func_id, + const struct bpf_prog *prog) +{ + /* Use base func proto which includes trace_printk and other basic helpers */ + return bpf_base_func_proto(func_id, prog); +} + static const struct bpf_verifier_ops bpf_testmod_verifier_ops = { .is_valid_access = bpf_testmod_ops_is_valid_access, + .get_func_proto = bpf_testmod_ops_get_func_proto, }; static int bpf_testmod_ops_init_member(const struct btf_type *t, diff --git a/src/features/struct_ops/struct_ops.bpf.c b/src/features/struct_ops/struct_ops.bpf.c index b97e962..7278f95 100644 --- a/src/features/struct_ops/struct_ops.bpf.c +++ b/src/features/struct_ops/struct_ops.bpf.c @@ -23,12 +23,11 @@ int BPF_PROG(bpf_testmod_test_2, int a, int b) } SEC("struct_ops/test_3") -void BPF_PROG(bpf_testmod_test_3, const char *buf, int len) +int BPF_PROG(bpf_testmod_test_3, const char *buf, int len) { bpf_printk("BPF test_3 called with buffer length %d\n", len); - if (len > 0) { - bpf_printk("First char: %c\n", buf[0]); - } + /* Note: Accessing buf pointer requires proper context setup in kernel module */ + return 0; } /* Define the struct_ops map */