Commit graph

28648 commits

Author SHA1 Message Date
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
Thomas Haller
bb8481f101
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.

(cherry picked from commit 4a4f214722)
2021-07-01 11:33:56 +02:00
Thomas Haller
36eacd8528
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.

(cherry picked from commit d9ebcc8646)
2021-07-01 11:33:56 +02:00
Thomas Haller
9e1d29d437
core: set _nm_utils_is_manager_process as first thing in daemon
(cherry picked from commit 6c5070da55)
2021-07-01 11:33:56 +02:00
Thomas Haller
29d64f148e
glib-aux: use NM_AUTO_PROTECT_ERRNO() in nm_auto_close and nm_auto_fclose
(cherry picked from commit f9f453994b)
2021-07-01 11:33:56 +02:00
Thomas Haller
309eba1078
std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux
(cherry picked from commit 2b55408cc7)
2021-07-01 11:33:56 +02:00
Thomas Haller
db744d2296
release: bump version to 1.32.3 (development) 2021-06-30 18:13:10 +02:00
Thomas Haller
bf1b09702e
release: bump version to 1.32.2 2021-06-30 18:13:10 +02:00
Thomas Haller
1216acefe8
NEWS: update 2021-06-30 17:14:31 +02:00
Thomas Haller
6a578faa24
libnm: document nm_ip_routing_rule_[gs]et_uid_range() as unusable
Fixes: 972d1ba046 ('libnm,core: support "uidrange" parameter for routing rules'):
2021-06-30 17:14:31 +02:00
Thomas Haller
af199191e6
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')
(cherry picked from commit 668c90dbb8)
2021-06-30 17:14:31 +02:00
Thomas Haller
7adbda7348
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
(cherry picked from commit 3a4822c52c)
2021-06-30 17:14:30 +02:00
Thomas Haller
9541b0bea4
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
(cherry picked from commit 4201ee5119)
2021-06-30 08:05:16 +02:00
Julian Wiedmann
f1196cb26e
nm-initrd-generator: document support for rd.znet option
rd.znet support was added with commit 11d4412ee1 ("process s390
specific device info from rd.znet parameter in nm-initrd-generator").

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>

https://github.com/NetworkManager/NetworkManager/pull/362
(cherry picked from commit 6bc6d45925)
2021-06-28 14:02:00 +02:00
Thomas Haller
0e6d4a99db
ifcfg-rh: merge branch 'th/ifcfg-fix-empty-ethtool'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/905

(cherry picked from commit f9040c3cca)
2021-06-28 13:30:33 +02:00
Thomas Haller
364bc8d737
ifcfg-rh: fix persisting all-default NMSettingEthtool settings
We somehow need to encode an NMSettingEthtool instance that has all
options unset. Previously, that would result in no "$ETHTOOL_OPTS"
variable and thus the reader would loose a previously existing setting.

Hack it by writing a bogus

  ETHTOOL_OPTS="-A $IFACE"

line.

(cherry picked from commit 26ed9e6714)
2021-06-28 13:30:32 +02:00
Thomas Haller
e78d9535a8
ifcfg-rh/tests: add unit test for persisting NMSettingEthtool
In particular the case with an all-default NMSettingEthtool is
currently broken. The test is checking the wrong behavior, which
will be fixed next.

(cherry picked from commit ef0f9b871b)
2021-06-28 13:30:31 +02:00
Thomas Haller
85ddfc8959
ifcfg-rh/tests: unlink test file in _writer_new_connection_reread() if not requested
(cherry picked from commit 3fdedde16f)
2021-06-28 13:30:31 +02:00
Thomas Haller
842db82686
ifcfg-rh/tests: evalute environment for $NMTST_IFCFG_RH_UPDATE_EXPECTED only once
It just seems ugly to call g_getenv() repeatedly. Environment variables
must not change (in a multi-threaded program after other threads start),
so determine the mode once and cache it.

(cherry picked from commit 1ae6719cf1)
2021-06-28 13:30:31 +02:00
Thomas Haller
b425793d90
ifcfg: always write ethernet.s390-options even without subchannels
For the umpteenth time: it is not ifcfg-rh writers decision to decide
what are valid configurations and only persist settings based on
some other settings.

If s390-options would only be allowed together with subchannels, then
this is alone nm_connection_verify()'s task to ensure.

Reproduce with

  $ nmcli connection add type ethernet autoconnect no con-name zz ethernet.s390-options bridge_role=primary

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

Fixes: 16bccfd672 ('core: handle s390 options more cleanly')
(cherry picked from commit d391f20730)
2021-06-25 11:26:34 +02:00
Thomas Haller
b5de7b2e48
supplicant: suppress warning log for P2PDevice.Cancel()
A failure to cancel something is not worth a warning. It probably
just means that no operation was in progress. In my logs I always
see a warning:

    CODE_FILE=src/core/supplicant/nm-supplicant-interface.c
    CODE_LINE=391
    MESSAGE=<warn>  [1624517233.8822] sup-iface[a22b181a321ffd9b,9,wlan0]: call-p2p-cancel: failed with P2P cancel failed

Downgrade this to trace level.

(cherry picked from commit 476598ca99)
2021-06-24 11:15:04 +02:00
Thomas Haller
056f69198f
gitlab-ci: bump tag for cached container images
This results in a rebuild of the containers, which is a good idea as we
didn't do that for a while.

(cherry picked from commit aba1754a80)
2021-06-23 21:08:15 +02:00