Commit graph

16554 commits

Author SHA1 Message Date
Beniamino Galvani
2259c519ab nmcli: increase strength of generated hotspot passwords
The password currently generated has ~48 bits of entropy; increase the
length from 8 to 12 to get ~70 bits. While at it, exclude characters
that look similar and might be entered wrongly by users.

(cherry picked from commit 231128d28d)
2023-03-28 10:57:28 +02:00
Beniamino Galvani
a08511a56f nmcli: don't set a fixed channel for wifi hotspots
Since commit f18bf17dea ('wifi: cleanup
ensure_hotspot_frequency()'), NetworkManager automatically selects a
stable channel for AP connections that don't specify a fixed one. The
advantage of this approach is that NM can select a channel that works
well in the current regulatory domain.

However, nmcli still sets fixed channels 1 for 2.4GHz and 7 for 5GHz
when using the "device wifi hotspot". In particular, channel 7 on 5GHz
seems a bad choice because according to [1] it is not usable anywhere
in the world.

It seems difficult to select channel that works everywhere in the 5GHz
band, so it's better to not set a channel in the profile and let NM
find a usable one. For consistency, do the same also for the 2.4GHz
band even if the default choice (channel 1) should always work; by
letting NM choose a channel, different hotspot created with nmcli have
the chance of using different bands and not interfere with each other.

[1] https://en.wikipedia.org/wiki/List_of_WLAN_channels

(cherry picked from commit e446d2b632)
2023-03-28 10:57:28 +02:00
Beniamino Galvani
b01524d5e7 nmcli: fix generating hotspot password
The generated password was all non-alphanumeric characters.

Fixes: 6e96d71731 ('all: use nm_random_*() instead of g_random_*()')
(cherry picked from commit ac2fb0e93d)
2023-03-28 10:57:28 +02:00
Beniamino Galvani
7982a3d2eb wifi: skip no-ir channels when determining AP channel
If the automatically selected channel for an AP is set as NO-IR in the
current regulatory domain, the hotspot connection will fail to
start. NO-IR means that any mechanisms that initiate radiation are not
permitted on this channel, this includes sending probe requests or
modes of operation that require beaconing such as AP. Skip channels
with the NO-IR flag.

(cherry picked from commit 1399aa925d)
2023-03-28 10:57:28 +02:00
Beniamino Galvani
c10b97d188 platform: store attributes of wifi channels
Store attributes of wifi channels so that in a later commit we can
make better decisions when selecting a channel for hotspot.

Don't skip completely disabled frequencies so that the index of
frequencies doesn't change and get_mesh_channel() and
set_mesh_channel() get a reliable result. This was changed by mistake
in 5abb113386 ('wifi: ignore disabled frequencies '); however
probably nobody is still using OLPC mesh networking at this point.

(cherry picked from commit df285b154e)
2023-03-28 10:57:27 +02:00
Thomas Haller
6064d3431a glib-aux/trivial: reword code comments about bad random fallback in "nm-random-utils.c"
(cherry picked from commit da3c9e470e)
2023-03-28 10:57:19 +02:00
Thomas Haller
d516a96bfe all: use nm_random_*() instead of g_random_*()
g_random_*() is based on GRand, which is not a CSPRNG. Instead, rely on
kernel to give us good random numbers, which is what nm_random_*() does.

Note that nm_random_*() calls getrandom() (or reads /dev/urandom), which
most likely is slower than GRand. It doesn't matter for our uses though.

It is cumbersome to review all uses of g_rand_*() whether their usage of
a non-cryptographically secure generator is appropriate. Instead, just
always use an appropriate function, thereby avoiding this question. Even
glib documentation refers to reading "/dev/urandom" as alternative. Which
is what nm_random_*() does. These days, it seems unnecessary to not use
the best random generator available, unless it's not fast enough or you
need a stable/seedable stream of random numbers.

In particular in nmcli, we used g_random_int_range() to generate
passwords. That is not appropriate. Sure, it's *only* for the hotspot,
but still.

(cherry picked from commit 6e96d71731)
2023-03-28 10:48:20 +02:00
Thomas Haller
f12ad37c36 glib-aux: add nm_random_u64_range() helper
(cherry picked from commit fb1d2da979)
2023-03-28 10:48:20 +02:00
Beniamino Galvani
5d95c20787 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)
2023-03-28 09:19:41 +02:00
Lubomir Rintel
d787c0c59d 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)
2023-03-23 12:44:32 +01:00
Joao Machado
894cb7966d platform/tests: ip6gre & ip6gretap test cases (ip6 tunnel flags)
(cherry picked from commit 1505ca3626)
2023-03-13 09:46:53 +01:00
Joao Machado
65f69ac5e1 libnmc-setting/docs: how to disable ip-tunnel.encapsulation-limit (ip6)
(cherry picked from commit 7c54d26ad6)
2023-03-13 09:46:53 +01:00
Joao Machado
be8ddf367f libnm-core-impl: allow ip6 tunnel flags for ip6gre & ip6gretap
(cherry picked from commit a239317a6b)
2023-03-13 09:46:53 +01:00
Lubomir Rintel
429f36cd81 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)
2023-03-09 15:12:31 +01:00
Lubomir Rintel
d99864ccba 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)
2023-03-09 15:12:31 +01:00
Lubomir Rintel
eff4372045 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)
2023-03-09 15:12:31 +01:00
Lubomir Rintel
6e8cfbae32 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)
2023-03-09 15:12:31 +01:00
Lubomir Rintel
23b9514080 cloud_setup: unexport nm_http_client_get()
It's not used anywhere.

