diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76eed714b1..d183f79eb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -305,6 +305,10 @@ have `-I. -I./src/` in their build arguments. So to include a header like [`src/libnm-glib-aux/nm-random-utils.h`](src/libnm-glib-aux/nm-random-utils.h) you'd do `#include "libnm-glib-aux/nm-random-utils.h"`. +Note that there are exceptions. For example, `src/libnm-std-aux/nm-linux-compat.h`](src/libnm-std-aux/nm-linux-compat.h) +may need to be included before system headers as it is supposed to include headers +from `src/linux-headers`](src/linux-headers). + See an example [here](src/core/nm-manager.c#L1). ### GObject Properties diff --git a/Makefile.am b/Makefile.am index db958db3da..32e88ee480 100644 --- a/Makefile.am +++ b/Makefile.am @@ -371,6 +371,7 @@ src_libnm_std_aux_libnm_std_aux_la_SOURCES = \ src/libnm-std-aux/c-list-util.h \ src/libnm-std-aux/nm-dbus-compat.h \ src/libnm-std-aux/nm-default-std.h \ + src/libnm-std-aux/nm-linux-compat.h \ src/libnm-std-aux/nm-networkmanager-compilation.h \ src/libnm-std-aux/nm-std-aux.h \ src/libnm-std-aux/nm-std-utils.c \ diff --git a/src/libnm-platform/nm-platform-utils.c b/src/libnm-platform/nm-platform-utils.c index 7a0f48ef70..f052273635 100644 --- a/src/libnm-platform/nm-platform-utils.c +++ b/src/libnm-platform/nm-platform-utils.c @@ -7,9 +7,7 @@ #include "nm-platform-utils.h" -/* includes . We thus need to include - * our copy first and violate the common order of includes. */ -#include "linux-headers/ethtool.h" +#include "libnm-std-aux/nm-linux-compat.h" #include #include diff --git a/src/libnm-platform/wpan/nm-wpan-utils.c b/src/libnm-platform/wpan/nm-wpan-utils.c index 5c2917b4dc..082cc3e7b7 100644 --- a/src/libnm-platform/wpan/nm-wpan-utils.c +++ b/src/libnm-platform/wpan/nm-wpan-utils.c @@ -7,11 +7,12 @@ #include "nm-wpan-utils.h" +#include "libnm-std-aux/nm-linux-compat.h" + #include #include "libnm-log-core/nm-logging.h" #include "libnm-platform/nm-netlink.h" -#include "linux-headers/nl802154.h" #include "libnm-platform/nm-platform-utils.h" #define _NMLOG_PREFIX_NAME "wpan-nl802154" diff --git a/src/libnm-std-aux/nm-linux-compat.h b/src/libnm-std-aux/nm-linux-compat.h new file mode 100644 index 0000000000..7ca7ec781c --- /dev/null +++ b/src/libnm-std-aux/nm-linux-compat.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#ifndef __NM_LINUX_COMPAT_H__ +#define __NM_LINUX_COMPAT_H__ + +/* We have copies of linux UAPI headers in `src/linux-headers` which + * should be preferred over the headers on the system. However, these + * newer headers might be incompatible with the installed UAPI headers. + * + * This nm-linux-compat.h header tries to solve that and apply the necessary + * workarounds. + * + * Unlike most NetworkManager headers, this header needs to be included + * *before* most system headers. */ + +#include + +#ifndef __KERNEL_DIV_ROUND_UP +#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) -1) / (d)) +#endif + +#include "linux-headers/ethtool.h" +#include "linux-headers/nl802154.h" + +#endif /* __NM_LINUX_COMPAT_H__ */