Commit graph

33048 commits

Author SHA1 Message Date
Beniamino Galvani
ff81488583 docs: document the hostname management workflow
(cherry picked from commit 543ebef32b)
(cherry picked from commit 9f09d4d364)
2024-08-19 17:05:12 +02:00
Beniamino Galvani
e3861be845 core: also use /etc/hosts for hostname resolution
Before introducing the hostname lookup via nm-daemon-helper and
systemd-resolved, we used GLib's GResolver which internally relies on
the libc resolver and generally also returns results from /etc/hosts.

With the new mechanism we only ask to systemd-resolved (with
NO_SYNTHESIZE) or perform the lookup via the "dns" NSS module. In both
ways, /etc/hosts is not evaluated.

Since users relied on having the hostname resolved via /etc/hosts,
restore that behavior. Now, after trying the resolution via
systemd-resolved and the "dns" NSS module, we also try via the "files"
NSS module which reads /etc/hosts.

Fixes: 27eae4043b ('device: add a nm_device_resolve_address()')
(cherry picked from commit 410afccb32)
(cherry picked from commit cb54fe7ce9)
2024-08-19 17:04:49 +02:00
Beniamino Galvani
e86ddd9fc5 nm-daemon-helper: add "service" argument
Introduce a new argument to specify a comma-separated list of NSS
services to use for the "resolve-address" command. For now only accept
"dns" and "files"; the latter can be used to do a lookup into
/etc/hosts.

Note that previously the command failed in presence of extra
arguments. Therefore, when downgrading NetworkManager without
restarting the service, the previously-installed version of the daemon
(newer) would spawn the helper with the extra argument, and the
newly-installed version of the helper (older) would fail. This issue
only impacts hostname resolution and can be fixed by just restarting
the daemon.

In the upgrade path everything works as before, with the only
difference that the helper will use by default both "dns" and "files"
services.

Don't strictly check for the absence of extra arguments, so that in
the future we can introduce more arguments without necessarily break
the downgrade path.

(cherry picked from commit 229bebfae9)
(cherry picked from commit c36a74f698)
2024-08-19 16:56:00 +02:00
Fernando Fernandez Mancera
90edd623ad merge: branch 'th/lldp-fix-crash'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2007

(cherry picked from commit 79c1f8c93a)

