Commit graph

29189 commits

Author SHA1 Message Date
josef radinger
3f5cb1f932
core/trivial: fix small typo Ipv vs IPv
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/978
2021-09-13 09:22:17 +02:00
gaoxingwang
2a36f8c2f1
libnm: fix leak and return "failures" from nm_client_load_connections()
Due to this, `nmcli connection load` would also not print a warning
about failure to load obviously bogus files:

  $ nmcli connection load /bogus

Note that load is also used to unload files, so if the file name is a
possibly valid name for a non-existing file, there is no failure. For
example, we get no warning for

  $ nmcli connection load /etc/NetworkManager/system-connections/bogus

Even if currently no such file is loaded, then the operation would still
silently succeed, instead of succeeding the first time only. That is because
load should be idempotent.

[thaller@redhat.com: rewrote commit message]

Fixes: 4af6219226 ('libnm: implement nm_client_load_connections_async() by using GDBusConnection directly')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/794

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/979
2021-09-13 08:32:45 +02:00
Thomas Haller
9ec9a92f17
platform: avoid bitfield at end of __NMPlatformIPAddress_COMMON macro
NMPlatformIPAddress, NMPlatformIP4Address and NMPlatformIP6Address are supposed
to have a common first part, which is address family agnostic. For that, the
is the macro __NMPlatformIPAddress_COMMON which defines the first fields.

Something similar is also done for routes and object types that have an ifindex.

Anyway, __NMPlatformIPAddress_COMMON used to have a bitfield as last element.
In particular NMPlatformIP4Address then has a bitfield as first IPv4 specific
field. With this it's not clear to me that the alignment is guaranteed
to be the same for all structs.

Avoid the trailing bitfield at __NMPlatformIPAddress_COMMON to workaround
this potential problem.
2021-09-10 13:43:34 +02:00
Thomas Haller
3a6b3e35da
l3cfg: merge branch 'th/l3cfg-ipv6ll'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/976
2021-09-10 13:27:15 +02:00
Thomas Haller
aa070fb821
core: add NML3IPv6LL helper
This helper class is supposed to encapsulate most logic about
configuring IPv6 link local addresses and exposes a simpler API in order
to simplify NMDevice. Currently this logic is spread out in NMDevice.

Also, NML3IPv6LL directly uses NML3Cfg, thereby freeing NMDevice to care
about that too much.

For several reasons, NML3IPv6LL works different than NML3IPv4LL.
For one, with IPv6 we need to configure the address in kernel, which does
DAD for us. So, NML3IPv6LL will tell NML3Cfg to configure those
addresses that it wants to probe. For IPv4, it only tells NML3Cfg to do
ACD, without configuring anything yet. That is left to the caller.
2021-09-10 13:26:52 +02:00
Thomas Haller
929eae245d
l3cfg: implement NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE and rework object state
NML3Cfg tracks state about all addresses/routes. It needs that (at
least) for the following reaons:

1) if a address/route gets added by NetworkManager and then gets
  externally removed then it is presumed that the user did this. In this
  case, we remember that ("externally-removed") to not re-add the
  address/route, until we do a full reapply. This was previously
  tracked as "externally_removed_objs_hash".

2) when NML3Cfg configures a address/route in kernel, and later the
  address/route is no longer to be configured, then NML3Cfg needs to
  delete it again. It thus needs to remember which addresses/routes
  it configured earlier to remove them. This was previously tracked via
  "last_addresses_x" and "last_routes_x".

3) kernel rejects configuring certain routes while a related IPv6
  address is still tentative. That means, NML3Cfg needs to detect that,
  remember it, and retry later. That is previously tracked as
  "routes_temporary_not_available_hash".

4) during NM_L3_CFG_COMMIT_TYPE_ASSUME, we don't remove extraneous
  and don't add missing addresses/routes. This commit mode is done
  while assuming a device, that is, gracefully taking over after
  a restart. However, sometimes while assuming a device we forcefully
  want to configure an address/route. That happens for example if we
  do IPv6 link local addressing. Then we really want to add that
  address/route, even in assume mode. That is what the
  NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE flag does, and to implement
  that we need to track whether we already tried to add the
  address/route previously. This is something new.

Consolidate these various states in a new "obj_state_hash" and
"ObjStateData" structure. This solves above points the following way:

1) to track externally removed objects, we have a flag in ObjStateData
  that indicates whether the object was every configured and whether
  it currently is configured. Based on that we make decisions to
  configure (or not) an address. See "_obj_states_sync_filter()".

2) we now mark objects that NML3Cfg configured, which are still in platform
  and which are no longer to be configured as "zombies".

3) this is now tracked via ObjStateData's "os_temporary_not_available_lst".

4) with the available ObjStateData we can make appropriate decisions
  in "_obj_states_sync_filter()".
