Commit graph

1152 commits

Author SHA1 Message Date
Thomas Haller
7d75ae5d34 core: fix setting FD flags in _rfkill_update_system()
F_SETFL will reset the flags. That is wrong, as we only want to add
O_NONBLOCK flag and leaving the other flags alone. Usually, we would
need to call F_GETFL first.

Note that on Linux, F_SETFL can only set certain flags, so the
O_RDWR|O_CLOEXEC flags were unaffected by this. That means, most likely
there are no other flags that our use of F_SETFL would wrongly clear.
Still, it's ugly, because it's not obvious whether there might be other
flags.

Avoid that altogether, by setting the flag already during open().

Fixes: 67e092abcb ('core: better handling of rfkill for WiMAX and WiFi (bgo #629589) (rh #599002)')
(cherry picked from commit 62a85fa845)
2023-04-06 12:26:24 +02:00
Thomas Haller
3364b8b804 core: fix setting non-blocking stderr in nm_utils_spawn_helper()
Fixes: d65702803c ('core: print stderr from nm-daemon-helper')
(cherry picked from commit d1f7e439c6)
2023-04-06 12:25:39 +02:00
Thomas Haller
909c7994fb core: fix setting non-blocking FD in nm_utils_spawn_helper()
Fixes: 6ac21ba916 ('core: add infrastructure for spawning a helper process')
(cherry picked from commit fd123315e5)
2023-04-06 12:25:34 +02:00
Thomas Haller
ee7f66e42c
wifi: fix aggressively roaming (background Wi-Fi scanning) based on seen-bssids
"wifi.seen-bssids" looks like a regular property, but it is not. Unlike
almost all other properties, it does not contain user configuration,
rather it gets filled by the daemon.

The values are thus stored in "/var/lib/NetworkManager/seen-bssids"
file, and the daemon maintains the values separately from the profile.
Only before exporting the profile on D-Bus, the value gets merged (see
NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->>getsettings_cached and
nm_connection_to_dbus_full().

Hence, looking at nm_setting_wireless_get_num_seen_bssids() is not
working. Fix that.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1253

Fixes: 0f3203338c ('wifi: roam aggressively if we on a multi-AP network')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1577
(cherry picked from commit 07c6f933d1)
(cherry picked from commit 3ddc17700d)
2023-03-29 14:27:23 +02:00
Beniamino Galvani
1395171326 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)
2023-03-28 09:32:13 +02:00
Thomas Haller
19d08eeb3d
platform/tests: avoid accessing in_addr_t via NMIPAddr union
The compiler may dislike this:

      CC       src/core/platform/tests/libNetworkManagerTest_la-test-common.lo
    In function '_ip_address_add',
        inlined from 'nmtstp_ip4_address_add' at ../src/core/platform/tests/test-common.c:1892:5:
    ../src/core/platform/tests/test-common.c:1807:63: error: array subscript 'NMIPAddr {aka const struct _NMIPAddr}[0]' is partly outside array bounds of 'in_addr_t[1]' {aka 'unsigned int[1]'} [-Werror=array-bounds]
     1807 |                                                   peer_address->addr4,
          |                                                   ~~~~~~~~~~~~^~~~~~~
    ../src/core/platform/tests/test-common.c: In function 'nmtstp_ip4_address_add':
    ../src/core/platform/tests/test-common.c:1886:36: note: object 'peer_address' of size 4
     1886 |                        in_addr_t   peer_address,
          |                        ~~~~~~~~~~~~^~~~~~~~~~~~
    ...

Fixes: 06aafabf14 ('platform/test: add test adding IPv4 addresses that only differ by their peer-address')
(cherry picked from commit 40dd8bf93a)
(cherry picked from commit adca87aba9)
2023-03-09 07:28:29 +01:00
Beniamino Galvani
164591f754 settings: preserve existing connection flags on update
We are passing to the plugin only 'sett_flags', which is the bitmask
of flags to change and works together with 'sett_mask'; however,
plugins interpret that value as the new flags value. The result is
that if there is no change needed (0/0), the existing flags are lost.
Simple reproducer:

  ip link add dummy1 type dummy
  ip link set dummy1 up
  ip addr add dev dummy1 fd01::12/64
  sleep 1

  # now, a external connection is created by NM

  echo "BEFORE:"
  cat /run/NetworkManager/system-connections/dummy1.nmconnection | grep "nm-generated\|volatile\|external"

  # just add a new address to the interface to make it lose
  # the external flag

  ip addr add dev dummy1 172.25.42.1/24
  sleep 1

  echo "AFTER:"
  cat /run/NetworkManager/system-connections/dummy1.nmconnection | grep "nm-generated\|volatile\|external"