(cherry picked from commit 62d745fc9f)
2024-08-19 15:24:05 +02:00
Thomas Haller
9905bcdcb7 lldp: fix multiple access to argument in logging macro
Fixes: 630de288d2 ('lldp: add libnm-lldp as fork of systemd's sd_lldp_rx')
(cherry picked from commit 4365de5226)
(cherry picked from commit a1c18ce20d)
2024-08-19 15:24:05 +02:00
Thomas Haller
6da9b98975 lldp: fix crash dereferencing NULL pointer during debug logging
During nm_lldp_neighbor_parse(), the NMLldpNeighbor is not yet added to
the NMLldpRX instance. Consequently, n->lldp_rx is NULL.

Note how we use lldp_x for logging, because we need it for the context
for which interface the logging statement is.

Thus, those debug logging statements will follow a NULL pointer and lead
to a crash.

Fixes: 630de288d2 ('lldp: add libnm-lldp as fork of systemd's sd_lldp_rx')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1550
(cherry picked from commit c2cddd3241)
(cherry picked from commit 8a2f7bd6e0)
2024-08-19 15:24:05 +02:00
Wen Liang
02db74ed0b policy: unblock the autoconnect for children when parent is available
When parent is available and in the process of activation, we should
unblock the autoconnect and schedule an auto activate for the children.
Notice that when the parent is the ovs-interface, the kernel link is
only created in stage3, if we only unblock the children in the stage1,
then the children device and connection will be blocked again due
to the fact the kernel link for the parent ovs-interface is not
existed yet, thus, we have to separately unblock the children
when the parent ovs-interface is in the activated state.

https://issues.redhat.com/browse/RHEL-46904
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2003
https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/1735
(cherry picked from commit 5f64f292e6)
(cherry picked from commit 8243425c6d)
2024-08-13 08:37:10 -04:00
Fernando Fernandez Mancera
f8f5626f72 ovs: fix triggering stage3 activation without DHCP client initialized
It is possible that we learn the link is ready on stage3_ip_config
rather than in link_changed event due to a stage3_ip_config scheduled by
another component. In such cases, we proceed with IP configuration
without allocating the resources needed like initializing DHCP client.

In order to avoid that, if we learn during stage3_ip_config that the
link is now ready, we need to schedule another stage3_ip_config to
allocate the resources we might need.

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

Fixes: 83bf7a8cdb ('ovs: wait for the link to be ready before activating')
(cherry picked from commit 40d51b9104)
(cherry picked from commit 63dfd3b60b)
2024-07-31 11:09:31 +02:00
Fernando Fernandez Mancera
6328a1a0d1 ovs: wait for the link to be ready before activating
When activating an ovs-interface we already wait for the cloned MAC
address to be set, ifindex is present and platform link also present but
in some cases this is not enough.

If an udev rule is in place it might modify the interface when it is in
a later stage of the activation causing some race conditions or
problems. In order to solve that, we must wait until the link is fully
initialized.

(cherry picked from commit 83bf7a8cdb)
(cherry picked from commit 00e178351b)
2024-07-25 10:43:09 +02:00
Gris Ge
79c81fc06a activation: Allow changing controller of exposed active connection
When activating a port with its controller deactivating by new
activation, NM will register `state-change` signal waiting controller to
have new active connections. Once controller got new active connection,
the port will invoke `nm_active_connection_set_controller()` which lead
to assert error on
    g_return_if_fail(!nm_dbus_object_is_exported(NM_DBUS_OBJECT(self)))

because this active connection is already exposed as DBUS object.

To fix the problem, we remove the restriction on controller been
write-only and notify DBUS object changes for controller property.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 83a2595970)
(cherry picked from commit 3f3d1a4f54)
2024-07-19 13:16:47 +02:00
Beniamino Galvani
c11e1738ab crypto: regenerate PKCS#12 certificates
The PKCS#12 certificates are using SHA1 and RC2-40, which are deprecated;
regenerate them with:

 $ openssl pkcs12 -export -in test_key_and_cert.pem -inkey test_key_and_cert.pem -certfile test_ca_cert.pem -name "test-pkcs12" -out test-cert.p12
 (key: test)

 $ openssl pkcs12 -export -in test2_key_and_cert.pem -inkey test2_key_and_cert.pem -certfile test2_ca_cert.pem -name "test2-pkcs12" -out test2-cert.p12
 (key: 12345testing)

Before:
 $ openssl pkcs12 -info -in test-cert.p12
 MAC: sha1, Iteration 2048
 MAC length: 20, salt length: 8
 PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048

After:
 $ openssl pkcs12 -info -in test-cert.p12
 MAC: sha256, Iteration 2048
 MAC length: 32, salt length: 8
 PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
(cherry picked from commit 0d657af256)
2024-06-28 13:20:11 +02:00
Íñigo Huguet
6888e82db9 merge: branch 'ih/ci-1-46'
ci: run with distros that uses the current version and fix code format

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1976
2024-06-28 11:14:30 +00:00
Íñigo Huguet
91efd19bfc code format: run code format script 2024-06-28 11:14:22 +00:00
Íñigo Huguet
27ec4a126b ci: run with distros that uses the current version
Tier 1 and Tier 2: distros that uses 1.46.
Tier 3: distros not EOLd that don't use 1.46.
2024-06-28 11:14:22 +00:00
Beniamino Galvani
39c0e8cf30 release.sh: update version check
(cherry picked from commit cfc3f3fed7)
2024-06-24 13:41:55 +02:00
Íñigo Huguet
322558a4ea release: bump version to 1.46.3 (development) 2024-06-21 21:34:10 +02:00
Íñigo Huguet
0e75947916 release: bump version to 1.46.2 2024-06-21 21:34:10 +02:00
Beniamino Galvani
ecb26f5ad9 ovs: allow specifying a system OVS interface by MAC address
The OVS interface can be matched via MAC address; in that case, the
"connection.interface-name" property of the connection is empty.

When populating the ovsdb, we need to pass the actual interface name
from the device, not the one from the connection.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')

https://issues.redhat.com/browse/RHEL-34617
(cherry picked from commit be28a11735)
(cherry picked from commit 129f9e5be6)
2024-06-21 20:42:20 +02:00
Jan Vaclav
fff23d22ba gen-metadata-nm-settings-nmcli: add missing va_end in _prop_log() after using vaargs
It was missing before.

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

Fixes: af5c1c8019 ('man nm-settings-nmcli: autogenerate the "Format" field')
(cherry picked from commit 7d0115ea98)
(cherry picked from commit 7f8bbd6fcb)
2024-06-21 20:40:33 +02:00
Thomas Haller
0a79e98012 contrib/rpm: rename section in "22-wifi-mac-addr.conf"
For [connection*] and [device*] sections, any suffix is allowed in
the group.

However (at least for configuration snippets we ship upstream), we
want to give a suffix that matches the name of the configuration
snippet.

It seems more common to use [connection-*] instead of [connection.].
See also "examples/nm-conf.d/*.conf" and "15-carrier-timeout.conf" file
which contains a [device-15-carrier-timeout] section.

Note that this file (in Fedora) is not configuration (installed in
/usr/lib). It is thus not problematic to modify.

Fixes: ea8dbd7a6d ('contrib/rpm: add "22-wifi-mac-addr.conf" to F40+')
(cherry picked from commit 439ddc5101)
(cherry picked from commit acc70b01b6)
2024-06-21 20:40:33 +02:00
Thomas Haller
697ee0388b config: fix crash in assertion during NetworkManager --print-config
Fixes: f6345180b1 ('core/config: fix duplicate entires in `NetworkManager --print-config` output')
(cherry picked from commit 5472f28a40)
(cherry picked from commit 41a5cb5308)
2024-06-21 20:40:32 +02:00
Íñigo Huguet
d8dea253c7 po: add nm-setting-generic.c for translation
Translatable strings were added to nm-setting-generic.c. Add this file to
POTFILES.in.

Fixes: 9322c3e9db ('libnm: add generic.device-handler property')
(cherry picked from commit f84282a880)
(cherry picked from commit 19247325bc)
2024-06-21 20:40:32 +02:00
Íñigo Huguet
02c1869ed4 meson: exclude intermediate files of docs generation from tarball
We want to distribute the generated documentation when we generate the
tarball because we normally do it when we do a release, but `meson dist`
only includes files that are commited to the repository, so a script
meson-dist-data.sh was added with meson.add_dist_script in commit
1c41066a40 ('build: include documentation in meson dist').

This script was copying the whole documentation folders, including some
intermediate files that are not useful for users that wants to read the
docs. Get rid of them and copy only the files that are useful for users:
the generated html pages in docs/api and docs/libnm and the final man
pages.

Also, including these intermediate files caused at least one build
failure, although quite difficult to reproduce:
- Generate tarball with meson
- Untar the generated tarball
- Using the sources from the tarball, configure the project with
  autotools, but building to an out-of-tree folder, not building in
  the source dir (i.e. using a 'build' subfolder). This is called
  a "VPATH build" by autotools and Make. See:
  - https://www.gnu.org/software/make/manual/html_node/General-Search.html
  - https://www.gnu.org/software/automake/manual/html_node/VPATH-Builds.html
- Build

In that scenario, we get an error trying to generate any file under man/
because the man/ subdirectory has not been created. The reason of this
was that the man/ subdirectory is created by the Makefile when
generating the file man/common.ent. However, this file was present in
the source directory because it has been included in the tarball, so
Make detects it and doesn't run the rules to generate it. The result is
that out-of-tree-dir/man folder is not created.

Not including the intermediate files solves this problem.

Fixes: 1c41066a40 ('build: include documentation in meson dist')
(cherry picked from commit 723ad4c0ad)
2024-06-21 20:40:32 +02:00
Jan Vaclav
581e0b0f2a libnm/wired: fix mac comparison in _remove_mac_blacklist_item_by_value
The comparison checking for MAC address equality had previously been flipped around.

Fixes: b084ad7f2b ('libnm-core: canonicalize hardware addresses in settings')
(cherry picked from commit a9c4c1d84e)
2024-06-21 20:40:32 +02:00
Íñigo Huguet
d86f7843a6 NEWS: update for new stable release 2024-06-20 16:58:15 +02:00
Beniamino Galvani
e17e207b3c libnm-core: fix memory leak in nm_setting_to_string()
Fixes: f957ea2b34 ('core/setting: rework nm_connection_dump()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1934
(cherry picked from commit ee5f4402bf)
(cherry picked from commit a9d7554a02)
2024-06-19 14:43:31 +02:00
Íñigo Huguet
dbae0113db merge: branch 'ih/secret_hint_tags'
vpn: handle hint tags in the daemon

Closes #1536

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

(cherry picked from commit 730752bfc5)

(cherry picked from commit 10b246d03d)
2024-06-18 16:06:13 +02:00
Íñigo Huguet
a8a59e3e0a libnmc: don't strip prefix tags from secret names
The daemon is now capable of understanding and removing these prefix
tags by itself. It is better than this is not a responsibility of the
secret agent because it requires changes in all secret agents to work
properly (see https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1536).

If the secret agent knows what these prefix tags are, it can remove them
only in the text that is displayed in the UI, but maintaining the
original string as the secret name that is returned to the daemon.

Secret agents that doesn't know what these prefix tags are won't do
anything with them, and they will also return the same string as secret
name, as expected. The only drawback is that they might display the full
string to the user, which is not a nice UX but it will at least work.

Also, allow to translate the secret name for the UI in libnmc.

(cherry picked from commit 18240bb72d)
(cherry picked from commit e217ec040d)
2024-06-18 16:06:13 +02:00
Íñigo Huguet
bdbcda1e22 vpn: handle hint tags in the daemon
Commit 345bd1b187 ('libnmc: fix secrets request on 2nd stage of 2FA
authentication') and commit 27c701ebfb ('libnmc: allow user input in
ECHO mode for 2FA challenges') introduced 2 new tags that hints for the
secret agents can have as prefix.

These tags were processed (and removed) in the secret agents, not in the
daemon. This is wrong because a system with an updated VPN plugin but a
not yet updated secret agent (like nm-plasma) will fail: it won't remove
the prefix and the daemon will save the secret with the prefix, i.e.
"x-dynamic-challenge:challenge-response" instead of just
"challenge-response". Then, VPN plugins doesn't recognize it, failing the
profile's activation. This is, in fact, an API break.

Also, if the VPN connection already existed before updating NM and the
VPN plugin, the secret flags are not added to the profile (they are only
added when the profile is created or modified). This causes the user's
first time response is saved to the profile, so the activation fails the
second and next times.

See:
- https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1536
- https://gitlab.gnome.org/GNOME/NetworkManager-openvpn/-/issues/142

Anyway, in a good design the daemon should contain almost all the logic
and the clients should keep as simple as possible. Fix above's problems
by letting the daemon to receive the secret names with the prefix
already included. The daemon will strip it and will know what it means.

Note that this is done only in the functions that saves the secrets from
the data received via D-Bus. For example, nm_setting_vpn_add_secret
doesn't need to do it because this value shouldn't come from VPN
plugin's hints.

(cherry picked from commit 0583e1f843)
(cherry picked from commit 574741783c)
2024-06-18 16:06:13 +02:00
Beniamino Galvani
b9ea10339c merge: branch 'bg/vpn'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1938

Resolves: https://issues.redhat.com/browse/RHEL-21875

(cherry picked from commit b8061dd4f6)

(cherry picked from commit e26b5b06af)
2024-06-17 15:37:08 +02:00
Beniamino Galvani
83847cc621 vpn: allow IP configurations with routes and without addresses
Usually, when the method is "auto" we want to avoid configuring routes
until the automatic method completes. To achieve that, we clear the
"allow_routes_without_address" flag of l3cds when the method is "auto".

For VPNs, IP configurations with only routes are perfectly valid,
therefore set the flag.

(cherry picked from commit d1ffdb28eb)
(cherry picked from commit 5b4ed809cc)
2024-06-17 15:37:08 +02:00
Beniamino Galvani
e008ec7345 core: add nm_l3_config_data_set_allow_routes_without_address()
Add a function to set the allow-routes-without-address flag for
l3cds. It will be used in the next commit.

(cherry picked from commit a3ce13c947)
(cherry picked from commit 5fa063f90d)
2024-06-17 15:37:08 +02:00
Beniamino Galvani
ea731bba9b core: rename l3cd's "dhcp_enabled" to "allow_routes_without_address"
The name "dhcp_enabled" is misleading because the flag is set for
method=auto, which doesn't necessarily imply DHCP. Also, it doesn't
convey what the flag is used for. Rename it to
"allow_routes_without_address".

(cherry picked from commit b31febea22)
(cherry picked from commit 6897b6ecfd)
2024-06-17 15:37:08 +02:00
Beniamino Galvani
476a9553f6 vpn: allow IP configurations without addresses
An IPv4-over-IPv6 (or vice-versa) IPsec VPN can return IP
configurations with routes and without addresses. For example, in this
scenario:

         +---------------+         +---------------+
         |  fd01::10/64  <-- VPN -->  fd02::20/64  |
         |     host1     |         |     host2     |
         +-------^-------+         +-------^-------+
                 |                         |
         +-------v-------+         +-------v-------+
         |    subnet1    |         |    subnet2    |
         | 172.16.1.0/24 |         | 172.16.2.0/24 |
         +---------------+         +---------------+

host1 and host2 establish a IPv6 tunnel which encapsulates packets
between the two IPv4 subnets. Therefore, in routed mode, host1 will
need to configure a route like "172.16.2.0/24 via ipsec1" even if the
host doesn't have any IPv4 address on the VPN interface.

Accept IP configurations without address from the VPN; only check that
the address and prefix are sane if they are provided.

(cherry picked from commit 97f185e1f8)
(cherry picked from commit 518b7c5bd5)
2024-06-17 15:37:08 +02:00
Gris Ge
91f63030b1 checkpoint: fix port reactivation when controller is deactivating
Problem:

    Given a OVS port with `autoconnect-ports` set to default or false,
    when reactivation required for checkpoint rollback,
    previous activated OVS interface will be in deactivate state after
    checkpoint rollback.

The root cause:

    The `activate_stage1_device_prepare()` will mark the device as
    failed when controller is deactivating or deactivated.
    In `activate_stage1_device_prepare()`, the controller device is
    retrieved from NMActiveConnection, it will be NULL when NMActiveConnection
    is in deactivated state. This will cause device been set to
    `NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED` which prevent all follow
    up `autoconnect` actions.

Fix:
    When noticing controller is deactivating or deactivated with reason
    `NM_DEVICE_STATE_REASON_NEW_ACTIVATION`, use new function
    `nm_active_connection_set_controller_dev()` to wait on controller
    device state between NM_DEVICE_STATE_PREPARE and
    NM_DEVICE_STATE_ACTIVATED. After that, use existing
    `nm_active_connection_set_controller()` to use new
    NMActiveConnection of controller to move on.

Resolves: https://issues.redhat.com/browse/RHEL-31972

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a68d2fd780)
(cherry picked from commit 4726822fb0)
2024-06-01 17:18:58 +02:00
Thomas Haller
3f3f446f6e core: workaround "-Wnonnull-compare" warning in nm_lldp_neighbor_tlv_get_oui()
../src/libnm-lldp/nm-lldp-neighbor.c: In function ‘nm_lldp_neighbor_tlv_get_oui’:
  ../src/libnm-std-aux/nm-std-aux.h:191:12: error: ‘nonnull’ argument ‘oui’ compared to NULL [-Werror=nonnull-compare]
    191 |         if (expr)                      \
        |            ^
  ../src/libnm-std-aux/nm-std-aux.h:202:27: note: in expansion of macro ‘_NM_BOOLEAN_EXPR_IMPL’
    202 |                           _NM_BOOLEAN_EXPR_IMPL(NM_UNIQ, expr))
        |                           ^~~~~~~~~~~~~~~~~~~~~
  ../src/libnm-glib-aux/nm-macros-internal.h:1693:31: note: in expansion of macro ‘NM_BOOLEAN_EXPR’
   1693 | #define _G_BOOLEAN_EXPR(expr) NM_BOOLEAN_EXPR(expr)
        |                               ^~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gmacros.h:1244:43: note: in expansion of macro ‘_G_BOOLEAN_EXPR’
   1244 | #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
        |                                           ^~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gmessages.h:661:9: note: in expansion of macro ‘G_LIKELY’
    661 |     if (G_LIKELY (expr)) \
        |         ^~~~~~~~
  ../src/libnm-lldp/nm-lldp-neighbor.c:651:5: note: in expansion of macro ‘g_return_val_if_fail’
    651 |     g_return_val_if_fail(oui, -EINVAL);
        |     ^~~~~~~~~~~~~~~~~~~~

(cherry picked from commit a500538fb2)
2024-06-01 17:18:58 +02:00
Beniamino Galvani
172278bbd7 merge: branch 'bg/rollback-in-memory'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1920
(cherry picked from commit a0f798342a)
2024-05-23 13:48:02 +02:00
Beniamino Galvani
ebf25794d9 checkpoint: preserve in-memory state of connections
If a connection is in-memory (i.e. has flag "unsaved"), after a
checkpoint and rollback it can be wrongly persisted to disk:

 - if the connection was modified and written to disk after the
   rollback, during the rollback we update it again with persist mode
   "keep", which keeps it on disk;

 - if the connection was deleted after the rollback, during the
   rollback we add it again with persist mode "to-disk".

Instead, remember whether the connection had the "unsaved" flag set
and try to restore the previous state.

However, this is not straightforward as there are 4 different possible
states for the settings connection: persistent; in-memory only;
in-memory shadowing a persistent file; in-memory shadowing a detached
persistent file (i.e. the deletion of the connection doesn't delete
the persistent file). Handle all those cases.

Fixes: 3e09aed2a0 ('checkpoint: add create, rollback and destroy D-Bus API')
(cherry picked from commit c979bfeb8b)
2024-05-23 13:46:24 +02:00
Beniamino Galvani
e5837aa1d3 settings: add nm_settings_connection_persist_mode_to_string()
(cherry picked from commit a48b7fe7b9)
2024-05-23 13:44:11 +02:00
Beniamino Galvani
9f992dd85e dcb: fix test compilation
GCC 14 with LTO generates the following warning:

  src/core/tests/test-dcb.c: In function 'test_dcb_cleanup':
  src/core/tests/test-dcb.c:283:5: error: array subscript _3 is outside array bounds of 'const char *[0:]' [-Werror=array-bounds=]
    283 |     g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
        |     ^
  src/core/tests/test-dcb.c:14:17: note: while referencing 'cmds'
     14 |     const char *cmds[];
        |                 ^
  src/core/tests/test-dcb.c:261:24: note: defined here 'expected'
    261 |     static DcbExpected expected = {
        |                        ^

Define the commands as a fixed array instead of flexible array member.

(cherry picked from commit 9ff7ff28fc)
2024-05-15 12:11:57 +02:00
Beniamino Galvani
efa1d0e173 libnm-core: avoid compiler warnings in team settings
GCC 14 with LTO complains with:

  In function 'nm_team_link_watcher_new_ethtool',
      inlined from 'nm_team_link_watcher_new_ethtool' at src/libnm-core-impl/nm-setting-team.c:106:1:
  src/libnm-core-impl/nm-setting-team.c:130:33: error: array subscript 'struct NMTeamLinkWatcher[0]' is partly outside array bounds of 'unsigned char[16]' [-Werror=array-bounds=]
    130 |     watcher->ref_count          = 1;
        |                                 ^
  src/libnm-core-impl/nm-setting-team.c:128:15: note: object of size 16 allocated by 'g_malloc'
    128 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^

even if the warning is disabled via pragma directives in that
code. This looks like the following GCC bug:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80922

saying

  We do not track warning options (and thus optimize pragmas /
  attributes) across LTO because they are not saved in the function
  specific optimization flag section.

We use a (NMTeamLinkWatcher *) to point to a memory area that is
shorter than the struct, because depending on the watcher type we need
to store different parameters; in this way we can save few bytes of
memory for some watcher types. However, this often breaks when
upgrading the compiler; instead just allocate the full struct.

(cherry picked from commit d369f55192)
2024-05-15 12:11:52 +02:00
Beniamino Galvani
78d5ba4d4f libnm-glib-aux: fix comments about UUID generation
Whether the length is supplied explicitly or implicitly (via -1), the
result is the same. Update the comment.

(cherry picked from commit fcea2f174e)
2024-05-15 12:11:42 +02:00
Beniamino Galvani
cbf20a2317 libnm-glib-aux: fix "maybe-uninitialized" error when generating UUID
GCC 14 complans with:

  src/libnm-glib-aux/nm-uuid.c: In function 'nm_uuid_generate_from_strings_strv':
  src/libnm-glib-aux/nm-uuid.c:492:12: error: '_1' may be used uninitialized [-Werror=maybe-uninitialized]
    492 |     return nm_uuid_generate_from_string_str(s, slen, uuid_type, type_args);
        |            ^
  src/libnm-glib-aux/nm-uuid.c:392:1: note: by argument 1 of type 'const char *' to 'nm_uuid_generate_from_string_str' declared here
    392 | nm_uuid_generate_from_string_str(const char   *s,
        | ^

"-Wmaybe-uninitialized" diagnoses passing pointers or references to
uninitialized memory to functions taking const-qualified arguments.

In this case, nm_uuid_generate_from_string_str()'s first argument is a
"const char *" and so the compiler expects that the string is always
initialized. However, it is not initialized when len is zero.

A non-null zero-length array can be specified in two ways: by setting
len to zero, or by setting len to -1 and having NULL as first
element. Handle both cases in the same way.

(cherry picked from commit 2386c0f52d)
2024-05-15 12:11:35 +02:00
Íñigo Huguet
15ffa8ec6f platform: avoid routes resync for routes that we don't track
When we recibe a Netlink message with a "route change" event, normally
we just ignore it if it's a route that we don't track (i.e. because of
the route protocol).

However, it's not that easy if it has the NLM_F_REPLACE flag because
that means that it might be replacing another route. If the kernel has
similar routes which are candidates for the replacement, it's hard for
NM to guess which one of those is being replaced (as the kernel doesn't
have a "route ID" or similar field to indicate it). Moreover, the kernel
might choose to replace a route that we don't have on cache, so we know
nothing about it.

It is important to note that we cannot just discard Netlink messages of
routes that we don't track if they has the NLM_F_REPLACE. For example,
if we are tracking a route with proto=static, we might receive a replace
message, changing that route to proto=other_proto_that_we_dont_track. We
need to process that message and remove the route from our cache.

As NM doesn't know what route is being replaced, trying to guess will
lead to errors that will leave the cache in an inconsistent state.
Because of that, it just do a cache resync for the routes.

For IPv4 there was an optimization to this: if we don't have in the
cache any route candidate for the replacement there are only 2 possible
options: either add the new route to the cache or discard it if we are
not interested on it. We don't need a resync for that.

This commit is extending that optimization to IPv6 routes. There is no
reason why it shouldn't work in the same way than with IPv4. This
optimization will only work well as long as we find potential candidate
routes in the same way than the kernel (comparing the same fields). NM
calls to this "comparing by WEAK_ID". But this can also happen with IPv4
routes.

It is worth it to enable this optimization because there are routing
daemons using custom routing protocols that makes tens or hundreds of
updates per second. If they use NLM_F_REPLACE, this caused NM to do a
resync hundreds of times per second leading to a 100% CPU usage:
https://issues.redhat.com/browse/RHEL-26195

An additional but smaller optimization is done in this commit: if we
receive a route message for routes that we don't track AND doesn't have
the NLM_F_REPLACE flag, we can ignore the entire message, thus avoiding
the memory allocation of the nmp_object. That nmp_object was going to be
ignored later, anyway, so better to avoid these allocations that, with
the routing daemon of the above's example, can happen hundreds of times
per second.

With this changes, the CPU usage doing `ip route replace` 300 times/s
drops from 100% to 1%. Doing `ip route replace` as fast as possible,
without any rate limitting, still keeps NM with a 3% CPU usage in the
system that I have used to test.

(cherry picked from commit 4d426f581d)
2024-05-13 13:33:06 +02:00
Wen Liang
86fbfb3806 device: use subnet when the applied connection has IPv6 method shared
We should use the IPv6 subnet when we have an applied connection
stored on the downlink device, and the IPv6 method should be "shared"
for that applied connection. It does not make sense to register l3cd
and set router config for ndisc instance when the downlink device is
already deactivated.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1880
Resolves: https://issues.redhat.com/browse/RHEL-17350

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
(cherry picked from commit 15901a7489)
2024-05-02 14:35:22 +02:00
Íñigo Huguet
2636797b0b man: fix missing deprecation message
In the gtkdoc comments, the text below tags like `Since: 1.2` is
discarded. In the property `autoconnect-slaves` a line indicating its
deprecation was below one of these tags. As a result, it was missing in
the man page. Fix it.

Fixes: 194455660d ('connection: deprecate NMSettingConnection autoconnect-slaves property')
(cherry picked from commit 7427e9d320)
2024-04-18 15:31:54 +02:00
Fernando Fernandez Mancera
2fac176986 libnm-lldp: use ETH_P_ALL instead of NM_ETHERTYPE_LLDP for the socket
When creating the socket for listening to LLDP frames we are setting
NM_ETHERTYPE_LLDP (0x88cc) as protocol. In most of the cases, that is
correct but when the interface is attached as a port to a OVS bridge,
kernel is not matching the protocol correctly. The reason might be that
some metadata is added to the packet, but we are not completely sure
about it.

Instead, we should use ETH_P_ALL to match all the protocols. Later, we
have a eBPF filter to drop the packet by multicast MAC address or
protocol. This is how lldpd is doing it for example.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1903
(cherry picked from commit 9ac1d6e22b)
2024-04-05 11:52:18 +02:00
Beniamino Galvani
809c2d7c50 device: ignore error setting mac if it's a global special value
If the distro sets a global special value for the cloned MAC address
(for example, "stable-ssid") and the driver doesn't support changing
the MAC, all activations will fail on the interface unless users know
that they need to change the cloned MAC. Be more tolerant to errors in
case the MAC is global and special.

https://bugzilla.redhat.com/show_bug.cgi?id=2270062
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1898
(cherry picked from commit d534f984f7)
2024-03-29 14:00:58 +01:00
Beniamino Galvani
6f3739e76f manager: fix race condition while enumerating devices at startup
While enumerating devices at startup, we take a snapshot of existing
links from platform and we start creating device instances for
them. It's possible that in the meantime, while processing netlink
events in platform_link_added(), a link gets renamed. If that happens,
then we have two different views of the same ifindex: the cached link
from `links` and the link in platform.

This can cause issues: in platform_link_added() we create the device
with the cached name; then in NMDevice's constructor(), we look up
from platform the ifindex for the given name. Because of the rename,
this lookup can match a newly created, different link.

The end result is that the ifindex from the initial snapshot doesn't
get a NMDevice and is not handled by NetworkManager.

Fix this problem by fetching the latest version of the link from
platform to make sure we have a consistent view of the state.

https://issues.redhat.com/browse/RHEL-25808
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1897
(cherry picked from commit de130df3e2)
2024-03-26 10:53:55 +01:00
Beniamino Galvani
669bf33de3 nm-dispatcher: fix crash when parsing output dictionary
'stdout' is NULL when the script didn't write anything or failed.

Fixes the following crash detected by NMCI in test
'dispatcher_device_handler_dummy'.

  nm-dispatcher[936339]: g_strsplit: assertion 'string != NULL' failed

  build_result_options (nm-dispatcher)
  complete_request (nm-dispatcher)
  complete_script (nm-dispatcher)
  script_watch_cb (nm-dispatcher)
  g_child_watch_dispatch (libglib-2.0.so.0)
  g_main_dispatch (libglib-2.0.so.0)
  g_main_context_iterate (libglib-2.0.so.0)
  g_main_context_iteration (libglib-2.0.so.0)
  main (nm-dispatcher)
  __libc_start_main (libc.so.6)
  _start (nm-dispatcher)

Fixes: d72f26b875 ('dispatcher: read device-handler's stdout into a dictionary')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1889
(cherry picked from commit e5c2c5f1c2)
2024-03-26 10:53:43 +01:00