From b2155be6ac1b756eafb7ec9a86407893e41a9683 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') (cherry picked from commit 2a070434896d0e2df41b565d593809e7b3b77bfa) --- 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 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/libnm-std-aux/nm-linux-compat.h diff --git a/Makefile.am b/Makefile.am index 2cb33dd9ce..7cc50332d5 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 95afae0d0f..ce847451b9 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__ */