Output:

  BEFORE:
  nm-generated=true
  volatile=true
  external=true
  AFTER:

Fixes: d35d3c468a ('settings: rework tracking settings connections and settings plugins')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1548
(cherry picked from commit 86b922695f)
(cherry picked from commit 4353f84230)
2023-03-02 11:25:39 +01:00
Beniamino Galvani
26d5ad4680 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)
2023-02-22 15:04:06 +01:00
Beniamino Galvani
51e3dd447d core: print stderr from nm-daemon-helper
Currently the only way to return an error code from the daemon helper
is via the process exit code, but that is not enough to fully describe
an error from getaddrinfo(); in fact, the function returns a EAI_*
error code and when the value is EAI_SYSTEM, the error code is
returned in errno.

At the moment, any messages printed to stderr by the helper goes to NM
stderr; instead, we want to capture it and pass it through the logging
mechanism of NM, so that it can be filtered according to level and
domain.

(cherry picked from commit d65702803c)
(cherry picked from commit f1f1aee711)
2023-02-22 15:01:52 +01:00
Beniamino Galvani
dfaee8d967 device: improve logging for hostname-from-dns events
Improve logging:
 - log only when something changes
 - print the new resolver state, instead of the old one
 - rename state "in-progress" to "started"
 - log when the resolver state is reset due to DNS changes

(cherry picked from commit 7037aa66c6)
(cherry picked from commit 7e3dccb781)
2023-02-22 15:01:51 +01:00
Beniamino Galvani
f4c7d3aa82 core: change buffer allocation size for the daemon helper
Use slightly more efficient sizes.

(cherry picked from commit 961824d43b)
(cherry picked from commit 8e312f6168)
2023-02-22 15:01:50 +01:00
Thomas Haller
4efd8565a6
dhcp: log used DHCP IAID as hexstr
This is also the format that we will use to expose it in the lease
information. It's the format that dhclient uses.

(cherry picked from commit 2fe4313b92)
(cherry picked from commit 657949eacd)
2023-02-21 09:46:42 +01:00
Thomas Haller
bec1b14f44
dhcp: add the DHCPv6 IAID to the lease information
We already get the IAID from the dhclient environment. This is actually
rather useful, because dhclient plugin does not support setting the
value (that is, what we request in "config.v6.iaid" is not actually
used). Already previously, was the IAID for dhclient present in the
lease information. Now also normalize/verify it.

Expose the used IAID also with the internal (systemd) plugin. There we
explicitly set the IAID and know it.

(cherry picked from commit 07f1789725)
(cherry picked from commit 2e0e38ab17)
2023-02-21 09:46:39 +01:00
Thomas Haller
c9ecac7098
dhcp: add "static_key" argument to nm_dhcp_option_add_option() etc.
Our lease is tracked in a plain string dictionary. For dhclient plugin
and similar, the keys are received via the environment, they are thus
unlimited. For the internal plugins they are known at compile time and
static strings. We thus sometimes need to clone the string, and
sometimes not.

Unfortunately, we cannot ask the GHashTable whether it has a free
function for the key, so we need to explicitly tell it. Add a parameter
for that.

(cherry picked from commit 5a05ba398b)
(cherry picked from commit 6e80a19059)
2023-02-21 09:46:13 +01:00
Thomas Haller
5dcfb89a48
core: reuse _nm_utils_iaid_verify() for parsing
There should be one function for parsing the string. Use it everywhere.

Also, because we will accept specifying the IAID as hex string so the
same parsing code should be used everywhere.

(cherry picked from commit 69106d0aef)
(cherry picked from commit 99825e727b)
2023-02-21 09:44:30 +01:00
Beniamino Galvani
68da283941 device: update address in nm_device_update_from_platform_link()
When a software device is deactivated, normally we schedule a idle
task to unrealize the device (delete_on_deactivate). However, if a new
activation is enqueued on the same device (and that implies that the
new profile is compatible with the device), then the idle task is not
scheduled and the device will normally transition to the different
states (disconnected, prepare, config, etc.).

