From 37e47fbdabd6439c022a5fc3b72176aa6c4e569f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Nov 2018 15:23:36 +0100 Subject: [PATCH] build: avoid header conflict for and with "nm-platform.h" In the past, the headers "linux/if.h" and "net/if.h" were incompatible. That means, we can either include one or the other, but not both. This is fixed in the meantime, however the issue still exists when building against older kernel/glibc. That means, including one of these headers from a header file is problematic. In particular if it's a header like "nm-platform.h", which itself is dragged in by many other headers. Avoid that by not including these headers from "platform.h", but instead from the source files where needed (or possibly from less popular header files). Currently there is no problem. However, this allows an unknowing user to include at the same time with "nm-platform.h", which is easy to get wrong. --- src/devices/nm-device-infiniband.c | 1 + src/devices/nm-device-ip-tunnel.c | 1 + src/devices/nm-device-macvlan.c | 1 + src/devices/nm-device-wpan.c | 1 + src/dhcp/nm-dhcp-dhclient-utils.c | 1 + src/ndisc/nm-ndisc.h | 1 + src/nm-test-utils-core.h | 4 ++-- src/platform/nm-fake-platform.c | 1 + src/platform/nm-platform-utils.c | 1 + src/platform/nm-platform.c | 1 + src/platform/nm-platform.h | 20 ++++++++++---------- src/platform/nmp-object.c | 1 + src/platform/tests/test-common.h | 3 +++ src/platform/wifi/nm-wifi-utils-nl80211.c | 1 + src/platform/wpan/nm-wpan-utils.c | 2 ++ src/tests/test-ip6-config.c | 1 + 16 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index afb565558..01edf8074 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -22,6 +22,7 @@ #include "nm-device-infiniband.h" +#include #include #include "NetworkManagerUtils.h" diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 568403c62..1c7e6d51e 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "nm-device-private.h" #include "nm-manager.h" diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index ff386c82e..2b2121545 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -23,6 +23,7 @@ #include "nm-device-macvlan.h" #include +#include #include "nm-device-private.h" #include "settings/nm-settings.h" diff --git a/src/devices/nm-device-wpan.c b/src/devices/nm-device-wpan.c index 7aa70aa3c..c2fa7f4e8 100644 --- a/src/devices/nm-device-wpan.c +++ b/src/devices/nm-device-wpan.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "nm-act-request.h" #include "nm-device-private.h" diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index a2c3bfb65..b442e2ef7 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "nm-utils/nm-dedup-multi.h" diff --git a/src/ndisc/nm-ndisc.h b/src/ndisc/nm-ndisc.h index 73eef368e..6c0c02644 100644 --- a/src/ndisc/nm-ndisc.h +++ b/src/ndisc/nm-ndisc.h @@ -23,6 +23,7 @@ #include #include +#include #include "nm-setting-ip6-config.h" #include "NetworkManagerUtils.h" diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h index 5e89cb39f..dbfe71ada 100644 --- a/src/nm-test-utils-core.h +++ b/src/nm-test-utils-core.h @@ -88,8 +88,8 @@ nmtst_platform_ip4_address_full (const char *address, const char *peer_address, { NMPlatformIP4Address *addr = nmtst_platform_ip4_address (address, peer_address, plen); - G_STATIC_ASSERT (IFNAMSIZ == sizeof (addr->label)); - g_assert (!label || strlen (label) < IFNAMSIZ); + G_STATIC_ASSERT (NMP_IFNAMSIZ == sizeof (addr->label)); + g_assert (!label || strlen (label) < NMP_IFNAMSIZ); addr->ifindex = ifindex; addr->addr_source = source; diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 460720ca8..1814eeb96 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "nm-utils.h" diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 85d2b3247..01651f466 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 1667edaa2..494e2ddaf 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 00dd02e9a..2a18d8adf 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -21,12 +21,6 @@ #ifndef __NETWORKMANAGER_PLATFORM_H__ #define __NETWORKMANAGER_PLATFORM_H__ -#include -#include -#include -#include -#include - #include "nm-dbus-interface.h" #include "nm-core-types-internal.h" @@ -53,6 +47,12 @@ /*****************************************************************************/ +/* IFNAMSIZ is both defined in and . In the past, these + * headers conflicted, so we cannot simply include either of them in a header-file.*/ +#define NMP_IFNAMSIZ 16 + +/*****************************************************************************/ + struct udev_device; typedef gboolean (*NMPObjectPredicateFunc) (const NMPObject *obj, @@ -208,7 +208,7 @@ typedef enum { struct _NMPlatformLink { __NMPlatformObject_COMMON; - char name[IFNAMSIZ]; + char name[NMP_IFNAMSIZ]; NMLinkType type; /* rtnl_link_get_type(), IFLA_INFO_KIND. */ @@ -355,7 +355,7 @@ struct _NMPlatformIP4Address { * */ in_addr_t peer_address; /* PTP peer address */ - char label[IFNAMSIZ]; + char label[NMP_IFNAMSIZ]; }; /** @@ -1106,12 +1106,12 @@ const char *nm_platform_error_to_string (NMPlatformError error, ((const char *) NULL), -1, (path) #define NMP_SYSCTL_PATHID_NETDIR_unsafe(dirfd, ifname, path) \ - nm_sprintf_bufa (NM_STRLEN ("net:/sys/class/net//\0") + IFNAMSIZ + strlen (path), \ + nm_sprintf_bufa (NM_STRLEN ("net:/sys/class/net//\0") + NMP_IFNAMSIZ + strlen (path), \ "net:/sys/class/net/%s/%s", (ifname), (path)), \ (dirfd), (path) #define NMP_SYSCTL_PATHID_NETDIR(dirfd, ifname, path) \ - nm_sprintf_bufa (NM_STRLEN ("net:/sys/class/net//"path"/\0") + IFNAMSIZ, \ + nm_sprintf_bufa (NM_STRLEN ("net:/sys/class/net//"path"/\0") + NMP_IFNAMSIZ, \ "net:/sys/class/net/%s/%s", (ifname), path), \ (dirfd), (""path"") diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 66fc69358..5e1ebb56e 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "nm-utils.h" diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index 1baadfa11..7e81baeac 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include "platform/nm-platform.h" #include "platform/nmp-object.h" diff --git a/src/platform/wifi/nm-wifi-utils-nl80211.c b/src/platform/wifi/nm-wifi-utils-nl80211.c index ca00bf9d5..c8ff0b4bf 100644 --- a/src/platform/wifi/nm-wifi-utils-nl80211.c +++ b/src/platform/wifi/nm-wifi-utils-nl80211.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "platform/nm-netlink.h" #include "nm-wifi-utils-private.h" diff --git a/src/platform/wpan/nm-wpan-utils.c b/src/platform/wpan/nm-wpan-utils.c index 53bd677d2..478a8f0b0 100644 --- a/src/platform/wpan/nm-wpan-utils.c +++ b/src/platform/wpan/nm-wpan-utils.c @@ -21,6 +21,8 @@ #include "nm-wpan-utils.h" +#include + #include "platform/linux/nl802154.h" #include "platform/nm-netlink.h" #include "platform/nm-platform-utils.h" diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index 306994483..51807dea6 100644 --- a/src/tests/test-ip6-config.c +++ b/src/tests/test-ip6-config.c @@ -22,6 +22,7 @@ #include #include +#include #include "nm-ip6-config.h"