Commit graph

29993 commits

Author SHA1 Message Date
Beniamino Galvani
99984e43c4 core: fix l3cd comparison
NM_CMP_SELF(a, b) returns immediately if the objects are the same.

Fixes: cb29244552 ('core: support compare flags in nm_l3_config_data_cmp_full()')
Fixes-test: @dracut_NM_iSCSI_ibft_table

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1583
(cherry picked from commit 0a02995175)
(cherry picked from commit 5d95c20787)
(cherry picked from commit 1395171326)
(cherry picked from commit 15236fcba6)
2024-01-15 17:34:24 +01:00
Gris Ge
295241c0d4 merge: branch 'nm-1-36'
[nm-1.36] [RFE] dispatch `dns-change` dispatcher event

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1764
2023-10-19 09:04:41 +00:00
Gris Ge
b431c89e29 dispatch dns-change dispatcher event
Introducing new dispatcher event -- `dns-change` which will be emitted when
DNS configuration changed(even in `dns=none` mode). This is to solve two
use cases:
 * Invoke dispatch script for DNS changes triggered by the global DNS
   API.

 * Do not invoke [OpenShift resolv-prepender][1] for non-DNS changes.

Bug reference: https://issues.redhat.com/browse/RHEL-1671

[1]: https://github.com/openshift/machine-config-operator/blob/master/templates/common/on-prem/files/resolv-prepender.yaml

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a1db61ebc9)
(cherry picked from commit 3cdce71b95)
(cherry picked from commit 9ae535c61a)
(cherry picked from commit e74a349e1e)
(cherry picked from commit 410f73e7e6)
2023-10-19 16:54:00 +08:00
Gris Ge
0bc49a757e emit DNS CONFIG_CHANGED signal even dns=none
Instruct the `NMDnsManager` to emit `CONFIG_CHANGED` signal even
`dns=none` or failed to modify `/etc/resolv.conf`.

The `NMPolicy` will only update hostname when DNS is managed.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a847ba8075)
(cherry picked from commit d10f20fd01)
(cherry picked from commit e0f3a91a95)
(cherry picked from commit cd9ebfd2bb)
(cherry picked from commit 43523d60f3)
2023-10-19 16:54:00 +08:00
Lubomir Rintel
35e76b509b cloud-setup: actually pass the HTTP method in nm_http_client_poll_req()
https://bugzilla.redhat.com/show_bug.cgi?id=2179718

Fixes: 8b7e12c2d6 ('cloud-setup/ec2: start with requesting a IMDSv2 token')
Fixes: cd74d75002 ('cloud-setup: make nm_http_client_req() accept a method argument')
(cherry picked from commit f07da04cd9)
(cherry picked from commit d787c0c59d)
(cherry picked from commit 6abbdaaa64)
(cherry picked from commit 16dc184845)
2023-09-15 13:49:26 +02:00
Lubomir Rintel
ee157ad48b cloud-setup/ec2: start with requesting a IMDSv2 token
The present version of the EC2 metadata API (IMDSv2) requires a header
with a token to be present in all requests. The token is essentially a
cookie that's not actually a cookie that's obtained with a PUT call that
doesn't put anything. Apparently it's too easy to trick someone into
calling a GET method.

EC2 now supports IMDSv2 everywhere with IMDSv1 being optional, so let's
just use IMDSv2 unconditionally. Also, the presence of a token API can
be used to detect the AWS EC2 cloud.

https://bugzilla.redhat.com/show_bug.cgi?id=2151986
(cherry picked from commit 8b7e12c2d6)
(cherry picked from commit 429f36cd81)
(cherry picked from commit e3ac982b32)
(cherry picked from commit c5a3e739b1)
2023-09-15 13:49:26 +02:00
Lubomir Rintel
181466c6da cloud-setup: make nm_http_client_req() accept a method argument
We'll need to be able to issue PUT calls.

(cherry picked from commit cd74d75002)
(cherry picked from commit eff4372045)
(cherry picked from commit aaf66e9174)
(cherry picked from commit 3d94f4fdf9)
2023-09-15 13:49:26 +02:00
Lubomir Rintel
4c846a112a cloud-setup: rename get/Get identifiers to req and Req
We're going to extend those to issue methods other than GET.
Also, "request" would've been too long, "req" looks nicer.

(cherry picked from commit 85ce088616)
(cherry picked from commit 6e8cfbae32)
(cherry picked from commit 20cd11ee49)
(cherry picked from commit 9ce530fa7a)
2023-09-15 13:49:26 +02:00
Thomas Haller
7e516418e0 cloud-setup: use nm_strv_dup_packed() in nm_http_client_poll_get()
No need to do a deep clone. The strv array is not ever modified and we
pack it together in one memory allocation.