For ovs-interfaces, we remove the db entry on disconnect and that
makes the link go away; however, we don't clear the hw_addr* fields of
the device struct.

When the new link appears, we try to set the new cloned MAC but the
stale hw_addr field indicates that it's already set. Avoid this
problem by updating the address as soon as the link appears.

https://bugzilla.redhat.com/show_bug.cgi?id=2168477
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1532
(cherry picked from commit d403ac3d40)
(cherry picked from commit b87fa496ce)
2023-02-20 17:41:23 +01:00
Beniamino Galvani
0c3ce61b02 device: preserve assume state if updating port fails
If we fail to update the port connection, don't forget the assume
state but try again later. This helps when assuming a team connection
and its ports: the ports may fail to generate a connection because
teamd was not started yet; in that case we need to try again.

https://bugzilla.redhat.com/show_bug.cgi?id=2092215
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1523
(cherry picked from commit 27ad228df1)
(cherry picked from commit c273962a73)
2023-02-13 16:02:53 +01:00
Beniamino Galvani
64212a06c4
dns: consider the dns-type and the priority when hashing DNS configs
The dns-type must be included in the hash because it contributes to
the generated composite configuration. Without this, when the type of
a configuration changes (e.g. from DEFAULT to BEST), the DNS manager
would determine that there was no change and it wouldn't call
update_dns().

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

Fixes: 8995d44a0b ('core: compare the DNS configurations before updating DNS')
(cherry picked from commit 46ccc82a81)
(cherry picked from commit 2a0f41af03)
2023-02-09 19:59:42 +01:00
Beniamino Galvani
784f9f7e9f
core,libnm: move enum NMDnsIPConfigType
The enum will be used outside of core/dns.

(cherry picked from commit 8a4632b56a)
(cherry picked from commit b14268290a)
2023-02-09 19:58:58 +01:00
Beniamino Galvani
a1b41b1e97
core: rename and move nm_ip_config_dns_hash()
The function operates on a NML3ConfigData, rename it and move it to
the right place.

(cherry picked from commit ec0a83b224)
(cherry picked from commit a7412e2c65)
2023-02-09 19:58:30 +01:00
Thomas Haller
6d96289942
core: fix type for nameservers in nm_ip_config_dns_hash()
nm_l3_config_data_get_nameservers() returns an array of in_addr_t or
struct in6_addr. This is not a string list.

Incidentally, it was still used correctly, using nm_ip_addr_from_packed_array().

Fix the code to use the right type. Also, only call g_checksum_update()
once for the packed array. No need to iterate over the list one by one.

Fixes: 8995d44a0b ('core: compare the DNS configurations before updating DNS')
2023-02-09 19:56:19 +01:00
Thomas Haller
fbc48c3612 ovs: fix _external_ids_to_string() to print strdict in logging
Fixes: a4b13d5069 ('core/ovs: log external-ids of Interfaces/Ports/Bridges')
(cherry picked from commit 17e16c8fa6)
2023-01-26 09:22:43 +01:00
Thomas Haller
83327bfc58 ovs: don't replace all "other_config" in _set_bridge_mac()
Doing an "update" is wrong, because that will replace all "other_config"
entries. We only want to reset the "hwaddr".

Note that https://www.rfc-editor.org/rfc/rfc7047 says about
"<mutations>":

  If <mutator> is "insert", then each of the key-value pairs in
  the map in <value> is added to <column> only if its key is not
  already present.  The required type of <value> is slightly
  relaxed, in that it may have fewer than the minimum number of
  elements specified by the column's type.

That means, we need to first delete, and then insert the key.

Fixes: 5d4c8521a3 ('ovs: set MAC address on the bridge for local interfaces')
(cherry picked from commit 2641af2cc9)
2023-01-26 09:22:43 +01:00
Thomas Haller
c3e1290e36 ovs: ensure existing "external-ids" get updated during reapply
"mutate" with operation "insert" does not update existing entries.
Delete them first.

Otherwise, a reapply that only change the value of an external-ids
entry does not work.

Note that https://www.rfc-editor.org/rfc/rfc7047 says about
"<mutations>":

  If <mutator> is "insert", then each of the key-value pairs in
  the map in <value> is added to <column> only if its key is not
  already present.  The required type of <value> is slightly
  relaxed, in that it may have fewer than the minimum number of
  elements specified by the column's type.

