On 23/06/2022 18:56, Andrii Nakryiko wrote: > On Thu, Jun 23, 2022 at 4:10 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote: >> >> when CONFIG_NF_CONNTRACK=m, vmlinux BTF does not contain >> BPF_F_CURRENT_NETNS or bpf_ct_opts; they are both found in nf_conntrack >> BTF; for example: >> >> bpftool btf dump file /sys/kernel/btf/nf_conntrack|grep ct_opts >> [114754] STRUCT 'bpf_ct_opts' size=12 vlen=5 >> >> This causes compilation errors as follows: >> >> CLNG-BPF [test_maps] xdp_synproxy_kern.o >> progs/xdp_synproxy_kern.c:83:14: error: declaration of 'struct bpf_ct_opts' will not be visible outside of this function [-Werror,-Wvisibility] >> struct bpf_ct_opts *opts, >> ^ >> progs/xdp_synproxy_kern.c:89:14: error: declaration of 'struct bpf_ct_opts' will not be visible outside of this function [-Werror,-Wvisibility] >> struct bpf_ct_opts *opts, >> ^ >> progs/xdp_synproxy_kern.c:397:15: error: use of undeclared identifier 'BPF_F_CURRENT_NETNS'; did you mean 'BPF_F_CURRENT_CPU'? >> .netns_id = BPF_F_CURRENT_NETNS, >> ^~~~~~~~~~~~~~~~~~~ >> BPF_F_CURRENT_CPU >> tools/testing/selftests/bpf/tools/include/vmlinux.h:43115:2: note: 'BPF_F_CURRENT_CPU' declared here >> BPF_F_CURRENT_CPU = 4294967295, >> >> While tools/testing/selftests/bpf/config does specify >> CONFIG_NF_CONNTRACK=y, it would be good to use this case to show >> how we can generate a module header file via split BTF. >> >> In the selftests Makefile, we define NF_CONNTRACK BTF via VMLINUX_BTF >> (thus gaining the path determination logic it uses). If the nf_conntrack >> BTF file exists (which means it is built as a module), we run >> "bpftool btf dump" to generate module BTF, and if not we simply copy >> vmlinux.h to nf_conntrack.h; this allows us to avoid having to pass >> a #define or deal with CONFIG variables in the program. >> >> With these changes the test builds and passes: >> >> Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED >> >> Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx> >> --- > > Why not just define expected types locally (doesn't have to be a full > definition)? Adding extra rule and generating header for each > potential module seems like a huge overkill. > True. I also forgot that if we use vmlinux in the kernel tree as the source for vmlinux BTF, this approach won't work since it assumes it will find nf_conntrack in the same directory. I'll figure out a simpler approach. Thanks for taking a look! Alan