Commit graph

33651 commits

Author SHA1 Message Date
Your Name
4cdca6b458 XXX create device 2024-12-17 02:24:45 +01:00
Your Name
48d30394fd XXX split validate_activation_request() 2024-12-17 02:24:40 +01:00
Your Name
007382855e XXX move setting of fallback prefix away from the device 2024-12-17 02:24:20 +01:00
Your Name
b960c0267f XXX device: simplify the nm_utils_complete_generic() machinery 2024-12-17 02:24:20 +01:00
Lubomir Rintel
81a239ef3b cloud-setup: skip connections unless given type mismatches
Wired and Ipv4 always there, rest varies by connection type (Wired,
Vlan, MacVlan).
2024-12-17 02:21:13 +01:00
Lubomir Rintel
8df0a5f1c4 cloud-setup: lookup device by MAC + type instead of just MAC
This will be useful for updating configuration of Vlans and MacVlans,
some of having same MAC addresses as devices of other type.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
3c720fa108 cloud-setup: make _device_get_hwaddr() work with all kinds of devices
We'll have Vlans and MacVlans soon, and those don't have permanent
addresses.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
871a53cbef cloud-setup: s/_nmc_get_hwaddrs()/_nmc_get_ethernet_hwaddrs()/
Make it clear that this only works for Ethernet devices.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
34f91312e5 cloud-setup: add a sync wrapper around AddAndActivate
These will be used to create the software devices.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
82546bb6c4 test/client: add nm-c-s OCI test
Very basic.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
b1aad5b64f test/nm-service: add support for creating a MACVLAN
...via AddAndActivate. nm-cloud-setup will do that.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
ad1e854f15 test/nm-service: create Vlan devices matching the parent by hwaddr
This is how OCI VLANS will be looking up their parents. Make sure the
mock is able to deal with this.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
cff03568f4 test/nm-service: create software devices on AddAndActivate()
This will be useful for testing VLAN bringup.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
40fe0d6b94 test/nm-service: add MacvlanDevice class
We'll need to test the nm-cloud-setup OCI multiple VNIC support.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
c6c63b0a8c test/nm-service: add Device.HwAddress property
nm-cloud-setup finds devices by hwaddr. Let's expose it for all device
types, so that we're be able to test once we add VLANs and MACVLANs.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
ad3064a547 test/cloud-meta-mock: do not print what we listen on if we got a FD
This message is useless for non-interactive use and clobbers over
otherwise very appealing test output.

