Commit graph

29973 commits

Author SHA1 Message Date
Beniamino Galvani
a8f8ca01fd core: wait for carrier before resolving hostname via DNS
If there is no carrier on a device, don't try to resolve the hostname
on it. Instead, subscribe to carrier change notifications and retry
again once carrier goes up.

https://bugzilla.redhat.com/show_bug.cgi?id=2118817
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1402
(cherry picked from commit e3cf5083fb)
(cherry picked from commit 1673e3f051)
(cherry picked from commit 69e66102ce)
2022-12-16 17:02:00 +01:00
Beniamino Galvani
5e71d9a26f ovs: wait that links disappear during initial cleanup
At startup, we remove from ovsdb any existing interface created by NM
and later an interface with the same name might be readded. This can
cause race conditions. Consider this series of events:

1. at startup NM removes the entry from ovsdb;
2. ovsdb reports success;
3. NM inserts an interface with the same name again;
4. ovs-vswitch monitors ovsdb changes, and gets events for removal and
   insertion. Depending on how those events are split in different
   batches, it might decide:
   4a. to delete the link and add it back, or
   4b. to keep the existing link because the delete and insertion
       cancel out each other.

When NM sees the link staying in platform, it doesn't know if it's
because of 4b or because 4a will happen eventually.

To avoid this ambiguity, after ovsdb reports the successful deletion
NM should also wait that the link disappears from platform.

Unfortunately, this means that ovsdb gets a dependency to the platform
code.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1386
(cherry picked from commit 4f60fe293c)
(cherry picked from commit f702be2992)
(cherry picked from commit 96f93e3a5b)
2022-12-16 16:30:23 +01:00
Fernando Fernandez Mancera
905b316c1d veth: drop iface peer check during create_and_realize()
When fetching the parent device, if the system is slow, NetworkManager
can hit a race condition where the property is still NULL. In that case,
NetworkManager should create the veth link.

Checking that the peer device exists, it is type NM_DEVICE_TYPE_VETH and
it have a parent device is enough to know that we can skip the link
creation.

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

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

Fixes: 4655b7c308 ('veth: fix veth activation on booting')
(cherry picked from commit 07e0ab48d1)
(cherry picked from commit 65d31a11f8)
(cherry picked from commit 4ae14b0bed)
2022-11-16 18:02:11 +01:00
Fernando Fernandez Mancera
9df887c0af veth: fix veth activation on booting
When creating one profile for each veth during activation the creation
of the veth could fail. When the link for the first profile is created
the link for the peer is generated in kernel. Therefore when trying to
activate the second profile it will fail because the link already
exists. NetworkManager must check if the link already exists and
corresponds to the same veth, if so, it should skip the link creation.

https://bugzilla.redhat.com/show_bug.cgi?id=2036023
https://bugzilla.redhat.com/show_bug.cgi?id=2105956
(cherry picked from commit 4655b7c308)
(cherry picked from commit 36bb9a569a)
2022-11-16 18:02:05 +01:00
Beniamino Galvani
328cac83e7 merge: branch 'bg/dhcp6-dad-on-1-36'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1428

(cherry picked from commit 4fac7c4a42)
2022-10-17 16:21:02 +02:00
Thomas Haller
1f3edc8c43 dhcp: fix EXTENDED DHCP event to accept lease for dhclient plugin
n-dhcp4 only supports calling ACCEPT during the GRANTED state.
Not during a EXTENDED event. So usually, we would not want
to call accept in that case.

And we didn't. During EXTENDED event, we would usually skip ACD (because
it's either not enabled or we already passed ACD for the current address).
In that case, in _nm_dhcp_client_notify() we hit the line

     if (client_event_type == NM_DHCP_CLIENT_EVENT_TYPE_BOUND && priv->l3cd_curr
         && nm_l3_config_data_get_num_addresses(priv->l3cd_curr, priv->config.addr_family) > 0)
         priv->l3cfg_notify.wait_dhcp_commit = TRUE;
     else
         priv->l3cfg_notify.wait_dhcp_commit = FALSE;

and would not set `wait_dhpc_commit`. That means, we never called _dhcp_client_accept().
For nettools, that doesn't really matter because calling ACCEPT during EXTENDED
is invalid anyway. However, for dhclient that is fatal because we wouldn't reply the
D-Bus request from nm-dhcp-helper. The helper times out after 60 seconds and dhclient
would misbehave.

We need to fix that by also calling _dhcp_client_accept() in the case when we don't
need to wait (the EXTENDED case).

However, previously _dhcp_client_accept() was rather peculiar and didn't like to be
called in an unexpected state. Relax that. Now, when calling accept in an unexpected
state, just do nothing and signal success. That frees the caller from the complexity
to understand when they must/must not call accept.

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