Fixes: 7055539c9f ('core/ovs: support setting OVS external-ids')
(cherry picked from commit d219527dba)
2023-01-26 09:22:43 +01:00
Thomas Haller
621b20fba2 device: fix available-connections for a device for user-request
There are two callers of available_connections_add(). One from
cp_connection_added_or_updated() (which is when a connection
gets added/modified) and one from nm_device_recheck_available_connections().

They both call first nm_device_check_connection_available() to see
whether the profile is available on the device. They certainly
need to pass the same check flags, otherwise a profile might
be available in some cases, and not in others.

I didn't actually test this, but I think this could result
in a profile wrongly not being listed as an available-connection.
Moreover, that might mean, that `nmcli connection up $PROFILE`
might work to find the device/profile, but `nmcli device up $DEVICE`
couldn't find the suitable profile (because the latter calls
nm_device_get_best_connection(), which iterates the
available-connections). I didn't test this, because regardless of
that, it seems obvious that the conditions for when we call
available_connections_add() must be the same from both places.
So the only question is what is the right condition, and it would
seem that _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST is the right
flag.

Fixes: 02dbe670ca ('device: for available connections check whether they are available for user-request')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1496
(cherry picked from commit 7af9562f28)
2023-01-26 09:22:43 +01:00
Thomas Haller
18047f09d4 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)
2023-01-26 09:22:43 +01:00
Thomas Haller
7122ef4007 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)
2023-01-26 09:22:43 +01:00
Thomas Haller
4c42f90e3c platform: fix nmp_lookup_init_route_by_weak_id() to honor the route-table
The route table is part of the weak-id. You can see that with:

  ip route replace unicast 1.2.3.4/32 dev eth0 table 57
  ip route replace unicast 1.2.3.4/32 dev eth0 table 58

afterwards, `ip route show table all` will list both routes. The replace
operation is only per-table. Note that NMP_CACHE_ID_TYPE_ROUTES_BY_WEAK_ID
already got this right.

Fixes: 10ac675299 ('platform: add support for routing tables to platform cache')
(cherry picked from commit a3cea7f6fb)
2023-01-26 09:22:43 +01:00
Lubomir Rintel
c6685f0179 config: fix a reversed conditional
This effectively makes [*global-dns-domain-*] sections in configuration be
ignored unless [*global-dns] is also present. This happens because
nm_config_keyfile_has_global_dns_config() mixes the group names up and
attempts to loop up [.intern.global-dns-domain-*] in user configuration and
[global-dns-domain-*] in the internal one.

Fixes: da0ded4927 ('config: drop global-dns.enable option in favor of .config.enable')
(cherry picked from commit de1c06daab)
(cherry picked from commit bd4f5333e8)
2023-01-26 09:22:43 +01:00
Thomas Haller
11d8d18c16
firewall: pass "--wait 2" to iptables to wait for concurrent invocations
iptables takes a file lock at /run/xtables.lock. By default, if
the file is locked, iptables will fail with error. When that happens,
the iptables rules won't be configured, and the shared mode
(for which we use iptables) will not be setup properly.

Instead, pass "--wait 2", to block. Yes, it's ugly that we use
blocking program invocations, but that's how it is. Also, iptables
should be fast to not be a problem in practice.

(cherry picked from commit 84a71771d9)
2023-01-16 10:22:05 +01:00
Thomas Haller
53a9ba354f
firewall: automatically add iptables path to _share_iptables_call() call
No need to redundantly specify the path. Also, next we will specify the
"--wait" option, so this will work better.

(cherry picked from commit 53422c8693)
2023-01-16 10:22:05 +01:00
Beniamino Galvani
3c5eb108e9 dhcp: fix test for out-of-tree build
New files must be written to the build directory, not to the source
one.

