Commit graph

14425 commits

Author SHA1 Message Date
Thomas Haller
eb634c6077
core: don't override user provided "connection.interface-name" in nm_utils_complete_generic()
nm_utils_complete_generic() is supposed to complete information which the user
didn't provide. If the profile already has an interface-name, keep it.
2021-07-08 17:20:15 +02:00
Thomas Haller
bc57c79d57
libnm: change behavior for normalizing wireguard/dummy profiles to use ipv6.method=disabled
"ipv6.method=ignore" really exists for historic reasons, from a time when
NetworkManager didn't support IPv6 autoconf and let kernel handle it.

Nowadays, we should choose an explicit mode, like "link-local" or
"disabled".

Let nm_connection_normalize() treat WireGuard and dummy profiles
different and set the IPv6 method to "disabled".
2021-07-08 17:20:15 +02:00
Thomas Haller
6185502ee9
libnm: let nm_connection_normalize() default to ipv{4,6}.method={disabled,ignore} on dummy devices
On a dummy device we cannot do DHCP. The default makes no sense.

This also affects `nmcli device connect dummy0`. We want that the
generated profile gets normalized to no IP configuration, because
DHCP/autoconf is not working on a dummy device.

Currently there is another problem and that command is not working. But
if that other problem would be fixed, then the generated profile would try
to do DHCP, fail, and retry endlessly (with backoff pauses).
That endless loop is a third problem. If `nmcli device connect` creates
a new profile, then upon failure the profile should be deleted again.
But these two other problems are not solved hereby.
2021-07-08 17:20:15 +02:00
Thomas Haller
93c6697413
libnm: add "ip4-config-method" normalization parameter
I guess, to a certain point these normalization options are hardly used.
Still, it feels right to also support it for IPv4. These options make
sense to me to control normalization.
2021-07-08 17:20:15 +02:00
Thomas Haller
ef6b942fd5
libnm/tests: check IP method in test_roundtrip_conversion() 2021-07-08 17:20:14 +02:00
Thomas Haller
f9dc0252db
libnm/tests: add test for normalizing "dummy" connection 2021-07-08 17:20:14 +02:00
Thomas Haller
f929bc9945
trivial: fix code style 2021-07-08 09:57:39 +02:00
Thomas Haller
0c4a65929c
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')
2021-07-08 08:31:47 +02:00
Lukasz Majewski
e874c5bf6b
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
2021-07-08 08:16:27 +02:00
Thomas Haller
c6be3404f8
platform/tests: add assertions to nmtstp_link_bridge_normalize_jiffies_time()
This is supposed to workaround a coverity warning.
2021-07-06 09:04:37 +02:00
Thomas Haller
951ba8f9fd
libnm: fix uninitialized variable in nm_connection_replace_settings_from_connection()
Found by Coverity.

