Commit graph

31026 commits

Author SHA1 Message Date
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
Thomas Haller
a0425b77c3
modem: fix unalined access in stage3_ip_config_start()
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 21887f88fa)
2022-12-09 12:47:52 +01:00
Thomas Haller
9ecb878164
core: check hardware address length in nm_utils_get_ipv6_interface_identifier()
nm_utils_get_ipv6_interface_identifier() has non-obvious requirements on
the hardware address. If the caller passes a wrong length, it will
trigger an assertion or even cause out of bound read. This would mean
that the caller needs to carefully check the length. Such requirements
on the caller are wrong.

Also, in practice the hardware length comes from platform/kernel. We
don't want to trust that what kernel tells us always has the required
address length, so the caller would always have to double check before
calling the function.

Instead, handle unexpected address lengths.

Fixes: e2270040c0 ('core: use Interface Identifiers for IPv6 SLAAC addresses')
Fixes: 1d396e9972 ('core-utils: use 64-bit WPAN address for a 6LoWPAN IID')
(cherry picked from commit 5d86db699b)
2022-12-09 12:47:52 +01:00
Thomas Haller
a59b9b6292
core: fix out-of-bounds for nm_utils_get_ipv6_interface_identifier()
For link type NM_LINK_TYPE_6LOWPAN, nm_utils_get_ipv6_interface_identifier()
expects 8 bytes hardware address. It even just accesses the buffer
without checking (that needs to be fixed too).

For 6lowpan devices, the caller might construct a fake ethernet MAC
address, which is only 6 bytes long. So wrong.

Fixes: 49844ea55f ('device: generate pseudo 48-bit address from the WPAN short one')
(cherry picked from commit 53d1d8ba91)
2022-12-09 12:47:51 +01:00
Thomas Haller
677be52f71
core: fix possible unaligned access in nm_utils_get_ipv6_interface_identifier()
Fixes: e2270040c0 ('core: use Interface Identifiers for IPv6 SLAAC addresses')
(cherry picked from commit 0f4114c27c)
2022-12-09 12:47:51 +01:00
Thomas Haller
ed47047a36
device: use correct field "l3cfg_" to clear in dispose()
The fields "l3cfg" and "l3cfg_" are union aliases. One of them is const,
the other is not. The idea is that all places that modify the field need
to use the special name "l3cfg_", and grepping for that will lead you to
all the relevant places.

This mistake happened, because g_clear_object() casts constness away.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 8cb739031d)
2022-12-09 12:46:02 +01:00
Thomas Haller
e4cc504af5
dhcp: fix crash in "nm-dhcp-helper" passing NULL to g_dbus_connection_flush_sync()
"connection" variable might be NULL, which fails an assertion in
g_dbus_connection_flush_sync(). Consequently, "error_flush" is also
NULL which leads to a crash of "nm-dhcp-helper".

Reported-by: Jules Maselbas <jmaselbas@zdiv.net>

Fixes: 240ec7f891 ('dhcp: implement ACD (address collision detection) for DHCPv4')
(cherry picked from commit 37e130232d)
2022-12-09 12:45:51 +01:00
Beniamino Galvani
e4f5d96d6a macsec: merge branch 'bg/macsec-ckn-len'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1460

(cherry picked from commit 8d6cba6555)
2022-12-05 17:15:06 +01:00
Beniamino Galvani
2dd070e646 macsec: document the format of CAK and CKN properties
(cherry picked from commit dfe63d9eb3)
2022-12-05 17:15:06 +01:00
Beniamino Galvani
faf8f0ff24 macsec: allow CKN shorter than 64 characters
See wpa_supplicant commit [1]:

    macsec: Make pre-shared CKN variable length

    IEEE Std 802.1X-2010, 9.3.1 defines following restrictions for
    CKN:

    "MKA places no restriction on the format of the CKN, save that it
    comprise an integral number of octets, between 1 and 32
    (inclusive), and that all potential members of the CA use the same
    CKN. No further constraints are placed on the CKNs used with PSKs,
    ..."

    Hence do not require a 32 octet long CKN but instead allow a
    shorter CKN to be configured.

    This fixes interoperability with some Aruba switches, that do not
    accept a 32 octet long CKN (only support shorter ones).

[1] https://w1.fi/cgit/hostap/commit/?id=b678ed1efc50e8da4638d962f8eac13312a4048f

(cherry picked from commit df999d1fca)
2022-12-05 17:15:06 +01:00
Beniamino Galvani
7158f58bfc device: merge branch 'bg/rh2122564'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1459
https://bugzilla.redhat.com/show_bug.cgi?id=2122564

(cherry picked from commit fb3be35b8b)
2022-12-05 17:14:49 +01:00
Beniamino Galvani
51062305dd device: fix missing transition from UNAVAILABLE to DISCONNECTED
When called with update_carrier=TRUE, nm_device_bring_up_full() checks
for carrier changes and it may queue a transition to DISCONNECTED
through the following call chain:

 -> nm_device_bring_up_full()
   -> nm_device_set_carrier_from_platform()
     -> nm_device_set_carrier()
       -> carrier_changed()
         -> nm_device_queue_state()

