Commit graph

31122 commits

Author SHA1 Message Date
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
Fernando Fernandez Mancera
920ab658b2 dns: add support to no-aaaa option
Users can set `no-aaaa` DNS option to suppress AAAA queries made by the
stub resolver, including AAAA lookups triggered by NSS-based interfaces
such as getaddrinfo. Only DNS lookups are affected.

(cherry picked from commit 9d4bbf78f0)
(cherry picked from commit f71cd2eb72)
2023-03-29 12:24:44 +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
Lubomir Rintel
6abbdaaa64 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)
2023-03-23 12:45:04 +01:00
Lubomir Rintel
e3ac982b32 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)
2023-03-09 15:13:32 +01:00
Lubomir Rintel
06fc0ef35d cloud-setup: document detect() and get_config() methods
Clarify that detect() needs to succeed before get_config().

I thought it's sort of common sense, but it's better to be explicit as
we're going to rely on that.

(cherry picked from commit 088bfd817a)
(cherry picked from commit d99864ccba)
2023-03-09 15:13:32 +01:00
Lubomir Rintel
aaf66e9174 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)
2023-03-09 15:13:32 +01:00
Lubomir Rintel
20cd11ee49 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)
2023-03-09 15:13:32 +01:00
Lubomir Rintel
36d417af60 cloud_setup: unexport nm_http_client_get()
It's not used anywhere.

(cherry picked from commit ce225b2c06)
(cherry picked from commit 23b9514080)
2023-03-09 15:13:32 +01:00
Thomas Haller
89a6ce575d 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)
2023-03-09 15:13:32 +01: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
Fernando Fernandez Mancera
8eed16dbf4
platform: compare arp_ip_targets_num before arp_ip_target values
We must first check whether a->arp_ip_targets_num and
b->arp_ip_targets_num are identical. Otherwise, this accesses
potentially uninitialized values.

Fixes: f900f7bc2c ('platform: add netlink support for bond link')
(cherry picked from commit 8dd18d91b2)
(cherry picked from commit c543c7f9d7)
2023-03-09 07:28:22 +01:00
Thomas Haller
daec3cf7c7
platform: ensure ext-data is of expected type
We just lookup the link info by ifindex. There is no guarantee that that
ifindex is of the expected type, to have a suitable ext-data. Check for
that.

Fixes: a7d2cad67e ('platform/linux: add support for WPAN links')
(cherry picked from commit 6dafe78088)
(cherry picked from commit ae1c4f45ad)
2023-03-09 07:28:04 +01:00
Thomas Haller
4a22be26cb
doc: fix documenting "carrier-wait-timeout" in NetworkManager-wait-online manual
Fixes: df94cb2116 ('man: add NetworkManager-wait-online.service.8 manual')
(cherry picked from commit 22c7fd33cc)
(cherry picked from commit e943387af7)
2023-03-09 07:22:40 +01:00
Thomas Haller
b3164a73bf
libnm: merge branch 'champtar:route-unreachable'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1549

(cherry picked from commit 90cc458d31)

(cherry picked from commit 0cdd822989)
2023-03-09 07:21:43 +01:00
Etienne Champetier
e37d6f1d75
platform/trivial: fix route type name (unavailable -> unreachable)
Fixes: 766349879e ('platform/trivial: add code comments for NMPGlobalTracker')
(cherry picked from commit 0decc027ba)
(cherry picked from commit 667ba52272)
2023-03-09 07:21:43 +01:00
Etienne Champetier
979591a067
doc: fix route type name (unavailable -> unreachable)
Fixes: 1cc3d00cb7 ('libnm/doc: list route attributes in `man nm-settings-nmcli`')
(cherry picked from commit fb03dbacd8)
(cherry picked from commit e308bd79e8)
2023-03-09 07:21:43 +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
7886f945ba release: bump version to 1.40.17 (development) 2023-02-23 09:59:17 +01:00
Beniamino Galvani
a9f8a9b550 release: bump version to 1.40.16 2023-02-23 09:59:17 +01:00
Beniamino Galvani
dc60f060c9 NEWS: update 2023-02-23 09:31:48 +01:00
Beniamino Galvani
4bccf2ab4c merge: branch 'bg/hostname-skip-ipv6-tentative'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1536

(cherry picked from commit 34417ac3e6)
(cherry picked from commit bc9482f0e5)
2023-02-22 15:04:23 +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
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
b681bcec1d
dhcp: merge branch 'th/dhcp-iaid'
https://bugzilla.redhat.com/show_bug.cgi?id=2169869

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

(cherry picked from commit afbbfebfdb)
(cherry picked from commit 422f086a68)
2023-02-21 09:50:42 +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
06d72e9cd5
release: bump version to 1.40.15 (development) 2023-02-13 15:43:09 +01:00
Thomas Haller
31e483e8af
release: bump version to 1.40.14 2023-02-13 15:43:09 +01:00
Thomas Haller
d24d2e6ad6
gitlab-ci: set OMP_NUM_THREADS=1 to avoid libgomp crash for msgmerge
It's not clear why this happens. But since recently in our gitlab-ci,
all the Fedora machines will fail. It happens in the step

  check_run_clean 6 && test $IS_FEDORA = 1 -o $IS_CENTOS = 1 && ./contrib/fedora/rpm/build_clean.sh -g -w crypto_gnutls -w debug -w iwd -w test -W meson

which explains why it only affects Fedora configurations.

It does not always fail, but the probability of failure is high.
The failure is:

  ...
  rm -f et.gmo && /usr/bin/msgmerge --for-msgfmt -o et.1po et.po NetworkManager.pot && /usr/bin/msgfmt -c --statistics --verbose -o et.gmo et.1po && rm -f et.1po
  libgomp: Thread creation failed: Resource temporarily unavailable
  make[3]: *** [Makefile:383: et.gmo] Error 1

Maybe some new resource restricting in gitlab. Let's add this workaround.
I don't really understand the cause, but this seems to avoid it, which is
good enough for me.

(cherry picked from commit 01730f5943)
2023-02-13 11:32:14 +01:00
Thomas Haller
c74a5acdc0
NEWS: update 2023-02-13 10:02:45 +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
a17b56f6d4
merge: branch 'bg/dns'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1506

(cherry picked from commit 6da2f3af4d)
(cherry picked from commit 618efd56a4)
2023-02-09 20:36:19 +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