build: avoid header conflict for <linux/if.h> and <net/if.h> 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 <net/if.h> at the same time with "nm-platform.h", which is easy
to get wrong.
This commit is contained in:
Thomas Haller
2018-11-12 15:23:36 +01:00
parent 45e54840db
commit 37e47fbdab
16 changed files with 29 additions and 12 deletions

View File

@@ -22,6 +22,7 @@
#include "nm-device-infiniband.h" #include "nm-device-infiniband.h"
#include <linux/if.h>
#include <linux/if_infiniband.h> #include <linux/if_infiniband.h>
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"

View File

@@ -27,6 +27,7 @@
#include <linux/if.h> #include <linux/if.h>
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/if_tunnel.h> #include <linux/if_tunnel.h>
#include <linux/ip6_tunnel.h>
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-manager.h" #include "nm-manager.h"

View File

@@ -23,6 +23,7 @@
#include "nm-device-macvlan.h" #include "nm-device-macvlan.h"
#include <string.h> #include <string.h>
#include <linux/if_link.h>
#include "nm-device-private.h" #include "nm-device-private.h"
#include "settings/nm-settings.h" #include "settings/nm-settings.h"

View File

@@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <linux/if.h>
#include "nm-act-request.h" #include "nm-act-request.h"
#include "nm-device-private.h" #include "nm-device-private.h"

View File

@@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <net/if.h>
#include "nm-utils/nm-dedup-multi.h" #include "nm-utils/nm-dedup-multi.h"

View File

@@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <linux/if_addr.h>
#include "nm-setting-ip6-config.h" #include "nm-setting-ip6-config.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"

View File

@@ -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); NMPlatformIP4Address *addr = nmtst_platform_ip4_address (address, peer_address, plen);
G_STATIC_ASSERT (IFNAMSIZ == sizeof (addr->label)); G_STATIC_ASSERT (NMP_IFNAMSIZ == sizeof (addr->label));
g_assert (!label || strlen (label) < IFNAMSIZ); g_assert (!label || strlen (label) < NMP_IFNAMSIZ);
addr->ifindex = ifindex; addr->ifindex = ifindex;
addr->addr_source = source; addr->addr_source = source;

View File

@@ -26,6 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <netinet/icmp6.h> #include <netinet/icmp6.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <linux/if.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include "nm-utils.h" #include "nm-utils.h"

View File

@@ -29,6 +29,7 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/sockios.h> #include <linux/sockios.h>
#include <linux/mii.h> #include <linux/mii.h>
#include <linux/if.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <fcntl.h> #include <fcntl.h>

View File

@@ -31,6 +31,7 @@
#include <netdb.h> #include <netdb.h>
#include <string.h> #include <string.h>
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/if.h>
#include <linux/if_tun.h> #include <linux/if_tun.h>
#include <linux/if_tunnel.h> #include <linux/if_tunnel.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>

View File

@@ -21,12 +21,6 @@
#ifndef __NETWORKMANAGER_PLATFORM_H__ #ifndef __NETWORKMANAGER_PLATFORM_H__
#define __NETWORKMANAGER_PLATFORM_H__ #define __NETWORKMANAGER_PLATFORM_H__
#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_addr.h>
#include <linux/if_link.h>
#include <linux/ip6_tunnel.h>
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-core-types-internal.h" #include "nm-core-types-internal.h"
@@ -53,6 +47,12 @@
/*****************************************************************************/ /*****************************************************************************/
/* IFNAMSIZ is both defined in <linux/if.h> and <net/if.h>. 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; struct udev_device;
typedef gboolean (*NMPObjectPredicateFunc) (const NMPObject *obj, typedef gboolean (*NMPObjectPredicateFunc) (const NMPObject *obj,
@@ -208,7 +208,7 @@ typedef enum {
struct _NMPlatformLink { struct _NMPlatformLink {
__NMPlatformObject_COMMON; __NMPlatformObject_COMMON;
char name[IFNAMSIZ]; char name[NMP_IFNAMSIZ];
NMLinkType type; NMLinkType type;
/* rtnl_link_get_type(), IFLA_INFO_KIND. */ /* rtnl_link_get_type(), IFLA_INFO_KIND. */
@@ -355,7 +355,7 @@ struct _NMPlatformIP4Address {
* */ * */
in_addr_t peer_address; /* PTP peer address */ 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) ((const char *) NULL), -1, (path)
#define NMP_SYSCTL_PATHID_NETDIR_unsafe(dirfd, ifname, 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)), \ "net:/sys/class/net/%s/%s", (ifname), (path)), \
(dirfd), (path) (dirfd), (path)
#define NMP_SYSCTL_PATHID_NETDIR(dirfd, ifname, 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), \ "net:/sys/class/net/%s/%s", (ifname), path), \
(dirfd), (""path"") (dirfd), (""path"")

View File

@@ -24,6 +24,7 @@
#include <unistd.h> #include <unistd.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/if.h>
#include <libudev.h> #include <libudev.h>
#include "nm-utils.h" #include "nm-utils.h"

View File

@@ -21,6 +21,9 @@
#include <syslog.h> #include <syslog.h>
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <linux/if.h>
#include <linux/if_link.h>
#include <linux/ip6_tunnel.h>
#include "platform/nm-platform.h" #include "platform/nm-platform.h"
#include "platform/nmp-object.h" #include "platform/nmp-object.h"

View File

@@ -30,6 +30,7 @@
#include <net/ethernet.h> #include <net/ethernet.h>
#include <unistd.h> #include <unistd.h>
#include <linux/nl80211.h> #include <linux/nl80211.h>
#include <linux/if.h>
#include "platform/nm-netlink.h" #include "platform/nm-netlink.h"
#include "nm-wifi-utils-private.h" #include "nm-wifi-utils-private.h"

View File

@@ -21,6 +21,8 @@
#include "nm-wpan-utils.h" #include "nm-wpan-utils.h"
#include <linux/if.h>
#include "platform/linux/nl802154.h" #include "platform/linux/nl802154.h"
#include "platform/nm-netlink.h" #include "platform/nm-netlink.h"
#include "platform/nm-platform-utils.h" #include "platform/nm-platform-utils.h"

View File

@@ -22,6 +22,7 @@
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <linux/if_addr.h>
#include "nm-ip6-config.h" #include "nm-ip6-config.h"