(cherry picked from commit 599fe234ea)
(cherry picked from commit 3787eacac9)
(cherry picked from commit 89a6ce575d)
(cherry picked from commit d14dc95be3)
2023-09-15 13:49:26 +02:00
Lubomir Rintel
f584b9c97b cloud_setup: unexport nm_http_client_get()
It's not used anywhere.

(cherry picked from commit ce225b2c06)
(cherry picked from commit 23b9514080)
(cherry picked from commit 36d417af60)
(cherry picked from commit d83537bff5)
2023-09-15 13:49:26 +02:00
Thomas Haller
1cf4fd0235 cloud-setup: track config-task-data in iface-data
Let NMCSProviderGetConfigIfaceData.get_config_data have a pointer to the
NMCSProviderGetConfigTaskData. This will allow two things:

- at several places we pass on `nm_utils_user_data_pack(get_config_data,
  config_iface_data)` as user data. We can avoid that, by just letting
  config_iface_data have a pointer to get_config_data.

- NMCSProviderGetConfigIfaceData contains a provider specific field
  "priv". That may also require special initialization or destruction,
  depending on the type. We thus need access to the provider type,
  which we have via iface_data->get_config_data->self.

Also let NMCSProviderGetConfigTaskData have a pointer "self" to the
NMCSProvider. While there was already the "task", which contains the
provider as source-object, this is more convenient.

