Commit graph

27901 commits

Author SHA1 Message Date
Thomas Haller
7fcc89db6e cloud-setup: cache number of valid interfaces in get-config result
Now that we return a struct from get_config(), we can have system-wide
properties returned.

Let it count and cache the number of valid iface_datas.

Currently that is not yet used, but it will be.

(cherry picked from commit a3cd66d3fa)
(cherry picked from commit e74375fc3b)
2021-10-05 09:35:48 +02:00
Thomas Haller
b2ed9e7d5d cloud-setup: return structure for get_config() result instead of generic hash table
Returning a struct seems easier to understand, because then the result
is typed.

Also, we might return additional results, which are system wide and not
per-interface.

(cherry picked from commit 323e182768)
(cherry picked from commit c94b1c43d4)
2021-10-05 09:35:48 +02:00
Thomas Haller
2585e34e59 libnm: expose nm_ip_address_dup(), nm_ip_route_dup() API in libnm
This fixes commit 21c8a6b20e ('libnm-core, all: merge IPv4 and IPv6
address/route types'), which introduced this API but didn't export it
in the library. In practice this API is thus only usable since 1.32.0.

(cherry picked from commit 05f2a0b024)
(cherry picked from commit eea912dfb3)
2021-10-05 09:35:48 +02:00
Thomas Haller
b8bb585052 glib-aux: add _nm_utils_ascii_str_to_int64_bin() helper
(cherry picked from commit 70b7ad1a76)
2021-10-05 09:35:48 +02:00
Beniamino Galvani
d01912d2fc platform: preserve IPv6 multicast route added by kernel
Kernels < 5.11 add a route like:

  unicast ff00::/8 dev $IFACE proto boot scope global metric 256 pref medium

to allow sending and receiving IPv6 multicast traffic. Ensure it's not
removed it when we do a route sync in mode ALL.

In kernel 5.11 there were commits:

  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ceed9038b2783d14e0422bdc6fd04f70580efb4c
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a826b04303a40d52439aa141035fca5654ccaccd

After those the route looks like

  multicast ff00::/8 dev $IFACE proto kernel metric 256 pref medium

As NM ignores routes with rtm_type multicast, the code in this commit
is not needed on newer kernels.

https://bugzilla.redhat.com/show_bug.cgi?id=2004212
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/984
(cherry picked from commit 8003ca68f7)
(cherry picked from commit ce8eb446b4)
2021-09-20 10:38:46 +02:00
Beniamino Galvani
183f2a1a59 merge: branch 'bg/rh1961666'
https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/966
(cherry picked from commit 9330d29a68)
(cherry picked from commit 5dfd80683d)
2021-09-07 16:29:25 +02:00
Beniamino Galvani
3565f155fb 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)
(cherry picked from commit 1b9cf8c513)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
65868803e0 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)
(cherry picked from commit 51e5df275c)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
253de76195 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)
(cherry picked from commit 08ce20481c)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
671dc82f94 initrd: rename NMI_WAIT_DEVICE_TIMEOUT_MS to _MSEC
(cherry picked from commit fa42ba9df2)
(cherry picked from commit f2d9f4bf66)
2021-08-20 10:48:19 +02:00
Thomas Haller
660932163f glib-aux: fix thread-safe initialization in _nm_g_source_sentinel_get_init()
Fixes: ce7c28c514 ('glib-aux: add nm_g_source_sentinel_get() util')
(cherry picked from commit 2140bbf7f5)
(cherry picked from commit c37f72acd3)
2021-08-20 10:48:19 +02:00
Thomas Haller
bd7cbd5770 glib-aux/tests: avoid coverity warning in test_nm_g_source_sentinel()
Coverity wrongly think there is a use after free in the test:

    Error: USE_AFTER_FREE (CWE-416): [#def559] [important]
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1305: alias: Assigning: "s1" = "_s". Now both point to the same storage.
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1324: freed_arg: "g_source_unref" frees "s1".
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1330: deref_after_free: Dereferencing freed pointer "s1".
    # 1328|               s2 = nm_g_source_sentinel_get(0);
    # 1329|               g_assert(s2 == s1);
    # 1330|->             g_assert_cmpint(g_atomic_int_get(&s1->ref_count), >=, 1);
    # 1331|           }
    # 1332|       }

Rework the code in the hope to avoid the false warning.

(cherry picked from commit 7825609f1f)
(cherry picked from commit c47c823c9d)
2021-08-20 10:23:03 +02:00
Thomas Haller
3a58255247 glib-aux: add nm_g_source_sentinel_get() util
This helper is useful to get a dummy GSource instance that can be
refed, unrefed and destroyed. It can act as a replacement for
a timeout source with infinite timeout.

(cherry picked from commit ce7c28c514)
2021-08-20 10:23:03 +02:00
Thomas Haller
f8645d6a86 initrd: cleanup parsing DNS in reader_parse_ip()
(cherry picked from commit e258410c87)
2021-08-20 10:23:03 +02:00
Beniamino Galvani
ce02f56356 libnm: add NM_VERSION_1_30_8 2021-08-20 09:44:18 +02:00
Beniamino Galvani
9121b961eb device: store the original MTU before force-setting it
In case the MTU is force-set (e.g. for bridges), priv->mtu_initial and
priv->ip6_mtu_initial must be initialized before changing the MTU,
otherwise the wrong value will be restored on deactivation.

Fixes: e23798a5e5 ('bridge: force (hack)-set of the MTU when explicitly set in the profile')

https://bugzilla.redhat.com/show_bug.cgi?id=1973536
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/955
(cherry picked from commit 3f42e2005a)
(cherry picked from commit 7730547721)
2021-08-06 15:41:57 +02:00
Beniamino Galvani
ca122d1a14 release: bump version to 1.30.7 (development) 2021-07-16 22:08:23 +02:00
Beniamino Galvani
427f58466b release: bump version to 1.30.6 2021-07-16 22:08:23 +02:00
Beniamino Galvani
edec742209 NEWS: update 2021-07-16 18:42:52 +02:00
Thomas Haller
9eb912ead1 libnm: fix memleak setting "ipv[46].dhcp-iaid" property
Fixes: 56a1a5426a ('all: add ipvX.dhcp-iaid properties')
(cherry picked from commit 47cdcb3ce2)
(cherry picked from commit 7aa2214014)
2021-07-16 18:40:00 +02:00
Thomas Haller
cd619a5c92 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)
(cherry picked from commit 3de83dd25c)
2021-07-16 18:40:00 +02:00
Thomas Haller
46e595cb26 platform: fix releasing thead-local stack of NMPNetns instances
Fixes: 12df49f8ab ('platform: make NMPNetns thread-safe')
(cherry picked from commit b433c21ae4)
(cherry picked from commit 724ef83e06)
2021-07-16 18:40:00 +02:00
Thomas Haller
41126d256a 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)
(cherry picked from commit 963c395cc2)
2021-07-16 18:40:00 +02:00
Thomas Haller
cfd37f2758 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)
(cherry picked from commit b425793d90)
2021-07-16 18:40:00 +02:00
Simon McVittie
d7c6fea149 libnm: Don't crash if service tells us a new key management mode
The NetworkManager service sometimes adds new key management modes.
If it does, an older client library (perhaps in a container, or loaded
into a pre-existing process before an upgrade) shouldn't crash when
talking to a newer NetworkManager service over D-Bus.

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