Fixes: 91aacbef41 ('libnm: refactor tracking of NMSetting in NMConnection')
2021-07-06 08:43:51 +02:00
Beniamino Galvani
bb9c72a543 libnm: adjust symbol version after backporting ipvx.required-timeout to 1.32.4
libnm symbol 'nm_setting_ip_config_get_required_timeout' was
backported to branch 1.32 in commit 08ce20481c ('all: add a new
ipv{4,6}.required-timeout property') in anticipation of 1.32.4. Add
the same symbol version so that an application linked against 1.32.4
also works with 1.34.0. We don't need a duplicate symbol version
because 1.34 is not yet released.
2021-07-05 21:18:35 +02:00
Björn Lindqvist
44481bd7c7
core: fail IPv6 early if disabled in kernel
Adds the following info message in case ipv6 is disabled:

    <info>  device (enp0s18f2u3): The kernel does not support IPv6.

[thaller@redhat.com: modified original patch]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/401
2021-07-05 16:27:48 +02:00
Beniamino Galvani
0a18e97345 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
2021-07-05 15:15:45 +02:00
Beniamino Galvani
35cccc41cb 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.
2021-07-05 15:15:45 +02:00
Beniamino Galvani
cb5960cef7 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.
2021-07-05 15:15:44 +02:00
Beniamino Galvani
fa42ba9df2 initrd: rename NMI_WAIT_DEVICE_TIMEOUT_MS to _MSEC 2021-07-05 15:15:44 +02:00
Thomas Haller
94121a1b48
glib-aux: avoid accessing thread-local variable in a loop
Dunno whether the compiler can optimize this out. Assign to an auto
variable.
2021-07-05 14:51:27 +02:00
Thomas Haller
3649efe2b5
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.
2021-07-05 14:51:27 +02:00
Thomas Haller
c127e1becc
glib-aux: fix releasing thead-local GRand instance from nm_utils_random_bytes()
Fixes: b01a453ca2 ('core: add nm_utils_random_bytes() and use getrandom()')
2021-07-05 14:51:27 +02:00
Thomas Haller
b433c21ae4
platform: fix releasing thead-local stack of NMPNetns instances
Fixes: 12df49f8ab ('platform: make NMPNetns thread-safe')
2021-07-05 14:51:27 +02:00
Thomas Haller
5bc39d9783
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()')
2021-07-05 14:51:27 +02:00
Thomas Haller
bec4a40437
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.
2021-07-05 14:51:27 +02:00
Thomas Haller
09fb7877a9
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.
2021-07-05 14:51:27 +02:00
Thomas Haller
30940222cc
libnm: better document "ethernet.s390-options" property 2021-07-02 08:28:30 +02:00
acabral
e5dca403dc bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913
2021-07-01 15:20:22 -03:00
Thomas Haller
47cdcb3ce2
libnm: fix memleak setting "ipv[46].dhcp-iaid" property
Fixes: 56a1a5426a ('all: add ipvX.dhcp-iaid properties')
2021-07-01 11:49:18 +02:00
Thomas Haller
34c663ca1a
settings: cleanup left over temporary files for timestamps/seen-bssids 2021-07-01 11:21:00 +02:00
Thomas Haller
3c0f1eb0fd
glib-aux: add nm_key_file_db_prune_tmp_files() helper 2021-07-01 11:20:59 +02:00
Thomas Haller
080d765447
glib-aux: add nm_utils_find_mkstemp_files() 2021-07-01 11:20:59 +02:00
Thomas Haller
2e720a1dc8
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.
2021-07-01 11:20:34 +02:00
Thomas Haller
f59def45c1
keyfile-aux: add nm_key_file_db_prune() helper
A helper function to remove entires that are no longer
relevant.
2021-07-01 11:17:06 +02:00
Thomas Haller
8278719840
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.
2021-07-01 11:17:06 +02:00
Thomas Haller
15a0271781
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.
2021-07-01 11:04:22 +02:00
Thomas Haller
4a4f214722
libnm: special handle serialization to D-Bus for "wifi.seen-bssid"
"wifi.seen-bssid" is an unusual property, therefore very ugly due to the
inconsistency.

It is not a regular user configuration that makes sense to store to
disk or modify by the user. It gets populated by the daemon, and
stored in "/var/lib/NetworkManager/seen-bssids" file.

As such, how to convert this to/from D-Bus needs special handling.

This means, that the to/from D-Bus functions will only serialize the
property when the seen-bssids are specified via
NMConnectionSerializationOptions, which is what the daemon does.
Also, the daemon ignores seen-bssids when parsing the variant.

This has the odd effect that when the client converts a setting to
GVariant, the seen-bssids gets lost. That means, a conversion to GVariant
and back looses information. I think that is OK in this case, because the
main point of to/from D-Bus is not to have a lossless GVariant representation
of a setting, but to transfer the setting via D-Bus between client and
daemon. And transferring seen-bssids via D-Bus makes only sense from the daemon
to the client.
2021-07-01 11:04:22 +02:00
Thomas Haller
d9ebcc8646
libnm/keyfile: ignore [wifi].seen-bssids for keyfile
"seen-bssids" primarily gets stored to "/var/lib/NetworkManager/seen-bssids",
it's not a regular property.

We want this property to be serialized/deserialized to/from GVariant,
because we expose these settings on the API like a property of the
profile. But it cannot be modified via nmcli, it cannot be stored
to ifcfg files, and it makes not sense to store it to keyfile either.

Stop doing that.
2021-07-01 11:04:22 +02:00
Thomas Haller
6c5070da55
core: set _nm_utils_is_manager_process as first thing in daemon 2021-07-01 11:04:22 +02:00
Thomas Haller
f9f453994b
glib-aux: use NM_AUTO_PROTECT_ERRNO() in nm_auto_close and nm_auto_fclose 2021-07-01 11:04:22 +02:00
Thomas Haller
2b55408cc7
std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux 2021-07-01 11:04:22 +02:00
Thomas Haller
668c90dbb8
libnm: fix crash in nm_ip_routing_rule_from_string()
import gi
    gi.require_version("NM", "1.0")
    from gi.repository import NM

    r = NM.IPRoutingRule.from_string('priority 10 type blackhole', NM.IPRoutingRuleAsStringFlags.AF_INET)
    r.to_string(NM.IPRoutingRuleAsStringFlags.NONE)

    r = NM.IPRoutingRule.from_string('priority 10 blackhole', NM.IPRoutingRuleAsStringFlags.AF_INET)
    r.to_string(NM.IPRoutingRuleAsStringFlags.NONE)

    r= NM.IPRoutingRule.from_string('priority 10 bogus', NM.IPRoutingRuleAsStringFlags.AF_INET)
    # CRASH

Fixes: e922404990 ('libnm,core: support "prohibit"/"blackhole"/"unreachable" type routing rules')
2021-06-30 17:13:23 +02:00
Thomas Haller
3a4822c52c
n-dhcp4: avoid maybe-uninitialized warning in n_dhcp4_c_connection_dispatch_io()
On RHEL-8.5, s390x with gcc-8.5.0-2.el8, we get a compiler warning:

  $ CFLAGS='-O2 -Werror=maybe-uninitialized' meson build
  ...
  cc -Isrc/libndhcp4-private.a.p -Isrc -I../src -Isubprojects/c-list/src -I../subprojects/c-list/src -Isubprojects/c-siphash/src -I../subprojects/c-siphash/src -Isubprojects/c-stdaux/src -I../subprojects/c-stdaux/src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c11 -g -D_GNU_SOURCE -O2 -Werror=maybe-uninitialized -fPIC -fvisibility=hidden -fno-common -MD -MQ src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o -MF src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o.d -o src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o -c ../src/n-dhcp4-c-connection.c
  ../src/n-dhcp4-c-connection.c: In function ‘n_dhcp4_c_connection_dispatch_io’:
  ../src/n-dhcp4-c-connection.c:1151:17: error: ‘type’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
           uint8_t type;
                   ^~~~

https://github.com/nettools/n-dhcp4/pull/24
2021-06-30 16:35:42 +02:00
Thomas Haller
4201ee5119
cloud-setup: preserve IPv4 addresses/routes/rules from profile
nm-cloud-setup automatically detects routes, addresses and rules and configures them
on the device using the emphermal Reapply() API. That is, it does not modify the
existing profile (on disk), but changes the runtime configuration only.

As such, it used to wipe otherwise statically configured IP addresses, routes and
rules. That seems unnecessary. Let's keep the configuration from the (persistent)
configuration.

There is of course the problem that nm-cloud-setup doesn't really
understand the existing IP configuration, and it can only hope that
it can be meaningfully combined with what nm-cloud-setup wants to
configure. This should cover most simple cases, for more complex setups,
the user probably should disable nm-cloud-setup and configure the
network explicitly to their liking.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/893
2021-06-30 08:04:39 +02:00
Thomas Haller
37b72e8984
hostname: cleanup file monitors in NMHostnameManager 2021-06-30 08:00:35 +02:00
Thomas Haller
05aa751957
core,glib-aux: move nm_hostname_manager_validate_hostname() to shared-utils
This function is badly named, because it has no NMHostnameManager self
argument. It's just a simple function that entirely operates on a string
argument.

Move it away from "nm-hostname-manager.h" to "libnm-glib-aux/nm-shared-utils.h".

Hostname handling is complicated enough. Simple string validation
functions should not obscure the view on the complicated parts.
2021-06-28 14:32:05 +02:00
Thomas Haller
dbe4803d84
hostname: use nm_utils_user_data_pack() instead of SetHostnameInfo struct 2021-06-28 14:32:05 +02:00
Thomas Haller
429816080e
hostname: simplify _set_hostname() code
- drop nm_hostname_manager_read_hostname() from header file.
  It's only used internally.

- inline some code and drop helper functions.
2021-06-28 14:32:05 +02:00
Thomas Haller
61d2af3518
all: use nm_{idle,timeout}_add_source() instead of g_source_attach() 2021-06-28 13:31:35 +02:00
Thomas Haller
34f48a33f3
glib-aux: add nm_g_unix_fd_add_source() helper 2021-06-28 13:31:35 +02:00
Thomas Haller
70e5d8e5bd
all: don't explicitly include <glib-unix.h>
We get it now always by "nm-macros-internal.h".
2021-06-28 13:31:34 +02:00
Thomas Haller
570bb6fe76
glib-aux: by default always include <glib-unix.h> in our sources
We already always include all of <glib.h>. <glib-unix.h> is small
and only not included by default to support non-UNIX systems,
which we don't care.
2021-06-28 13:31:34 +02:00