2021-09-10 13:26:52 +02:00
Thomas Haller
8a3d913de8
l3cfg: add NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE flag
It's a bit tricky how this flag works. It's needed for IPv6
link local addresses, which commits changes in %NM_L3_CFG_COMMIT_TYPE_ASSUME
mode. See the code comments how it works.

This commit only adds the flags and let's the NMPlatformIP{Address,Route}
properly track it. What is still needed is to actually implement any
meaning to that during the sync.
2021-09-08 18:33:44 +02:00
Thomas Haller
a909a4b305
platform: move ip4acd_not_ready flag to NMPlatformIP4Address
This flag is only relevant for IPv4. That is, because the way we do
ACD/DAD is fundamentally different between IPv4 and IPv6. For IPv4, we
use libn-acd while IPv6 we configure the address in kernel and wait for
the tentative flag to go away.
2021-09-08 18:33:44 +02:00
Thomas Haller
e07b41c430
platform: add assume_config_once flags to NMPlatformIP{Address,Route}
NMPlatformIP{Address,Route} are mainly the structs that we receive via
netlink and get cached in the NMPlatform cache.

However, the same structures are also used by the upper layers to track
which addresses to add.

Add a flag to addresses and routes, for a certain behavior, relevant
during NML3Cfg commit. The idea is that during commits for NML3Cfg of
type NM_L3_CFG_COMMIT_TYPE_ASSUME, no new addresses are added that
are not already configured. In some cases, we want to override that,
and need a flag to track that. More about that later.
2021-09-08 18:33:44 +02:00
Thomas Haller
2eb7983a04
l3cfg: refactor modification of address in nm_l3_config_data_merge() 2021-09-08 18:33:43 +02:00
Thomas Haller
075bdefb71
l3cfg: also call nm_l3_config_data_merge()'s add-obj-hook for routes 2021-09-08 18:33:43 +02:00
Thomas Haller
cfebd0e504
l3cfg: add a "result" structure to nm_l3_config_data_merge()'s add-obj-hook 2021-09-08 18:33:43 +02:00
Thomas Haller
3b92ad8b6d
l3cfg: change NM_L3_CONFIG_MERGE_FLAGS_ONLY_FOR_ACD to be a NML3CfgConfigFlags value
It's really not related to NML3ConfigMergeFlags, but fits better
to NML3CfgConfigFlags.
2021-09-08 18:33:43 +02:00
Thomas Haller
4c3eed28cd
l3cfg: add config_flags argument to nm_l3cfg_add_config()
We will need to present additional options for tracking the configuration.
Add a flags argument.
2021-09-08 18:33:43 +02:00
Thomas Haller
49e85bee0e
core/tests: add nmtst_utils_host_id_{push,pop}() helpers to stub the host-id
The host-id gets read from /var/lib/NetworkManager/secret_key, and cached in
a global variable. Other parts of the code can get the host ID using a
singleton function.

For testing, we need to inject a different host-id. Add two push/pop
functions for that.

Unlike nm_utils_host_id_get(), these functions are not thread-safe (nor
is it possible to make them thread-safe in a reasonable manner).
2021-09-08 18:33:43 +02:00
Thomas Haller
0f5ed15008
glib-aux/tests: add NMTST_COPY() helper 2021-09-08 18:33:43 +02:00
Thomas Haller
d422434945
glib-aux: add nm_g_array_{first,last}() helpers
A GArray can commonly used like a stack or a fifo list.
Add convenience accessors to get the first/last element.
2021-09-08 18:33:43 +02:00
Thomas Haller
e38ddb52e3
all: rename nmtst_* functions that are used by the daemon
The name prefix "nmtst_*" is reserved for test helpers and stub
function. Such functions should not be in the actual build artifacts,
like the NetworkManager binary.

Instead, nmtst_connection_assert_unchanging() is not a test helper. It
is a assertion function that is only enabled with NM_MORE_ASSERTS
builds. That's different.

Rename.

In other words,

  $ nm src/core/NetworkManager src/libnm-client-impl/.libs/libnm.so | grep nmtst

should give no results.
2021-09-08 18:33:43 +02:00
Thomas Haller
7df4b2a2eb
platform: use IFA_F_SECONDARY instead of IFA_F_TEMPORARY
These names are aliases. Prefer one over the other.
2021-09-08 18:33:43 +02:00
Thomas Haller
31df5d554a
platform: add missing flags to nm_platform_addr_flags2str() 2021-09-08 18:33:43 +02:00
Thomas Haller
398f6a8afb
glib-aux: add nm_assert_is_bool() helper 2021-09-08 18:33:42 +02:00
Thomas Haller
2d828bdbf9
release: bump version to 1.33.2 (development) 2021-09-08 16:49:22 +02:00
Thomas Haller
2a07043489
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')
2021-09-08 15:27:17 +02:00
Thomas Haller
426491a500
platform: fix build using our copy of header "linux-headers/ethtool.h"
Fixes: 34d48d2596 ('platform: clear all BASE types when setting advertised modes for ethernet autoneg')
2021-09-08 13:35:33 +02:00
Thomas Haller
52d18db0e3
ethtool: merge branch 'th/ethtool-autoneg-fixes'
https://bugzilla.redhat.com/show_bug.cgi?id=1897004#c10

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/972
2021-09-07 08:38:33 +02:00
Thomas Haller
78b3711522
core: always reset ethtool autoneg/speed to fix reactivation
The check whether the current setting are already as expected are wrong.

