Commit graph

34212 commits

Author SHA1 Message Date
Yuri Chornoivan
bcd37e2df8
po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1490
2023-01-02 09:42:19 +01:00
Frederic Martinsons
c62d6fa84e
Correct meson command examples
The change directory option must be after subcommand.
Moreover use directly build directory (which is default showing
in 'Building from Source' section)
The install command must specify the build directory

Signed-off-by: Frederic Martinsons <frederic.martinsons@unabiz.com>
2023-01-02 09:29:16 +01:00
Fernando Fernandez Mancera
bf34212345 merge: branch 'ff/ipv4_ecmp'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1365
2022-12-23 16:58:21 +01:00
Fernando Fernandez Mancera
b71e695c9b nm-netns: fix crash due to use of EcmpTrackObj after freeing it
When committing ECMP routes we are cleaning up dirty routes and freeing
the EcmpTrackObj. We need to free EcmpTrackObj only when it is not
needed anymore so it is the last thing we do when cleaning up the
routes.
2022-12-23 16:47:29 +01:00
Fernando Fernandez Mancera
ffbcf01589 test-ndisc-fake: free l3cfg after creating fake-ndisc
Considering nm_netns_l3cfg_acquire returns a l3cfg reference and only
keeps a weak reference we need to free l3cfg in fake-ndisc after
creating the object.
2022-12-23 16:47:29 +01:00
Fernando Fernandez Mancera
8b27a2b09a nm-netns: mark the ECMP route as needs_update when registering
If an L3Cfg try to register an ECMP route that we are tracking we must
mark it as needs_update because it means it could be dropped from
kernel. When merging them if the merged route didn't change we should
commit the route anyway because we know it needed update.
2022-12-23 16:47:29 +01:00
Fernando Fernandez Mancera
737cb5d424 nm-netns: add onlink routes for ECMP routes
When adding a static route, kernel enforce that the gateway is
reachable. To solve this, NetworkManager generates onlink routes for
each static route. As ECMP routes does not follow the same logic than
singlehop routes, we need to add the onlink route for each hop of ECMP
routes once merged.

NML3Cfg will take ownership of the onlink route added and will purge it
when it is not needed anymore.
2022-12-23 16:47:29 +01:00
Thomas Haller
5b5ce42682 nm-netns: track ECMP routes
Co-authored-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2022-12-23 16:47:29 +01:00
Fernando Fernandez Mancera
af26b19dae route: introduce weight property for ipv4 routes
Introduce the weight property for IPv4 ECMP routes. The value will be
ignored if there is only a single nexthop.
2022-12-23 16:47:29 +01:00
Thomas Haller
59f68a8d4e l3cfg: closer integrate NML3Cfg and NMNetns
NML3Cfg and NMNetns are already strongly related and cooperate.
An NML3Cfg instance is created via NMNetns, which is necessary
because NMNetns ensures that there is only one NML3Cfg instance per
ifindex and it won't ever make sense to have multiple NML3Cfg instances
per namespace.

Note that NMNetns tracks additional information for each NML3Cfg.
Previously, in a pointless attempt to separate code, it did so
by putting that information in another struct (L3CfgData).
But as the classes are strongly related, there really is no
reason why we cannot just attach this information to NML3Cfg
directly. Sure, we want that code has low coupling, high cohesion
but that doesn't mean we gain anything by putting data that is
strongly related to the NML3Cfg to another struct L3CfgData.

The advantage is we save some redundant data and an additional
L3CfgData. But the bigger reason is that with this change, it
will be possible to access the NMNetns specific data directly from
an NML3Cfg instance, without another dictionary lookup. Currently
such a lookup is never used, but it will be.

Basically, NML3Cfg and NMNetns shares some state. It is now in the
"internal_netns" field of the NML3Cfg instead of L3CfgData.
2022-12-23 16:47:29 +01:00
Fernando Fernandez Mancera
c177cf8fdd nm-netns: skip nodev routes in platform signal callback
Platform signal callback could be trigger by nodev routes and they do
not have an ifindex. Skip the l3cfg notification for nodev routes.
2022-12-23 16:47:29 +01:00
Beniamino Galvani
6ea924fa74 device: fix condition for scheduling stage3 after carrier change
When the device gets carrier, we should reschedule stage3 even if the
device state is not exactly IP_CONFIG.

