Commit graph

31050 commits

Author SHA1 Message Date
Beniamino Galvani
af1bbe8bd9 device: fix condition for scheduling stage3 after carrier change
When the device gets carrier, we should reschedule stage3 even if the
device state is not exactly IP_CONFIG.

For example if IPv6 autoconf is waiting for carrier and IPv6 is
may-fail=yes, the device could be already ACTIVATED because manual
IPv4 succeeded; after getting carrier, we need to call
nm_device_activate_schedule_stage3_ip_config() to start IPv6 autoconf.

Fixes: bcf31a9b29 ('device: fix assertion failure on master carrier change')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1165
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1485
(cherry picked from commit 6ea924fa74)
2023-01-11 10:05:15 +01:00
Thomas Haller
1b0d98ab55 ndisc/tests: fix reference counting in nm_fake_ndisc_new()
This adjusts the change from commit ffbcf01589 ('test-ndisc-fake:
free l3cfg after creating fake-ndisc').

ndisc_new() already correctly handles the reference count of l3cfg via
"gs_unref_object". The party that took the wrong reference was
nm_fake_ndisc_new().

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit da371f8108)
2023-01-11 10:04:57 +01:00
Beniamino Galvani
a69a52fd0a NEWS: update 2023-01-11 09:42:14 +01:00
Wen Liang
0de9cf6dfa dns: merge branch "wl/dns"
https://bugzilla.redhat.com/show_bug.cgi?id=2120763

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344

(cherry picked from commit a5d8f8321f)
2023-01-11 09:05:36 +01:00
Wen Liang
b97b12ed94 dns: kill pending dnsmasq process when mode is not 'dnsmasq'
When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq
process should be killed by NM.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
(cherry picked from commit 6058445aea)
2023-01-11 09:05:36 +01:00
Wen Liang
1e112d7e65 dnsmasq: silently ignore if pid file is not existed when killing
(cherry picked from commit 9b3a96f821)
2023-01-11 09:05:36 +01:00
Beniamino Galvani
63a8cec1b1 merge: branch 'bg/coverity'
Fix some coverity warnings.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1487
(cherry picked from commit 5fe4be6c06)
2022-12-23 09:48:03 +01:00
Beniamino Galvani
23ec020dd5 nmtui: fix memory leak
Fixes: 3bda3fb60c ('nmtui: initial import of nmtui')
(cherry picked from commit 1c6935e49d)
2022-12-23 09:47:43 +01:00
Beniamino Galvani
2e966436d8 nmcli: fix double free
src/nmcli/devices.c:1196: double_free: Calling "_nm_auto_strfreev" frees pointer "arg_arr" which has already been freed.

Fixes: c5d45848dd ('cli: mark argv argument for command line parsing as const')
(cherry picked from commit a39ec8ca75)
2022-12-23 09:47:13 +01:00
Thomas Haller
ba66312366
Revert "policy: track the autoconnect retries in devices for multi-connect"
With multi-connect enabled, this can cause infinite retries to autoconnect,
see [1].

That has bad consequences for example in initrd, where
nm-wait-online-initrd.service would wait up to one hour before failing
and blocking boot.

This reverts commit 1656d82045.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2039734#c5

Fixes: 1656d82045 ('policy: track the autoconnect retries in devices for multi-connect')
(cherry picked from commit aec7ae8279)
2022-12-20 17:55:21 +01:00
Thomas Haller
a4ff4f9849
dhcp: fix unused variable in nm_dhcp_client_start()
Fixes: 28d7f9b7c4 ('dhcp: drop NMDhcpClientClass.get_duid() hook')
(cherry picked from commit b9bbbfc41f)
2022-12-19 16:18:31 +01:00
Thomas Haller
caff311fd6
cloud-setup,core: merge branch 'th/cloud-setup-preserve-external-ip'
This is a partial backport of "th/cloud-setup-preserve-external-ip"
branch from 1.41.6.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1476