(cherry picked from commit 069946cda1)
(cherry picked from commit 061c05ca39)
2023-09-15 13:48:57 +02:00
Thomas Haller
b41a82a35e core: fix enum argument in prototype of nm_utils_kill_process_sync(), etc.
This avoids a new compiler warning with gcc 13.0.0-0.9.fc38:

  ../src/core/nm-core-utils.c:482:1: error: conflicting types for 'nm_utils_kill_child_async' due to enum/integer mismatch; have 'void(pid_t,  int,  NMLogDomain,  const char *, guint32,  void (*)(pid_t,  gboolean,  int,  void *), void *)' {aka 'void(int,  int,  NMLogDomain,  const char *, unsigned int,  void (*)(int,  int,  int,  void *), void *)'} [-Werror=enum-int-mismatch]
    482 | nm_utils_kill_child_async(pid_t                   pid,
        | ^~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from ../src/core/nm-core-utils.c:9:

Fixes: 067202b34e ('core: use explict NMLogDomain enum instead of int')
(cherry picked from commit a60476b27f)
(cherry picked from commit 18047f09d4)
(cherry picked from commit b2b49df992)
2023-07-05 09:25:51 +02:00
Thomas Haller
23f79bf1df curl: use CURLOPT_PROTOCOLS_STR instead of deprecated CURLOPT_PROTOCOLS
CURLOPT_PROTOCOLS [0] was deprecated in libcurl 7.85.0 with
CURLOPT_PROTOCOLS_STR [1] as a replacement.

Well, technically it was only deprecated in 7.87.0, and retroactively
marked as deprecated since 7.85.0 [2]. But CURLOPT_PROTOCOLS_STR exists
since 7.85.0, so that's what we want to use.

This causes compiler warnings and build errors:

  ../src/core/nm-connectivity.c: In function 'do_curl_request':
  ../src/core/nm-connectivity.c:770:5: error: 'CURLOPT_PROTOCOLS' is deprecated: since 7.85.0. Use CURLOPT_PROTOCOLS_STR [-Werror=deprecated-declarations]
    770 |     curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
        |     ^~~~~~~~~~~~~~~~
  In file included from ../src/core/nm-connectivity.c:13:
  /usr/include/curl/curl.h:1749:3: note: declared here
   1749 |   CURLOPTDEPRECATED(CURLOPT_PROTOCOLS, CURLOPTTYPE_LONG, 181,
        |   ^~~~~~~~~~~~~~~~~

This patch is largely taken from systemd patch [2].

Based-on-patch-by: Frantisek Sumsal <frantisek@sumsal.cz>

[0] https://curl.se/libcurl/c/CURLOPT_PROTOCOLS.html
[1] https://curl.se/libcurl/c/CURLOPT_PROTOCOLS_STR.html
[2] 6967571bf2
[3] e61a4c0b7c

Fixes: 7a1734926a ('connectivity,cloud-setup: restrict curl protocols to HTTP and HTTPS')
(cherry picked from commit dabfea2fc2)
(cherry picked from commit 7122ef4007)
(cherry picked from commit 309cc0e2f2)
2023-07-05 00:20:42 +02:00
Thomas Haller
229f7a5f63 platform/tests: skip test_netns_bind_to_path() test on failure
Our copr builds start to fail, since the copr builds updated to Fedora
38 ([1]).

  ERROR: src/core/platform/tests/test-link-linux - Bail out! nm:ERROR:src/core/platform/tests/test-link.c:3486:test_netns_bind_to_path: assertion failed (nmtstp_run_command("ip netns exec " P_NETNS_BINDNAME " true") == 0): (65280 == 0)

The cause is not understood, but it seems not worth investigating.
Just skip the test.

[1] https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/KOR3HE2VHHIPDBLDLXTYRMON6JQXCHMW/#J4K5VB5SA6I5P2ZLI65OHNQ6X7SINSHA

(cherry picked from commit 8dfca3d552)
(cherry picked from commit e06432cc7f)
(cherry picked from commit 533310ca09)
(cherry picked from commit fa4de663bb)
2023-07-04 20:43:19 +02:00
Thomas Haller
526f701bcc platform/tests: check errno on failure to umount() in test_netns_bind_to_path()
The umount() call failed in a test. Rework the assertion, so
we might see the errno of the problem.

(cherry picked from commit 1a0fa85397)
(cherry picked from commit c66ae93415)
(cherry picked from commit edf23f434e)
(cherry picked from commit 01134c6fe8)
2023-07-04 20:43:13 +02:00
Beniamino Galvani
c1312de171 dns: fix tracking of best ip config
When a IP configuration has type "best", it is the configuration with
the best (lowest) metric default route for the specific address
family. Therefore, there can be only one best configuration for
address family.

When a new configuration is added as best, make sure it is the only
one for the address family.

This reverts commit 0abc14b3a0.

Fixes: 0abc14b3a0 ('core: remove unused best_ip_config_[46] field in NMDnsManager')

https://lists.freedesktop.org/archives/networkmanager/2023-June/000123.html
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1331
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1683
(cherry picked from commit 646e041523)
(cherry picked from commit 2ddb4e5942)
(cherry picked from commit 9cb9dfa77b)
(cherry picked from commit d61196451d)
2023-06-29 15:29:38 +02:00
Gris Ge
387ae9d7ff setting-connection: Unblock autoconnect upon finish of Reapply
The activation of a connection will clear the block of autoconnect,
we should do the same for reapply.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 0486efd358)
(cherry picked from commit 18ce5f43bd)
(cherry picked from commit 2695396939)
(cherry picked from commit 32d2e3c14b)
2023-06-27 20:01:19 +08:00
Beniamino Galvani
194200cd19 ipv6ll: don't regenerate the address when it's removed externally
Currently if the IPv6 link-local address is removed after it passed
DAD, NetworkManager tries to generate a new link-local address. If
this fails, which is always the case for EUI64, ipv6ll is considered
as failed and the connection can go down (depending on may-fail).

This is particularly bad for virtual interfaces because if somebody
removes the link-local address, the activation can fail and destroy
the interface, breaking all services that require it. Also, it's a
change in behavior introduced in 1.36.0.

It seems that a better approach here is to re-add the address that was
removed externally.

[bgalvani@redhat.com: since the branch is missing commit 7ca95cee15
('platform: always reconfigure IP routes even if removed externally'),
we need to set flag NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE when committing
the address, otherwise it's not re-added]

Fixes: aa070fb821 ('core: add NML3IPv6LL helper')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1622
(cherry picked from commit 53ba9f4701)
(cherry picked from commit 2976e4c3b7)
(cherry picked from commit 4a13b5f522)
(cherry picked from commit f61519167d)
2023-05-23 22:04:11 +02:00
Beniamino Galvani
90ef7aeed3 device: skip DNS resolution for tentative IPv6 addresses
A tentative IPv6 address can still fail DAD, so don't use it to
resolve the hostname via DNS. Furthermore, tentative addresses can't
be used to contact the nameserver and so the resolution will fail if
there is no other valid IPv6 address. Wait that the address becomes
non-tentative.

(cherry picked from commit 4138be6a5a)
(cherry picked from commit 0ebd753819)
(cherry picked from commit 26d5ad4680)
(cherry picked from commit 115634d3b1)
2023-03-01 11:51:04 +01:00
Thomas Haller
fcf2e40f5f
libnm/tests: adjust test for glib change in 2.75.0 for assertion warning
See-also: 0ffe86a1f7
(cherry picked from commit 861fc6854c)
(cherry picked from commit c5917b0a50)
(cherry picked from commit 66d1039520)
2023-02-11 18:35:17 +01:00
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