Signed-off-by: Simon McVittie <smcv@collabora.com>

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

Fixes: 4c4f59674a ('2007-10-23  Dan Williams  <dcbw@redhat.com>')

(cherry picked from commit 18c76388f0)
(cherry picked from commit a90a7b2d5f)
2021-07-16 18:40:00 +02:00
Thomas Haller
5999a7b093 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)
(cherry picked from commit 17987b7546)
2021-07-16 18:40:00 +02:00
Thomas Haller
9b3f5025a4 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)
(cherry picked from commit e83aad1972)
2021-07-16 18:40:00 +02:00
Thomas Haller
86f21d4aaf std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux
(cherry picked from commit 2b55408cc7)
(cherry picked from commit 309eba1078)
2021-07-16 18:40:00 +02:00
Thomas Haller
68c63af016 glib-aux: fix NM_AUTO_PROTECT_ERRNO() macro
(cherry picked from commit 95208e0655)
2021-07-16 18:40:00 +02:00
acabral
38fdbe0739 bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913

(cherry picked from commit e5dca403dc)
(cherry picked from commit a636c25b59)
2021-07-16 18:16:19 +02:00
Beniamino Galvani
429b07c107 core: merge branch 'bg/ipv6-pd'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/924

(cherry picked from commit fbce4e4ab0)
(cherry picked from commit c7fd0fb077)
2021-07-13 09:56:07 +02:00
Beniamino Galvani
a2fb5167ce 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)
(cherry picked from commit 75b8ced29a)
2021-07-13 09:52:16 +02:00
Beniamino Galvani
b358fa3dc5 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)
(cherry picked from commit cea673a273)
2021-07-13 09:52:16 +02:00
Beniamino Galvani
0fd36b7ba3 core: merge branch 'bg/rh1956793'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/917

(cherry picked from commit ec643237cd)

(cherry picked from commit a12c7f7839)
2021-07-13 09:40:17 +02:00
Beniamino Galvani
f1cdd702e3 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)
(cherry picked from commit 70aeccf605)
2021-07-13 09:40:17 +02:00
Beniamino Galvani
288f774887 acd: log the MAC when announcing an IP
(cherry picked from commit 314024ea96)
(cherry picked from commit 786cd854d7)
2021-07-13 09:40:16 +02:00
Beniamino Galvani
b793925889 policy: prefer IPv4 to determine the hostname
When determining the hostname, it is preferable to evaluate devices in
a predictable order to avoid that the hostname changes between
different boots.

The current order is based first on hostname priority, then on the
presence of a best default route, and then on activation order.