The reason is that nm_platform_ethtool_set_link_settings() also sets
the announced ethernet modes, but nm_platform_ethtool_get_link_settings()
does not give them.

That means, we cannot check whether the current link configuration is
the same, because the getter doesn't give that information.
Consequently, we must not skip the setting on the assumption that
there is nothing to change.

This bug has bad effects. If the device is currently activated with ethtool
option set, then re-activating the profile will result in wrongly
skipping the update.
2021-09-06 10:07:16 +02:00
Thomas Haller
bd92df3e56
platform: also set advertised modes when disabling ethernet autoneg
Disabling autoneg is not supported for Gigabit ethernet. But it seems that
ixgbe also doesn't honor

  ethtool -s enp5s0f0 speed 100 duplex full autoneg off

As a workaround, when we disable autoneg then always set the advertised
modes too. I think (hope) that should not have a bad effect otherwise,
but seems most sensible for ixgbe.
2021-09-06 10:07:16 +02:00
Thomas Haller
d5f062cecd
core: during reset of ethtool autoneg enable all modes 2021-09-06 10:07:15 +02:00
Thomas Haller
ea2b965ac2
core: cleanup logging of set-link for speed/autoneg
There is no point in logging the current speed/duplex. OK, with
the "*", we could at least see whether the printed values are
to be set, or are currently configured on the interface.

But mixing these two outputs is confusing and meaningless.
Either log what we are about to do, or what the current configuration
is. Not a mix of both.
2021-09-06 10:07:15 +02:00
Thomas Haller
5c789c030a
platform: add debug logging for setting link autoneg/speed 2021-09-06 10:07:15 +02:00
Thomas Haller
34d48d2596
platform: clear all BASE types when setting advertised modes for ethernet autoneg
Get the list of supported flags from ethtool utility ([1]).

When we enable auto-negotiation, the user may select only one mode to
be advertised. But then we need to clear all other modes, the previous
define BASET_ALL_MODES did not cover them all.

[1] https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/ethtool.c?id=7cca9692b9b0c4e2c7eb7868a7791f97202014b0#n397
2021-09-06 10:07:15 +02:00
Thomas Haller
595099f27a
platform: don't set lp_advertising in set_link_settings_new()
I don't understand why this was done. I don't think it's necessary nor
correct.
2021-09-06 10:07:14 +02:00
Thomas Haller
94e23ebba5
platform: simplify accessing ethtool_link_settings.link_mode_masks in set_link_settings_new() 2021-09-06 10:07:14 +02:00
Thomas Haller
f992b2bc25
platform/build: fix linking "test-nm-platform" test
libnm-platform.la depends on libnm-udev-aux and libnm-base.
Only by accident this was working, because we happened to use
no symbol in the test that required any of these dependencies.

A small change to the test can (and will soon) change that. Fix the
build to link the right library.
2021-09-06 10:06:13 +02:00
Thomas Haller
c3d0249859
linux-headers: update nl802154.h kernel header
Taken from "include/net/nl802154.h", Linux 5.14,
7d2a07b769330c34b4deabeed939325c77a7ec2f, Aug 30, 2021.
2021-09-06 10:00:36 +02:00
Thomas Haller
aadcd0935e
linux-headers: add ethtool.h kernel header
Taken from Linux 5.14, 7d2a07b769330c34b4deabeed939325c77a7ec2f,
Aug 30, 2021.
2021-09-06 10:00:36 +02:00
Thomas Haller
023c8ad88b
code-format: exclude "src/linux-headers" from "nm-code-format.sh" script 2021-09-06 10:00:35 +02:00
Thomas Haller
1d019308f4
glib-aux: fix compiler error using thread-local for _nm_utils_to_string_buffer
On CentOS 7, gcc.x86_64 0:4.8.5-44.el7 fails compilation:

  In file included from ./src/libnm-glib-aux/nm-default-glib.h:69:0,
                   from ./src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                   from src/libnm-core-aux-extern/nm-libnm-core-aux.c:6:
  ./src/libnm-glib-aux/nm-shared-utils.h:1051:1: error: '__thread' before 'extern'
   _nm_thread_local extern char _nm_utils_to_string_buffer[2096];
   ^