In _set_state_full(state=UNAVAILABLE) after bringing the interface up
we also call nm_device_cleanup() which clears the enqueued state
change to DISCONNECTED. When this happens, the device remains in
UNAVAILABLE and never gets activated even if it was ready.

This was observed with macsec interfaces, but in theory can happen
with all those interfaces that get carrier immediately after being
brought up.

Avoid this issue by not checking the carrier synchronously from
_set_state_full(). The carrier change event will be processed in the
next asynchronous invocation of device_link_changed().

https://bugzilla.redhat.com/show_bug.cgi?id=2122564
(cherry picked from commit 07bc5121a7)
2022-12-05 17:14:49 +01:00
Beniamino Galvani
54170fdfb0 device: add "update_carrier" argument to nm_device_bring_up_full()
In some situations we need to avoid updating the carrier status
synchronously from nm_device_bring_up_full(). Add a flag for that.

(cherry picked from commit 9fd9eaf276)
2022-12-05 17:14:49 +01:00
Beniamino Galvani
738e41cd3e device: add nm_device_bring_up_full()
In the next commit nm_device_bring_up() will be extended with a new
argument. Most callers just want to bring up the device synchronously
and don't care about the "no_firmware" argument. Introduce a
nm_device_bring_up_full() for callers that need special behavior.

(cherry picked from commit 861934a510)
2022-12-05 17:14:49 +01:00
Thomas Haller
fb6e1ec549
release: bump version to 1.40.7 (development) 2022-11-30 16:27:13 +01:00
Thomas Haller
ba35cff250
release: bump version to 1.40.6 2022-11-30 16:27:13 +01:00
Thomas Haller
2e5598b258
NEWS: update 2022-11-30 15:36:30 +01:00
Thomas Haller
b73230ee20
libnm: workaround compiler warning in nm_sock_addr_endpoint_new()
gcc-12.2.1_git20220924-r4 (on Alpine Linux) warns:

  ../src/libnm-core-impl/nm-utils.c: In function 'nm_sock_addr_endpoint_new':
  ../src/libnm-core-impl/nm-utils.c:168:18: error: 'port' may be used uninitialized [-Werror=maybe-uninitialized]
    168 |         ep->port = port;
        |         ~~~~~~~~~^~~~~~
  ../src/libnm-core-impl/nm-utils.c:150:25: note: 'port' was declared here
    150 |     guint16             port;
        |                         ^~~~

Workaround.

Fixes: 713e879d76 ('libnm: add NMSockAddrEndpoint API')
(cherry picked from commit 3515324e90)
2022-11-30 15:25:18 +01:00
Lubomir Rintel
0a43082efa team: set port configuration even if it's empty
Call teamdctl_port_config_update_raw() when we're attaching a port even
if all of team-slave setting properties are default.

This is done to ensure teamd "knows" about the port (that is,
"teamdctl ...  port present" returns success) when we're done activating
the slave connection. It will pick it up anyway from netlink, but that
can happen after the activation is done, resulting in a possible race.

Fixes-test: @remove_active_team_profile

https://bugzilla.redhat.com/show_bug.cgi?id=2102375
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1421
(cherry picked from commit 6897f6e6df)
2022-11-28 08:51:59 +01:00
Lubomir Rintel
bcf11ebead team: restore port configuration after teamd respawn
If teamd crashes, we restore it. That's very nice, but if it really
crashed then it left ports attached and the slave connections are not
going to fail and the port configuration (e.g. priority or link watcher) in
teamd's memory will be gone.

This will restore the port configuration when the teamd connection is
re-established. This probably also fixes a race where a slave connection
would be enslaved (only possible externally and manually?) while we
didn't establish a connection to teamd yet. We'll just send the port
configuration in once're connected.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1361
(cherry picked from commit f3327835c1)
2022-11-28 08:51:48 +01:00
Lubomir Rintel
130691daff team: trivial: use a variable instead of nm_device_get_ip_iface() calls
This reads a little better and performs marginally better.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1361
(cherry picked from commit 38251ad59f)
2022-11-28 08:51:44 +01:00
Thomas Haller
25f9adb19e
release: bump version to 1.40.5 (development) 2022-11-18 10:01:06 +01:00
Thomas Haller
86b82bf358
release: bump version to 1.40.4 2022-11-18 10:01:06 +01:00
Thomas Haller
f70b4394a9
NEWS: update 2022-11-18 07:38:19 +01:00
Thomas Haller
e5e8515dd9
libnm/tests: check assigning same setting in nm_connection_add_setting()
Fixes: 3e3b629586 ('libnm: fix leak with self assignment in nm_connection_add_setting()')
(cherry picked from commit a87fd2e4d2)
2022-11-17 16:36:28 +01:00