From 2a070434896d0e2df41b565d593809e7b3b77bfa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Sep 2021 15:18:10 +0200 Subject: [PATCH] std-aux: add "libnm-std-aux/nm-linux-compat.h" header to avoid build errors We have a copy of a few linux user space headers in `src/linux-headers`. The idea is that we want to use recent kernel API, and not depend on the kernel UAPI headers installed on the build system (and not need to workaround that). However, we may not be able to simply compile them, because they too have dependencies. For example, ../src/linux-headers/ethtool.h:1389:2: error: implicit declaration of function '__KERNEL_DIV_ROUND_UP' [-Werror=implicit-function-declaration] __u32 queue_mask[__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32)]; ^ As workaround, don't include headers from "linux-headers" directly, but only include the new "libnm-std-aux/nm-linux-compat.h" adapter header, which tries to solve these incompatibilities. Fixes: 34d48d2596f7 ('platform: clear all BASE types when setting advertised modes for ethernet autoneg') --- CONTRIBUTING.md | 4 ++++ Makefile.am | 1 + src/libnm-platform/nm-platform-utils.c | 4 +--- src/libnm-platform/wpan/nm-wpan-utils.c | 3 ++- src/libnm-std-aux/nm-linux-compat.h | 25 +++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/libnm-std-aux/nm-linux-compat.h 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__ */