]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make sure net/if.h is included before any linux/ header
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 9 Apr 2024 10:44:46 +0000 (12:44 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 9 Apr 2024 19:19:15 +0000 (21:19 +0200)
The linux/ headers include linux/libc-compat.h that makes sure the
linux/ headers won't redeclare symbols already declared by net/if.h, but
glibc's net/if.h doesn't do that, so if the include order is reversed
we'll end up with a bunch of errors about redeclared stuff:

[3/519] Compiling C object test-network-tables.p/src_network_test-network-tables.c.o
FAILED: test-network-tables.p/src_network_test-network-tables.c.o
cc -Itest-network-tables.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -Isrc/libsystemd-network -I../src/libsystemd-network -Isrc/network -I../src/network -I../src/network/netdev -I../src/network/tc -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Wno-nonnull-compare -Warray-bounds -Warray-bounds=2 -Wdate-time -Wendif-labels -Werror=format=2 -Werror=format-signedness -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=strict-flex-arrays -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wzero-length-bounds -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong -fstrict-flex-arrays --param=ssp-buffer-size=4 -Wno-unused-result -Werror=shadow -fno-strict-aliasing -fstrict-flex-arrays=1 -fvisibility=hidden -fno-omit-frame-pointer -include config.h -pthread -DTEST_CODE=1 -MD -MQ test-network-tables.p/src_network_test-network-tables.c.o -MF test-network-tables.p/src_network_test-network-tables.c.o.d -o test-network-tables.p/src_network_test-network-tables.c.o -c ../src/network/test-network-tables.c
In file included from ../src/basic/linux/if_bonding.h:47,
                 from ../src/network/netdev/bond.h:5,
                 from ../src/network/test-network-tables.c:3:
../src/basic/linux/if.h:111:41: error: redeclaration of enumerator ‘IFF_UP’
  111 | #define IFF_UP                          IFF_UP
      |                                         ^~~~~~
../src/basic/linux/if.h:84:9: note: previous definition of ‘IFF_UP’ with type ‘enum net_device_flags’
   84 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
../src/basic/linux/if.h:112:41: error: redeclaration of enumerator ‘IFF_BROADCAST’
  112 | #define IFF_BROADCAST                   IFF_BROADCAST
      |                                         ^~~~~~~~~~~~~
...

This also drops remaining workarounds from the last time this issue was
brought up (6f270e6bd8) since they shouldn't be needed anymore if the
order of the includes is the "correct" one. I also added a comment to
each affected include when this is inevitably encountered again in the
future.

Resolves: #32160

36 files changed:
src/basic/socket-util.c
src/core/bpf-firewall.c
src/libsystemd-network/dhcp-network.c
src/libsystemd-network/icmp6-util.c
src/libsystemd-network/test-acd.c
src/libsystemd-network/test-ipv4ll-manual.c
src/libsystemd/sd-netlink/test-netlink.c
src/libudev/libudev-device.c
src/network/netdev/bridge.c
src/network/netdev/fou-tunnel.c
src/network/netdev/geneve.c
src/network/netdev/ipvlan.c
src/network/netdev/macvlan.c
src/network/netdev/netdev.c
src/network/netdev/tuntap.c
src/network/netdev/veth.c
src/network/netdev/vlan.c
src/network/netdev/vrf.c
src/network/netdev/vxlan.c
src/network/netdev/wireguard.c
src/network/networkctl.c
src/network/networkd-address-label.c
src/network/networkd-bridge-mdb.c
src/network/networkd-can.c
src/network/networkd-link.c
src/network/networkd-network.c
src/network/networkd-nexthop.c
src/network/networkd-routing-policy-rule.c
src/network/test-network-tables.c
src/nspawn/nspawn-network.c
src/shared/firewall-util-iptables.c
src/shared/socket-netlink.c
src/test/test-arphrd-util.c
src/test/test-local-addresses.c
src/test/test-netlink-manual.c
src/udev/udev-builtin-net_id.c

index 537f1e8c64cb00101d7908181aef426b1f5cfae7..e66bc426a4daf9f445e3e19b52f99cdecde75340 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <limits.h>
-#include <net/if.h>
 #include <netdb.h>
 #include <netinet/ip.h>
 #include <poll.h>
index 3bac231c97502424246253b933c1e75f6f3e67cd..185ed7d07084957bd9a8d4fa949f2895958e0788 100644 (file)
@@ -1,12 +1,13 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/bpf_insn.h>
 #include <net/ethernet.h>
-#include <net/if.h>
 #include <netinet/ip.h>
 #include <netinet/ip6.h>
 #include <stddef.h>
index 1f4ad095d5dedc147355daaf6a85747276ee4d27..2e73983d6bc474ea6a9c3b64301b6edd0af11f33 100644 (file)
@@ -3,15 +3,16 @@
   Copyright © 2013 Intel Corporation. All rights reserved.
 ***/
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <errno.h>
+#include <linux/filter.h>
+#include <linux/if_infiniband.h>
+#include <linux/if_packet.h>
 #include <net/ethernet.h>
-#include <net/if.h>
 #include <net/if_arp.h>
 #include <stdio.h>
 #include <string.h>
-#include <linux/filter.h>
-#include <linux/if_infiniband.h>
-#include <linux/if_packet.h>
 
 #include "dhcp-network.h"
 #include "dhcp-protocol.h"
index 070e94add1b638ddd8025cf395e89840bef61658..d4b7ae58558b5b545984c9fa9582733cca7eefc8 100644 (file)
@@ -3,7 +3,10 @@
   Copyright © 2014 Intel Corporation. All rights reserved.
 ***/
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <errno.h>
+#include <linux/if_packet.h>
 #include <netinet/icmp6.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
@@ -11,8 +14,6 @@
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <net/if.h>
-#include <linux/if_packet.h>
 
 #include "fd-util.h"
 #include "icmp6-util.h"
index 4b5ad70cf15302d7f54f17d0bc116d429779362b..6ed7260a72bec8cd0496379e3b3a5466aa6f0e4a 100644 (file)
@@ -1,11 +1,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <errno.h>
+#include <linux/veth.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <linux/veth.h>
-#include <net/if.h>
 
 #include "sd-event.h"
 #include "sd-ipv4acd.h"
index 5dc6b1034761d52f4bb0ee40238baf344e8b2eca..b4e6d2428fe03e3badef49967840516c6995811a 100644 (file)
@@ -1,10 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <errno.h>
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
+#include <errno.h>
+#include <linux/veth.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <linux/veth.h>
 
 #include "sd-event.h"
 #include "sd-ipv4ll.h"
index fb3150f1310ef4c22100e29e896e735248681db8..cf19c48213965369be92365adf6261617dd255cf 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/ether.h>
 #include <netinet/in.h>
index 7b9f54c976bf6caf4b73477c48e912f176049c58..50e2459a06365df607e7dee8bad504f92142a8e6 100644 (file)
@@ -1,11 +1,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/sockios.h>
-#include <net/if.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
index 3e394edadfd331e8e9a75e8db4cdd74eada2da9e..d426c0c5019f03e4118cadc05feb8e1bc4e2b518 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
 #include <linux/if_arp.h>
 #include <linux/if_bridge.h>
+#include <netinet/in.h>
 
 #include "bridge.h"
 #include "netlink-util.h"
index 3bf41a8bf2979f988d922f03e8150b81a2659317..bddee5e98cde0bb560bf0438a016ba3829817165 100644 (file)
@@ -1,7 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/fou.h>
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
+#include <linux/fou.h>
 #include <netinet/in.h>
 #include <linux/ip.h>
 
index bc655ec7ffd9960a38ad8905421a385aaaefb8fb..22c2b00e1b700634719b02ba5bf2da8c8885b630 100644 (file)
@@ -1,8 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
 #include <linux/if_arp.h>
+#include <netinet/in.h>
 
 #include "alloc-util.h"
 #include "conf-parser.h"
index 05d5d010f65c7b74db53359d60a31c8ccdd07422..51ae64341db2c9c1d984b03143ad6fb0a9079873 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/if_arp.h>
index 85011e11de40a3da85a8c3c972b44042e84ef237..21933d3970a13e24170a22e4e2eea1d68f5db756 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/if_arp.h>
index 894cec44cbb574923d9d4a3cf64041ec4604b280..229520dfb2b667bd0a8710a74ce1e90bed9c10e1 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/if_arp.h>
index 97b4b928e768af45380a50d3f0660b73c56e40ec..f5be31ed9438e09ca06028609cd8a0cf72136029 100644 (file)
@@ -1,13 +1,14 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <net/if.h>
+#include <linux/if_tun.h>
 #include <netinet/if_ether.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <linux/if_tun.h>
 
 #include "alloc-util.h"
 #include "daemon-util.h"
index e0f5b4ebb1a7c61a2046a981c4cbdb5d42a5ee07..78555286d1a4cc86a4765e8908b5ef8c080caeb6 100644 (file)
@@ -1,10 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <errno.h>
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
+#include <errno.h>
 #include <linux/if_arp.h>
 #include <linux/veth.h>
+#include <netinet/in.h>
 
 #include "netlink-util.h"
 #include "veth.h"
index adbba14a6e84555db343f7831e6ebc02c79c922c..60e49a5b8a9aec2ee03a345496f8f5080ccd6dfc 100644 (file)
@@ -1,7 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <errno.h>
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
+#include <errno.h>
 #include <linux/if_arp.h>
 #include <linux/if_vlan.h>
 
index b75ec2bcc686263956698155687ca5f01448265c..24079a7203c89063a9c2c4bd3a501d2b57c40873 100644 (file)
@@ -1,8 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
 #include <linux/if_arp.h>
+#include <netinet/in.h>
 
 #include "vrf.h"
 
index f333abc6c04f6aba61f052af2cb6f49b90a97a77..37f65967a6bd5b352b8065939c10364feecd82bc 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/if_arp.h>
index 95c9c8c330093d5e20f666b49d9184c9f937b5b8..fed1be8d1104613d37408b18e8f186b0df44f0b4 100644 (file)
@@ -3,11 +3,12 @@
   Copyright © 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
 ***/
 
-#include <sys/ioctl.h>
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
-#include <netinet/in.h>
 #include <linux/if_arp.h>
 #include <linux/ipv6_route.h>
+#include <netinet/in.h>
+#include <sys/ioctl.h>
 
 #include "sd-resolve.h"
 
index fab9ff465bae3d655548bb91d7e23ff4b9457856..56fa373b1d2418f86aa9cf655e384cacc31a2e76 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <getopt.h>
 #include <linux/if_addrlabel.h>
-#include <net/if.h>
 #include <stdbool.h>
 #include <sys/stat.h>
 #include <sys/types.h>
index 745b959f7748cc592fffa694474f80b2d493dc04..e91ce3d2fa46f1c8e9b0778793e197a2c08b0d2c 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/if_addrlabel.h>
 
index bd1a9745dce63fa73e137ef38a7c9d1df6cabb22..7ff4a188467185c13147d2aa3edcfc073b3feb24 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/if_bridge.h>
 
index b8a1871a35016b1bbbc1518a021b84c61b8ff972..a5b003ad228d842fa3712db324dd15b40c036324 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/can/netlink.h>
 
index 192e9df979b66e35dde903207a990ee9bcc62b9f..bac44a3858181e2221e20a3f6fe786a4a79b0d7e 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/if.h>
index 880856f596d91a261a1dada57ae5744ae5e39079..d42ded61608b2150893effa04bbe029db3c7a491 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/netdevice.h>
index b07feede2ba5140ee684487284c7a7f037e6793a..1b44ef320c9dfaff2d08a0df3d51b67bcce37091 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright © 2019 VMware, Inc.
  */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/nexthop.h>
 
index bb757eed71fbfbc1366d84a53c105384613509e8..886b4da8e0a774207d150254982177a6b17e8fe6 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/fib_rules.h>
 
index 564ca096099ada89acfa95ac4f2f17555e88b929..96f5b4d705aedb460434f4bb9ccf35523981cf95 100644 (file)
@@ -1,5 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
+#include <linux/if.h>
+
 #include "bond.h"
 #include "dhcp6-internal.h"
 #include "dhcp6-protocol.h"
index e89f087aea68347efd9f2406dcbf7d3ce5f3a053..1e804a2be3c8f63d40e6d84e568932aedcdc1a32 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/if.h>
 #include <linux/nl80211.h>
index b70b74074bf203df04b54eb0ec6e8b5d03dc9682..044d2d074474c91891e4458e075c19477908a4aa 100644 (file)
@@ -1,19 +1,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-/* Temporary work-around for broken glibc vs. linux kernel header definitions
- * This is already fixed upstream, remove this when distributions have updated.
- */
-#define _NET_IF_H 1
-
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <endian.h>
 #include <errno.h>
 #include <stddef.h>
 #include <string.h>
-#include <net/if.h>
-#ifndef IFNAMSIZ
-#define IFNAMSIZ 16
-#endif
 #include <linux/if.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include <linux/netfilter/nf_nat.h>
index 6865b045b5e9172837d207bea420f8f6668f7d1f..a126d5d73b1eac40a1321ebbb786223f07570f4f 100644 (file)
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <linux/net_namespace.h>
-#include <net/if.h>
 #include <string.h>
 
 #include "alloc-util.h"
index d81feff01508aad2260ce03aa6074de2618185f5..15b79977504311ea30f47f394613d2e3f7a12cf3 100644 (file)
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <linux/if_arp.h>
 
 #include "arphrd-util.h"
index e3d6c08d145f7d4379b0a1f96c475385889cb472..f418f3712d115b6f9ebf1d96e73c1abf71c88eec 100644 (file)
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <linux/if.h>
 #include <stdio.h>
 
index 73943bf428f847e8900a5012a9c484204900ab12..f03fcffc6246101b40b0748655d6271029bafe7e 100644 (file)
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <linux/if_tunnel.h>
 #include <linux/ip.h>
index 0d87a35288a80f90815379c6e2879756e90350b1..ac4541edd7177572f4d11573c69cedeb49edc363 100644 (file)
  * When the code here is changed, man/systemd.net-naming-scheme.xml must be updated too.
  */
 
+/* Make sure the net/if.h header is included before any linux/ one */
+#include <net/if.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <net/if.h>
 #include <stdarg.h>
 #include <unistd.h>
 #include <linux/if.h>