Commit graph

16048 commits

Author SHA1 Message Date
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
0a00b2a95a nm-daemon-helper: log to stderr any error from getaddrinfo()
Print errors from getaddrinfo() to stderr so that they will be logged
by NM.

(cherry picked from commit ac5325e96b)
(cherry picked from commit 41cd94f46a)
2023-02-22 15:01:53 +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
bb20948b7b
libnm/docs: improve documentation for ipv[46].dhcp-iaid setting
(cherry picked from commit f36fabc0fa)
(cherry picked from commit e1d6d72f8e)
2023-02-21 09:46:42 +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
c45c5c37a4
libnm: accept ipv[46].dhcp-iaid as hexstr
dhclient exports the currently used IAID in the environment as
hex string. We expose this environment in our API, so this is also
the format that NetworkManager uses.

Accept setting the ipv[46].dhcp-iaid as hex string, so that the same
format is accepted on the profile.

While at it, also accept a hex number (0x) because it is also
convenient, and this change already introduces the precedent that the
IAID string is not unique/normalized.

(cherry picked from commit e5dc489197)
(cherry picked from commit 0b4446e252)
2023-02-21 09:45:25 +01:00
Thomas Haller
5f8b0c4713
base: add nm_dhcp_iaid_{from,to}_hexstr() helpers
(cherry picked from commit 4c18adbc74)
(cherry picked from commit 05c6a0d6fa)
2023-02-21 09:45:11 +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
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