[PATCH bpf-next] samples/bpf: Fix sockex3: missing BPF prog type

From: Rong Tao
Date: Sat Oct 29 2022 - 03:53:30 EST


From: Rong Tao <rongtao@xxxxxxxx>

since commit 450b167fb9be("libbpf: clean up SEC() handling"),
sec_def_matches() does not recognize "socket/xxx" as "socket", therefore,
the BPF program type is not recognized, set "socket/xxx" to SOCKET_FILTER
solves this error.

$ cd samples/bpf
$ sudo ./sockex3
libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3'
libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22
libbpf: failed to load object './sockex3_kern.o'
ERROR: loading BPF object file failed

Signed-off-by: Rong Tao <rongtao@xxxxxxxx>
---
samples/bpf/sockex3_user.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index cd6fa79df900..dc79c17ad195 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -39,6 +39,9 @@ int main(int argc, char **argv)
return 0;
}

+ bpf_object__for_each_program(prog, obj)
+ bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER);
+
/* load BPF program */
if (bpf_object__load(obj)) {
fprintf(stderr, "ERROR: loading BPF object file failed\n");
--
2.31.1