(cherry picked from commit ce225b2c06)
2023-03-09 15:12:31 +01:00
Thomas Haller
3787eacac9 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)
2023-03-09 15:12:31 +01:00
Haochen Tong
d835556e4c
core: fix constructing the IP4Config.Nameservers property
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1563

Fixes: c68e148b02 ('core: extend NML3ConfigData:nameserver to track DNS as string')
(cherry picked from commit c22703b68d)
2023-03-09 07:16:03 +01:00
Thomas Haller
adca87aba9
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)
2023-03-09 07:13:31 +01:00
Beniamino Galvani
fb4de0013a
core: fix crash when reloading global dns configuration
When reloading the configuration and there is a global DNS
configuration without domains, NM crashes in global_dns_equal()
because `old->domains` and `new->domains` are both NULL. Fix that.

  Thread 1 "NetworkManager" received signal SIGTRAP, Trace/breakpoint trap.
  0  g_logv (log_domain=0x7fe81a2110be "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=<optimized out>) at ../glib/gmessages.c:1433
  1  g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at ../glib/gmessages.c:1471
  2  g_hash_table_size (hash_table=<optimized out>) at ../glib/ghash.c:2183
  3  g_hash_table_size (hash_table=<optimized out>) at ../glib/ghash.c:2181
  4  global_dns_equal (new=0xecc540, old=0xe618e0) at ../src/core/nm-config-data.c:1466
  5  nm_config_data_diff (old_data=old_data@entry=0xe60020, new_data=new_data@entry=0xe606a0) at ../src/core/nm-config-data.c:1946
  6  _set_config_data (self=0xe45810, new_data=0xe606a0, reload_flags=NM_CONFIG_CHANGE_CAUSE_SIGHUP) at ../src/core/nm-config.c:2923
  7  nm_config_reload (self=0xe45810, reload_flags=NM_CONFIG_CHANGE_CAUSE_SIGHUP, emit_warnings=emit_warnings@entry=1) at ../src/core/nm-config.c:2875
  8  nm_main_config_reload (signal=<optimized out>) at ../src/core/main.c:141
  9  sighup_handler (user_data=<optimized out>) at ../src/core/main-utils.c:26
  10 g_main_dispatch (context=0xe619e0) at ../glib/gmain.c:3444
  11 g_main_context_dispatch (context=0xe619e0) at ../glib/gmain.c:4162
  12 g_main_context_iterate.constprop.0 (context=0xe619e0, block=1, dispatch=1, self=<optimized out>) at ../glib/gmain.c:4238
  13 g_main_loop_run (loop=0xe5e310) at ../glib/gmain.c:4438
  14 main (argc=<optimized out>, argv=<optimized out>) at ../src/core/main.c:515

Fixes: 1f0d1d78d2 ('dns-manager: always apply options from [global-dns]')
(cherry picked from commit ba4a9ea79a)
2023-03-09 07:13:31 +01:00
Fernando Fernandez Mancera
c543c7f9d7
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)
2023-03-09 07:11:36 +01:00
Beniamino Galvani
89888f85aa dnsmasq: process both global and per-device configuration
The global configuration now can be valid when there are no global
domains defined. The dnsmasq backend must process it and then, if
there is no global default domain, also process the per-connection
settings.