Fixes: fb94903444 ('glib-aux: mark _nm_utils_to_string_buffer at thread-local')
2021-09-06 09:38:23 +02:00
Thomas Haller
f3603cbdaa
core: merge branch 'th/device-cleanup-and-kernel-features'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/968
2021-09-02 10:37:46 +02:00
Thomas Haller
c950517cda
l3cfg/trivial: rename "NM_L3_ACD_DEFEND_TYPE_NONE" to "_NM_L3_ACD_DEFEND_TYPE_NONE"
This value is only used internally. It's not part of the public API of
NML3Cfg, and not a value that users could/should set.
2021-09-01 23:25:45 +02:00
Thomas Haller
0dac741e5a
l3cfg: simplify creating l3cd for NML3IPv4LL 2021-08-31 16:49:58 +02:00
Thomas Haller
149e66305f
l3cfg: various minor cleanup to NML3Cfg/NML3ConfigData 2021-08-31 16:49:47 +02:00
Thomas Haller
5a4124f738
core: refactor nm_utils_ipv6_addr_set_stable_privacy() to not fail
It's great to have functions that cannot fail, because it allows to
skip any error handling.

_set_stable_privacy() as it was could not fail, so the only reason why
nm_utils_ipv6_addr_set_stable_privacy() could fail is because the DAD
counter exhausted.

Also, it will be useful to have a function that does not do the counter
check, where the caller wants to handle that differently.

Rename some functions, and make the core nm_utils_ipv6_addr_set_stable_privacy()
not failable.
2021-08-31 16:49:46 +02:00
Thomas Haller
4b6e119010
all: pass pointer to "struct NMUtilsIPv6IfaceId" to functions instead of struct
While NMUtilsIPv6IfaceId is only 8 bytes large, it seems unidiomatic to
pass the plain struct around.

With a "const NMUtilsIPv6IfaceId *" argument it is more clear what the
meaning of this is.

Change to use pointers.
2021-08-31 16:49:46 +02:00
Thomas Haller
bcd2c99aab
platform: require RTA_PREF support in kernel
The preference for IPv6 routes was added in kernel v4.1,
22 June 2015. It is even in latest RHEL7 kernels.

Drop trying to be compatible with such old kernels.
2021-08-31 16:41:57 +02:00
Thomas Haller
eb1c266280
platform: require extended IFA_FLAGS support in kernel
We use extended IFA_FLAGS for IFA_F_MANAGETEMPADDR (IPv6) and
IFA_F_NOPREFIXROUTE (IPv4 and IPv6).

These flags for IPv4 were added to kernel 3.14, 30 March, 2014.
The flag for IPv4 was added to kernel 4.4, 11 January 2016.
Even latest RHEL-7 kernels have backport for IFA_F_NOPREFIXROUTE
for IPv4 (rh#1221311).

Drop this. The backward compatibility code paths are likely broken
anyway, and add considerable complexity.
2021-08-31 16:41:57 +02:00
Thomas Haller
b2b50eba1b
platform: require IFLA_INET6_ADDR_GEN_MODE support in kernel
This is supported since kernel 3.17, dated 5 October, 2014. Drop the backward
compatibility for that.

It's very hard to sensibly support a mode where we set the interface up,
but prevent kernel from enabling IPv6. We would hack around that by disabling
IPv6 altogether.

But these code paths are not tested and likely make no sense. And it's hard
to implement a sensible behavior in this case anyway.
2021-08-31 16:41:57 +02:00
Thomas Haller
98ed0e9858
platform: rename "user_ipv6ll" API to "inet6_addr_gen_mode"
The term "user_ipv6ll" is confusing and not something somebody familiar
with kernel or `ip -d link` would understand.

Also, it maps a boolean to addr-gen-mode "none" or "eui64", although
there are 2 more address generation modes in kernel.

Don't abstract the underlying API, and name things as they are in
kernel.
2021-08-31 16:41:57 +02:00
Thomas Haller
0d0f532b12
device: setup firewall zone inside stage3_ip_config_start()
nm_device_activate_schedule_stage3_ip_config_start() should only... schedule.
2021-08-31 16:41:57 +02:00
Thomas Haller
ff7231afd5
device/ppp: rework IP config result handling for NMDevicePpp
NMDevice's act_stage3_ip_config_start() has an out parameter,
so that an NMIPConfig object can be returned. That is (luckily)
not used much, and it's fundamentally flawed. We want that
the start method becomes simpler and idempotent. That argument
is problematic there.

Instead, of the result is already ready, postpone the activation
and process the return on an idle handler.

Why not use nm_device_set_dev2_ip_config() to pass the configuration?
Good question, who knows? For now, just mimic the previous behavior.
Usually the IP configuration would be announced late, so we can just
do that artificially by scheduling an idle action.
2021-08-31 16:41:57 +02:00