(cherry picked from commit f0e8b6f0e2)
2022-12-19 16:11:16 +01:00
Thomas Haller
5608070764
nm-cloud-setup: simplify clearing variables in retry loop
The label "try_again" is only reached by one goto. So it was correct
and sufficient to reset the state only there.

It is still error prone. The slighlty clearer approach is to clear
the state at each begin of the "try_again" step.

There should be no change in behavior.

I didn't confirm, but an optimizing compiler should (could) be able
to see that the cleanup is only necessary on retry, and generate the
same code as before. In any case, we should write code that is easier
to read, not optimize for something that a compiler should be able to
optimize itself.

(cherry picked from commit 911b550140)
2022-12-19 15:46:51 +01:00
Thomas Haller
467c028ac1
nm-cloud-setup: refactor skipping reapply be checking for skip first
There should be no change in behavior, but this way seems nicer.
Now _nmc_mangle_connection() doesn't return FALSE, it always
will try to mangle the connection and requires the caller to
first check whether that is appropriate.

Just move some code outside of _nmc_mangle_connection() and let
the caller check for the skip first.

The point is consistency, as the caller already does some checks to
whether skip the reapply. So it should do all the checks, so that
"mangle" never fails/skips.

(cherry picked from commit bbd32fba15)
2022-12-19 15:46:49 +01:00
Thomas Haller
37dc0a9c2f
nm-cloud-setup: set preserve-external-ip flag during reapply
Externally added IP addresses/routes should be preserved by
nm-cloud-setup. This allows other tools to also configure the interface
and the Reapply() call from nm-cloud-setup would not interfere
with those tools.

https://bugzilla.redhat.com/show_bug.cgi?id=2132754
(cherry picked from commit 29b0420be7)
2022-12-19 15:46:48 +01:00
Thomas Haller
5f8bfb82b7
examples: add python example for reapply
(cherry picked from commit a467f55bef)
2022-12-19 15:46:47 +01:00
Thomas Haller
7218daac78
core: support flag "preserve-external-ip" for Reapply() call
Reapply() is supposed to make sure that the system (the interface)
is configured as indicated by the applied-connection. That means,
it will remove/add configuration to make the system match the requested
configuration.

Add a flag "preserve-external-ip" which relaxes this. During reapply,
IP addresses/routes that exist on the interface and which are not known
(or added) by NetworkManager will be left alone.

This will be used by nm-cloud-setup, so that it can reconfigure the
interface in a less destructive way, which does not conflict with
external `ip addr/route` calls.

Note that the previous commit just adds "VersionInfo" and the
possibility to expose capabilities (patch-level). This is not used
for the new reapply flag, because, while we might backport the
reapply flag, we won't backport the "VersionInfo" property. Exposing
new capabilities via the "VersionInfo" property will only become useful
in the future, where we can backport a capability to older NM versions
(but those that have "VersionInfo" too).

(cherry picked from commit 2c1fb50fb5)
2022-12-19 15:46:45 +01:00
Thomas Haller
c9a8fd6808
device: change error code for Reapply() rejecting unsupported flags argument
Changing an error code is an API change. But, so far no flags existed,
so it's unlikely that somebody would send invalid flags or care about
the return code.

(cherry picked from commit b88cdf2a6b)
2022-12-19 14:32:42 +01:00
Thomas Haller
82d5f00961
dhcp: merge branch 'th/dhcp-client-id-in-lease'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1477

(cherry picked from commit 831b8f8e7e)
2022-12-19 11:33:53 +01:00
Thomas Haller
6bc03e9c95
dhcp/dhclient: fix honoring "ipv6.dhcp-duid" when explicitly set
Previously, we only set the "default-duid" line in the lease file. That
means, if the lease already contained a matching entry with a
"dhcp6.client-id" option, it was not honored. That is wrong.

If the profile has "ipv6.dhcp-duid" set, then we must use it and get
rid of those options from the lease.