Fixes: 1f0d1d78d2 ('dns-manager: always apply options from [global-dns]')
(cherry picked from commit 5c0a927e0f)
2023-03-03 14:56:02 +01:00
Beniamino Galvani
4353f84230 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)
2023-03-02 11:24:19 +01:00
Thomas Haller
ae1c4f45ad
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)
2023-02-28 13:12:18 +01:00
Etienne Champetier
667ba52272
platform/trivial: fix route type name (unavailable -> unreachable)
Fixes: 766349879e ('platform/trivial: add code comments for NMPGlobalTracker')
(cherry picked from commit 0decc027ba)
2023-02-28 13:11:08 +01:00
Etienne Champetier
e308bd79e8
doc: fix route type name (unavailable -> unreachable)
Fixes: 1cc3d00cb7 ('libnm/doc: list route attributes in `man nm-settings-nmcli`')
(cherry picked from commit fb03dbacd8)
2023-02-28 13:11:07 +01:00
Beniamino Galvani
56ec877f94 device: fix copy/paste error in nm-device-ip-tunnel.c
Fixes: 351c562491 ('devices: support VTI tunnels')
(cherry picked from commit 933e8ea11c)
2023-02-27 13:42:55 +01:00
Fernando Fernandez Mancera
6a438d5157 client/tests: adjust expected output for new order of replace-local-rule
Now replace-local-rule is under routing-rules and therefore expected
output need to be adjusted in tests.

(cherry picked from commit b5e347b313)
2023-02-22 22:37:16 +00:00
Fernando Fernandez Mancera
d09e53ccb7 libnmc-setting: place replace-local-rule under routing-rules
This affects the order in which properties are listed in `nmcli
connection show`. The replace-local-rule property should be after the
routing-rule property.

(cherry picked from commit f46512c54f)
2023-02-22 15:11:05 +01:00
Wen Liang
3ca901483e dbus: deprecate the NMActiveConnection Master property
To embrace the inclusive language, deprecate the NMActiveConnection
Master property and in favor of the NMActiveConnection Controller
property.

(cherry picked from commit af677542b5)
2023-02-21 13:56:16 -05:00
Wen Liang
723b76c8b8 nm-client: expose the method nml_dbus_property_o_notify()
(cherry picked from commit b4e96ec067)
2023-02-21 13:46:24 -05:00
Fernando Fernandez Mancera
4f959945a3 all: add new "ipv[46].replace-local-rule" setting
This setting allows the user to remove the local route rule that is
autogenerated for both IPv4 and IPv6. By default, NetworkManager won't
touch the local route rule.

(cherry picked from commit d2ca44ffc6)
2023-02-21 17:46:30 +01:00
Fernando Fernandez Mancera
779cf25606 platform: introduce function to globally track local route rule
The new function tracks local route rule in the GlobalTracker properly.
It also allow the developer to specify the untrack user tag.

(cherry picked from commit 79611e4fcc)
2023-02-21 17:46:30 +01:00
Wen Liang
934e019270 libnm: add NM_VERSION_1_42_2 2023-02-21 17:46:30 +01:00
Beniamino Galvani
0ebd753819 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)
2023-02-21 13:55:30 +01:00
Beniamino Galvani
41cd94f46a 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)
2023-02-21 13:55:30 +01:00
Beniamino Galvani
f1f1aee711 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)
2023-02-21 13:55:30 +01:00
Beniamino Galvani
7e3dccb781 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)
2023-02-21 13:55:29 +01:00
Beniamino Galvani
8e312f6168 core: change buffer allocation size for the daemon helper
Use slightly more efficient sizes.

(cherry picked from commit 961824d43b)
2023-02-21 13:55:29 +01:00
Thomas Haller
e1d6d72f8e
libnm/docs: improve documentation for ipv[46].dhcp-iaid setting
(cherry picked from commit f36fabc0fa)
2023-02-21 09:30:55 +01:00
Thomas Haller
657949eacd
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)
2023-02-21 09:30:54 +01:00
Thomas Haller
2e0e38ab17
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)
2023-02-21 09:30:54 +01:00
Thomas Haller
6e80a19059
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)
2023-02-21 09:30:53 +01:00
Thomas Haller
0b4446e252
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)
2023-02-21 09:30:53 +01:00
Thomas Haller
05c6a0d6fa
base: add nm_dhcp_iaid_{from,to}_hexstr() helpers
(cherry picked from commit 4c18adbc74)
2023-02-21 09:30:52 +01:00
Thomas Haller
99825e727b
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)
2023-02-21 09:30:52 +01:00
Beniamino Galvani
b87fa496ce 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)
2023-02-20 17:39:45 +01:00
Beniamino Galvani
a2026a8b24 dispatcher: fix constructing the IPv4 nameserver variable
Use the value of the address instead of its pointer.

Fixes: c68e148b02 ('core: extend NML3ConfigData:nameserver to track DNS as string')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1217
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1539
(cherry picked from commit a839395e30)
2023-02-20 09:39:19 +01:00