For example if IPv6 autoconf is waiting for carrier and IPv6 is
may-fail=yes, the device could be already ACTIVATED because manual
IPv4 succeeded; after getting carrier, we need to call
nm_device_activate_schedule_stage3_ip_config() to start IPv6 autoconf.

Fixes: bcf31a9b29 ('device: fix assertion failure on master carrier change')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1165
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1485
2022-12-23 16:00:40 +01:00
Beniamino Galvani
c1d234ce30 libnm/client: fix assertions during device-removed event
The current implementation of libnm guarantees that "o" and "ao"
properties are cleared when the device object goes away, i.e. when all
its interfaces disappear from the bus.

The "manager:device-removed" signal is emitted just before the device
is unexported, and usually properties are not cleared at that
time. So, the assertions about empty available connections and active
connection during "device-removed" seem wrong; remove them.

Whether the test passes or not depends on a race condition in the way
the mock NM service is stopped: we first close the pipe to the process
to force a clean shutdown (where all objects are orderly unexported)
but just after that we send SIGTERM which causes the service to drop
from the bus.

If libnm sees the service dropping from the bus, it deletes all
objects (thus clearing properties) and then emits
"device-removed"; in this case the test passes.

However in case of a clean shutdown, NM first emits the
"device-removed" signal and then unexports devices, leading to a
failure.