It's easy to reproduce:

    PROFILE=eth1

    nmcli connection down "$PROFILE"
    rm -f /var/lib/NetworkManager/*lease
    nmcli connection modify "$PROFILE" ipv6.dhcp-duid "aa:bb:cc:dd:00:00:11"
    nmcli connection up "$PROFILE"
    # Verify the expected duid in /var/lib/NetworkManager/*lease and "/run/NetworkManager/devices/$IFINDEX"

    nmcli connection modify "$PROFILE" ipv6.dhcp-duid "aa:bb:cc:dd:00:00:22"
    nmcli connection up "$PROFILE"
    # Check the DUID again.

(cherry picked from commit 1d85608e1c)
2022-12-19 11:33:50 +01:00
Thomas Haller
b7d343af05
dhcp/dhclient: better handle "\r\n" line breaks in dhclient lease file
Splitting by any of "\r\n" and then joining the lines with "\n"
leads to double-newlines. That's certainly wrong.

Maybe we shouldn't care about "\r", I don't know why this was done. But
handle it differently.

(cherry picked from commit c990d6a81a)
2022-12-19 11:33:49 +01:00
Thomas Haller
9a2d2c8522
dhcp/dhclient: avoid rewriting unchanged file in nm_dhcp_dhclient_save_duid()
It updates the file timestamp, which seems undesirable. Skip the update,
if the content didn't change.

(cherry picked from commit 0e63fe58a7)
2022-12-19 11:33:48 +01:00
Thomas Haller
b48da72a71
dhcp/tests: add more tests for nm_dhcp_dhclient_save_duid()
(cherry picked from commit 7d1cfec0b8)
2022-12-19 11:33:47 +01:00
Thomas Haller
874ade4f9d
dhcp/tests: refactor tests for nm_dhcp_dhclient_save_duid()
So much duplicate, boilerplate code. Get rid of it.

(cherry picked from commit 5ee2f3d1dc)
2022-12-19 11:33:46 +01:00
Thomas Haller
c13cc6fb0f
glib-aux: add "with_leading_zero" to nm_utils_bin2hexstr_full()
dhclient writes binary data as colon-separated hex strings
like nm_utils_bin2hexstr_full() does. But it only writes single
digits for values smaller than 0x10. Add an option to support
that mode.

However, there are many callers of nm_utils_bin2hexstr_full() already,
and they all don't care about the new option. Maybe this should this
not be a boolean argument, instead the function should accept a
flags argument. That is not done for now. Just add another "fuller"
variant. It's still easy to understand, because the "full" variant
is just a more limited functionality of "fuller".

(cherry picked from commit b23c505fca)
2022-12-19 11:33:45 +01:00
Thomas Haller
771589e276
dhcp/trivial: rename DUID_PREFIX define to DEFAULT_DUID_PREFIX
(cherry picked from commit df0408f0f6)
2022-12-19 11:33:45 +01:00
Thomas Haller
919d66f049
dhcp: don't destroy old value before setting new in nm_dhcp_client_set_effective_client_id()
Of course, the old "priv->effective_client_id" and the new
"client_id" instances are truly separate, that is, they don't
share data, and destroying "priv->effective_client_id" before
taking a reference on "client_id" causes no problem.

It's still a code smell. It makes the function unnecessarily unsafe
under (very unusual) circumstances.

(cherry picked from commit a3e4f764d1)
2022-12-19 11:33:44 +01:00
Thomas Haller
1f30005d5e
dhcp: set the "dhcp_client_identifier"/"dhcp6_client_id" lease options
Also for the internal DHCP clients. And validate/normalize the setting
for the dhclient/dhcpcd/dhcdcanon plugins.

(cherry picked from commit ef5333e5cf)
2022-12-19 11:33:43 +01:00
Thomas Haller
34d3898427
dhcp: add and use nm_dhcp_client_create_options_dict()
This will be used to pre-fill the lease with client-specific options.

(cherry picked from commit c020f618ed)
2022-12-19 11:33:43 +01:00
Thomas Haller
2535395a8c
dhcp: use nm_dhcp_option_create_options_dict() in nm_dhcp_client_handle_event()
The point of using this trivial helper function is to have one function
that is related to the construction of the options dictionary, that we
can search for.

It answers the question, where do we create a option hash (at `git grep
nm_dhcp_option_create_options_dict`).

(cherry picked from commit ccbe76b81d)
2022-12-19 11:33:42 +01:00
Thomas Haller
63a6bc1bc9
dhcp: add static-keys argument to nm_dhcp_option_create_options_dict()
This is so that we can use the same function also to create the
hash for dhclient plugin.

(cherry picked from commit 492818b529)
2022-12-19 11:33:42 +01:00
Thomas Haller
2987bb7e8d
dhcp: set effective-client-id for all DHCP plugins
(cherry picked from commit 84b90fbdd3)
2022-12-19 11:33:41 +01:00
Thomas Haller
fb03159028
dhcp: fix "ipv6.dhcp-duid=lease" for dhclient DHCPv6 client
The "lease" mode is unusual, because it means to prefer the DUID
configuration from the DHCP plugin over the explicit configuration in
NetworkManager. It is only for the DHCPv6 DUID and not for the IPv4
client-id. It also is only special for the "dhclient" plugin, because
with the internal plugin, this always corresponds to a generated, stable
DUID.

Commit 58287cbcc0 ('core: rework IP configuration in NetworkManager
using layer 3 configuration') broke this. The commit refactored the code
to track the effective-client-id separately. Previously, the client-id which
was read from the dhclient lease, was overwriting NMDhcpClient.client_id. But
with the refactor, it broke because nm_dhcp_client_get_effective_client_id()
was never called.

Fix that.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit bea72c3d6d)
2022-12-19 11:33:41 +01:00
Thomas Haller
a4bce41fa0
dhcp: drop NMDhcpClientClass.get_duid() hook
Note that there are no callers of nm_dhcp_client_get_effective_client_id(),
hence calling the setter had no effect. This is a bug, that we will fix
later.

But before fixing the bug, change how this works. Drop the get_duid() hook.
It's only confusing and backward.

We will keep the nm_dhcp_client_[gs]et_effective_client_id() functions.
They will be used later.

(cherry picked from commit 28d7f9b7c4)
2022-12-19 11:33:41 +01:00
Thomas Haller
4f2d774b9c
dhcp: don't use nm_dhcp_client_get_effective_client_id() from systemd DHCPv6 client
The "effective-client-id" is handled wrongly. Step 1 to clean this up.

Note that NMDhcpClientPrivate.effective_client_id is only ever get/set
via the nm_dhcp_client_[gs]et_effective_client_id() functions.
Note that only a NMDhcpDhclient instance ever calls
nm_dhcp_client_set_effective_client_id().

Hence, for NMDhcpSystemd the effective-client-id is really just the DUID
from the config. Clean this up by not calling nm_dhcp_client_get_effective_client_id()
but use the config directly. There is no change in behavior here.

(cherry picked from commit 05ae48d64e)
2022-12-19 11:33:40 +01:00
Thomas Haller
49fdd3d4b1
dhcp/trivial: fix naming for internal NM_DHCP_OPTION_DHCP6_{CLIENT,SERVER}_ID enums
(cherry picked from commit 9073628bd6)
2022-12-19 11:33:40 +01:00
Thomas Haller
6aa1111aea
core/trivial: fix indentation
(cherry picked from commit 191a1c74bf)
2022-12-19 11:33:40 +01:00
Beniamino Galvani
2f0a5f305c merge: branch 'bg/veth-detect-existing'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1483

(cherry picked from commit 37ee8ee097)
2022-12-19 11:17:23 +01:00
Beniamino Galvani
9131829f7b veth: fix detection of existing interfaces in create_and_realize()
The current implementation only checks that a device with name equal
to veth.peer exists and it has a parent device; it doesn't check that
its parent is actually the device we want to create. So for example,
if the profile specifies interface-name A and peer B, while in
platform we have a veth pair {B,C}, we'll skip the interface creation
and the device will remain without a ifindex, leading to a crash
later. Fix this by adding the missing check.

While at it, don't implement the check by inspecting NMDevices but
look directly at the platform cache; that seems more robust because
devices are often updated from platform events via idle handlers and
so the information there could be outdated.

Fixes: 07e0ab48d1 ('veth: drop iface peer check during create_and_realize()')

https://bugzilla.redhat.com/show_bug.cgi?id=2129829
(cherry picked from commit 50f738bde5)
2022-12-19 11:17:23 +01:00
Beniamino Galvani
a794a349fb veth: improve comment about skipping creation of interfaces
(cherry picked from commit bdd826a044)
2022-12-19 11:17:23 +01:00
Thomas Haller
472f8c3595
libnm" fix type description for LTE,5GNR modems
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1148
(cherry picked from commit 0da9f059e1)
2022-12-19 08:38:10 +01:00
Lubomir Rintel
220a29d9c5 release: bump version to 1.40.9 (development) 2022-12-16 15:47:43 +01:00
Lubomir Rintel
56e2966662 release: bump version to 1.40.8 2022-12-16 15:47:43 +01:00
Thomas Haller
ef1ae93fc1 core: fix returning invalid pointer from nm_netns_l3cfg_get()
The code isn't actually used outside of tests.

Fixes: 15f5d10352 ('l3cfg: add nm_netns_get_l3cfg() accessor')
(cherry picked from commit e3d3b001e0)
2022-12-16 15:25:02 +01:00
Lubomir Rintel
4eb6051041 NEWS: update 2022-12-16 15:15:51 +01:00
Beniamino Galvani
fe42644fcd macsec: fix tracking of parent ifindex
For MACsec interfaces, kernel announces the parent ifindex in the
generic IFLA_LINK netlink attribute, which we save in
NMPlatformLink.parent. There is no need to have a dedicate member in
NMPlatformLnkMacsec.

The dedicate member was never set and during a restart of
NetworkManager the parent of the MACsec device could be unset leading
to a failed assertion:

  act_stage2_config: assertion 'parent' failed

Fixes: 85103656e9 ('platform: add support for macsec links')

https://bugzilla.redhat.com/show_bug.cgi?id=2122564
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1481
(cherry picked from commit cf11884a85)
2022-12-15 16:35:12 +01:00
Thomas Haller
b30ac826c5
examples: fix handling "--last" argument in "examples/python/gi/checkpoint.py"
Fixes: 3ce3ed4c92 ('examples: improve finding last checkpoint in "checkpoint.py"')
(cherry picked from commit 135bbcc0e4)
2022-12-09 12:49:25 +01:00
Thomas Haller
8bb16e44d2
glib-aux/tests: fix bogus cast in _nmtst_connection_normalize_v()
Fixes: 0da0293f7e ('nmtst: add nmtst_connection_normalize() function')
(cherry picked from commit afac3d8102)
2022-12-09 12:49:25 +01:00
Thomas Haller
02665e022b
libnm-base: fix bogus and unnecessary cast in nm_ethtool_data_get_by_optname()
Fixes: df30651b89 ('libnm, cli, ifcfg-rh: add NMSettingEthtool setting')
(cherry picked from commit 373cbcb749)
2022-12-09 12:49:24 +01:00
Thomas Haller
d78e87232d
ndisc: fix iterating arrays in calc_pre_expiry_rs_msec()
Fixes: de6d069dce ('ndisc: send router solicitations before expiry')
(cherry picked from commit 3f04778df2)
2022-12-09 12:49:00 +01:00