Commit graph

34212 commits

Author SHA1 Message Date
Beniamino Galvani
b571e2be5a man: fix syntax to match on connection-id
Fixes: 604c611cd0 ('core: add nm_utils_connection_match_spec_list()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1746
2025-04-15 11:15:02 +02:00
Filip Pokryvka
ec6d122cc9 release: bump version to 1.53.3 (development) 2025-04-14 19:16:15 +02:00
Beniamino Galvani
065fd3e046 merge: branch 'bg/rto-min'
platform: always set the lock flag for RTO_MIN

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2179
2025-04-14 14:43:09 +00:00
Beniamino Galvani
6478e5158a platform: always set the lock flag for RTO_MIN
The rto-min value is ignored by kernel unless the lock flag is set.
2025-04-14 16:41:39 +02:00
Beniamino Galvani
2b922a93a5 platform: accept 0 as valid rto_min value
iproute2 and the kernel accept 0 as valid rto_min value:

  # ip route add 172.16.0.1 dev enp1s0 rto_min 0ms
  # ip route show
  172.16.0.1 dev enp1s0 scope link rto_min lock 0ms

Even if a value of 0ms would not be useful in practice, it is better
to exactly track what kernel reports, instead of assuming that when
the value is zero it is "not set".
2025-04-14 16:41:39 +02:00
Beniamino Galvani
14106431fb libnm-core: set ovs-dpdk and ovs-patch as non-base settings
Settings "ovs-dpdk" and "ovs-patch" are currently marked with priority
NM_SETTING_PRIORITY_HW_BASE, which makes them "base" settings. This
means that they can be used as connection type, for example via "nmcli
connection add type ovs-dpdk ...".

This is wrong, as both settings can only belong to a connection of
type "ovs-interface". Decrease their priority and make them non-base
settings.

The problem was spotted when trying to add a ovs-patch connection via
nmcli:

  # nmcli connection add type ovs-patch ifname p con-name q ovs-patch.peer r controller s port-type ovs-port
  Warning: controller='s' doesn't refer to any existing profile.

  (process:4580): nm-CRITICAL **: 10:15:42.807: file ../src/libnm-core-impl/nm-connection.c: line 1682 (_normalize_ovs_interface_type): should not be reached

  (process:4580): nm-WARNING **: 10:15:42.807: connection did not verify after normalization: ??

  (process:4580): nm-CRITICAL **: 10:15:42.807: file ../src/libnm-core-impl/nm-connection.c: line 2170 (_connection_normalize): should not be reached
  Error: Failed to add 'q' connection: ovs-interface.type: A connection with 'ovs-patch' setting must be of connection.type "ovs-interface" but is "ovs-patch"

Fixes: d0ec501163 ('cli: assert that valid_parts are set for base types')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2178
2025-04-14 13:39:13 +02:00
Beniamino Galvani
37d8945b13 libnm: fix memory leak when parsing IP configuration
When the dictionary contains keys "address" and "uri", the first value
is leaked.

  ==4730== 14 bytes in 1 blocks are definitely lost in loss record 51 of 1,755
  ==4730==    at 0x4841866: malloc (vg_replace_malloc.c:446)
  ==4730==    by 0x4CC5CB9: g_malloc (gmem.c:100)
  ==4730==    by 0x4CDF518: g_strdup (gstrfuncs.c:323)
  ==4730==    by 0x496A6B8: g_strdup_inline (gstrfuncs.h:321)
  ==4730==    by 0x496A6B8: nm_inet_ntop_dup (nm-inet-utils.h:355)
  ==4730==    by 0x496A95B: nm_inet_parse_str (nm-inet-utils.c:539)
  ==4730==    by 0x48AF3A3: _notify_update_prop_nameservers (nm-ip-config.c:179)

Fixes: 4422b14704 ('core, libnm: support per-connection DNS URIs')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2184
2025-04-14 13:36:57 +02:00
Íñigo Huguet
26f2673b90 merge: branch 'ih/nmcli-ovs-port-type'
nmcli: connection: process port-type, type and controller properties first

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2165
2025-04-14 10:08:28 +00:00
Íñigo Huguet
9f6562869b nmcli: improve the warning message about no controller found
When nmcli tries to match a controller it filters by its type. The
controller's type must match with the port's port-type. If no controller
matches, the printed warning was "doesn't refer to any existing
profile". However, the profile might exist, but with wrong type. Improve
the message so it makes that clear.

Fixes: aa12bb353b ('cli: discover slave type for a connection with a master')
2025-04-14 10:08:01 +00:00
Íñigo Huguet
87a5d89f75 nmcli: choose the right port-type for OVS
Normally it is possible not to define port-type in nmcli and it deduces
it from connection.type or connection.controller. Some types like 'bond-slave'
have a single possible value for port-type. In other cases nmcli deduces
the port-type by getting the controller's type, like 'bond'.

For OVS connections, the second method of guessing by the controller's
type was used.  However, in OVS it is common to have different devices
with the same name, causing nmcli to use "ovs-interface" as port-type
if it matched by controller name.

Fix if by deducing the port-type from the connection's type. An ovs-port
connection must always have port-type=ovs-bridge, and an ovs-interface
connection must always have port-type=ovs-port.

Note that this is something that should be done in the daemon, not in
the clients, but this is a small patch that makes it to work in nmcli,
at least. Without this, the mechanism of guessing from the parent would
act, leading to wrong results.

Ideally, all this should be done in the daemon, but currently many
checks in nmcli/libnm depends on having the port-type set, and it
would be lot of work to change it.

Fixes: c5324ed285 ('nmcli: streamline connection addition')
2025-04-14 10:08:01 +00:00
Íñigo Huguet
6a133d10a1 nmcli: connection: don't overwrite port-type if explicitly set
When processing the "type" property we deduce the port-type in some
cases and set it. If the user has chosen a port-type we must not
overwrite it. In any case, we should raise an error when validating the
connection.

Fixes: c5324ed285 ('nmcli: streamline connection addition')
2025-04-14 10:08:01 +00:00
Íñigo Huguet
bb850fda0e nmcli: connection: process port-type, type and controller first
If the connection is a port we need to set the connection.port-type
property. Usually this property is guessed by nmcli depending on the
connection type or the chosen controller, so it doesn't need to be
specified by the user. However, if it is explicitly set by the user
we should not guess, but just use it.

When we process arguments like "controller" or "type" we call custom
functions like set_connection_controller that will guess the port-type
if needed. By processing port-type first, it will be set in the
connection by the time that these other properties are processed, so they
won't try to guess.

After port-type, process connection.type and connection.controller, as we
are usually capable of deducing the port-type from them. Type needs to
be processed first because some types like bond-slave or ovs-port have
only one possible port-type value so we must not try to guess from the
controller.

Fixes: c5324ed285 ('nmcli: streamline connection addition')
2025-04-14 10:08:01 +00:00
Beniamino Galvani
fcf304bbf1 merge: branch 'carrier-down'
device: renew dhcp lease if carrier was down

Closes #1663

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2173
2025-04-14 07:48:44 +00:00
Friedrich Altheide
163c2574d8 device: renew dhcp lease only if carrier was down
Make sure nm_device_update_dynamic_ip_setup is called every time a carrier was down before and the link is now up again.
Previously the dhcp lease was not renewed if the carrier went down and then up again quickly enough.
This led to cases where an old IP was retained even though the device was connected to a different network with a different DHCP server.

This commit introduces device_link_carrier_changed_down

Fixes: d6429d3ddb ('device: ensure DHCP is restarted every time the link goes up')
2025-04-14 07:04:03 +02:00
Lubomir Rintel
fe0b6ad68c merge: branch 'lr/oci-vm-new-conn'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2180
2025-04-11 12:09:49 +02:00
Lubomir Rintel
cb7157f552 test-client: add test for OCI VNIC on VM
Tests that we create a connection for disconnected device.
2025-04-11 11:44:05 +02:00
Lubomir Rintel
c42322bd0d test-client: split up _mock_devices()
The new VM OCI VNIC tests will need to create the devices, but leave one
disconnected.
2025-04-11 11:44:05 +02:00
Lubomir Rintel
39db524d94 test-client: expand MAC addresses from variable
Less literals, more expanded variables. Makes it a little easier to read
for me.
2025-04-11 11:44:05 +02:00
Lubomir Rintel
79b1877c02 test/nm-service: default the devices to DISCONNETED not UNAVAILABLE
It is a little odd that client tests connect "UNAVAILABLE" devices, and
the devices return to "DISCONNECTED" after deactivation.

It differs from what happens in reality, and some client tools
(hey nm-cloud-setup) can break when they rightly assume that the
device is not ready for activation when it's "UNAVAILABLE" not
"DISCONNECTED".
2025-04-11 11:44:05 +02:00
Lubomir Rintel
548e27ef5f cloud-setup: configure disconnected wired devices on OCI
On OCI VMs (virtual machines, as opposed to BM -- bare metal), the VNICs
don't get their addresses via DHCP and need us to get the address from
the metadata and apply it.

https://issues.redhat.com/browse/NMT-1432
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2180
2025-04-11 11:44:05 +02:00
Lubomir Rintel
0540b3c9bc cloud-setup: add a chicken bit variable for creation of new connections
Make it possible to opt in or out of the behavior of creating
connections for disconnected devices. It's not clear why such policy was
in place, and the feature might come useful outside OCI.

Let's add an (undocumented) knob to configure the behavior. We might
remove it (and perhaps make the behaviour default everywhere), or
document and keep it if it turns out we need to use it.
2025-04-11 11:43:28 +02:00
Lubomir Rintel
93960639e8 cloud-setup: factor out creation of new connection
We're going to create connections on wired devices for OCI VM VNICs, and
they're going to also need the same user setting. Factor it out.
2025-04-11 11:43:20 +02:00
Lubomir Rintel
9895540a24 cloud-setup: add device argument to nmcs_add_and_activate()
This will allow us to add & complete connections for existing devices,
such as VNICs on OCI VMs.
2025-04-11 11:43:00 +02:00
Lubomir Rintel
961be7d971 cloud-setup: split up _nmc_skip_connection_by_type()
Split _nmc_skip_connection_by_type() so that we can get a little
more finely grained error reporting.
2025-04-11 11:42:54 +02:00
Íñigo Huguet
95b9b4b678 merge: branch 'ih/coverity'
Fix some defects detected by Coverity

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2174
2025-04-07 14:15:27 +00:00
Íñigo Huguet
9edfc0438c n-dhcp4: fix resource leaks
The function n_dhcp4_c_connection_send_request does not release or take
ownership of its request argument. Because of that, setting it to NULL
in the caller prevents the auto-cleanup of the variable to be executed,
causing a resource leak. Fix it.

Fixes: e23b3c9c3a ('Squashed 'shared/n-dhcp4/' content from commit fb1d43449')
Fixes: 243cc433fb ('n-dhcp4: add new client probe function to send RELEASE message')
2025-04-07 14:15:09 +00:00
Íñigo Huguet
ae7de5b353 core: fix use after free in ping operations
Detected by coverity, the ping_op pointers are used after being freed in
cleanup_ping_operations. Although calling to g_list_remove is probably
safe because it only needs the value of the pointer, not to dereference
it, better to follow best practices. One of the use after free was
actually an error because we dereference ping_op->log_domain.

Fixes: 658aef0fa1 ('connection: Support connection.ip-ping-addresses')
2025-04-07 14:15:09 +00:00
Íñigo Huguet
42edb37499 bond-slb: initialize dest hw address in GARP packets
Detected by Coverity:
    1. NetworkManager-1.53.1/src/core/nm-bond-manager.c:885:5: var_decl: Declaring variable "data" without initializer.
    7. NetworkManager-1.53.1/src/core/nm-bond-manager.c:948:13: uninit_use_in_call: Using uninitialized value "data". Field "data.d_hw_addr" is uninitialized when calling "sendto".
       946|               unaligned_write_ne32(data.s_ip_addr, tmp_addr);
       947|               unaligned_write_ne32(data.d_ip_addr, tmp_addr);
       948|->             if (sendto(sockfd, &data, sizeof(data), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
       949|                   return FALSE;
       950|           }

Fixes: 3f2f922dd9 ('bonding: send ARP announcement on bonding-slb link/carrier down')
2025-04-07 14:15:09 +00:00
Lubomir Rintel
cc0222ba01 nmcli/connections: fix build with libedit
This has always been broken (libedit-0:3.1-17.20160618cvs.fc26 is too
old to work and libedit-0:3.1-20.20170329cvs.fc27.x86_64 has this type
mismatch), but new GCC complains (14, 15).

  ../src/nmcli/connections.c: In function ‘nmcli_editor_tab_completion’:
  ../src/nmcli/connections.c:6862:64: error: assignment to ‘void (*)(char **, int,  int)’ from incompatible pointer type ‘void (*)(void)’ [-Wincompatible-pointer-types]
   6862 |                             rl_completion_display_matches_hook = uuid_display_hook;
        |                                                                ^
  ../src/nmcli/connections.c:6909:60: error: assignment to ‘void (*)(char **, int,  int)’ from incompatible pointer type ‘void (*)(void)’ [-Wincompatible-pointer-types]
   6909 |                         rl_completion_display_matches_hook = uuid_display_hook;
        |                                                            ^

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2172
2025-04-07 15:27:59 +02:00
Herman Semenov
7ab3f0999f nm-cloud-setup: removed excess validation check fields
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2150
2025-04-07 15:25:49 +02:00
Íñigo Huguet
a4401ae0a6 merge: branch 'ih/fec-uninit-var'
core: fail early if we cannot get current FEC value

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2177
2025-04-07 11:05:25 +00:00
Íñigo Huguet
245f0e0b35 core: optimize hash table search in _ethtool_fec_set
Break the loop as soon as we've found the value.

Fixes: 19bed3121f ('ethtool: support Forward Error Correction(fec)')
2025-04-03 09:44:59 +02:00
Íñigo Huguet
cbdd0d9cca core: fail early if we cannot get current FEC value
If we cannot get current FEC value probably we won't be able to set it a
few lines later. Also, if it fails to set, we try to use the value of
the old one that we tried to retrieve without success. In that case, the
variable old_fec_mode would be uninitialized. Fix it by returning early
if we cannot get the current value.

Fixes: 19bed3121f ('ethtool: support Forward Error Correction(fec)')
2025-04-03 09:44:54 +02:00
Beniamino Galvani
355edef8b5 merge: branch 'bg/prefix-delegation'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2162
2025-04-02 17:05:57 +02:00
Beniamino Galvani
b6386b3d27 core: support prefix-delegation.subnet-id 2025-04-02 11:21:59 +02:00
Beniamino Galvani
b372caf0c4 libnm, nmcli: introduce new "prefix-delegation" setting
Introduce a new "prefix-delegation" setting. It contains properties
related to the configuration of downstream interfaces using IPv6
prefix-delegation. The only property at the moment is "subnet-id",
which specifies which prefix to choose when the delegation contains
multiple /64 networks.
2025-04-02 11:21:59 +02:00
Beniamino Galvani
4a8bedcd89 device: remove the prefix-delegation IP configuration on cleanup
When a device in IPv6 shared mode obtains a prefix, it adds a new l3cd
of type L3_CONFIG_DATA_TYPE_PD_6 for that prefix. However, that l3cd
is never removed later and so the address lingers on the interface
even after the connection goes down. Remove the l3cd on cleanup.
2025-04-02 11:18:02 +02:00
Beniamino Galvani
037b14965e libnmc-setting: add new flag for property descriptors
Add a new flag "print_hex_negative_as_base10" in the property
descriptor _NMMetaPropertyTypData.

Normally, when a property has "base = 16", it is printed as unsigned
even if the gtype is signed.

For some properties, we want to print the hexadecimal representation
for positive values, and the base10 representation with minus sign for
negative values. A typical use case is to encode the default value as
"-1" and use positive values as a hexadecimal number.
2025-04-02 11:18:02 +02:00
Beniamino Galvani
dbc4ff0a1d libnm-glib-aux: add nm_ip6_addr_get_subnet_id()
Add function nm_ip6_addr_get_subnet_id() to get the subnet ID of a
IPv6 address.
2025-04-02 11:18:02 +02:00
Beniamino Galvani
4ed1d04aff libnm-glib-aux: add nm_puint64_hash()/nm_puint64_equal()
The two new functions can be used as GHashFunc and GEqualFunc when
creating hash tables whose keys are pointers to a guint64.
2025-04-02 11:18:02 +02:00
Beniamino Galvani
0e4330f2b4 ovs: introduce new "ovs-dpdk.lsc-interrupt" property
Introduce a new "ovs-dpdk.lsc-interrupt", used to configure the Link
State Change (LSC) detection mode.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2149
2025-04-02 11:13:31 +02:00
Beniamino Galvani
4b572a1a4a device: forget about carrier deferred action when ifindex changes
When the carrier of an interface goes down, we defer the handling of
that event by some time (by default 6 seconds), to detect if the
carrier change was a spurious event.

It was observed that in some conditions the carrier goes down and we
register the timer for the deferred action on the device. Then the
link is deleted and recreated. At this point the timer fires and
aborts the new activation of the device.

Once the ifindex changes, cancel the timer for the deferred
carrier-down action.
2025-04-02 10:01:38 +02:00
Beniamino Galvani
ba86c208e0 Revert "core: prevent the activation of unavailable OVS interfaces only"
This was a workaround until the real cause of the issue was found.

This reverts commit a1c05d2ce6.
2025-04-02 10:01:38 +02:00
Wen Liang
40ddff9cc9 merge: branch 'wl/per_iface_ip_forward'
ip-config: Support configuring per-device IPv4 sysctl forwarding option

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2071
2025-04-01 13:43:11 +00:00
Wen Liang
2ad5fbf025 policy: refresh IPv4 forwarding after connection activation and disconnection
Previously, IPv4 shared method will automatically enable the IPv4
global forwarding, all the per-interface level IPv4 forwarding settings
may be changed to match the global setting. Also, all the per-inteface
level forwarding settings can not be restored when deactivating the
shared connection. This is problematic as it may disrupt custom
configurations and lead to inconsistent forwarding behavior across
different network interfaces.

To address this, the implementation now ensures that the original
per-interface forwarding settings are preserved. Upon activating a
shared connection, instead of enabling IPv4 global forwarding
automatically, the per-interface forwarding is enabled on all other
connections unless a connection explicitly has the forwarding set to
"no" in its configuration. Upon deactivating all shared connection,
per-interface forwarding settings are restored to sysctl's default
value. Furthermore, deactivating any connection explicitly sets the
forwarding to sysctl's default value ensuring that network forwarding
behavior remains consistent.
2025-04-01 09:32:46 -04:00
Wen Liang
a8a2e6d727 ip-config: Support configuring per-device IPv4 sysctl forwarding option
Add support for configuring per-interface IPv4 sysctl forwarding setting
in NetworkManager. The feature allows users to configure the
net.ipv4.conf.<interface>.forward setting directly through
NetworkManager, enabling targeted forwarding configurations for
interfaces. This is particularly useful for cases such as enabling
forwarding for MetalLB load balancing without requiring a global
ip_forward=1 setting.

While forwarding setting can be managed via /etc/sysctl.conf,
configuring sysctl options for dynamically created or
software-configured interfaces (e.g., bridges) poses challenges. With
this feature, NetworkManager can configure these settings when
interfaces are created or updated, users no longer need to rely on
nm-dispatcher scripts for per-interface sysctl configuration, which can
be error-prone and complex. This feature ensures a more seamless and
integrated way to manage per-interface forwarding configurations,
reducing user overhead and improving usability in complex network
setups.

We do not support configuring per-device IPv6 sysctl forwarding because
in order to make per-device IPv6 sysctl forwarding work, we also need to
enable the IPv6 global sysctl forwarding setting, but this has potential
security concerns because it changes the behavior of the system to
function as a router, which expose the system to new risks and
unintended traffic flows, especially when enabling forwarding on the
interface the user previously explicitly disabled. Also enabling
per-device IPv6 sysctl setting will change the behavior of router
advertisement (accept_ra), which is not expected. Therefore, we
only support configuring per-device IPv4 sysctl forwarding option in
NetworkManager.

Resolves: https://issues.redhat.com/browse/RHEL-60237
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2071
https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/1833
2025-04-01 09:32:46 -04:00
Jan Vaclav
5e17b52810 merge: branch 'jv/wg-nftables'
wireguard: add connmark and filtering firewall rules

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2158
2025-04-01 08:09:17 +00:00
Jan Vaclav
2106251e46 firewall/utils: replace ipv4 iptables macro with ipxtables macro 2025-04-01 08:08:52 +00:00
Jan Vaclav
18d5b7d641 firewall/utils: remove _share prefix from iptables_get_name
It's no longer used just for shared mode.
2025-04-01 08:08:52 +00:00
Jan Vaclav
a769c17af7 firewall/wireguard: drop packets received to wrong interface
If we receive a packet sent to the WG interface's address,
but it does not come from the WG tunnel, let's assume something
is broken and drop the packet.

This is also inspired by wg-quick firewall rules:
https://git.zx2c4.com/wireguard-tools/tree/src/wg-quick/linux.bash?id=17c78d31c27a3c311a2ff42a881057753c6ef2a4#n221
2025-04-01 08:08:52 +00:00