The activation order is not a very strong condition, as it is
basically useless for devices that are autoactivated at boot.

As we already prefer IPv4 over IPv6 within the same connection, also
prefer it when 2 connections have the same priority and the same
default route status, to achieve better predictability.

https://bugzilla.redhat.com/show_bug.cgi?id=1970335
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/895
(cherry picked from commit 637a45e25b)
(cherry picked from commit 21051dc6d8)
2021-06-21 09:00:49 +02:00
Beniamino Galvani
85b8b07e27 merge: branch 'bg/tc-ignore'
https://bugzilla.redhat.com/show_bug.cgi?id=1928078
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/871
(cherry picked from commit 74f9272d3d)
2021-06-17 17:17:45 +02:00
Beniamino Galvani
acf0c4df2b ifcfg-rh: preserve an empty tc configuration
If the TC setting contains no qdiscs and filters, it is lost after a
write-read cycle. Fix this by adding a new property to indicate the
presence of the (empty) setting.

(cherry picked from commit 6a88d4e55c)
2021-06-17 17:07:05 +02:00
Beniamino Galvani
2a8181bcd7 core,libnm: don't touch device TC configuration by default
NetworkManager supports a very limited set of qdiscs. If users want to
configure a unsupported qdisc, they need to do it outside of
NetworkManager using tc.

The problem is that NM also removes all qdiscs and filters during
activation if the connection doesn't contain a TC setting. Therefore,
setting TC configuration outside of NM is hard because users need to
do it *after* the connection is up (for example through a dispatcher
script).

Let NM consider the presence (or absence) of a TC setting in the
connection to determine whether NM should configure (or not) qdiscs
and filters on the interface. We already do something similar for
SR-IOV configuration.

Since new connections don't have the TC setting, the new behavior
(ignore existing configuration) will be the default. The impact of
this change in different scenarios is:

 - the user previously configured TC settings via NM. This continues
   to work as before;

 - the user didn't set any qdiscs or filters in the connection, and
   expected NM to clear them from the interface during activation.
   Here there is a change in behavior, but it seems unlikely that
   anybody relied on the old one;

 - the user didn't care about qdiscs and filters; NM removed all
   qdiscs upon activation, and so the default qdisc from kernel was
   used. After this change, NM will not touch qdiscs and the default
   qdisc will be used, as before;

 - the user set a different qdisc via tc and NM cleared it during
   activation. Now this will work as expected.

So, the new default behavior seems better than the previous one.

https://bugzilla.redhat.com/show_bug.cgi?id=1928078
(cherry picked from commit a48edd0410)
2021-06-17 16:51:25 +02:00
Beniamino Galvani
08d9341b0c merge: branch 'bg/dns-update-on-sigusr1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/832
(cherry picked from commit a3306d538c)
2021-06-10 18:10:11 +02:00
Beniamino Galvani
cdc1e9ecff nmcli: invoke ReloadConnections() D-Bus method asynchronously
(cherry picked from commit 9d0aca6757)
2021-06-10 18:09:52 +02:00
Beniamino Galvani
9d15ae640d nmcli: invoke Reload() D-Bus method asynchronously
Invoke Reload() asynchronously and run the main loop. In this way, the
polkit agent built into nmcli can be used to authenticate the reload
request.

Fixes: 5afcf9c045 ('cli: add 'general reload' command')
(cherry picked from commit 1d82c39bfa)
2021-06-10 18:09:03 +02:00
Beniamino Galvani
ecda9fb41a libnm-glib-aux: add nm_dbus_call()
Add nm_dbus_call() to get a D-Bus connection and call a method
asynchronously.

(cherry picked from commit 126ee6a1e8)
2021-06-10 18:08:28 +02:00
Beniamino Galvani
e18f03a34a man: document the 'nmcli general reload' command
(cherry picked from commit 43fc984989)
2021-06-10 18:08:26 +02:00
Beniamino Galvani
d1729ac5e8 core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1
If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.

(cherry picked from commit fa1f628bce)
2021-06-10 18:08:24 +02:00
Thomas Haller
f8624ea2e5
contrib/scripts: use "main" branch name in "checkpatch-feature-branch.sh"
(cherry picked from commit 172dace30d)
2021-06-10 17:48:07 +02:00
Thomas Haller
1b97be1f34
bluez: fix leak of private data "conn_data_elems" in NMBluezManager
Found by valgrind.

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
(cherry picked from commit 6813a4fe75)
(cherry picked from commit a25c577556)
2021-06-10 16:03:20 +02:00
Thomas Haller
62d9c702b2
supplicant: fix leaking handle in nm_supplicant_manager_create_interface()
Found by valgrind.

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
(cherry picked from commit 01df4a5ad0)
(cherry picked from commit 80a8a5d16d)
2021-06-10 16:03:20 +02:00
Wade Berrier
79b2105759
wifi: fix WPS PBC string typo
Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/845
(cherry picked from commit 3839db5191)
2021-06-04 21:32:57 +02:00