From aa7acb0ae3046d142a5469b50a9464bc9e6543ac 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. (cherry picked from commit 37e47fbdabd6439c022a5fc3b72176aa6c4e569f) --- 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 41fac157dd..5138b68460 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 568403c626..1c7e6d51e5 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 ff386c82ed..2b21215451 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 f910b0b899..05b507d585 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 8128b5c8df..be8d06d988 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 73eef368ed..6c0c026442 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 5e89cb39f1..dbfe71ada3 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 82f9e2fb29..ef69b391b7 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 216b15478e..cc43b27fbe 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 7ddcf41ae5..52ec4fec64 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 11495aff4f..f7a23616b2 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]; }; /** @@ -1105,12 +1105,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 fdc27440cc..f7fa6cb3cb 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 1baadfa116..7e81baeac0 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 b3bb2bb6e6..39e3f97181 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 0544539ac6..882c4eec21 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" diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index a03d89b07b..5b25506835 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"