Fixes: 156d84217c ('dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1308
(cherry picked from commit 5077018ff4)
(cherry picked from commit f7ced16ccc)
2022-10-17 09:19:27 +02:00
Beniamino Galvani
bd286f6894 dhcp: nettools: save the lease after it gets accepted
Currently the lease gets saved only on the extended (renewal)
event. Also save it after it gets accepted.

Fixes: 52a0fe584c ('dhcp/nettools: better track currently granted lease')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1261
(cherry picked from commit 2807f6a893)
(cherry picked from commit 409546a5fc)
2022-10-17 09:19:16 +02:00
Beniamino Galvani
076b9c186e dhcp: decline IPv6 lease if all adresses fail DAD
Currently we accept the DHCPv6 just after addresses are configured on
kernel, without waiting DAD result. Instead, wait that DAD completes
and decline the lease if all addresses are detected as duplicate.

Note that when an address has non-infinite lifetime and fails DAD,
kernel removes it automatically. With iproute2 we see something like:

602: testX6    inet6 2620:🔢5678/128 scope global tentative dynamic noprefixroute
       valid_lft 7500sec preferred_lft 7200sec
Deleted 602: testX6    inet6 2620:🔢5678/128 scope global dadfailed tentative dynamic noprefixroute
       valid_lft 7500sec preferred_lft 7200sec

Since the address gets removed from the platform cache, at the moment
we don't have a way to check the flags of the removal
message. Therefore, we assume that any address that goes away in
tentative state was detected as duplicate.

https://bugzilla.redhat.com/show_bug.cgi?id=2096386
(cherry picked from commit a7eb77260a)
(cherry picked from commit b671c36189)
Conflicts:
	src/core/dhcp/nm-dhcp-client.c
	[bgalvani: changed 'priv->l3cd_curr' to 'priv->l3cd' because
         nm-1-38 is missing 240ec7f891 ('dhcp: implement ACD
         (address collision detection) for DHCPv4')]
(cherry picked from commit c36bc32d83)
2022-10-14 11:29:59 +02:00
Beniamino Galvani
38c0944f23 dhcp: wait DAD completion for DHCPv6 addresses
Wait that addresses received through DHCPv6 complete duplicate address
detection before reporting that the lease can be used.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://bugzilla.redhat.com/show_bug.cgi?id=2096386
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1258
(cherry picked from commit 393bc628ff)
(cherry picked from commit 2fd5fb14ba)
2022-10-14 11:29:58 +02:00
Thomas Haller
b9b625f56e dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin
dhclient itself doesn't do ACD. However, it expects the dhclient-script
to exit with non-zero status, which causes dhclient to send a DECLINE.

`man dhclient-script`:

  BOUND:
     Before actually configuring the address, dhclient-script should
     somehow ARP for it and exit with a nonzero status if it receives a
     reply. In this case, the client will send a DHCPDECLINE  message  to
     the server and acquire a different address.   This may also be done in
     the RENEW, REBIND, or REBOOT states, but is not required, and indeed may
     not be desirable.

See also Fedora's dhclient-script ([1]).

https://gitlab.isc.org/isc-projects/dhcp/-/issues/67#note_97226
33226f2d76/client/dhclient.c (L1652)

[1] a8f6fd046f/f/dhclient-script (_878)

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
(cherry picked from commit 156d84217c)
(cherry picked from commit 47c8d212ad)
2022-10-14 11:29:58 +02:00
Thomas Haller
41d00231bd dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable.
  It feels nicer to only call the macro once. Of course, the macro
  expands to plain pointer dereferences, so there is little difference
  in terms of executed code.

- handle the default case with no virtual function first.

(cherry picked from commit 0f6df633fa)
(cherry picked from commit 6a2c459d86)
2022-10-14 11:29:58 +02:00
Thomas Haller
b3f804f917 dhcp/nettools: cleanup logging for dhcp4_event_handle()
It's pretty pointless to log

  <trace> [1653389116.6288] dhcp4 (br0): client event 7
  <debug> [1653389116.6288] dhcp4 (br0): received OFFER of 192.168.121.110 from 192.168.121.1

where the obscure event #7 is only telling you that we are going
to log something.  Handle logging events first.

In general, drop the "client event %d" message and make sure that all
code paths log something (useful), so we can see in the log that the
event was reached.

(cherry picked from commit 85b15e02fd)
(cherry picked from commit c9bd7cfc5d)
2022-10-14 11:29:58 +02:00
Thomas Haller
405bb67e3b dhcp/nettools: better track currently granted lease
When we accept/decline a lease, then that only works if we are in state
GRANTED. n-dhcp4 API also requires us, to provide the exact lease, that
we were announced earlier.

As such, we need to make sure that we don't accept/decline in the wrong
state. That means, to keep track of what we are doing more carefully.

The functions _dhcp_client_accept()/_dhcp_client_decline() now take
a l3cd argument, the one that we announced earlier. And we check that it
still matches.

(cherry picked from commit 52a0fe584c)
(cherry picked from commit 1f7bede222)
2022-10-14 11:29:58 +02:00
Thomas Haller
c2e25b30d0 dhcp: move accept/decline function inside "nm-dhcp-client.c"
They are no longer used from outside, NMDhcpClient fully handles this.
Make them static and internal.

Also, decline is currently unused. It will be used soon, with ACD
support.

(cherry picked from commit 4a256092ee)
(cherry picked from commit 27eb23ea44)
2022-10-14 11:29:58 +02:00
Thomas Haller
c19a0fa1f6 dhcp/trivial: rename connect_l3cfg_notify() to l3_cfg_notify_check_connected()
The function subscribes a callback l3_cfg_notify_cb(). Rename so that
related functions have a clearly related name.

(cherry picked from commit 9abcf3a53c)
(cherry picked from commit 344c0b3dfc)
2022-10-14 11:29:58 +02:00
Thomas Haller
3453bf09e8 dhcp: replace switch in l3_cfg_notify_cb() with if blocks
The l3_cfg_notify_cb() handler is used for different purposes, and
different events will be considered.

Usually a switch statement is very nice for enums, especially if all
enum values should be handled (because the compiler can warn about
unhandled cases). In this case, not all events are supposed to be
handled. At this point, it seems nicer to just use an if block. It
better composes.

The compiler should be able to optimize both variants to the same
result. In any case, checking some integers for equality is in any case
going to be efficient.

(cherry picked from commit 7db07faa5e)
(cherry picked from commit 9acb6f9082)
2022-10-14 11:29:58 +02:00
Thomas Haller
1cd5276952 dhcp: move addr-family specific data to union in NMDhcpClientPrivate
(cherry picked from commit e756533002)
(cherry picked from commit 962bcadec9)
2022-10-14 11:29:58 +02:00
Thomas Haller
517f1d7867 dhcp/trivial: drop obsolete code comment
This is done already.

(cherry picked from commit 05cc160494)
(cherry picked from commit 68b3868427)
2022-10-14 11:29:58 +02:00
Thomas Haller
3d7ba2327c dhcp: fix logging of event in _nm_dhcp_client_notify()
(cherry picked from commit cd09f3d364)
(cherry picked from commit 11d2b5597b)
2022-10-14 11:29:58 +02:00
Thomas Haller
9d1f40afc3 dhcp: merge nm_dhcp_client_start_ip4() and nm_dhcp_client_start_ip6() implementations
As almost always, there is a point in keeping IPv4 and IPv6 implementations
similar. Behave different where there is an actual difference, at the bottom
of the stack.

(cherry picked from commit 7f943f5fa6)
(cherry picked from commit 0edfa4456a)
2022-10-14 11:29:58 +02:00
Thomas Haller
c6decf3b45 dhcp: move code in "nm-dhcp-client.c" (2)
(cherry picked from commit 2b8aeba06d)
(cherry picked from commit 17425aa0dd)
2022-10-14 11:29:58 +02:00
Thomas Haller
387688379a dhcp: minor cleanup in config_init()
(cherry picked from commit 600467b96f)
(cherry picked from commit 97241b277a)
2022-10-14 11:29:58 +02:00
Thomas Haller
ac95e0a693 dhcp: remove assertion in nm_dhcp_client_handle_event()
Technically, g_warn_if_reached() may not be an assertion, according to
glib. However, there is G_DEBUG=fatal-warnings and we want to run with
that.

So this is an assertion to us. Also, logging to stderr/stdout is not a
useful thing to the daemon. Don't do this. Especially, since it depends
on user provided (untrusted) input.

(cherry picked from commit 892cde1436)
(cherry picked from commit 38b8fdb75c)
2022-10-14 11:29:58 +02:00
Thomas Haller
5686f7aa50 dhcp: move code in nm_dhcp_client_handle_event()
(cherry picked from commit 9097679aad)
(cherry picked from commit d0fcd690dc)
2022-10-14 11:29:58 +02:00
Thomas Haller
0c1a2f9408 dhcp: drop NMDhcpState enum
It's unused now.

(cherry picked from commit 802f343d9f)
(cherry picked from commit 116e53352b)
2022-10-14 11:29:58 +02:00
Thomas Haller
ea9b5d3d1d dhcp: rename/refactor nm_dhcp_client_set_state() to be notifications
Optimally we want stateless, pure code. Obviously, NMDhcpClient needs to
keep state to know what it's doing. However, we should well encapsulate
the state inside NMDhcpClient, and only accept events/notifications that
mutate the internal state according to certain rules.

Having a function public set_state(self, new_state) means that other
components (subclasses of NMDhcpClient) can directly mangle the state.
That means, you no longer need to only reason about the internal state
of NMDhcpClient (and the events/notifications/state-changes that it
implements). You also need to reason that other components take part of
maintaining that internal state.

Rename nm_dhcp_client_set_state() to nm_dhcp_client_notify(). Also, add
a new enum NMDhcpClientEventType with notification/event types.

In practice, this is only renaming. But naming is important, because it
suggests the reader how to think about the code.

(cherry picked from commit 97e65e4b50)
(cherry picked from commit 2dba874c5a)
2022-10-14 11:29:58 +02:00
Thomas Haller
87ee78e3cc dhcp: fix handling of NM_DHCP_STATE_NOOP
The "noop" state is almost unused, however, nm_dhcp_set_state()
has a check "if (new_state >= NM_DHCP_STATE_TIMEOUT)", so the order
of the NOOP state matters.

Fix that by reordering.

Also, just return right away from NOOP.

(cherry picked from commit 9761e38f7e)
(cherry picked from commit 62ae5c0d0d)
2022-10-14 11:29:58 +02:00
Thomas Haller
d15e64360a dhcp: drop most of NMDhcpState usage from nm_dhcp_client_handle_event()
NMDhcpState is very tied to events from dhclient. But most of these
states we don't care about, and NMDhcpClient definitely should abstract
and hide them.

We should repurpose NMDhcpState to simpler state. For that, first drop
the state from nm_dhcp_client_handle_event().

This is only the first step (which arguably makes the code more
complicated, because reason_to_state() gets spread out and the logic
happens more than once). That will be addressed next.

(cherry picked from commit f102051a29)
(cherry picked from commit 2c7f74ad94)
2022-10-14 11:29:58 +02:00
Thomas Haller
ab2846d22d dhcp/trivial: add comment about nm_dhcp_utils_merge_new_dhcp6_lease()
(cherry picked from commit 70cbf3dc1e)
(cherry picked from commit e042011be4)
2022-10-14 11:29:58 +02:00
Thomas Haller
4bcc079195 dhcp: move code in "nm-dhcp-client.c"
So that it makes more sense, related parts are closer together.

(cherry picked from commit 8d121b17b5)
(cherry picked from commit f82c6d06e5)
2022-10-14 11:29:58 +02:00
Thomas Haller
d4b1dff1eb glib-aux: add nm_g_bytes_ref() helper
g_bytes_ref() does not accept NULL. But doing so can be convenient,
add a helper for that.

Note that g_bytes_unref() does accept NULL, so there is no corresponding
helper.

(cherry picked from commit 222f404928)
(cherry picked from commit 01bcde8ab0)
2022-10-14 11:29:58 +02:00
Thomas Haller
bbd902cb9a dhcp: minor code cleanups in "nm-dhcp-client.c"
(cherry picked from commit 1093e66776)
(cherry picked from commit fa4fcf6142)
2022-10-14 11:29:58 +02:00
Thomas Haller
c1fee605d8 dhcp: use GSource for watching child process instead of numeric source id
(cherry picked from commit c8542a5d50)
(cherry picked from commit 3f1b53c851)
2022-10-14 11:29:58 +02:00
Thomas Haller
6c2d34cd4f dhcp: cleanup reason_to_state() in "nm-dhcp-client.c"
- use NM_IN_STRSET_ASCII_CASE().
- don't use else block after we return.
- don't accept the "iface" argument just for logging. The caller
  can do the logging, if they wish.

(cherry picked from commit 9b9c07530c)
(cherry picked from commit ea7ad68ed2)
2022-10-14 11:29:58 +02:00
Thomas Haller
e64350bd2b dhcp: simplify nm_dhcp_client_set_effective_client_id()
The "take" parameter of _set_effective_client_id() was always "FALSE". Drop it.
Also, drop _set_effective_client_id() and just call nm_dhcp_client_set_effective_client_id()
directly.

(cherry picked from commit 6b191d6ea7)
2022-10-14 11:29:58 +02:00
Thomas Haller
871d17a6f3 dhcp: use nm_g_bytes_equal0() in _set_effective_client_id()
(cherry picked from commit 874403b588)
2022-10-14 11:29:58 +02:00
Beniamino Galvani
4c89c7df38 dns: merge branch 'bg/dns-sort'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1427

(cherry picked from commit e03b8fa447)

(cherry picked from commit 925ea8b24c)

(cherry picked from commit 53eba18d60)
2022-10-14 10:53:34 +02:00
Beniamino Galvani
2ae89526ca dns: sort the ip-data list when a new element is added
In nm_dns_manager_set_ip_config() we try to avoid calling update_dns()
unless something changes, because updating DNS is expensive and can
trigger other actions such as a new hostname resolution.

When we add a new ip_data, even if the new element is equivalent to
the old one that was removed, we need to sort the list again.

Fixes: ce0a36d20f ('dns: better track l3cd changes')
https://bugzilla.redhat.com/show_bug.cgi?id=2098574
(cherry picked from commit 3cc7801779)
(cherry picked from commit db4c55c8d3)
(cherry picked from commit 6ac62a746f)
2022-10-14 10:53:34 +02:00
Beniamino Galvani
79c08e8d59 dns: add comment explaining the purpose of any_removed
(cherry picked from commit 4d1ecd8d6d)
(cherry picked from commit 01b4040a7a)
(cherry picked from commit ad8a6a59af)
2022-10-14 10:53:34 +02:00
Thomas Haller
cd855580f7
doc: fix bind-activation description for AddAndActivateConnection2 D-Bus API
Fixes: eb883e34a5 ('core: Add option to AddAndActivateConnection2 to bind the lifetime')
(cherry picked from commit 88f5e7518a)
(cherry picked from commit afe53b902f)
(cherry picked from commit 659ee74d8d)
2022-10-05 10:59:19 +02:00
Thomas Haller
f0b5345ab0
core: merge branch 'th/mlag-bonding-slb' (part 2)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1385

(cherry picked from commit c5beec90a8)

(cherry picked from commit 278d32c7e7)

(cherry picked from commit fff62917b7)
2022-09-29 16:53:08 +02:00
Thomas Haller
ae34c8d32b
firewall: introduce helper function for add/flush/delete nft table command
(cherry picked from commit e796a67d6c)
(cherry picked from commit 56a503c879)
(cherry picked from commit 798d8ee832)
2022-09-29 16:53:06 +02:00
Thomas Haller
819a93591d
firewall: fail from nm_firewall_nft_call() on non-zero exit code
(cherry picked from commit 02feefb1df)
(cherry picked from commit d7bc25b3bd)
(cherry picked from commit 403c6de957)
2022-09-29 16:53:06 +02:00
Thomas Haller
c5089ebcc3
device: allow resetting the devip state via nm_device_devip_set_state()
There is no reason to disallow resetting the state.

(cherry picked from commit 607a9544cb)
(cherry picked from commit 6af0233a21)
(cherry picked from commit aebfb3461e)
2022-09-29 16:53:06 +02:00
Thomas Haller
6c7010a3a9
glib-aux: add NM_UTILS_ERROR_COMMAND_FAILED error code
(cherry picked from commit a5f125f8cb)
(cherry picked from commit f4126a12cd)
(cherry picked from commit 9b982c4ea3)
2022-09-29 16:53:05 +02:00
Thomas Haller
299fad171e
glib-aux: add nm_utils_get_process_exit_status_desc_buf() helper
(cherry picked from commit 95e6ebec66)
(cherry picked from commit 431c219ad1)
(cherry picked from commit f3f99e03f5)
2022-09-29 16:53:05 +02:00
Thomas Haller
ce39ec3c3b
firewall: merge branch 'th/firewall-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1379

(cherry picked from commit a939324a78)

(cherry picked from commit 234ec6f263)

(cherry picked from commit e3330ba1d4)
2022-09-29 16:49:18 +02:00
Thomas Haller
b0a567e350
firewall: move logging stdin argument to nft call
(cherry picked from commit b74e2cbfaa)
(cherry picked from commit 8139b27584)
(cherry picked from commit ff04405391)
2022-09-29 16:49:16 +02:00
Thomas Haller
d7f504518f
firewall: expose nm_firewall_nft_call() in header file
(cherry picked from commit cfeecbedff)
(cherry picked from commit 07c519c37f)
(cherry picked from commit 4ac934cbe4)
2022-09-29 16:49:16 +02:00
Thomas Haller
9fcef5ae34
firewall-utils: move _append() macro to be used by other places
(cherry picked from commit 0a0c197916)
(cherry picked from commit 49ae45f838)
(cherry picked from commit 8ec2391f9a)
2022-09-29 16:49:15 +02:00