Commit graph

30267 commits

Author SHA1 Message Date
Ana Cabral
f9db66f8db NEWS: update 2022-08-24 11:15:07 +02:00
Thomas Haller
ffe59f4ca6
release: bump version to 1.38.5 (development) 2022-08-11 18:18:37 +02:00
Thomas Haller
89f351d453
release: bump version to 1.38.4 2022-08-11 18:18:37 +02:00
Thomas Haller
6eaee2b13f
device: fix reapply for lldp/mdns/llmnr/dns-over-tls settings
When only one of those connection.{lldp,mdns,llmnr,dns-over-tls}
settings changes, we still need to do a full restart of the IP
configuration to reapply the changes.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit f4b128c63b)
2022-08-11 18:10:12 +02:00
Thomas Haller
dced08e3b0
glib-aux: add nm_g_hash_table_contains_any() helper
(cherry picked from commit e0fc8a11d5)
2022-08-11 18:10:12 +02:00
Thomas Haller
47d2f43d87
NEWS: update 2022-08-11 15:28:52 +02:00
Thomas Haller
bf0c71dd9d
glib-aux: merge branch 'th/random-utils'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1323

(cherry picked from commit cf141f3e7a)
2022-08-05 19:41:48 +02:00
Thomas Haller
b4bc5e62d2
core: block to get good random bytes for "/var/lib/NetworkManager/secret_key"
_host_id_read() is the only place where we really care to have good
random numbers, because that is the secret key that we persist to disk.

Previously, we tried only nm_random_get_bytes_full(), which is a best
effort to get strong random numbers. If it fails to generate those,
it would simply remember the generated key in memory and proceed, but not
persist it to disk.

nm_random_get_bytes_full() does not block waiting for good numbers.

Change that. Now, first call nm_random_get_crypto_bytes(), which would
block and try hard to get good random numbers. Only if that fails,
fallback to nm_random_get_bytes_full() as before. The difference is of
course only in early boot, when we might not yet have entropy. In that
case, I think it's better for NetworkManager to block.

(cherry picked from commit 67a5cf7675)
2022-08-05 19:41:02 +02:00
Thomas Haller
4ca7c9057a
glib-aux: rework random number utils
Heavily inspired by systemd ([1]).

We now also have nm_random_get_bytes{,_full}() and
nm_random_get_crypto_bytes(), like systemd's random_bytes()
and crypto_random_bytes(), respectively.

Differences:

- instead of systemd's random_bytes(), our nm_random_get_bytes_full()
  also estimates whether the output is of high quality. The caller
  may find that interesting. Due to that, we will first try to call
  getrandom(GRND_NONBLOCK) before getrandom(GRND_INSECURE). That is
  reversed from systemd's random_bytes(), because we want to find
  out whether we can get good random numbers. In most cases, kernel
  should have entropy already, and it makes no difference.

Otherwise, heavily rework the code. It should be easy to understand
and correct.

There is also a major bugfix here. Previously, if getrandom() failed
with ENOSYS and we fell back to /dev/urandom, we would assume that we
have high quality random numbers. That assumption is not warranted.
Now instead poll on /dev/random to find out.

[1] a268e7f402/src/basic/random-util.c (L81)

(cherry picked from commit d20343c9d0)
2022-08-05 19:41:01 +02:00
Thomas Haller
e3722827bf
glib-aux: add assertions to nm_utils_fd_wait_for_event()
(cherry picked from commit e80fc43f2a)
2022-08-05 19:41:00 +02:00
Thomas Haller
b9c42c9b64
glib-aux: accept zero bytes for nm_utils_random_bytes()
As an edge case, also accept requesting zero bytes of
randomness.

(cherry picked from commit 614e050b24)
2022-08-05 19:40:42 +02:00
Thomas Haller
c4630858ce
glib-aux: reseed state for "bad" random bytes every time
nm_utils_random_bytes() is supposed to give us good random number from
kernel. It guarantees to always provide some bytes, and it has a
boolean return value that estimates whether the bytes are good
randomness. In practice, most callers ignore that return value, because
what would they do about it anyway?

Of course, we want to primarily use getrandom() (or "/dev/urandom"). But
if we fail to get random bytes from them, we have a fallback path that
tries to generate "random" bytes.

It does so, by initializing a global seed from various sources, and keep
sha256 hashing the buffer in a loop. That's certainly not efficient nor
elegant, but we already are in a fallback path.

Still, we can do slightly better. Instead of just using the global state
and keep updating it (entirely deterministically), every time also mix in
the results from getrandom() and a current timestamp. The idea is that if you
have a virtual machine that gets cloned, we don't want that our global
state keeps giving the same random numbers. In particular, because
getrandom() might handle that case, even if it doesn't have good
entropy.

(cherry picked from commit 3c349ee11b)
2022-08-05 19:40:42 +02:00
Georg Müller
8e748944f0
crypto: support EC private keys
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1324
(cherry picked from commit 1d614dbded)
2022-08-04 10:03:05 +02:00
avery
40870dd6d0
nmcli-completion: fix support for embedded quote characters
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/455

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

Fixes: 9d2290135c ('cli: make nmcli do its own command completion')
(cherry picked from commit ebdf3bd376)
2022-08-04 10:03:01 +02:00
Beniamino Galvani
4430e663c6 bridge: don't reset vlan filtering parameters on external connections
Fixes: 96fab7b462 ('all: add vlan-filtering and vlan-default-pvid bridge properties')

https://bugzilla.redhat.com/show_bug.cgi?id=2107647
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1305
(cherry picked from commit 2c70fef12e)
2022-07-26 09:05:14 +02:00
Beniamino Galvani
5481fced57 supplicant: increase the PMK lifetime for WPA-EAP
By default, wpa_supplicant sets these parameters according to the
802.11 standard:

  dot11RSNAConfigPMKLifetime = 43200 seconds (12 hours)
  dot11RSNAConfigPMKReauthThreshold = 70%

With these, the supplicant triggers a new EAP authentication every 8
hours and 24 minutes. If the network uses one-time secrets, the
reauthentication fails and the supplicant disconnects. It doesn't seem
desirable that the client starts a reauthentication so early; bump the
lifetime to a week.

Currently, due to a bug, the new value is ignored by wpa_supplicant
when set via D-Bus. This patch needs the fix at [1], not yet merged.

[1] http://lists.infradead.org/pipermail/hostap/2022-July/040664.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1306
(cherry picked from commit e35f2494f8)
2022-07-26 09:05:12 +02:00
Thomas Haller
f7ced16ccc
dhcp: fix EXTENDED DHCP event to accept lease for dhclient plugin
n-dhcp4 only supports calling ACCEPT during the GRANTED state.
Not during a EXTENDED event. So usually, we would not want
to call accept in that case.

And we didn't. During EXTENDED event, we would usually skip ACD (because
it's either not enabled or we already passed ACD for the current address).
In that case, in _nm_dhcp_client_notify() we hit the line

     if (client_event_type == NM_DHCP_CLIENT_EVENT_TYPE_BOUND && priv->l3cd_curr
         && nm_l3_config_data_get_num_addresses(priv->l3cd_curr, priv->config.addr_family) > 0)
         priv->l3cfg_notify.wait_dhcp_commit = TRUE;
     else
         priv->l3cfg_notify.wait_dhcp_commit = FALSE;

and would not set `wait_dhpc_commit`. That means, we never called _dhcp_client_accept().
For nettools, that doesn't really matter because calling ACCEPT during EXTENDED
is invalid anyway. However, for dhclient that is fatal because we wouldn't reply the
D-Bus request from nm-dhcp-helper. The helper times out after 60 seconds and dhclient
would misbehave.

We need to fix that by also calling _dhcp_client_accept() in the case when we don't
need to wait (the EXTENDED case).

However, previously _dhcp_client_accept() was rather peculiar and didn't like to be
called in an unexpected state. Relax that. Now, when calling accept in an unexpected
state, just do nothing and signal success. That frees the caller from the complexity
to understand when they must/must not call accept.

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

Fixes: 156d84217c ('dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1308
(cherry picked from commit 5077018ff4)
2022-07-25 20:48:16 +02:00
Ana Cabral
4a219f149a
rpm: make the ifcfg informational message available from RHEL 9
(cherry picked from commit 41b5831331)
2022-07-25 20:25:08 +02:00
Ana Cabral
74e9ec0411
rpm: include a warning message for network configuration on /etc/sysconfig/network-scripts directory
NetworkManager now does not support network configuration through
ifcfg files by default anymore, it is provided in a separated
package:
https://fedoramagazine.org/converting-networkmanager-from-ifcfg-to-keyfiles/

This commits include a file in rpm packages located in ifcfg scripts
directory, /etc/sysconfig/network-scripts/, to inform the user of
the new location of network configuration files.

https://bugzilla.redhat.com/show_bug.cgi?id=2074020
(cherry picked from commit 96d7362613)
2022-07-25 20:24:23 +02:00
Beniamino Galvani
562239779c ovs: fail device only when it's activating
It doesn't make sense to fail a device that is not activating.

Especially, if the device was in state UNMANAGED, it would enter state
FAILED (and then DISCONNECTED) or ACTIVATED (when external or
assumed); both are wrong.

https://bugzilla.redhat.com/show_bug.cgi?id=2077950
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1302
(cherry picked from commit 93372e8100)
2022-07-19 14:08:51 +02:00
Beniamino Galvani
6fbb1c282e core: merge branch 'bg/l3cd-dns-priority'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1045
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1298

(cherry picked from commit e122df6005)
2022-07-18 07:56:22 +02:00
Beniamino Galvani
6a83fad831 ppp,wwan: remove explicit initialization of DNS priority
It's no longer necessary, as modem devices get the priority from the
ipmanual configuration created from the profile.

(cherry picked from commit 8c17760f62)
2022-07-18 07:56:22 +02:00
Beniamino Galvani
2ddb643319 wwan: enable manual IP configuration
Before 1.36, manual addresses from the profile were assigned to the
interface; restore that behavior.

The manual IP configuration also contains the DNS priority from the
profile; so this change ensures that the merged l3cd has a DNS
priority and that dynamically discovered DNS servers are not ignored
by the DNS manager.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 0717589972)
2022-07-18 07:56:22 +02:00
Beniamino Galvani
2128e4542e device: add "is_manual" argument to ready_for_ip_config() device method
Some device types might want to run manual ip configuration while
skipping other methods.

(cherry picked from commit 2ae8433520)
2022-07-18 07:56:22 +02:00
Beniamino Galvani
95df70112f core: update DNS when the device enters IP_CONFIG state
Update DNS information when the device enters the IP_CONFIG state. In
this way, when dispatcher events "dhcp4-change,dhcp6-change" are
emitted resolv.conf already contains the information received from
the DHCP lease.

https://bugzilla.redhat.com/show_bug.cgi?id=2100456
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1283
(cherry picked from commit 1784fc9fa1)
2022-07-11 15:57:57 +02:00
Thomas Haller
2946192217
libnm: fix timestamp in LIBNM_CLIENT_DEBUG debug logging
Fixes: 9c01d6ca67 ('libnm: print timestamp in LIBNM_CLIENT_DEBUG debug logging')
(cherry picked from commit 287a34990a)
2022-07-04 17:27:21 +02:00
Thomas Haller
ce629741f1
libnm: fix "parameters" argument in nm_client_dbus_call() to be optional
It was documented to be an optional parameter. That is also in line
with g_dbus_connection_call(), which is essentially wrapped by nm_client_dbus_call().

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
(cherry picked from commit ea85f6dfa3)
2022-07-04 17:27:14 +02:00
Slava Monich
25f41811c5
supplicant: fix a memory leak
==30980== 8 bytes in 1 blocks are definitely lost in loss record 1,117 of 6,137
==30980==    at 0x4841C38: malloc (vg_replace_malloc.c:309)
==30980==    by 0x4A246C7: g_malloc (gmem.c:106)
==30980==    by 0x4A4A4BB: g_variant_get_strv (gvariant.c:1607)
==30980==    by 0x4A4CA73: g_variant_valist_get_nnp (gvariant.c:4901)
==30980==    by 0x4A4CA73: g_variant_valist_get_leaf (gvariant.c:5058)
==30980==    by 0x4A4CA73: g_variant_valist_get (gvariant.c:5239)
==30980==    by 0x4A4D11D: g_variant_get_va (gvariant.c:5502)
==30980==    by 0x4A4D1BD: g_variant_lookup (gvariant.c:989)
==30980==    by 0xE9389: parse_capabilities (nm-supplicant-interface.c:1241)
==30980==    by 0xEBF99: _properties_changed_main (nm-supplicant-interface.c:1941)
==30980==    by 0xEF549: _properties_changed (nm-supplicant-interface.c:2867)
==30980==    by 0xEF7ED: _get_all_main_cb (nm-supplicant-interface.c:2972)
==30980==    by 0x262057: _nm_dbus_connection_call_default_cb (nm-dbus-aux.c:70)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DBF43: g_task_return.part.3 (gtask.c:1285)
==30980==    by 0x4918885: g_dbus_connection_call_done (gdbusconnection.c:5765)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DB6D7: complete_in_idle_cb (gtask.c:1229)
==30980==    by 0x4A20981: g_main_dispatch (gmain.c:3325)
==30980==    by 0x4A20981: g_main_context_dispatch (gmain.c:4016)
==30980==    by 0x4A20BEF: g_main_context_iterate.isra.23 (gmain.c:4092)
==30980==    by 0x4A20E33: g_main_loop_run (gmain.c:4290)
==30980==    by 0x2C5C9: main (main.c:509)

Fixes: cd1e0193ab ('supplicant: add BIP interface capability')
(cherry picked from commit 8c5356cec6)
2022-07-04 17:27:10 +02:00
Beniamino Galvani
b3036782dd wifi: wait supplicant to settle before renewing DHCP after roam
After roaming to a different AP, if we trigger a DHCP renewal while
the supplicant is still reauthenticating the REQUEST will be lost and
the client will fall back to sending a DISCOVER, potentially getting a
different address.

Wait that the supplicant state settles before renewing.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1024
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1263
(cherry picked from commit fb4ac007ba)
2022-07-04 13:23:15 +02:00
Beniamino Galvani
409546a5fc
dhcp: nettools: save the lease after it gets accepted
Currently the lease gets saved only on the extended (renewal)
event. Also save it after it gets accepted.

Fixes: 52a0fe584c ('dhcp/nettools: better track currently granted lease')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1261
(cherry picked from commit 2807f6a893)
2022-07-04 11:50:57 +02:00
Beniamino Galvani
4fac7c4a42 merge: branch 'bg/dhcp6-dad' into nm-1-38
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1284
2022-07-01 17:14:41 +02:00
Beniamino Galvani
2fd5fb14ba dhcp: wait DAD completion for DHCPv6 addresses
Wait that addresses received through DHCPv6 complete duplicate address
detection before reporting that the lease can be used.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://bugzilla.redhat.com/show_bug.cgi?id=2096386
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1258
(cherry picked from commit 393bc628ff)
2022-07-01 12:00:13 +02:00
Thomas Haller
47c8d212ad dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin
dhclient itself doesn't do ACD. However, it expects the dhclient-script
to exit with non-zero status, which causes dhclient to send a DECLINE.

`man dhclient-script`:

  BOUND:
     Before actually configuring the address, dhclient-script should
     somehow ARP for it and exit with a nonzero status if it receives a
     reply. In this case, the client will send a DHCPDECLINE  message  to
     the server and acquire a different address.   This may also be done in
     the RENEW, REBIND, or REBOOT states, but is not required, and indeed may
     not be desirable.

See also Fedora's dhclient-script ([1]).

https://gitlab.isc.org/isc-projects/dhcp/-/issues/67#note_97226
33226f2d76/client/dhclient.c (L1652)

[1] a8f6fd046f/f/dhclient-script (_878)

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
(cherry picked from commit 156d84217c)
2022-07-01 11:41:47 +02:00
Thomas Haller
6a2c459d86 dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable.
  It feels nicer to only call the macro once. Of course, the macro
  expands to plain pointer dereferences, so there is little difference
  in terms of executed code.

- handle the default case with no virtual function first.

(cherry picked from commit 0f6df633fa)
2022-07-01 11:41:47 +02:00
Thomas Haller
c9bd7cfc5d dhcp/nettools: cleanup logging for dhcp4_event_handle()
It's pretty pointless to log

  <trace> [1653389116.6288] dhcp4 (br0): client event 7
  <debug> [1653389116.6288] dhcp4 (br0): received OFFER of 192.168.121.110 from 192.168.121.1

where the obscure event #7 is only telling you that we are going
to log something.  Handle logging events first.

In general, drop the "client event %d" message and make sure that all
code paths log something (useful), so we can see in the log that the
event was reached.

(cherry picked from commit 85b15e02fd)
2022-07-01 11:41:47 +02:00
Thomas Haller
1f7bede222 dhcp/nettools: better track currently granted lease
When we accept/decline a lease, then that only works if we are in state
GRANTED. n-dhcp4 API also requires us, to provide the exact lease, that
we were announced earlier.

As such, we need to make sure that we don't accept/decline in the wrong
state. That means, to keep track of what we are doing more carefully.

The functions _dhcp_client_accept()/_dhcp_client_decline() now take
a l3cd argument, the one that we announced earlier. And we check that it
still matches.

(cherry picked from commit 52a0fe584c)
2022-07-01 11:41:47 +02:00
Thomas Haller
27eb23ea44 dhcp: move accept/decline function inside "nm-dhcp-client.c"
They are no longer used from outside, NMDhcpClient fully handles this.
Make them static and internal.

Also, decline is currently unused. It will be used soon, with ACD
support.

(cherry picked from commit 4a256092ee)
2022-07-01 11:41:47 +02:00
Thomas Haller
344c0b3dfc dhcp/trivial: rename connect_l3cfg_notify() to l3_cfg_notify_check_connected()
The function subscribes a callback l3_cfg_notify_cb(). Rename so that
related functions have a clearly related name.

(cherry picked from commit 9abcf3a53c)
2022-07-01 11:41:47 +02:00
Thomas Haller
9acb6f9082 dhcp: replace switch in l3_cfg_notify_cb() with if blocks
The l3_cfg_notify_cb() handler is used for different purposes, and
different events will be considered.

Usually a switch statement is very nice for enums, especially if all
enum values should be handled (because the compiler can warn about
unhandled cases). In this case, not all events are supposed to be
handled. At this point, it seems nicer to just use an if block. It
better composes.

The compiler should be able to optimize both variants to the same
result. In any case, checking some integers for equality is in any case
going to be efficient.

(cherry picked from commit 7db07faa5e)
2022-07-01 11:41:47 +02:00
Thomas Haller
962bcadec9 dhcp: move addr-family specific data to union in NMDhcpClientPrivate
(cherry picked from commit e756533002)
2022-06-29 15:38:41 +02:00
Thomas Haller
68b3868427 dhcp/trivial: drop obsolete code comment
This is done already.

(cherry picked from commit 05cc160494)
2022-06-29 15:38:39 +02:00
Thomas Haller
11d2b5597b dhcp: fix logging of event in _nm_dhcp_client_notify()
(cherry picked from commit cd09f3d364)
2022-06-29 15:38:36 +02:00
Thomas Haller
0edfa4456a dhcp: merge nm_dhcp_client_start_ip4() and nm_dhcp_client_start_ip6() implementations
As almost always, there is a point in keeping IPv4 and IPv6 implementations
similar. Behave different where there is an actual difference, at the bottom
of the stack.

(cherry picked from commit 7f943f5fa6)
2022-06-29 15:38:08 +02:00
Thomas Haller
17425aa0dd dhcp: move code in "nm-dhcp-client.c" (2)
(cherry picked from commit 2b8aeba06d)
2022-06-29 15:38:05 +02:00
Thomas Haller
97241b277a dhcp: minor cleanup in config_init()
(cherry picked from commit 600467b96f)
2022-06-29 15:37:57 +02:00
Thomas Haller
38b8fdb75c dhcp: remove assertion in nm_dhcp_client_handle_event()
Technically, g_warn_if_reached() may not be an assertion, according to
glib. However, there is G_DEBUG=fatal-warnings and we want to run with
that.

So this is an assertion to us. Also, logging to stderr/stdout is not a
useful thing to the daemon. Don't do this. Especially, since it depends
on user provided (untrusted) input.

(cherry picked from commit 892cde1436)
2022-06-29 15:37:28 +02:00
Thomas Haller
d0fcd690dc dhcp: move code in nm_dhcp_client_handle_event()
(cherry picked from commit 9097679aad)
2022-06-29 15:37:24 +02:00
Thomas Haller
116e53352b dhcp: drop NMDhcpState enum
It's unused now.

(cherry picked from commit 802f343d9f)
2022-06-29 15:37:08 +02:00
Thomas Haller
2dba874c5a dhcp: rename/refactor nm_dhcp_client_set_state() to be notifications
Optimally we want stateless, pure code. Obviously, NMDhcpClient needs to
keep state to know what it's doing. However, we should well encapsulate
the state inside NMDhcpClient, and only accept events/notifications that
mutate the internal state according to certain rules.

Having a function public set_state(self, new_state) means that other
components (subclasses of NMDhcpClient) can directly mangle the state.
That means, you no longer need to only reason about the internal state
of NMDhcpClient (and the events/notifications/state-changes that it
implements). You also need to reason that other components take part of
maintaining that internal state.

Rename nm_dhcp_client_set_state() to nm_dhcp_client_notify(). Also, add
a new enum NMDhcpClientEventType with notification/event types.

In practice, this is only renaming. But naming is important, because it
suggests the reader how to think about the code.

(cherry picked from commit 97e65e4b50)
2022-06-29 15:36:57 +02:00
Thomas Haller
62ae5c0d0d dhcp: fix handling of NM_DHCP_STATE_NOOP
The "noop" state is almost unused, however, nm_dhcp_set_state()
has a check "if (new_state >= NM_DHCP_STATE_TIMEOUT)", so the order
of the NOOP state matters.

Fix that by reordering.

Also, just return right away from NOOP.

(cherry picked from commit 9761e38f7e)
2022-06-29 15:30:19 +02:00