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: 34d48d2596 ('platform: clear all BASE types when setting advertised modes for ethernet autoneg')
This commit is contained in:
Thomas Haller 2021-09-08 15:18:10 +02:00
parent 426491a500
commit 2a07043489
No known key found for this signature in database
GPG Key ID: 29C2366E4DFC5728
5 changed files with 33 additions and 4 deletions

View File

@ -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

View File

@ -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 \

View File

@ -7,9 +7,7 @@
#include "nm-platform-utils.h"
/* <linux/mii.h> includes <linux/ethtool.h>. 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 <unistd.h>
#include <sys/ioctl.h>

View File

@ -7,11 +7,12 @@
#include "nm-wpan-utils.h"
#include "libnm-std-aux/nm-linux-compat.h"
#include <linux/if.h>
#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"

View File

@ -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 <linux/const.h>
#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__ */