Commit graph

16036 commits

Author SHA1 Message Date
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
Thomas Haller
66d1039520
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)
2023-02-11 18:33:39 +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
227f0fdfaf
glib-aux: drop usage of malloc_usable_size() in nm_free_secret()
The idea of nm_free_secret() is to clear the secrets from memory. That
surely is some layer of extra snake oil, because we tend to pass secrets
via D-Bus, where the memory gets passed down to (D-Bus) libraries which
have no idea to keep it private. Still...

But turns out, malloc_usable_size() might not actually be usable for
this. Read the discussion at [1].

Stop using malloc_usable_size(), which seems unfortunate.

There is probably no secret relevant data after the NUL byte anyway,
because we tend to create such strings once, and don't rewrite/truncate
them afterwards (which would leave secrets behind as garbage).

Note that systemd's erase_and_free() still uses malloc_usable_size()
([2]) but the macro foo to get that right is terrifying ([3]).

[1] https://github.com/systemd/systemd/issues/22801#issuecomment-1343041481
[2] 11c0f0659e/src/basic/memory-util.h (L101)
[3] 7929e180aa

Fixes: d63cd26e60 ('shared: improve nm_free_secret() to clear entire memory buffer')
(cherry picked from commit 8b66865a88)
(cherry picked from commit 6e7fb78b18)
2023-02-09 19:20:13 +01:00
Thomas Haller
4ac1d3d0fb
cli: fix leaking "value" string in ask_option()
Fixes: c5324ed285 ('nmcli: streamline connection addition')
(cherry picked from commit ea3e61047f)
(cherry picked from commit e60ff37f79)
2023-02-09 14:10:18 +01:00
Thomas Haller
5199bd51e2
cli: use "free()" for string from readline
Since glib 2.45, we are guaranteed that g_free() just calls free(), so
both can be used interchangeably. However, we still only depend on glib
2.40.

In any case, it's ugly to mix the two. Memory allocated by plain
malloc(), should be only freed with free(). The buffer in question comes
from readline, which allocates it using the system allocator.

Fixes: 995229181c ('cli: remove editor thread')
(cherry picked from commit 5dc07174d3)
(cherry picked from commit 633c734255)
2023-02-09 14:10:18 +01:00
Thomas Haller
e2c83c61f0
cli: avoid leak in readline_cb() overwriting previous line
Such leaks show up in valgrind, and are simply bugs.

Also, various callers (not all of them, which is another bug!) like to
take ownership of the returned string and free it. That means, we leave
a dangling pointer in the global variable, which is very ugly and error
prone.

Also, the callers like to free the string with g_free(), which is not
appropriate for the "rl_string" memory which was allocated by readline.
It must be freed with free(). Avoid that, by cloning the string using
the glib allocator.

Fixes: 995229181c ('cli: remove editor thread')
(cherry picked from commit 89734c7553)
(cherry picked from commit de87340b2f)
2023-02-09 14:10:18 +01:00
Lubomir Rintel
09eb729d59 platform: retry link change on RESULT_FAILED_RESYNC
Sometimes the buffer space of the netlink socket runs out and we lose
the response to our link change:

  <info>  [1670321010.2952] platform-linux: netlink[rtnl]: read: too many netlink events. Need to resynchronize platform cache
  <warn>  [1670321010.3467] platform-linux: do-change-link[2]: failure changing link: internal failure 3

With 3 above being WAIT_FOR_NL_RESPONSE_RESULT_FAILED_RESYNC.

Let's try harder.

https://bugzilla.redhat.com/show_bug.cgi?id=2154350
(cherry picked from commit b8738002ed)
2023-01-26 09:24:04 +01:00
Lubomir Rintel
a2345c318d platform: log something nice about RESULT_FAILED_RESYNC
This is not nice:

  <warn>  [1670321010.3467] platform-linux: do-change-link[2]: failure changing link: internal failure 3

Let's explain what "internal failure 3" is.

(cherry picked from commit 1e6fd1288d)
2023-01-26 09:23:59 +01:00
Lubomir Rintel
c83740aaa7 platform: remove log_result from do_change_link()
It conveys no useful information beyond what
wait_for_nl_response_to_string() returns.

(cherry picked from commit ad659de3ba)
2023-01-26 09:23:56 +01:00
Lubomir Rintel
4591241d28 platform: don't negate lefthand argument in set comparison
This 1.) was ugly, 2.) makes it cumbersome to check for both positive
and negative elements in one go.

(cherry picked from commit 3f6d040274)
2023-01-26 09:23:52 +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
Beniamino Galvani
23ec020dd5 nmtui: fix memory leak
Fixes: 3bda3fb60c ('nmtui: initial import of nmtui')
(cherry picked from commit 1c6935e49d)
2022-12-23 09:47:43 +01:00
Beniamino Galvani
2e966436d8 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')
(cherry picked from commit a39ec8ca75)
2022-12-23 09:47:13 +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
5608070764
nm-cloud-setup: simplify clearing variables in retry loop
The label "try_again" is only reached by one goto. So it was correct
and sufficient to reset the state only there.

It is still error prone. The slighlty clearer approach is to clear
the state at each begin of the "try_again" step.

There should be no change in behavior.

I didn't confirm, but an optimizing compiler should (could) be able
to see that the cleanup is only necessary on retry, and generate the
same code as before. In any case, we should write code that is easier
to read, not optimize for something that a compiler should be able to
optimize itself.

(cherry picked from commit 911b550140)
2022-12-19 15:46:51 +01:00
Thomas Haller
467c028ac1
nm-cloud-setup: refactor skipping reapply be checking for skip first
There should be no change in behavior, but this way seems nicer.
Now _nmc_mangle_connection() doesn't return FALSE, it always
will try to mangle the connection and requires the caller to
first check whether that is appropriate.

Just move some code outside of _nmc_mangle_connection() and let
the caller check for the skip first.

The point is consistency, as the caller already does some checks to
whether skip the reapply. So it should do all the checks, so that
"mangle" never fails/skips.

(cherry picked from commit bbd32fba15)
2022-12-19 15:46:49 +01:00
Thomas Haller
37dc0a9c2f
nm-cloud-setup: set preserve-external-ip flag during reapply
Externally added IP addresses/routes should be preserved by
nm-cloud-setup. This allows other tools to also configure the interface
and the Reapply() call from nm-cloud-setup would not interfere
with those tools.

https://bugzilla.redhat.com/show_bug.cgi?id=2132754
(cherry picked from commit 29b0420be7)
2022-12-19 15:46:48 +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
c13cc6fb0f
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".

(cherry picked from commit b23c505fca)
2022-12-19 11:33:45 +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