Fixes: 5ee2f3d1dc ('dhcp/tests: refactor tests for nm_dhcp_dhclient_save_duid()')
(cherry picked from commit 2c056cf9a3)
2023-01-11 11:14:18 +01:00
Beniamino Galvani
af1bbe8bd9 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
(cherry picked from commit 6ea924fa74)
2023-01-11 10:05:15 +01:00
Thomas Haller
1b0d98ab55 ndisc/tests: fix reference counting in nm_fake_ndisc_new()
This adjusts the change from commit ffbcf01589 ('test-ndisc-fake:
free l3cfg after creating fake-ndisc').

ndisc_new() already correctly handles the reference count of l3cfg via
"gs_unref_object". The party that took the wrong reference was
nm_fake_ndisc_new().

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit da371f8108)
2023-01-11 10:04:57 +01:00
Wen Liang
b97b12ed94 dns: kill pending dnsmasq process when mode is not 'dnsmasq'
When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq
process should be killed by NM.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
(cherry picked from commit 6058445aea)
2023-01-11 09:05:36 +01:00
Wen Liang
1e112d7e65 dnsmasq: silently ignore if pid file is not existed when killing
(cherry picked from commit 9b3a96f821)
2023-01-11 09:05:36 +01:00
Thomas Haller
ba66312366
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')
(cherry picked from commit aec7ae8279)
2022-12-20 17:55:21 +01:00
Thomas Haller
a4ff4f9849
dhcp: fix unused variable in nm_dhcp_client_start()
Fixes: 28d7f9b7c4 ('dhcp: drop NMDhcpClientClass.get_duid() hook')
(cherry picked from commit b9bbbfc41f)
2022-12-19 16:18:31 +01:00
Thomas Haller
7218daac78
core: support flag "preserve-external-ip" for Reapply() call
Reapply() is supposed to make sure that the system (the interface)
is configured as indicated by the applied-connection. That means,
it will remove/add configuration to make the system match the requested
configuration.

Add a flag "preserve-external-ip" which relaxes this. During reapply,
IP addresses/routes that exist on the interface and which are not known
(or added) by NetworkManager will be left alone.

This will be used by nm-cloud-setup, so that it can reconfigure the
interface in a less destructive way, which does not conflict with
external `ip addr/route` calls.

Note that the previous commit just adds "VersionInfo" and the
possibility to expose capabilities (patch-level). This is not used
for the new reapply flag, because, while we might backport the
reapply flag, we won't backport the "VersionInfo" property. Exposing
new capabilities via the "VersionInfo" property will only become useful
in the future, where we can backport a capability to older NM versions
(but those that have "VersionInfo" too).

(cherry picked from commit 2c1fb50fb5)
2022-12-19 15:46:45 +01:00
Thomas Haller
c9a8fd6808
device: change error code for Reapply() rejecting unsupported flags argument
Changing an error code is an API change. But, so far no flags existed,
so it's unlikely that somebody would send invalid flags or care about
the return code.

(cherry picked from commit b88cdf2a6b)
2022-12-19 14:32:42 +01:00
Thomas Haller
6bc03e9c95
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.

(cherry picked from commit 1d85608e1c)
2022-12-19 11:33:50 +01:00
Thomas Haller
b7d343af05
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.

(cherry picked from commit c990d6a81a)
2022-12-19 11:33:49 +01:00
Thomas Haller
9a2d2c8522
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.

(cherry picked from commit 0e63fe58a7)
2022-12-19 11:33:48 +01:00
Thomas Haller
b48da72a71
dhcp/tests: add more tests for nm_dhcp_dhclient_save_duid()
(cherry picked from commit 7d1cfec0b8)
2022-12-19 11:33:47 +01:00
Thomas Haller
874ade4f9d
dhcp/tests: refactor tests for nm_dhcp_dhclient_save_duid()
So much duplicate, boilerplate code. Get rid of it.

(cherry picked from commit 5ee2f3d1dc)
2022-12-19 11:33:46 +01:00
Thomas Haller
771589e276
dhcp/trivial: rename DUID_PREFIX define to DEFAULT_DUID_PREFIX
(cherry picked from commit df0408f0f6)
2022-12-19 11:33:45 +01:00
Thomas Haller
919d66f049
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.

(cherry picked from commit a3e4f764d1)
2022-12-19 11:33:44 +01:00
Thomas Haller
1f30005d5e
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.

(cherry picked from commit ef5333e5cf)
2022-12-19 11:33:43 +01:00
Thomas Haller
34d3898427
dhcp: add and use nm_dhcp_client_create_options_dict()
This will be used to pre-fill the lease with client-specific options.

(cherry picked from commit c020f618ed)
2022-12-19 11:33:43 +01:00
Thomas Haller
2535395a8c
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`).

(cherry picked from commit ccbe76b81d)
2022-12-19 11:33:42 +01:00