The callers knows what we're going to listen on, it passed us the file
descriptor.
2024-12-17 02:21:13 +01:00
Íñigo Huguet
0dab43c1a0 cloud-setup: oci: remove the max 2 phys NICs limit
Right now, on any baremetal only max. 2 physical NICs are available.
This might change in the future, so better to directly accept larger
nicIndex if we receive it. No behaviour change with this, just remove
an artificial limit.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
4041f94bb5 fixup! cloud-setup: parse OCI metadata related to VLAN config
nm-code-format
2024-12-17 02:21:13 +01:00
Lubomir Rintel
e9f1d6be5a fixup! cloud-setup: parse OCI metadata related to VLAN config
.get_config_data is only alive while the get_config task is running. We
can't reach into it afterwards.

  ==92303== Invalid read of size 8
  ==92303==    at 0x41247D: _iface_data_free (nmcs-provider.c:228)
  ==92303==    by 0x4CB33C1: ??? (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x4CB8082: g_hash_table_unref (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x412425: nm_g_hash_table_unref (nm-shared-utils.h:2171)
  ==92303==    by 0x412425: nmcs_provider_get_config_result_free (nmcs-provider.c:133)
  ==92303==    by 0x407871: main (main.c:995)
  ==92303==  Address 0x63b63f8 is 8 bytes inside a block of size 64 free'd
  ==92303==    at 0x4847B4C: free (vg_replace_malloc.c:989)
  ==92303==    by 0x4CCB76C: g_free (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x4CE81DF: g_slice_free1 (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x411C7B: _get_config_done_cb (nmcs-provider-oci.c:247)
  ==92303==    by 0x4AF2489: ??? (in /usr/lib64/libgio-2.0.so.0.6800.4)
  ==92303==    by 0x4AF268A: ??? (in /usr/lib64/libgio-2.0.so.0.6800.4)
  ==92303==    by 0x40A91C: _poll_req_done_cb (nm-http-client.c:529)
  ==92303==    by 0x4AF2489: ??? (in /usr/lib64/libgio-2.0.so.0.6800.4)
  ==92303==    by 0x4AF268A: ??? (in /usr/lib64/libgio-2.0.so.0.6800.4)
  ==92303==    by 0x415381: _poll_return (nm-shared-utils.c:7174)
  ==92303==    by 0x416D97: _poll_done_cb (nm-shared-utils.c:7201)
  ==92303==    by 0x4AF2489: ??? (in /usr/lib64/libgio-2.0.so.0.6800.4)
  ==92303==  Block was alloc'd at
  ==92303==    at 0x484482F: malloc (vg_replace_malloc.c:446)
  ==92303==    by 0x4CCEB88: g_malloc (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x4CE8C64: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6800.4)
  ==92303==    by 0x413113: nmcs_provider_get_config (nmcs-provider.c:304)
  ==92303==    by 0x4076BD: _get_config (main.c:359)
  ==92303==    by 0x4076BD: main (main.c:985)
2024-12-17 02:21:13 +01:00
Íñigo Huguet
2580e03a15 cloud-setup: parse OCI metadata related to VLAN config
Baremetal instances in Oracle Cloud require special VLAN config. Parse
the metadata related to it.
2024-12-17 02:21:13 +01:00
Íñigo Huguet
4210ab1828 nmcs: remove nmcs_provider_*_get_type forward declaration
There is no need to avoid including the full header, they are small
headers with some GLib type system stuff and no more. Just include them
where they are needed.
2024-12-17 02:21:13 +01:00
Íñigo Huguet
5a98d81db5 nmcs: oci: use macro to log warnings 2024-12-17 02:21:13 +01:00
Lubomir Rintel
007ea4bb39 connection: warn if return from nm_connection_normalize() is unused
If we try to normalize a connection, we generally rely on it being
already valid and be normalized afterwards.

There's one particular case (nmcli interactive add/edit), where we call
it repeatedly on a best-effort basis and don't care about the failures.
Disable the warning there.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
e6efe8b066 core/utils: assert that completion results in a valid connection
Completion of a connection must always result in a valid connection and
the call to normalize() is always expected to succeed here.

Croak if it doesn't because the rest basically relies on the connection
being normalized. If it's not valid, and can't be normalized, it's a bug.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
194e15d133 XXX FIXME initrd/cmdline: drop useless call to normalize
The caller normalizes connections before spitting them out. On top of it
it actually handles the errors.

Rename the routine accordingly.

XXX FIXME test botched
2024-12-17 02:21:13 +01:00
Lubomir Rintel
b97fe38603 device: get_connection_parent() accept incomplete connections
All of these are wrong asserting that a connection has a particular
setting. On AddAndActivate, the connection can be pretty much empty:

  impl_manager_add_and_activate_connection ()
    validate_activation_request ()
      nm_manager_get_best_device_for_connection ()
      iface = nm_manager_get_connection_iface ()
        find_parent_device_for_connection ()
          nm_device_factory_get_connection_parent () <====== *shriek*
        nm_device_factory_get_connection_iface ()
      find_device_by_iface (iface)
    nm_device_complete_connection ()

Remove those assertions.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
c5bd1cf930 device: cleanup get_connection_iface() callbacks
Some of them are wrong: they assert a connection has a particular
setting even though this can be called on AddAndActivate against a
connection that is not complete or normalized:

  impl_manager_add_and_activate_connection ()
    validate_activation_request ()
      nm_manager_get_best_device_for_connection ()
      iface = nm_manager_get_connection_iface ()
        find_parent_device_for_connection ()
          nm_device_factory_get_connection_parent ()
        nm_device_factory_get_connection_iface () <====== here
      find_device_by_iface (iface)
    nm_device_complete_connection ()

Fix those by removing the assertions.

Some of them are also fall back to just calling
nm_connection_get_interface_name() which is a pretty useless thing to do
because nm_device_factory_get_connection_iface() only calls the
device-specific routine if nm_device_factory_get_connection_iface()
doesn't return anything, to give the factory a chance to make up a name
(like <parent>.<vlan-id> for Vlan) on its own. Drop those.
2024-12-17 02:21:13 +01:00
Lubomir Rintel
9694ad03d6 device/factory: document that some callbacks get an incomplete connection
It's get_connection_parent() and get_connection_iface().
2024-12-17 02:21:13 +01:00
Lubomir Rintel
5238ab7fc9 client/tests: move run_post() TestNmcli
It attempts to modify attributes clearly belong to TestNmcli such as
_skip_test_for_l10n_diff or call methods that are in unittest.TestCase:

  ======================================================================
  ERROR: test_002 (__main__.TestNmcli.test_002)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File ".../src/tests/client/test-client.py", line 1508, in f
      self.ctx.run_post()
      ~~~~~~~~~~~~~~~~~^^
    File ".../src/tests/client/test-client.py", line 1185, in run_post
      self.fail(
      ^^^^^^^^^
  AttributeError: 'NMTestContext' object has no attribute 'fail'

It has presumably been moved out of TestNmcli at some point, but that
seems to have been in error, as it's also pretty specific to the nmcli
test cases. Not useful for cloud-init tests that also utilize
NMTestContext. Move it back.
2024-12-17 02:21:13 +01:00
Your Name
41840262bc devices/ipvlan,macvlan: rephrase an error message 2024-12-17 02:20:58 +01:00
Íñigo Huguet
3bcbe6ed01 merge: branch 'ih/rt-leftover'
l3cfg: remove routes added by NM on reapply

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2080
2024-12-11 15:55:40 +00:00
Íñigo Huguet
c06d130c38 l3cfg: get routes to prune from the list of routes configured by NM
We always sync routes in the main table, but routes in tables other
than main are only pruned if were added by NM, by default. Get the list
of routes to prune from other tables using obj_state->os_nm_configured,
as this tracks what routes were effectively added by NM.

The list should be the same that the one obtained from l3cfg_old. It
could be different if we commited the l3cfg with an NMIPRouteTableSyncMode
of NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, thus not deleting some routes at
commit time. However, since the previous commit, we never do it.

What all this shows is that starting to use different NMIPRouteTableSyncModes
is probably a bad idea: it will be a source of bugs of routes not being
always synced as users expect, and the use case for them is still to be
known.
2024-12-11 15:52:09 +00:00
Íñigo Huguet
e330eb9c4a l3cfg: remove routes added by NM on reapply
By default, on reapply we were only syncing the main routes table. This
causes that routes added by NM to other tables are not removed on
reapply. This was done to preserve routes added externally, but routes
added by NM itself should be removed.

Add a new route table syncing mode "main + NM routes". This mode
maintains the normal behaviour of syncing completely the main table,
and for other tables removes only routes that were added by us, leaving
the rest untouched. Use this mode by default, as this is what a user
would expect on reapply.

Note: this might not work if NM is restarted between the profile being
modified and the reapply, because NM forgets what routes were added by
itself because of the restart. This is a rare corner case, though.

Use the D-Bus property "VersionInfo" to expose a capability flag
indicating that this bug is fixed. It is the first capability that we
expose in this way. However, it is convenient to do it this way as it's
something that clients like nmstate needs to know, so they can decide
whether a conn down is needed or not. It is not enough to decide that by
version number because it might be fixed via a downstream patch in distros
like RHEL.

https://issues.redhat.com/browse/RHEL-67324
https://issues.redhat.com/browse/RHEL-66262

Fixes: e9c17fcc9b ('l3cfg: default to 'main' route table sync mode')
2024-12-11 15:52:09 +00:00
Íñigo Huguet
e1840ad5fb platform: rename NM_IP_ROUTE_TABLE_SYNC_MODE_FULL -> ALL_EXCEPT_LOCAL
The difference between FULL and ALL was not obvious without reading the
documentation. Moreover, a new mode is going to be introduced so the
confusion could grow. Rename to a more explicit name.
2024-12-11 15:52:09 +00:00
Íñigo Huguet
5a65170b49 libnmc: fix bug checking VersionInfo's capabilities
Remove the `+ 31u` that was making that it would search for bit 1 at
array's element 1, instead of element 0. Fixed comparison >len that
shoudl be >=len. Fix a few typos.

Fixes: bc6098d441 ('libnm: add internal nmc_client_has_{version_info_v,version_info_capability,capability}() helper')
2024-12-11 15:52:09 +00:00
Roman Pavelka
38d1bcee3b ip: configurable address pool and lease time of DHCP server in shared mode
Introduce a new options to NMSettingIpConfig. When set, ipv4.shared-dhcp-range
and ipv4.shared-dhcp-lease-time can be passed to dnsmasq to allow configuration
of DHCP server address pool range and lease time.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/941
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2028
2024-12-11 09:20:15 +01:00
Beniamino Galvani
0209a55d24 contrib/copr: update the URL for nm-git-bundle
The old bundle is no longer available, use the latest one.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2086
2024-12-09 17:38:36 +01:00
Yuki Inoguchi
7fc9711c54 device: add IPv6 sysfs existence check in some ipv6 sysctl functions.
when the kernel boot parameter ipv6.disable=1 is set, NetworkManager
attempts to read files under /proc/sys/net/ipv6, resulting in numerous
error messages in the debug logs. For example:

NetworkManager[758]: <debug> [1726699000.9384] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/disable_ipv6: Failed to open file "/proc/sys/net/ipv6/conf/lo/disable_ipv6": No such file or directory
NetworkManager[758]: <debug> [1726699000.9400] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/accept_ra: Failed to open file "/proc/sys/net/ipv6/conf/lo/accept_ra": No such file or directory
NetworkManager[758]: <debug> [1726699000.9401] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/disable_ipv6: Failed to open file "/proc/sys/net/ipv6/conf/lo/disable_ipv6": No such file or directory
NetworkManager[758]: <debug> [1726699000.9401] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/hop_limit: Failed to open file "/proc/sys/net/ipv6/conf/lo/hop_limit": No such file or directory
NetworkManager[758]: <debug> [1726699000.9401] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/use_tempaddr: Failed to open file "/proc/sys/net/ipv6/conf/lo/use_tempaddr": No such file or directory
NetworkManager[758]: <debug> [1726699000.9401] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/temp_valid_lft: Failed to open file "/proc/sys/net/ipv6/conf/lo/temp_valid_lft": No such file or directory
NetworkManager[758]: <debug> [1726699000.9401] platform-linux: error reading /proc/sys/net/ipv6/conf/lo/temp_prefered_lft: Failed to open file "/proc/sys/net/ipv6/conf/lo/temp_prefered_lft": No such file or directory
...

This also results unnecessary system calls by attempting to open non-existent sysfs.

This patch adds checks in some ipv6 sysctl functions to verify the existence of /proc/sys/net/ipv6.
While there are still other paths that attempts to open IPv6 sysfs, this
eliminates many reading errors.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2040
2024-12-09 15:03:45 +01:00
Beniamino Galvani
6c18fda519 ndisc: honor default route parameters from RA route options
RFC 4191 section-3.1 says:

  When processing a Router Advertisement, a type C host first updates a
  ::/0 route based on the Router Lifetime and Default Router Preference
  in the Router Advertisement message header. [...] The Router Preference
  and Lifetime values in a ::/0 Route Information Option override the
  preference and lifetime values in the Router Advertisement header.

Fix the RA parsing so that the parameters from a default route option
are applied to the gateway.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2072

Fixes: c3a4656a68 ('rdisc: libndp implementation')
2024-12-06 09:03:32 +01:00
Fernando Fernandez Mancera
bfcc63c37a merge: branch 'bg/keyfile-doc'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2078
2024-12-04 10:38:11 +01:00
Beniamino Galvani
69b18ce914 keyfile: emit a warning when the gateway is set in different keys
The gateway can be set both in the "address*" and and in the "gateway"
keys. Raise a warning when it is set multiple times to different
values.
2024-12-03 17:17:53 +01:00
Beniamino Galvani
38dca2f044 keyfile: write the gateway explicitly
The keyfile format allows to specify the gateway in two ways: with a
separate "gateway" key, or by appending the gateway address to one of
the address$N lines:

  [ipv4]
  address1=192.0.2.1/24
  gateway=192.0.2.254

  [ipv4]
  address1=192.0.2.1/24,192.0.2.254

The former syntax is self-documenting and easier to understand for
users, but NetworkManager defaults to the latter when writing
connection files, for historical reasons. Change that and use the
explicit form.

Note that if a users has scripts manually parsing keyfiles, they could
stop working and so this can be considered an API breakage. OTOH,
those scripts are buggy if they don't support both forms, and they can
already break with perfectly valid user-generated keyfiles.

I think it's acceptable to change the default way to persist keyfiles;
the only precaution would be that this patch should not be applied
during a stable release cycle of a distro.
2024-12-03 17:17:53 +01:00
Beniamino Galvani
dfe9398306 libnm-core: improve keyfile documentation
Clarify the special behavior of some keyfile options.
2024-12-03 17:17:53 +01:00
Beniamino Galvani
40b139bc65 keyfile: test that the output is stable
We already check that a connection doesn't not change when it's
written and re-read from disk. Add another check to verify that the
generated keyfile matches a static one, so that we don't introduce
unwanted changes. The reference keyfiles can be generated by running
the test with "NM_TEST_REGENERATE=1".
2024-12-03 17:17:53 +01:00
Fernando Fernandez Mancera
dd9aca4bd9 libnm: fix warnings due to invalid "closure" annotation
The "closure" annotation needs to be set on the callback parameter
instead of on the data for the callback function.

This patch fixes the following warning:

"""
../src/libnm-core-impl/nm-utils.c:3632: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:4778: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:5776: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:5849: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:5976: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6091: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6448: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6521: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6581: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6663: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-client.c:6728: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:974: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:1014: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:1041: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:974: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:1014: Warning: NM: invalid "closure" annotation: only valid on callback parameters
../src/libnm-client-impl/nm-secret-agent-old.c:1041: Warning: NM: invalid "closure" annotation: only valid on callback parameters
"""
2024-11-27 12:57:00 +01:00
Beniamino Galvani
3b75577871 wifi: fix list corruption when scanning with explicit SSID
Calling c_list_link_tail() on a list entry that already belongs to
another list corrupts the other list, in this case 'old_lst_head';
this is explained in the documentation of c_list_link_before():

 * @what is not inspected prior to being linked. Hence, it better not
 * be linked into another list, or the other list will be corrupted.

This can be reproduced by invoking "nmcli device wifi rescan ssid x"
multiple times; in this way, _scan_request_ssids_track() reuses the
previous SSID data, the list gets corrupted and this causes a crash.

Fixes: 7500e90b53 ('wifi: rework scanning of Wi-Fi device')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2076
2024-11-26 16:17:01 +01:00
Wen Liang
e0b6a2ce92 merge: branch 'wl/skip_acd_noarp'
l3cfg: never retry ACD on NOARP interfaces

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2066
2024-11-15 13:47:22 +00:00
Wen Liang
883399606f l3cfg: never retry ACD on NOARP interfaces
After upgrading to RHEL-9.4, customers have reported that `ip monitor`
repeatedly logs the same route additions every 30 seconds. This issue
appears to stem from NetworkManager continually retrying to add the same
routes due to keep retrying Address Conflict Detection (ACD) on NOARP
interfaces.

To prevent unnecessary route additions and reduce log noise, this change
modifies NetworkManager's behavior to stop retrying ACD on interfaces
with the NOARP flag.

This fix addresses route instability and excessive logging for affected
NOARP configurations.

https://issues.redhat.com/browse/RHEL-59125
2024-11-15 13:46:37 +00:00
Beniamino Galvani
eb620e0e7e platform: fix to_string() functions for IPv6 tunnels
We can hit an assertion at trace log level when printing IPv6 tunnel
links, because the buffer for the local and remote addresses is not
big enough. Increase the buffer size.

Fixes: 32f6e1ef2e ('platform: add IP6TNL links support')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2063
2024-11-14 09:57:26 +01:00
Íñigo Huguet
4b65e716c8 release: bump version to 1.51.4 (development) 2024-11-13 15:21:42 +01:00