Commit graph

28780 commits

Author SHA1 Message Date
Thomas Haller
4e109bacab
clang-format: use "IndentPPDirectives:None" instead of "BeforeHash"
Subjectively, I think this looks better.
2021-07-09 08:49:06 +02:00
Thomas Haller
dedd228667
mailmap: update to add Ana 2021-07-08 22:57:45 +02:00
Thomas Haller
e16c50f507
all: merge branch 'th/device-connect-dummy'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/915
2021-07-08 17:24:36 +02:00
Thomas Haller
94a5ae58ae
cli: drop duplicate dot in error message
$ nmcli connection add type dummy con-name x autoconnect no ipv4.method disabled ipv6.method disabled ifname d0
  $ ip link add d1 type dummy
  $ nmcli connection up x ifname d1
  Error: device 'd1' not compatible with connection 'x': The interface names of the device and the connection didn't match..
2021-07-08 17:20:16 +02:00
Thomas Haller
d0349f17b7
cli: fail nmcli connection up $PROFILE ifname $DEVICE for non-existing virtual device
$ nmcli connection add type dummy con-name x autoconnect no ipv4.method disabled ipv6.method disabled ifname d0
  $ mcli connection up x ifname bogus
  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

This is not right. A non-existing ifname argument was simply ignored
and nmcli would tell NetworkManager to activate the profile (on any
device).

Instead, if the user specifies a device argument, also for a virtual
type, it must exist.

Note that usually for virtual devices (like 'dummy'), the device
in fact does not exist, so passing `ifname` is likely to fail.
If the device already exists, then the command is no going to work
as expected, with

  $ mcli connection up x ifname d0

succeeding, while

  $ mcli connection up x ifname d1

fails (as intended) with

  Error: device 'd1' not compatible with connection 'x': The interface names of the device and the connection didn't match..
2021-07-08 17:20:15 +02:00
Thomas Haller
bb3c93bfd4
cli: improve error message for device not found
$ nmcli connection add type ethernet con-name x autoconnect no ipv4.method disabled ipv6.method disabled
  $ nmcli connection up x ifname bogus
  Error: device 'bogus' not compatible with connection 'x'.

Better would be:

  Error: device 'bogus' not found for connection 'x'.
2021-07-08 17:20:15 +02:00
Thomas Haller
409c87af2c
cli: replace strcmp() uses with nm_streq()/NM_IN_STRSET() 2021-07-08 17:20:15 +02:00
Thomas Haller
e5484476f6
device: don't add-and-activate dummy profiles with autoconf enabled
Let the default normalization from nm_connection_normalize() choose
'ipv6.method'. It will now choose "disabled" for dummy profiles, which
is just what we need.

In particular, we don't want to enable autoconf for dummy devices --
unless the profile which the user provides already has it enabled (in
which case nm_connection_normalize() doesn't change it).
2021-07-08 17:20:15 +02:00
Thomas Haller
a32d04f0bb
core: fix nmcli device connect dummy0 to add-and-activate dummy profile
$ ip link add dd type dummy

   $ nmcli device
   DEVICE             TYPE      STATE                   CONNECTION
   ...
   dd                 dummy     unmanaged               --

   $ nmcli device connect dd
   Error: Failed to add/activate new connection: A 'dummy' setting is required.

There are two problems here. The first is that we don't pass
the interface name to nm_utils_complete_generic(), but dummy
devices require "connection.interface-name" set. As a consequence,
nm_utils_complete_generic() fails to normalize the connection
and there is no [dummy] setting. Which then results in a failure
with complete_connection().

The important part of the fix is to set the interface name. Once
we do that, nm_utils_complete_generic() should be able to add
the [dummy] setting and the second part is not strictly necessary.
Still, the job of complete_connection() is not to verify the
profile but to create it with best effort. If a [dummy] setting
is still missing, we should just add it. The caller will then
again try to normalize/verify the connection, and that might then
fail -- but this time not with the wrong error message about
missing 'dummy' setting.

https://bugzilla.redhat.com/show_bug.cgi?id=1763054
2021-07-08 17:20:15 +02:00
Thomas Haller
f9b43ed7d4
core: add parameters options to nm_utils_complete_generic() 2021-07-08 17:20:15 +02:00
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
dd595c6c1d
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')
2021-07-06 09:08:36 +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
9330d29a68 merge: branch 'bg/rh1961666'
https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/907
2021-07-05 15:43:28 +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
581092b078
glib-aux: merge branch 'th/thread-local-storage-destroy'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/914
2021-07-05 15:07:25 +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
c1ac20abb6
NEWS: update
Add the NEWS entries that were also present in 1.32.2 release.
2021-07-01 11:44:05 +02:00
Thomas Haller
c76b15b45b
NEWS: update 2021-07-01 11:36:53 +02:00
Thomas Haller
26f38b9ffa
core: merge branch 'th/keyfile-db-stale-entries'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/906
2021-07-01 11:32:48 +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