Commit graph

15986 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Thomas Haller
ef29015d0b
libnm: fix leak with self assignment in nm_connection_add_setting()
We must consume the reference, like we would in the other case.

Interestingly, I am unable to reproduce a case where valgrind would
complain about the leak. But it is there nonetheless.

Fixes: 0a22f4e490 ('libnm: refactor tracking of NMSetting in NMConnection')
(cherry picked from commit 3e3b629586)
2022-11-17 16:34:01 +01:00
Thomas Haller
3e9b5217f3
libnm: workaround crash in nm_vpn_editor_plugin_import() for plugin requiring GError
The "GError **error" parameter in GLib API should be optional. Due to a
bug in at least nm-vpnc ([1]), this is not the case. Workaround in
libnm.

[1] c7d197477c/properties/nm-vpnc-editor-plugin.c (L281)

(cherry picked from commit 3b2eb689f3)
2022-11-16 13:37:52 +01:00
Fernando Fernandez Mancera
4e857e33fc core: set routing rule protocol properly
When creating NMPlatformRoutingRule from NMIPRouteRule object, the
protocol is being set to RTPROT_UNSPEC. According to linux kernel
documentation FRA_PROTOCOL indicates the originator of the rule.

In this case the route rule is coming from a connection and therefore
the originator of the rule is the user. The correct value is
RTPROT_STATIC which means the rule is installed by the administrator.

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

Fixes: 3f9347745b ('core: add handling of IP routing rules to NMDevice')
(cherry picked from commit 82009e21d2)
2022-11-14 22:46:04 +01:00
Lubomir Rintel
86a30b9900 libnm: test that Gir data matches actual exports
This verifies that what's in our public headers has version nodes, and
that they match Since: tags.

Not pretty (because python) but discovered a *lot* of issues.

(cherry picked from commit 133540763c)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
8080aceb0f libnm: actually export a lot of routines that were supposed to be public
Add them to @libnm_1_40_4 as opposed to @libnm_1_42_0 because we now know
this is going to be backported to 1.40.4 first.

(cherry picked from commit 45d9f1c01c)

Compared to version in main branch, the Since tags and
NM_AVAILABLE_IN_* macros indicate the branched version.
2022-11-11 16:49:39 +01:00
Lubomir Rintel
78e94e63b6 libnm: export nm_utils_ip_{address,rout}es_{from,to}_variant
These are present in a public header yet are not properly commented,
versioned or exported.

Export them now. Another option would be to move them to a private
header; but I suspect someone has intended them to be exported at some
point.

Add them to @libnm_1_40_4 as opposed to @libnm_1_42_0 because we now know
this is going to be backported to 1.40.4 first.

(cherry picked from commit d78000d921)

Compared to version in main branch, the Since tags and
NM_AVAILABLE_IN_* macros indicate the branched version.
2022-11-11 16:49:39 +01:00
Lubomir Rintel
af6be92033 libnm/connection: fix a handful of versioning tags
These are marked as being available sooner than they actually appear in
libnm.ver.

(cherry picked from commit c0b2b5e3a8)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
e401307bec libnm: fix a large amount of Since tags
Some comments are malformed, some are missing altogether.

(cherry picked from commit 117a440cd9)

Compared to version in main branch, the Since tags document the
branched version as well.

The backport omits changes to nm_client_wait_shutdown(), since that one
is not yet present in 1.40.
2022-11-11 16:49:39 +01:00
Lubomir Rintel
41306668e3 libnm: drop nm_vpn_plugin_old_set_{,ip6_}config()
Remove the functions from a public header. They were missing from
libnm.ver and thus never actually exported.

There's no point in salvaging them now as the whole NMVpnPluginOld has
been replaced NMVpnServicePlugin and new uses are discouraged.

(cherry picked from commit 1c6b0edb30)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
8fb4da584c libnm: remove nm_device_wpan_get_hw_address()
Remove the function from a public header. It was missing from libnm.ver
and thus never actually exported.

There's no point in salvaging it now as it nm_device_get_hw_address()
exists as a better option.

(cherry picked from commit ecb9a48040)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
ec500391d6 libnm: remove nm_device_6lowpan_get_hw_address()
Remove the function from a public header. It was missing from libnm.ver
and thus never actually exported.

There's no point in salvaging it now as it nm_device_get_hw_address()
exists as a better option.

(cherry picked from commit bd3239cf6c)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
3c1471d9ca libnm: export nm_setting_ip_config_get_dhcp_iaid
The export was left out when the symbol was added; apparently by
accident.

Let's also bump the documented version of when is the symbol supposed to
be available, because it actually wasn't.

Fixes: 56a1a5426a ('all: add ipvX.dhcp-iaid properties')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1447
(cherry picked from commit 941e8b70f8)

Compared to version in main branch, the Since tags and
NM_AVAILABLE_IN_* macros indicate the branched version.

Backport also includes commit c7f6a506ef ('libnm: move
nm_setting_ip_config_get_dhcp_iaid() to @libnm_1_40_4 version node'),
it wouldn't be possible to backport both separately.
2022-11-11 16:49:39 +01:00
Lubomir Rintel
310b5c66bb libnm: add NM_VERSION_1_40_4 2022-11-11 16:49:39 +01:00
Thomas Haller
f0203ba8ac nm-setting: fix static assertions for NM_SETTING_PARAM_* flags and numeric values
- the static assertions were wrong, there was a "," instead of "==".

- the numeric values were wrong, as shown by the static assertions.

- move the code comment to the implementation. This does not seem
  relevant for the library user and should not be in the public header.

Fixes: 08e845f651 ('nm-setting: mangle public constant to make g-ir-scanner happy')
(cherry picked from commit c884d4d347)
2022-11-11 16:49:39 +01:00
Lubomir Rintel
bf9a1bedb8 nm-setting: mangle public constant to make g-ir-scanner happy
Some versions of g-ir-scanner's C parser silently coerce unrecognized
symbols into zeroes [1]. Let's avoid that so that we don't end up with
wrong constants in our Gir data.

[1] https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/366

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1446
(cherry picked from commit 08e845f651)
2022-11-11 16:49:39 +01:00
Thomas Haller
ee6bf84559
core: filter out invalid Wake-On-Lan flags
NMSettingWired does not reject invalid flags. Filter them out in wake_on_lan_enable().
In practice, it makes no difference, the unknown flags were ignored anyway.

(cherry picked from commit c593834842)
2022-11-10 13:49:30 +01:00
Thomas Haller
40564c5d6a
ifcfg-rh: fix persisting all-default NMSettingEthtool with autoneg/wol flags
Fixes: 26ed9e6714 ('ifcfg-rh: fix persisting all-default NMSettingEthtool settings')
(cherry picked from commit 4303d33727)
2022-11-10 13:49:30 +01:00
Thomas Haller
553e037220
ifcfg-rh: fix persisting ethtool options
If there were any pause options and any non-pause options,
the created setting was invalid.

I don't think it's reasonably possible to parse the broken settings.
So there is no workaround trying to read the existing broken settings
from disk. Luckily, the broken setting was just silently ignored by
the parser, so you simply could not persist certain settings.

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

Fixes: 652ddca04c ('ethtool: Introducing PAUSE support')
(cherry picked from commit 21661c6f71)
2022-11-10 13:49:29 +01:00
Thomas Haller
3b3ed9f1cc
ifcfg-rh/tests: add test checking persisting ethtool settings to ifcfg-rh
There are still various failures. That will be fixed next.

(cherry picked from commit 3755e6b175)
2022-11-10 13:49:29 +01:00