Fixes: aaa9a9cd25 ('libnm/client: don't reset properties when interface goes away')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1486
2022-12-23 15:57:10 +01:00
Beniamino Galvani
5fe4be6c06 merge: branch 'bg/coverity'
Fix some coverity warnings.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1487
2022-12-23 09:35:12 +01:00
Beniamino Galvani
1c6935e49d nmtui: fix memory leak
Fixes: 3bda3fb60c ('nmtui: initial import of nmtui')
2022-12-22 11:48:59 +01:00
Beniamino Galvani
9c4b27e3d2 devices: remove unneeded pointer check
src/core/devices/nm-lldp-listener.c:911: check_after_deref:
  Null-checking "self" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.

Fixes: 04e72b6b4d ('lldp: use new libnm-lldp instead of systemd's sd_lldp_rx')
2022-12-22 11:39:08 +01:00
Beniamino Galvani
2883203df4 platform: fix NULL pointer dereference
src/libnm-platform/nmp-object.c:930: var_deref_op: Dereferencing null pointer "klass->cmd_plobj_to_string_id".

Fixes: 8feeb199ad ('platform: drop redundant hook implementations from NMPObject classes')
2022-12-22 11:34:09 +01:00
Beniamino Galvani
a39ec8ca75 nmcli: fix double free
src/nmcli/devices.c:1196: double_free: Calling "_nm_auto_strfreev" frees pointer "arg_arr" which has already been freed.

Fixes: c5d45848dd ('cli: mark argv argument for command line parsing as const')
2022-12-22 11:24:37 +01:00
Beniamino Galvani
d1f010b305 platform: remove fwmark from vti/vti6 tests
Older versions of iproute2 don't support the fwmark option. Remove it.

Fixes: 1cf8df2f35 ('platform: support VTI tunnels')
Fixes: b669a3ae46 ('platform: support VTI6 tunnels')
2022-12-22 09:57:32 +01:00
Beniamino Galvani
115102efe9 platform: fix build failures due to missing VTI definitions
Older kernel headers don't ship definitions for IFLA_VTI_*, redefine
them.

Fixes: 1cf8df2f35 ('platform: support VTI tunnels')
Fixes: b669a3ae46 ('platform: support VTI6 tunnels')
2022-12-22 09:57:28 +01:00
Beniamino Galvani
f2974b1c61 ip-tunnel: merge branch 'bg/vti'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/985
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1435
2022-12-21 16:03:23 +01:00
Beniamino Galvani
c0b0f823ca devices: support VTI6 tunnels 2022-12-21 14:04:44 +01:00
Beniamino Galvani
351c562491 devices: support VTI tunnels
A VTI tunnel is similar to a IPIP one, but it allows adding a fwmark
to packets and supports IPsec encapsulation.
2022-12-21 14:04:44 +01:00
Beniamino Galvani
199eb725ad libnm: support VTI properties in the ip-tunnel setting
Add the fwmark property and allow setting input and output key for VTI
tunnels.
2022-12-21 14:04:44 +01:00
Beniamino Galvani
b669a3ae46 platform: support VTI6 tunnels 2022-12-21 14:04:44 +01:00
Beniamino Galvani
1cf8df2f35 platform: support VTI tunnels 2022-12-21 14:04:43 +01:00
Beniamino Galvani
715a3cf84c ip-tunnel: simplify handling of {input,output} key 2022-12-21 10:38:47 +01:00
Thomas Haller
aec7ae8279
Revert "policy: track the autoconnect retries in devices for multi-connect"
With multi-connect enabled, this can cause infinite retries to autoconnect,
see [1].

That has bad consequences for example in initrd, where
nm-wait-online-initrd.service would wait up to one hour before failing
and blocking boot.

This reverts commit 1656d82045.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2039734#c5

Fixes: 1656d82045 ('policy: track the autoconnect retries in devices for multi-connect')
2022-12-20 16:12:43 +01:00
Thomas Haller
ea80a4a813
contrib/scripts: update "nm-copr-build.sh" script to use new nm-git-bundle 2022-12-20 11:38:32 +01:00
Thomas Haller
3e20608300
libnm: merge branch 'th/libnm-atomic-ref'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1484
2022-12-20 10:43:23 +01:00
Thomas Haller
9bd833da6b
libnm: make NMRange ref/unref thread-safe
Like for our other immutable/sealable types, make ref/unref thread safe.
That is important, as the boxed types only increase the ref-count on
copy. If ref/unref is not thread-safe, it means you cannot copy a boxed
type, and operate on the copy on another thread.

Fixes: 041e38b151 ('libnm: add NMRange')
2022-12-20 10:35:02 +01:00
Thomas Haller
71454ae4cd
libnm: make ref counting of immutable types thread safe
The types NMBridgeVlan, NMIPRoutingRule, NMRange, NMWireGuardPeer
are immutable (or immutable, after the seal() function is called).

Immutable types are great, as it means a reference to them can be shared
without doing a full clone. Hence the G_DEFINE_BOXED_TYPE() for these
types prefers to take a reference instead of cloning the objects. Except
for sealable types, where it will prefer to clone unsealed values.
Likewise, nm_simple_connection_new_clone() probably will just take
another reference to the value, instead of doing a deep clone.

libnm is not a thread-safe library in the sense that you could pass a
NMConnection or NMClient instance to multiple threads and access them
without your own synchronization. However, it should be possible that
multiple threads access (seemingly) distinct objects.

As the copy function of these boxed types (and nm_simple_connection_new_clone()
and similar) prefers to share the references to immutable types, it is important
that the ref function is thread-safe too. Otherwise you cannot just clone a
NMConnection on thread1, hand the clone to thread2 and operate on the
clone and the original independently. If you do before this patch, you would
hit a subtle race condition.

Avoid that. While atomic operations have a runtime overhead, being safe
is more important. Also, we already save a full malloc()/free() by
having immutable, ref-counted types. We just need to make it safe to use
in order to fully benefit from it.
2022-12-20 10:35:02 +01:00
Thomas Haller
1e29b36420
libnm: document nm_team_link_watcher_{ref,unref}() as thread-safe 2022-12-20 10:35:02 +01:00
Thomas Haller
77f3227cb8
libnm: use struct initialization in nm_bridge_vlan_new()
I think it's just a nicer pattern. It also ensures that all
fields are initialized to their type's default and don't
rely on memset().
2022-12-20 10:34:55 +01:00
Thomas Haller
b9bbbfc41f
dhcp: fix unused variable in nm_dhcp_client_start()
Fixes: 28d7f9b7c4 ('dhcp: drop NMDhcpClientClass.get_duid() hook')
2022-12-19 16:17:05 +01:00
Thomas Haller
831b8f8e7e
dhcp: merge branch 'th/dhcp-client-id-in-lease'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1477
2022-12-19 11:29:20 +01:00
Thomas Haller
1d85608e1c
dhcp/dhclient: fix honoring "ipv6.dhcp-duid" when explicitly set
Previously, we only set the "default-duid" line in the lease file. That
means, if the lease already contained a matching entry with a
"dhcp6.client-id" option, it was not honored. That is wrong.

If the profile has "ipv6.dhcp-duid" set, then we must use it and get
rid of those options from the lease.

It's easy to reproduce:

    PROFILE=eth1

    nmcli connection down "$PROFILE"
    rm -f /var/lib/NetworkManager/*lease
    nmcli connection modify "$PROFILE" ipv6.dhcp-duid "aa:bb:cc:dd:00:00:11"
    nmcli connection up "$PROFILE"
    # Verify the expected duid in /var/lib/NetworkManager/*lease and "/run/NetworkManager/devices/$IFINDEX"

    nmcli connection modify "$PROFILE" ipv6.dhcp-duid "aa:bb:cc:dd:00:00:22"
    nmcli connection up "$PROFILE"
    # Check the DUID again.
2022-12-19 11:29:19 +01:00
Thomas Haller
c990d6a81a
dhcp/dhclient: better handle "\r\n" line breaks in dhclient lease file
Splitting by any of "\r\n" and then joining the lines with "\n"
leads to double-newlines. That's certainly wrong.

Maybe we shouldn't care about "\r", I don't know why this was done. But
handle it differently.
2022-12-19 11:29:19 +01:00
Thomas Haller
0e63fe58a7
dhcp/dhclient: avoid rewriting unchanged file in nm_dhcp_dhclient_save_duid()
It updates the file timestamp, which seems undesirable. Skip the update,
if the content didn't change.
2022-12-19 11:29:18 +01:00
Thomas Haller
7d1cfec0b8
dhcp/tests: add more tests for nm_dhcp_dhclient_save_duid() 2022-12-19 11:29:17 +01:00
Thomas Haller
5ee2f3d1dc
dhcp/tests: refactor tests for nm_dhcp_dhclient_save_duid()
So much duplicate, boilerplate code. Get rid of it.
2022-12-19 11:29:16 +01:00
Thomas Haller
b23c505fca
glib-aux: add "with_leading_zero" to nm_utils_bin2hexstr_full()
dhclient writes binary data as colon-separated hex strings
like nm_utils_bin2hexstr_full() does. But it only writes single
digits for values smaller than 0x10. Add an option to support
that mode.

However, there are many callers of nm_utils_bin2hexstr_full() already,
and they all don't care about the new option. Maybe this should this
not be a boolean argument, instead the function should accept a
flags argument. That is not done for now. Just add another "fuller"
variant. It's still easy to understand, because the "full" variant
is just a more limited functionality of "fuller".
2022-12-19 11:29:16 +01:00
Thomas Haller
df0408f0f6
dhcp/trivial: rename DUID_PREFIX define to DEFAULT_DUID_PREFIX 2022-12-19 11:29:15 +01:00
Thomas Haller
a3e4f764d1
dhcp: don't destroy old value before setting new in nm_dhcp_client_set_effective_client_id()
Of course, the old "priv->effective_client_id" and the new
"client_id" instances are truly separate, that is, they don't
share data, and destroying "priv->effective_client_id" before
taking a reference on "client_id" causes no problem.

It's still a code smell. It makes the function unnecessarily unsafe
under (very unusual) circumstances.
2022-12-19 11:29:14 +01:00
Thomas Haller
ef5333e5cf
dhcp: set the "dhcp_client_identifier"/"dhcp6_client_id" lease options
Also for the internal DHCP clients. And validate/normalize the setting
for the dhclient/dhcpcd/dhcdcanon plugins.
2022-12-19 11:29:14 +01:00
Thomas Haller
c020f618ed
dhcp: add and use nm_dhcp_client_create_options_dict()
This will be used to pre-fill the lease with client-specific options.
2022-12-19 11:29:13 +01:00
Thomas Haller
ccbe76b81d
dhcp: use nm_dhcp_option_create_options_dict() in nm_dhcp_client_handle_event()
The point of using this trivial helper function is to have one function
that is related to the construction of the options dictionary, that we
can search for.

It answers the question, where do we create a option hash (at `git grep
nm_dhcp_option_create_options_dict`).
2022-12-19 11:29:13 +01:00
Thomas Haller
492818b529
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.
2022-12-19 11:29:12 +01:00
Thomas Haller
84b90fbdd3
dhcp: set effective-client-id for all DHCP plugins 2022-12-19 11:29:12 +01:00
Thomas Haller
bea72c3d6d
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')
2022-12-19 11:29:11 +01:00