[PATCH bpf-next v1 5/8] selftests/bpf: Fix order-of-include compile errors in lwt_reroute.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Tony Ambardar <tony.ambardar@xxxxxxxxx>

Fix redefinition errors seen compiling lwt_reroute.c for mips64el/musl-libc
by adjusting the order of includes in lwt_helpers.h. The ordering required
is:
<net/if.h>  -->  <arpa/inet.h> (from "test_progs.h")  -->  <linux/icmp.h>.

Because of the complexity and large number of includes, ordering appears to
be fragile however. Previously, with "test_progs.h" at the end of this
sequence, compiling with GCC 12.3 for mips64el/musl-libc yields errors:

In file included from .../include/arpa/inet.h:9,
                 from ./test_progs.h:18,
                 from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:11,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
.../include/netinet/in.h:23:8: error: redefinition of 'struct in6_addr'
   23 | struct in6_addr {
      |        ^~~~~~~~
In file included from .../include/linux/icmp.h:24,
                 from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:9:
.../include/linux/in6.h:33:8: note: originally defined here
   33 | struct in6_addr {
      |        ^~~~~~~~
.../include/netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6'
   34 | struct sockaddr_in6 {
      |        ^~~~~~~~~~~~
.../include/linux/in6.h:50:8: note: originally defined here
   50 | struct sockaddr_in6 {
      |        ^~~~~~~~~~~~
.../include/netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq'
   42 | struct ipv6_mreq {
      |        ^~~~~~~~~
.../include/linux/in6.h:60:8: note: originally defined here
   60 | struct ipv6_mreq {
      |        ^~~~~~~~~

Similarly, with "test_progs.h" at the beginning of this sequence, compiling
with GCC 12.3 for x86_64 using glibc would fail like this:

In file included from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:8,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
/usr/include/linux/if.h:83:9: error: redeclaration of enumerator ‘IFF_UP’
   83 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
/usr/include/net/if.h:44:5: note: previous definition of ‘IFF_UP’ with type ‘enum <anonymous>’
   44 |     IFF_UP = 0x1,               /* Interface is up.  */
      |     ^~~~~~
/usr/include/linux/if.h:84:9: error: redeclaration of enumerator ‘IFF_BROADCAST’
   84 |         IFF_BROADCAST                   = 1<<1,  /* __volatile__ */
      |         ^~~~~~~~~~~~~
/usr/include/net/if.h:46:5: note: previous definition of ‘IFF_BROADCAST’ with type ‘enum <anonymous>’
   46 |     IFF_BROADCAST = 0x2,        /* Broadcast address valid.  */
      |     ^~~~~~~~~~~~~

...

In file included from /usr/include/linux/icmp.h:23,
                 from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:10,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
/usr/include/linux/if.h:194:8: error: redefinition of ‘struct ifmap’
  194 | struct ifmap {
      |        ^~~~~
In file included from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:8,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
/usr/include/net/if.h:111:8: note: originally defined here
  111 | struct ifmap
      |        ^~~~~
In file included from /usr/include/linux/icmp.h:23,
                 from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:10,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
/usr/include/linux/if.h:232:8: error: redefinition of ‘struct ifreq’
  232 | struct ifreq {
      |        ^~~~~
In file included from tools/testing/selftests/bpf/prog_tests/lwt_helpers.h:8,
                 from tools/testing/selftests/bpf/prog_tests/lwt_reroute.c:52:
/usr/include/net/if.h:126:8: note: originally defined here
  126 | struct ifreq
      |        ^~~~~

Fixes: 43a7c3ef8a15 ("selftests/bpf: Add lwt_xmit tests for BPF_REDIRECT")
Signed-off-by: Tony Ambardar <tony.ambardar@xxxxxxxxx>
---
 tools/testing/selftests/bpf/prog_tests/lwt_helpers.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/lwt_helpers.h b/tools/testing/selftests/bpf/prog_tests/lwt_helpers.h
index fb1eb8c67361..8e5e28af03c5 100644
--- a/tools/testing/selftests/bpf/prog_tests/lwt_helpers.h
+++ b/tools/testing/selftests/bpf/prog_tests/lwt_helpers.h
@@ -6,10 +6,9 @@
 #include <time.h>
 #include <net/if.h>
 #include <linux/if_tun.h>
+#include "test_progs.h" /* between <net/if.h> and <linux/icmp.h> or errors */
 #include <linux/icmp.h>
 
-#include "test_progs.h"
-
 #define log_err(MSG, ...) \
 	fprintf(stderr, "(%s:%d: errno: %s) " MSG "\n", \
 		__FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)
-- 
2.34.1





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux