Commit graph

28669 commits

Author SHA1 Message Date
Thomas Haller
bbfdbf5f76
device/dhcp: avoid crash by not starting DHCPv6 client without ifindex
https://bugzilla.redhat.com/show_bug.cgi?id=1973199
(cherry picked from commit 85f53f43e9)
2021-07-14 18:27:15 +02:00
Thomas Haller
d525a3b795
glib-aux: avoid compiler warning about ignoring getrandom() result
src/libnm-glib-aux/nm-random-utils.c:112:12: error: ignoring return value of 'getrandom' declared with attribute 'warn_unused_result' [-Werror=unused-result]

Fixes: 18597e33cb ('glib-aux: also use getrandom() for seeding pseudo random generator')
(cherry picked from commit 11d59f81cf)
2021-07-14 12:05:02 +02:00
Thomas Haller
20e3975fd2
device: avoid crash setting VPN config during unrealize
During nm_device_unrealize(), we first clear the device's ifindex. Then
we call _set_state_full(NM_DEVICE_STATE_UNMANAGED).

NMVpnConnection are subclasses of NMActiveConnection, it is that way
connected to NM_DEVICE_STATE_CHANGED signal. And this leads to a call
to _set_vpn_state(), which then calls nm_device_replace_vpn6_config()
to unregister the config. Thereby an assertion fails because the
ifindex no longer matches.

Fix that by relaxing the assertion. Also, don't apply the IP
configuration in unexpected device states.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/927
(cherry picked from commit 63a248ecb2)
2021-07-13 17:25:05 +02:00
Thomas Haller
22594864e8
core/wwan: avoid assertion failure in modem_ip{4,6}_config_result()
NMDeviceModem has priv->modem set from construction to dispose, and
the NM_MODEM_IP4_CONFIG_RESULT/NM_MODEM_IP6_CONFIG_RESULT signals
connected all the time.

On the other hand, NMModem may hook up to NMPPPManager's
NM_PPP_MANAGER_SIGNAL_IP{4,6}_CONFIG signals, which emit the
config-results signals. And PPP manager emits the config signals
from impl_ppp_manager_set_ip{4,6}_config().

That means, at any moment can be a D-Bus calls, which leads to emitting
those signals and calling into modem_ip4_config_result() and
modem_ip6_config_result().

At least, it's not clear from review what would prevent that from
happening. If you cannot easily verify that certain conditions are
satisfied, then this is not the place to assert, but to handle the case
as something that can happen regularly.

Handle signals in the unexpected state by ignoring them.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/926
(cherry picked from commit fa786e1f46)
2021-07-13 17:15:03 +02:00
Thomas Haller
a8d5c346bd
glib-aux: cleanup handling of getrandom() and handle EAGAIN
- the return value of getrandom() is ssize_t.
- handle EAGAIN to indicate low entropy.
- treat a return value of zero the same as any other
  low "n", by falling back to bad random bytes.

(cherry picked from commit 416f97c5a9)
2021-07-13 17:06:40 +02:00
Thomas Haller
2a9dd6c2e5
glib-aux: also use getrandom() for seeding pseudo random generator
It's worth a try.

Also, drop STATIC_SALT.

(cherry picked from commit 18597e33cb)
2021-07-13 17:06:40 +02:00
Thomas Haller
bb3da1e01c
glib-aux: merge branch 'th/bad-random-bytes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/922

(cherry picked from commit 5eb1b706fc)
2021-07-13 14:34:10 +02:00
Thomas Haller
e427f53b8f
glib-aux: add getrandom() syscall wrapper as fallback
We make an effort to get a better fallback case with
_bad_random_bytes().

Also make an effort to get good randomness in the first place. Even if
we compile against libc headers that don't provide getrandom(). Also,
this isn't really ugly, because for a long time glibc was reluctant to
add getrandom() wrapper and using syscall() was the way to go.

(cherry picked from commit 05a6936bef)
2021-07-13 14:33:33 +02:00
Thomas Haller
f84ebc4611
glib-aux: simplify logic in nm_utils_random_bytes()
There should be no change in behavior.

(cherry picked from commit 62c60653a7)
2021-07-13 14:32:45 +02:00
Thomas Haller
139fc5c81e
glib-aux: rework fallback random generator to use sha256
nm_utils_random_bytes() tries to get good randomness. If it fails, we still
try our own approach, but also signal that the returned numbers are bad.
In practice, none of the callers cares about the return value, because they
wouldn't know what to do in case of bad randomness (abort() is not an
option and retry is not expected to help and sending an email to the
admin isn't gonna help either). So the fallback case really should try
its best.

The fallback case depends on a good random seed and a good pseudorandom
number generator.

Getting a good seed is in reality impossible, after kernel let us down.
That is part of the problem, but we try our best.

The other part is to use a cryptographic pseudorandom number generator.
GRand uses a Mersenne Twister, so that is not good enough. In this low
level code we also cannot call gnutls/nss, because usually we don't have
that dependency. Maybe we could copy&paste the chacha20 implementation,
it's simple enough and a compatible license. That might be good, but
instead cock our own by adding some sha256 into the mix. This is
fallback code after all, and we want to try hard, but not *that* hard to
add chacha20 to NetworkManager.

So, what we do is to use a well seeded GRand instance, and XOR that
output with a sha256 digest of the state. It's probably slow, but
performance is not the issue in this code path.

(cherry picked from commit c22c3ce9f9)
2021-07-13 14:32:45 +02:00
Ana Cabral
033d000d33 nmcli: include 'searches' field for nmcli device show
Merge Request !919

(cherry picked from commit 34b499f1ef)
2021-07-13 08:14:06 -03:00
Beniamino Galvani
c7fd0fb077 core: merge branch 'bg/ipv6-pd'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/924

(cherry picked from commit fbce4e4ab0)
2021-07-13 09:50:20 +02:00
Beniamino Galvani
75b8ced29a device: start DHCPv6 when a prefix delegation is needed
If a prefix delegation is needed, currently NM restarts DHCPv6 on the
device with default route, but only if DHCPv6 was already running.

Allow the device to start DHCPv6 for a PD even if it was running
without DHCPv6.

See also: https://github.com/coreos/fedora-coreos-tracker/issues/888

(cherry picked from commit 62869621bd)
2021-07-13 09:50:20 +02:00
Beniamino Galvani
cea673a273 contrib: add script to test IPv6 prefix delegation
Add a script to test IPv6 prefix delegation with NM, in different
modes.

(cherry picked from commit 1e3bbdfbbb)
2021-07-13 09:50:20 +02:00
Beniamino Galvani
a12c7f7839 core: merge branch 'bg/rh1956793'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/917

(cherry picked from commit ec643237cd)
2021-07-13 09:36:36 +02:00
Beniamino Galvani
70aeccf605 device: send ARP announcements when there is carrier
Previously we sent announcements immediately for non-controllers, or
after the first port was attached for controllers.

This has two problems:

 - announcements can be sent when there is no carrier and they would
   be lost;

 - if a controller has a port, the port could be itself a controller;
   in that case we start sending ARPs with the fake address of the
   port. Later, when a leaf port is added to the second-level
   controller, the correct port MAC will be propagated by kernel up to
   both controllers.

To solve both problems, send ARP announcements only when the interface
has carrier. This also solves the second issue because controllers
created by NM have carrier only when there is a port with carrier.

Fixes: de1022285a ('device: do ARP announcements only after masters have a slave')

https://bugzilla.redhat.com/show_bug.cgi?id=1956793
(cherry picked from commit 1377f160ed)
2021-07-13 09:36:35 +02:00
Beniamino Galvani
786cd854d7 acd: log the MAC when announcing an IP
(cherry picked from commit 314024ea96)
2021-07-13 09:36:35 +02:00
Thomas Haller
17987b7546
libnm: fix NM_SETTING_IP_CONFIG_CLASS() macro
Fixes: 3f30c6f1c2 ('libnm-core: extract NMSettingIPConfig superclass out of IP4, IP6 classes')
(cherry picked from commit 478754a504)
2021-07-09 16:34:52 +02:00
Thomas Haller
d90baeecd8
mailmap: update to add Ana
(cherry picked from commit dedd228667)
2021-07-08 23:05:19 +02:00
Thomas Haller
07c4b6e6d4
trivial: fix code style
(cherry picked from commit f929bc9945)
2021-07-08 09:59:27 +02:00
Thomas Haller
2d7c9b36c0
glib-aux: use nm_utils_gettid() instead of gettid()
I missed that we already have a gettid() wrapper. Drop the duplicated
again and use nm_utils_gettid().

Fixes: e874c5bf6b ('random: Provide missing gettid() declaration')
(cherry picked from commit 0c4a65929c)
2021-07-08 08:33:53 +02:00
Lukasz Majewski
ff0b6d8662
random: Provide missing gettid() declaration
Provide missing declaration of gettid() function necessary for entropy
generation for hash table in the _rand_init_seed() function in the
src/libnm-glib-aux/nm-random-utils.c.

Fixes: 3649efe2b5 ('glib-aux: put more effort into seeding GRand fallback for nm_utils_random_bytes()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/754

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/918
(cherry picked from commit e874c5bf6b)
2021-07-08 08:33:52 +02:00
Thomas Haller
8edf13d0b4
tools: fix bogus code in "tools/generate-docs-nm-property-infos.py"
Coverity warns about this:

  2. NetworkManager-1.32.2/tools/generate-docs-nm-property-infos.py:117: identical_branches:
  The same code is executed regardless of whether "temp.index(subelement) < len(temp) - 1" is
  true, because the then and else branches are identical. Should one of the branches be modified,
  or the entire 'if' statement replaced?

Fixes: c3504f7e62 ('Rewrite `./tools/generate-docs-nm-property-infos.py` with XML library')
(cherry picked from commit dd595c6c1d)
2021-07-06 09:33:59 +02:00
Thomas Haller
3ce3a93200
platform/tests: add assertions to nmtstp_link_bridge_normalize_jiffies_time()
This is supposed to workaround a coverity warning.

(cherry picked from commit c6be3404f8)
2021-07-06 09:33:58 +02:00
Thomas Haller
1e5f003714
libnm: fix uninitialized variable in nm_connection_replace_settings_from_connection()
Found by Coverity.

Fixes: 91aacbef41 ('libnm: refactor tracking of NMSetting in NMConnection')
(cherry picked from commit 951ba8f9fd)
2021-07-06 08:59:03 +02:00
Beniamino Galvani
5dfd80683d merge: branch 'bg/rh1961666'
https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/907
(cherry picked from commit 9330d29a68)
2021-07-05 17:21:50 +02:00
Beniamino Galvani
1b9cf8c513 initrd: set required-timeout for default IPv4 configuration
If the kernel command-line doesn't contain an explict ip=$method,
currently the generator creates connections with both IPv4 and IPv6
set to 'auto', and both allowed to fail.

Since NM is run in configure-and-quit mode in the initrd, NM can get
an IPv4 address or an IPv6 one (or both) depending on which address
family is quicker to complete. This unpredictable behavior is not
present in the legacy module, which always does IPv4 only by default.

Set a required-timeout of 20 seconds for IPv4, so that NM will
preferably get an IPv4, or will fall back to IPv6.

See also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/729

(cherry picked from commit 0a18e97345)
2021-07-05 17:17:19 +02:00
Beniamino Galvani
51e5df275c device: use the 'required-timeout' property from IP setting
Change the logic in check_ip_state() to delay the connection ACTIVATED
state if an address family is pending and its required-timeout has not
expired.

(cherry picked from commit 35cccc41cb)
2021-07-05 17:17:19 +02:00
Beniamino Galvani
08ce20481c all: add a new ipv{4,6}.required-timeout property
Add a new property to specify the minimum time interval in
milliseconds for which dynamic IP configuration should be tried before
the connection succeeds.

This property is useful for example if both IPv4 and IPv6 are enabled
and are allowed to fail. Normally the connection succeeds as soon as
one of the two address families completes; by setting a required
timeout for e.g. IPv4, one can ensure that even if IP6 succeeds
earlier than IPv4, NetworkManager waits some time for IPv4 before the
connection becomes active.

(cherry picked from commit cb5960cef7)
2021-07-05 17:17:19 +02:00
Beniamino Galvani
f2d9f4bf66 initrd: rename NMI_WAIT_DEVICE_TIMEOUT_MS to _MSEC
(cherry picked from commit fa42ba9df2)
2021-07-05 16:41:03 +02:00
Beniamino Galvani
843af11d84 libnm: add NM_VERSION_1_32_4 2021-07-05 16:40:28 +02:00
Thomas Haller
32ad94bbb8
glib-aux: merge branch 'th/thread-local-storage-destroy'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/914

(cherry picked from commit 581092b078)
2021-07-05 15:11:01 +02:00
Thomas Haller
87d0e73e93
glib-aux: avoid accessing thread-local variable in a loop
Dunno whether the compiler can optimize this out. Assign to an auto
variable.

(cherry picked from commit 94121a1b48)
2021-07-05 15:10:44 +02:00
Thomas Haller
07cd629245
glib-aux: put more effort into seeding GRand fallback for nm_utils_random_bytes()
g_rand_new() reads /dev/urandom and falls back to timestamp and pid.
At this point, we already unsuccessfully tried getrandom()/urandom,
so that doesn't seem promising to try.

Try harder to get good random seeds for our GRand instance.

Have one global instance, that gets seeded with various things that come
to mind. The random sequence of that instance is then used to initialize
the thread-local GRand instances.

Maybe this is all snake oil. If we fail to get good randomness by using
kernel API, what can we do? But really, callers also don't know how they
should handle a failure to get random data (short of abort() or
logging), so there is value in nm_utils_random_bytes() trying really
the best it can, and callers pretending that it doesn't fail.
This aims to improve the fallback case.

(cherry picked from commit 3649efe2b5)
2021-07-05 15:10:43 +02:00
Thomas Haller
3de83dd25c
glib-aux: fix releasing thead-local GRand instance from nm_utils_random_bytes()
Fixes: b01a453ca2 ('core: add nm_utils_random_bytes() and use getrandom()')
(cherry picked from commit c127e1becc)
2021-07-05 15:10:42 +02:00
Thomas Haller
724ef83e06
platform: fix releasing thead-local stack of NMPNetns instances
Fixes: 12df49f8ab ('platform: make NMPNetns thread-safe')
(cherry picked from commit b433c21ae4)
2021-07-05 15:10:41 +02:00
Thomas Haller
963c395cc2
glib-aux: fix releasing thread-local storage from nm_strerror_native()
The previous implementation was just wrong.

Fixes: e1ca3bf7ed ('shared: add nm_strerror_native() to replace strerror() and g_strerror()')
(cherry picked from commit 5bc39d9783)
2021-07-05 15:10:40 +02:00
Thomas Haller
e83aad1972
glib-aux: add nm_utils_thread_local_register_destroy() helper
_nm_thread_local is very neat, but when we allocate resources
we need to make sure that they are destroyed when the thread
exits.

We can use pthread_setspecific() for that, but using it is cumbersome.
Add a helper function to make that simpler.

Also, the number of possible pthread_key_t keys is limited. With this
way, we only need one key in total.

(cherry picked from commit bec4a40437)
2021-07-05 15:10:33 +02:00
Thomas Haller
caea7ab56a
build: fix linking libnm-log-null into different test programs
We require these, otherwise we can get a linker error about
_nm_utils_monotonic_timestamp_initialized symbol being undefined.

(cherry picked from commit 09fb7877a9)
2021-07-05 15:09:52 +02:00
acabral
a636c25b59 bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913

(cherry picked from commit e5dca403dc)
2021-07-02 13:28:34 -03:00
Thomas Haller
7aa2214014
libnm: fix memleak setting "ipv[46].dhcp-iaid" property
Fixes: 56a1a5426a ('all: add ipvX.dhcp-iaid properties')
(cherry picked from commit 47cdcb3ce2)
2021-07-01 12:09:07 +02:00
Thomas Haller
f8766e8239
NEWS: update 2021-07-01 11:38:28 +02:00
Thomas Haller
ba0e61840d
core: merge branch 'th/keyfile-db-stale-entries'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/906

(cherry picked from commit 26f38b9ffa)
2021-07-01 11:33:57 +02:00
Thomas Haller
35402a7e90
settings: cleanup left over temporary files for timestamps/seen-bssids
(cherry picked from commit 34c663ca1a)
2021-07-01 11:33:57 +02:00
Thomas Haller
4b942e9519
glib-aux: add nm_key_file_db_prune_tmp_files() helper
(cherry picked from commit 3c0f1eb0fd)
2021-07-01 11:33:57 +02:00
Thomas Haller
567499cddd
glib-aux: add nm_utils_find_mkstemp_files()
(cherry picked from commit 080d765447)
2021-07-01 11:33:56 +02:00
Thomas Haller
006733d9b1
settings: prune old entries from keyfile databases
We have two GKeyfile files (timestamps and seen-bssids).

When a profile was deleted while NetworkManager was running, then
entries were removed from these keyfiles. But if a profile disappeared
while NetworkManger was stopped, then those UUIDs piled up.
This also happens if you have temporary connections in /run and reboot.

We need a way to garbage collect entries that are no longer relevant.

As the keyfile databases only get loaded once from disk, we will prune
all UUIDs for which we have no more connection loaded, on the first time
we write out the files again.

Note what this means: if you "temporarily" remove a connection profile
(without NetworkManager noticing) and restore it later, then the additional
information might have been pruned. There is no way how NetworkManager
could know that this UUID is coming back. The alternative is what we did
before: pile them up indefinitely. That seems more problematic.

(cherry picked from commit 2e720a1dc8)
2021-07-01 11:33:56 +02:00
Thomas Haller
697a445f6b
keyfile-aux: add nm_key_file_db_prune() helper
A helper function to remove entires that are no longer
relevant.

(cherry picked from commit f59def45c1)
2021-07-01 11:33:56 +02:00
Thomas Haller
1afc327c5d
settings: limit number of seen-bssids and preserve order
Previously, there was no limit how many seen-bssids are tracked.
That seems problematic, also because there is no API how to get
rid of an excessive list of entries.

We should limit the number of entries. Add an (arbitrary) limit
of 30.

But this means that we drop the surplus of entries, and for that it
seems important to keep the newest, most recently seen entries.
Previously, entries were merely sorted ASCIIbetically. Now, honor
their order (with most recently seen first).

Also, normalize the BSSIDs. From internal code, we should only get
normalize strings, but when we load them from disk, they might be bogus.
As we might cut of the list, we don't want that invalid entries
cut of valid ones. And of course, invalid entries make no sense at
all.

(cherry picked from commit 8278719840)
2021-07-01 11:33:56 +02:00
Thomas Haller
b31cafc4a4
settings: don't populate seen-bssids list from connection profile
ifcfg-rh plugin never stored the seen bssid list to file, and
keyfile no longer does, and it's no longer parsed from GVariant.

So there is actually no way how anything could be set here.

The seen-bssids should only be populate from
"/var/lib/NetworkManager/seen-bssids". Nowhere else.

(cherry picked from commit 15a0271781)
2021-07-01 11:33:56 +02:00