BPF List
 help / color / mirror / Atom feed
* lsm_cgroup.c selftest fails to compile when CONFIG_PACKET!=y
@ 2024-01-18 11:58 Shung-Hsi Yu
  2024-01-18 15:58 ` Eduard Zingerman
  0 siblings, 1 reply; 11+ messages in thread
From: Shung-Hsi Yu @ 2024-01-18 11:58 UTC (permalink / raw)
  To: bpf
  Cc: linux-kselftest, Andrii Nakryiko, Mykola Lysenko, Yonghong Song,
	Jiri Olsa, Eduard Zingerman

Hi,

Compilation of lsm_cgroup.c will fail if the vmlinux.h comes from a
kernel that does _not_ have CONFIG_PACKET=y. The reason is that the
definition of struct sockaddr_ll is not present in vmlinux.h and the
compiler will complain that is has an incomplete type.

    CLNG-BPF [test_maps] lsm_cgroup.bpf.o
  progs/lsm_cgroup.c:105:21: error: variable has incomplete type 'struct sockaddr_ll'
    105 |         struct sockaddr_ll sa = {};
        |                            ^
  progs/lsm_cgroup.c:105:9: note: forward declaration of 'struct sockaddr_ll'
    105 |         struct sockaddr_ll sa = {};
        |                ^
  1 error generated.

While including linux/if_packet.h somehow made the compilation works for
me, IIUC this isn't a proper solution because vmlinux.h and kernel
headers should not be used at the same time (and would lead to
redefinition error when the kernel is built with CONFIG_PACKET=y, e.g.
on BPF CI).

What would be the suggested way to work around this?

Thanks,
Shung-Hsi

---
 tools/testing/selftests/bpf/progs/lsm_cgroup.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/progs/lsm_cgroup.c b/tools/testing/selftests/bpf/progs/lsm_cgroup.c
index 02c11d16b692..5394ec7ae1d8 100644
--- a/tools/testing/selftests/bpf/progs/lsm_cgroup.c
+++ b/tools/testing/selftests/bpf/progs/lsm_cgroup.c
@@ -2,6 +2,7 @@
 
 #include "vmlinux.h"
 #include "bpf_tracing_net.h"
+#include <linux/if_packet.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-01-19 23:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-18 11:58 lsm_cgroup.c selftest fails to compile when CONFIG_PACKET!=y Shung-Hsi Yu
2024-01-18 15:58 ` Eduard Zingerman
2024-01-18 16:05   ` Eduard Zingerman
2024-01-18 20:57     ` Yonghong Song
2024-01-19  8:04   ` Shung-Hsi Yu
2024-01-19 12:23     ` Eduard Zingerman
2024-01-19 15:00       ` Vincent Li
2024-01-19 22:26         ` Alexei Starovoitov
2024-01-19 23:12           ` Vincent Li
2024-01-19 23:35             ` Andrii Nakryiko
2024-01-19 23:54               ` Vincent Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox