Commit graph

1791 commits

Author SHA1 Message Date
Thomas Haller
a67c312d5d
wireguard: fix configuring larger number of allowed-ips on WireGuard link
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/640

Fixes: a5c894c35f ('platform: create wireguard netdev interface')
2021-01-27 11:33:14 +01:00
Thomas Haller
9901aeef2c
platform: move "nm-platform-utils.[hc]" to "shared/nm-platform" library
By now it has no further dependencies on libnm-core or NetworkManager core.
Make it part of "shared/nm-platform" library.
2021-01-15 11:32:53 +01:00
Thomas Haller
c0bc296a51
platform: use NMOptionBool instead of NMTernary
NMTernary is a dependency for libnm-core. Avoid it.
2021-01-15 11:32:49 +01:00
Thomas Haller
874bd8994e
libnm,shared: move nm-ethtool helper to "libnm-base"
We want to use this by "shared/nm-platform", which should have
no dependency on "libnm-core".

Move "libnm-core/nm-ethtool-utils.h" to "libnm/nm-ethtool-utils.h" so
that it is only used by libnm. This file contains the defines for
the option names.

Also, symlink "libnm/nm-ethtool-utils.h" as "shared/nm-base/nm-ethtool-utils-base.h".
We want to use the same defines also internally. Since they are both
public API (must be in libnm) and should be in "shared/nm-base", this
is the way.
2021-01-15 11:32:41 +01:00
Thomas Haller
19242f56d7
libnm: split ethtool option names to a new header "libnm-core/nm-ethtool-utils.h"
We want to use these defines for option names also in "shared/nm-base"
(and in turn in "shared/nm-platform), which cannot include "libnm-core".

However, they are also public API of libnm.

To get this done, in a first step, move these defines to a new header
"libnm-core/nm-ethtool-utils.h".

Since now the name "nm-ethtool-utils.h" is taken, also rename
nm-libnm-core-intern files.
2021-01-15 11:32:39 +01:00
Thomas Haller
9a5a95e0fa
platform: remove unnecessary includes from "nm-platform-utils.c" 2021-01-15 11:32:38 +01:00
Thomas Haller
90881953ed
platform: move nm_platform_link_duplex_type_to_string() to "nm-platform-utils.c"
There should be a clear hierarchie of dependency. That is,
"nm-platform.h" may use "nm-platform-utils.h", but not the
other way around.

Move nm_platform_link_duplex_type_to_string().
2021-01-15 11:32:36 +01:00
Thomas Haller
84d67d3a4f
shared: add duplicate for NM_UTILS_HWADDR_LEN_MAX to "nm-base/nm-base.h"
We will need this in "shared/nm-platform", but we don't want
to include "libnm-core/nm-utils.h" for that.
2021-01-15 11:32:35 +01:00
Thomas Haller
126681a965
platform: move types from "nm-platform-utils.h" to nmp-base.h"
Thereby, also no longer include "nm-platform.h" and "nm-setting-wired.h"
in "nm-platform-utils.h".
2021-01-15 11:32:34 +01:00
Thomas Haller
2bb5c8b13b
platform: add duplicate of NMSettingWiredWakeOnLan to nm-base for platform
Currently src/platform depends on libnm-core. libnm-core is large
optimally we have a better separation between our code. That means
libnm-core does not depend on platform and vice versa.

However, nm-platform re-uses some enums from libnm-core for internal code.
To avoid that dependency, add _NMSettingWiredWakeOnLan as a duplicate to
nm-base/nm-base.h. nm-base can both be used by libnm-core, nm-platform
and src/platform.

The only problem is that NMSettingWiredWakeOnLan is also part of public
API of libnm. It means, we must duplicate the enum. But with several
static assertions in unit tests I think that is not a problem to do.
2021-01-15 11:32:33 +01:00
Thomas Haller
e5d2a05ad5
libnm: add "shared/nm-base/nm-base.h"
Our dependencies are complicated.

Currently "src/platform" uses parts of libnm-core and is relatively
strongly entangled with core. It would be nice to have that part
clearly independent from "src" and from "libnm-core".

Also, "src/platform/nm-platform-utils.h" uses NMEthtoolID enum, which
previously was defined in "libnm-core/nm-libnm-core-intern/nm-ethtool-utils.h".

Move that to a new place "shared/nm-base/nm-base.h".

Note that we have "libnm-core/nm-libnm-core-intern", which is
libnm/core related code which uses and is used by libnm-core.
There is a need for a library which is used by libnm-core, but
does not depend on libnm-core itself. Here comes "shared/nm-base".

Yes, many libraries. But the goal is to entangle the dependencies
and have a clear hierarchy of includes. And to have "shared/nm-platform"
independent of libnm-core.
2021-01-15 11:32:32 +01:00
Thomas Haller
31dca65e04
shared,platform: move "nmp-netns.[hc]" to shared/nm-platform 2021-01-15 11:32:31 +01:00
Thomas Haller
186f2da2fc
shared,platform: add "shared/nm-platform" library
NetworkManager core is huge. We should try to split out
parts that are independent.

Platform code is already mostly independent. But due to having it
under "src/", there is no strict separation/layering which determines
the parts that can work independently. So, while the code is mostly
independent (in practice), that is not obvious from looking at the
source tree. It thus still contributes to cognitive load.

Add a shared library "shared/nm-platform", which should have no
dependencies on libnm-core or NetworkManager core.

In a first step, move the netlink code there. More should follow.
2021-01-15 11:32:30 +01:00
Thomas Haller
6aa6da2b08
shared: add _nm_utils_hwaddr_aton_exact()
This is the same as libnm's nm_utils_hwaddr_aton(), which however
is public API.

We want to use this function also without libnm(-core). Hence add
the helper to "shared/nm-glib-aux".
2021-01-15 11:32:28 +01:00
Thomas Haller
cd754680a6
src/tests: avoid "-Wmaybe-uninitialized" warning in nmtstp_acd_defender_new()
With gcc-10.2.1-9.fc33.s390x we get a (false positive) warning:

    src/platform/tests/test-common.c: In function nmtstp_acd_defender_new:
    src/platform/tests/test-common.c:2688:15: error: probe may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2688 |     *defender = (NMTstpAcdDefender){
          |               ^
    src/platform/tests/test-common.c:2656:56: note: probe was declared here
     2656 |     NAcdProbe *                                        probe;
          |                                                        ^
2021-01-13 13:23:12 +01:00
Thomas Haller
fc6475bbf7
platform: avoid "-Wmaybe-uninitialized" warning in ip_route_add()
When building without "more-asserts" and LTO enabled, we can get
a warning about uninitalized "obj" variable:

    src/platform/nm-linux-platform.c: In function 'ip_route_add':
    src/platform/nm-platform.c:4761:24: warning: 'MEM[(struct NMPlatformIPRoute *)&obj + 24B].rt_source' may be used uninitialized in this function [-Wmaybe-uninitialized]
     4761 |     route->rt_source = nmp_utils_ip_config_source_round_trip_rtprot(route->rt_source);
          |                        ^
    src/platform/nm-platform.h:2139:25: warning: 'BIT_FIELD_REF <MEM[(const struct NMPlatformIPRoute *)&obj + 24B], 8, 72>' may be used uninitialized in this function [-Wmaybe-uninitialized]
     2139 |     return r->table_any ? 254u /* RT_TABLE_MAIN */
          |

That is due to the "default" switch case which was unhandled
when building without more-asserts". Avoid that by reworking the
code.
2021-01-08 13:10:14 +01:00
Thomas Haller
02f4b0cbd5
platform/tests: workaround failure to add veth device on copr
On copr builds, the unit tests sometimes fail to create a veth
interface. In those cases, kernel rejects the netlink request
with EPERM. copr uses mock on Fedora 33 hosts.

I think this is a kernel bug. Add a workaround by retrying a few times.
2021-01-08 09:06:18 +01:00
Thomas Haller
977ea352a0
all: update deprecated SPDX license identifiers
These SPDX license identifiers are deprecated ([1]). Update them.

[1] https://spdx.org/licenses/

  sed \
     -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \
     -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \
     -i \
     $(git grep -l SPDX-License-Identifier -- \
         ':(exclude)shared/c-*/' \
         ':(exclude)shared/n-*/' \
         ':(exclude)shared/systemd/src' \
         ':(exclude)src/systemd/src')
2021-01-05 09:46:21 +01:00
Thomas Haller
c50da167bc
all: adjust imports to fix libc/linux headers
Linux headers and some libc headers have overlapping defines
for network types and functions.

In the past years, glibc and linux headers were improved to cooperate
so you could include either one, in any order.

With musl and possibly some older glibc versions that doesn't work so
well.

Reorder and change includes to make it work better. Yes, this looks
pretty random and unmotivated. The includes are changed in order to
successfully build on various libc/kernel versions, with the goal
of not using #if.
2020-12-23 10:48:26 +01:00
Thomas Haller
0fca809bfd
all: explicit include <linux/if_{ether,infiniband,vlan}.h> as needed
Currently libnm headers include <linux/if_{ether,infiniband,vlan}.h>.
These are public headers, that means we drag in the linux header to all
users of <NetworkManager.h>.

Often the linux headers work badly together with certain headers from libc.
Depending on the libc version, you have to order linux headers in the right
order with respect to libc headers.

We should do better about libnm headers. As a first step, assume that
the linux headers don't get included by libnm, and explicitly include
them where they are needed.
2020-12-22 16:33:33 +01:00
Thomas Haller
a6456fe1f4
platform: rework nm_platform_dedup_multi_iter_next_*() and add more implementations
I want to add more such accessors, because they are the base for
the corresponding for-each macros.

Add a helper macro _nm_platform_dedup_multi_iter_next() to do that,
which should make it simpler to add these nm_platform_dedup_multi_iter_next*()
functions.

Note that previously these functions were inline functions, now they are
macros. I think there is very little difference here. Also before those
functions could be entirely inlined. By using the macro the result
doesn't really change.

One difference is that we now require an "out" pointer. Previously that
was not required, but I guess it makes little sense otherwise.
2020-11-24 08:52:58 +01:00
Thomas Haller
42156b6010
wifi: use NMEtherAddr struct for bssid 2020-11-19 20:17:03 +01:00
Thomas Haller
07a60e859c
wifi: drop Wext handlers get_rate()/get_bssid()/get_qual() from NMWifiUtilsClass
Wext is anyway deprected. Our NMWifiUtilsClass should not have API
to accomodate it. That means, we don't need dedicated get_rate(),
get_bssid(), get_qual() hooks, when they all are only called by
get_station().

Instead, push the Wext specific code down.
2020-11-19 20:13:16 +01:00
Andrew Zaborowski
5d4dfcd8d2
platform: Drop nm_platform_wifi_get_{bssid,rate,quality}
These are unused now so remove them and revert most of
e0394689b3 which attempted to fix the same
issue of the platform wifi API not mapping well the nl80211 commands
resulting in redundant netlink commands being used.

In the wext driver there are still three individual getters for the
three values and nm_wifi_utils_get_station() uses either these or the
collective get_station method depending on the driver.
2020-11-19 13:38:07 +01:00
Andrew Zaborowski
e5a2520069
platform: Add a wifi_get_station utility
Merge nm_platform_wifi_get_bssid, nm_platform_wifi_get_quality,
nm_platform_wifi_get_rate into one utility, nm_platform_wifi_get_station
that uses the single NL80211_CMD_GET_STATION command dump when the
nl80211 driver is used.  With wext each function mapped to one ioctl
while with nl80211 all three can be obtained with one netlink command.
The new function should use the minimum number of calls with either
driver.
2020-11-19 13:38:06 +01:00
Antonio Cardace
516c623618
bridge: set MTU at link creation time
https://bugzilla.redhat.com/show_bug.cgi?id=1778590

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-11-02 17:23:16 +01:00
Antonio Cardace
ba2ee46254
platform: allow setting the MTU at link creation time
Add a parameter to the 'link_add()' virtual function so that
the MTU will be configured (via netlink) by the kernel when
creating the link.

https://bugzilla.redhat.com/show_bug.cgi?id=1778590

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-11-02 17:23:05 +01:00
Thomas Haller
6c9a289451
core: cleanup IPv4/IPv6 checks using NM_IS_IPv4()
- we commonly use "int addr_family" as parameters to functions.
  But then inside the function, we often need to do something for
  IPv4 or IPv6 specifically. Instead of having lots of redundant
  "if (addr_family == AF_INET)" checks, prefer to have a variable
  IS_IPv4 and/or use NM_IS_IPv4() macro.

- don't make the "IS_IPv4" variable a gboolean but an int. gboolean
  is a typedef for int, so it's in practice exactly the same. However,
  we use "IS_IPv4" as index to arrays of length 2, where at position
  "1" we have the value related to IPv4. Using a gboolean to index
  an array is a bit odd. Maybe a "int" is preferable here.
  This is more about doing consistently one or the other. There are
  no strong reasons to prefer gboolean or int.
2020-10-30 16:52:59 +01:00
Thomas Haller
931573dfda
shared: rename nm_add_u32_clamped() to nm_add_clamped_u32() 2020-10-27 17:04:19 +01:00
Thomas Haller
3874e061d4
platform/tests: add NMTstpAcdDefender helper for testing 2020-10-23 17:11:55 +02:00
Thomas Haller
60da4cb494
platform: interpret metric_any for routes to accept offset for default metric
The DHCP client likes to order multiple default routes by adding
them with different, increasing metric.

To support that, let "metric_any" not completely disable the "metric"
field, but instead interpret it as an offset that should be added to
the default metric.
2020-10-23 17:11:55 +02:00
Thomas Haller
515df289de
all/trivial: fix formatting 2020-10-22 17:22:09 +02:00
Andrew Zaborowski
e0394689b3 platform/wifi: Cache GET_STATION dump data between calls
The wifi backends call nm_platform_wifi_get_quality and
nm_platform_wifi_get_rate one after another in periodic_update (every
6s) and the same information is queried twice, synchronously.  For the
lack of a better mechanism to decide whether we're still inside the same
periodic_update call, store the timestamp in msecs and reuse the data
for 500ms.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
277e8eaa1f platform/wifi: Use GET_STATION instead of GET_SCAN dumps
As an optimization, use the NL80211_CMD_GET_STATION dump data instead
of the NL80211_CMD_GET_SCAN dump + GET_STATION command (non-dump) to
implement the following methods:
wifi_nl80211_get_bssid
wifi_nl80211_get_rate
wifi_nl80211_get_qual

GET_STATION records vary in size from a few hundred bytes to a few kB.
GET_SCAN records are usually on the few hundred bytes side, but there
can be many of them.  In managed mode there will only be one
GET_STATION record.  In AdHoc mode there may be more.  These methods are
not used in AP or Mesh mode.

So without that patch we'd have a GET_SCAN dump that could be quite big
and then a GET_STATION with one record.  Now it should be a GET_STATION
dump with one record or a few records, in any case fewer synchronous
commands is better.  Additionally this should now not depend on the
currently-connected BSS being in the kernel's scan result cache.

The downside is that the signal strength is "optional" in the
GET_STATION records, depends on the driver's capabilities.  Most
mainline drivers do seem to include it (the mac80211 based ones and a
few full-mac ones) but I can't know if all of them do.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
c6456dd104 platform/wifi: Read frequency from NL80211_CMD_GET_INTERFACE
As an optimization, implement wifi_nl80211_get_freq() using the
GET_INTERFACE nl8022 command instead of the GET_SCAN dump.
The GET_SCAN dump can be over 10kB of data that the kernel has to build
and we have to parse.  Additionally the GET_SCAN dump is not guaranteed
to contain the currently-connected BSS if there was no recent scan (30s),
or if the recent scan missed the beacon from the current BSS, or if the
recent scan was for a subset of channels/SSIDs/BSSIDs etc. and the last
full scan was already flushed.  Scan results are flushed after (I think)
30 seconds or if a new scan has the flush flag set.

In IWD we do occasionally do partial scans (on a subset of channels or
for a specific SSID) with the flush flag.  In that case the previous
wifi_nl80211_get_freq() logic would probably return 0.
2020-10-22 16:58:27 +02:00
Thomas Haller
e155e4a153
platform: add NMPlatformIP4Address.ip4acd_not_ready flag
It is not yet used, but it will be used to mark instances that
are not supposed to be configured in platform, because ACD is
either still pending of failed.
2020-10-13 13:39:01 +02:00
Thomas Haller
422294974c
platform: fix handlng of NMPlatformIP4Address.use_ip4_broadcast_address to be considered for hash/cmp functions
This is an important field. The hash/cmp function cannot just honor
nm_platform_ip4_broadcast_address_from_addr().
2020-10-13 13:39:01 +02:00
Thomas Haller
28bbe2a798
shared,platform: take pointer to NMEtherAddr in NM_ETHER_ADDR_FORMAT_VAL() macro
It seems nicer to require a pointer than the plain struct.
2020-10-13 12:56:25 +02:00
Thomas Haller
6807774b7d
clang-format: mark "nm_platform_iter_obj_for_each()"/"nm_l3_config_data_iter_*()" as ForEachMacros 2020-10-13 12:56:25 +02:00
Thomas Haller
fb2d11f1f9
all: use _NM_DUMMY_STRUCT_FOR_TRAILING_SEMICOLON define for trailing semicolon 2020-10-08 17:00:22 +02:00
Thomas Haller
6cf7c6739f
platform/tests: skip test_platform_ip_address_pretty_sort_cmp() on non-amd64 archs
The test only works on amd64, because it relies on the memory layout of
the structures.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/546
2020-10-07 09:10:09 +02:00
Thomas Haller
3576f54100
platform/tests: print details about test failure for test_platform_ip_address_pretty_sort_cmp()
When the test is about to fail, print the wrong data to help debugging
the test failure.
2020-10-07 09:01:17 +02:00
Thomas Haller
4fc7973498
platform/tests: adjust regeneration of test code for test_platform_ip_address_pretty_sort_cmp()
Since re-formatting our source code, the generated output no longer
matched the required formatting. Adjust it.
2020-10-07 08:48:13 +02:00
Alfonso Sánchez-Beato
9c8275bedc
platform: use also statvfs() to check for udevd
Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES).

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/639
2020-10-06 19:01:24 +02:00
Thomas Haller
6220b08c78
platform: reorder fields in NMPClass struct
Almost always we don't care about the order of our fields inside
structs. Hence, choose an order in which holes due to memory alignment
are minimized.
2020-10-05 15:54:09 +02:00
Thomas Haller
0d7bf62aac
test/trivial: rename ASSERT_nmp_cache_is_consistent() function to nmtst_assert_nmp_cache_is_consistent()
We sometimes expose test-only functions as part of our API, to give direct
access to unit tests. Such functions should have a "NMTST" prefix. Rename.
2020-10-05 15:46:42 +02:00
Thomas Haller
f2b5812af3
platform: add typedefs for casting functions pointers to improve formatting
The autogenerated formating in these cases is rather ugly. Instead,
introduce a typedef and use that for casting the function pointer.
2020-10-05 15:46:42 +02:00
Thomas Haller
c6308162cf
platform: fix formatting for _vt_cmd_plobj_id_cmp()/_vt_cmd_plobj_id_hash_update() 2020-10-05 15:46:42 +02:00
Thomas Haller
456d26d816
platform/tests: fix bug in nmtstp_ip_address_check_lifetime() calculating timeouts with unsigned integers
As one of the arguments in unsigned, the calculation is performed as
unsigned integers. That can actually lead to the wrong result. Fix it by
casting to the right (signed) types.
2020-10-01 17:37:15 +02:00
Thomas Haller
dc559a9af7
platform/trivial: use in_addr_t type for address in nm_platform_ip4_address_get() 2020-10-01 17:35:14 +02:00