samples/bpf: Fix sockex3 error: Missing BPF prog type
authorRong Tao <rongtao@cestc.cn>
Sat, 5 Nov 2022 06:48:00 +0000 (14:48 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 8 Nov 2022 01:13:35 +0000 (17:13 -0800)
commite5659e4e19e49f1eac58bb07ce8bc2d78a89fe65
tree48fd4f7279c5948d2f489a45e60d4a73db0f7f5e
parente8f50c4f0c14214b6430b8b3493654a286681a2b
samples/bpf: Fix sockex3 error: Missing BPF prog type

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.

Instead of sockex3_user.c parsing section names to get the BPF program fd.
We use the program array map to assign a static index to each BPF program
(get inspired by selftests/bpf progs/test_prog_array_init.c).
Therefore, use SEC("socket") as section name instead of SEC("socket/xxx"),
so that the BPF program is parsed to SOCKET_FILTER type. The "missing BPF
prog type" problem is solved.

How to reproduce 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@cestc.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/tencent_EBA3C18864069E42175946973C2ACBAF5408@qq.com
samples/bpf/sockex3_kern.c
samples/bpf/sockex3_user.c