Commit graph

29865 commits

Author SHA1 Message Date
Thomas Haller
2e6d70e51f
glib-aux/tests: avoid invalid prefix length in test_platform_ip_address_pretty_sort_cmp()
Next we are going to assert that the prefix length is valid.
The test needs to have valid prefix lengths too. Adjust.

(cherry picked from commit a850e438a7)
(cherry picked from commit fee1d627e9)
2022-06-14 12:55:44 +02:00
Thomas Haller
90e1ba4067
glib-aux: use uint32 type for prefix length parameter
Of course, the prefix length cannot be larger than 32 or 128.
But as C does implicit conversions, a buggy prefix length can
lead to a (wrongly) valid prefix length.

Make the type uint32, to prevent that (at least for common cases,
unless you pass a huge 64 bit integer).

(cherry picked from commit 0cf9db42d4)
(cherry picked from commit fb6e912810)
2022-06-14 12:55:44 +02:00
Thomas Haller
1986c73d3b
glib-aux: move nm_utils_ip4_address_clear_host_address() to header so it can be inlined
(cherry picked from commit b5a06dedd4)
(cherry picked from commit e5fa1a30c2)
2022-06-14 12:55:44 +02:00
Thomas Haller
f94b0e1669
glib-aux: move ip address utils in "nm-shared-utils.h" header
Some were duplicated. Drop those.

Some function were in an order where they required forward declarations.
Reorder.

(cherry picked from commit d7990b359b)
(cherry picked from commit 04d982e278)
2022-06-14 12:55:44 +02:00
Thomas Haller
e5c06f0c45
platform: use nm_utils_ip4_address_clear_host_address()
We have this util function, presumably because it's good to have it.
Use it.

(cherry picked from commit 3a545fd041)
(cherry picked from commit 09832c5639)
2022-06-14 12:55:44 +02:00
Thomas Haller
a585910b49
platform: guard logging statements with check whether logging is enabled
(cherry picked from commit 4fc25d523a)
(cherry picked from commit 57065cc50d)
2022-06-14 12:55:44 +02:00
Thomas Haller
fa1ba1ea11
glib-aux: assert that nm_utils_to_string_buffer_init() does not use the global buffer
For convenience, most to-string methods call nm_utils_to_string_buffer_init().
This allows to omit the string buffer and use a global (thread-local)
buffer.

That "convenience" seems error prone. Start drop it.

Start by adding a g_return_if_reached() assertion to catch the cases
that use it.

(cherry picked from commit 27752bfd5b)
(cherry picked from commit 3b56f33aa2)
2022-06-14 12:55:44 +02:00
Thomas Haller
314910e8c2
all: avoid using global string buffer for to-string methods
These string functions allow to omit the string buffer. This is for
convenience, to use a global (thread-local) buffer. I think that is
error prone and we should drop that "convenience" feature.

At various places, pass a stack allocated buffer.

(cherry picked from commit b87afac8e8)
(cherry picked from commit 14b920d3cf)
2022-06-14 12:55:43 +02:00
Thomas Haller
61c6107797
all: use "NM_UTILS_TO_STRING_BUFFER_SIZE" macro
(cherry picked from commit 02a8d21e4e)
(cherry picked from commit c21034f494)
2022-06-14 12:55:43 +02:00
Thomas Haller
59d34fc64f
all: add "NM_UTILS_TO_STRING_BUFFER_SIZE" macro
I want to get rid of "_nm_utils_to_string_buffer" (or at least, limit
and control its use). Currently it's used all over the place only
to get the size of it. Add a define instead.

(cherry picked from commit 36e709c021)
(cherry picked from commit e13c2426c8)
2022-06-14 12:55:43 +02:00
Thomas Haller
180aa89e8d
platform: avoid unnecessary configuration of IP address in nm_platform_ip_address_sync()
We call sync many times. Often there is nothing to update. Check the
cache first, before (re) adding it.

Note that many addresses have a limited lifetime, that is, a lifetime
that keeps counting down with seconds granularity. For those (common)
cases we will only avoid the call to kernel if there are two syncs
within less than a second.

(cherry picked from commit 528a63d9cc)
(cherry picked from commit 429540a6b7)
2022-06-14 12:55:43 +02:00
Thomas Haller
579edd886f
platform: add nm_platform_ip_address_get() helper
(cherry picked from commit a815212214)
(cherry picked from commit aa764f5fcc)
2022-06-14 12:55:43 +02:00
Thomas Haller
02110433aa
platform: avoid duplicated code in _nmp_object_stackinit_from_type()
(cherry picked from commit 3bd5d2bca9)
(cherry picked from commit 07c4b3ec71)
2022-06-14 12:55:43 +02:00
Thomas Haller
3f0394df4c
platform: rename local variable in nm_platform_ip_address_sync()
(cherry picked from commit 31299473cd)
(cherry picked from commit e38dac5226)
2022-06-14 12:55:43 +02:00
Thomas Haller
62b85be236
platform: make "idx" argument in _addr_array_clean_expired() mandatory
There is only one caller of _addr_array_clean_expired(), and it always
provides the "idx" pointer.

(cherry picked from commit de9f174d51)
(cherry picked from commit 1f05866821)
2022-06-14 12:55:42 +02:00
Thomas Haller
f1ff00092c
platform: add ascending/descending functions for ip6_address_scope_cmp*()
It seems easier to read, than passing a boolean parameter.

(cherry picked from commit 305f11069f)
(cherry picked from commit 2e6d45cb4e)
2022-06-14 12:55:42 +02:00
Thomas Haller
46b55b3680
platform: allocate result array when needed in nm_platform_ip_{address,route}_get_prune_list()
It is rather unlikely, that we call this function with no existing
routes/addresses. Hence, usually this does not safe an allocation
of the GPtrArray.

However, it's slightly less code and makes more sense this way
(instead of checking afterwards, whether the array is empty and
destroy it).

(cherry picked from commit 6bc9b73c55)
(cherry picked from commit e9d3ba66df)
2022-06-14 12:55:42 +02:00
Thomas Haller
12805adce2
platform: add logging statements to nm_platform_ip_address_sync() for printf() debugging
The code is disabled at compile time. It's only useful for printf
debugging to modify the source to get more logging.

(cherry picked from commit fcb4033a81)
(cherry picked from commit d361bfc945)
2022-06-14 12:55:42 +02:00
Thomas Haller
e646824643
Revert "platform: workaround for preserving IPv6 address order"
Revert this change again. We are going to backport all the relevant
fixes from nm-1-38 about the address order.

This reverts commit da721a3f320b1e7e4628f7661bf3f78b7f12ed24.
2022-06-14 12:55:42 +02:00
Thomas Haller
dc9e4a07e4
platform: workaround for preserving IPv6 address order
Before 1.34, DHCPv6 addresses were preferred over SLAAC addresses
and all was good. Well, actually, we didn't have any CI tests, so
whether it really worked is only an assumption. But it probably was.

With 1.36 this broke for two reasons:

1) 1.36 would now prefer SLAAC over DHCPv6 over manual addresses.
2) 1.36 would also not adjust the order of already existing addresses.
   This means, we first would get the SLAAC address and the DHCPv6
   address later. Adding the address later would mean that it becomes
   more important. This would go against 1), but due to 2) effectively
   DHCPv6 was still preferred over SLAAC.

Commit [1] would fix 2), but now the address order changed.
We will need to fix also 1), but in the meantime, disable parts of
commit [1] so that we still get the old behavior.

[1] cd4601802d ('platform: fix address order in nm_platform_ip_address_sync()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/ ## 1021
2022-06-14 12:55:42 +02:00
Beniamino Galvani
5b8e7dac34 merge: branch 'bg/ppp-race-rh2085382'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1240
https://bugzilla.redhat.com/show_bug.cgi?id=2085382

(cherry picked from commit d98d72c061)

(cherry picked from commit 05e8c5511b)
2022-06-14 12:35:59 +02:00
Beniamino Galvani
813b5dfb4b ppp: don't remove addresses from interface while IPCP/IPV6CP is running
pppd also tries to configure addresses by itself through some
ioctls. If we remove between those calls an address that was added,
pppd fails and quits.

To avoid this race condition, don't remove addresses while IPCP and
IPV6CP are running. Once pppd sends an IP configuration, it has
finished configuring the interface and we can proceed normally.

https://bugzilla.redhat.com/show_bug.cgi?id=2085382
(cherry picked from commit b41b11d613)
(cherry picked from commit e95b44bacb)
2022-06-14 12:35:59 +02:00
Beniamino Galvani
565b389bf6 core: add nm_l3cfg_block_obj_pruning()
Add a function prevent the removal of addresses and routes from the
interface for a given address family.

(cherry picked from commit e8275d7139)
(cherry picked from commit 59ef1b4c78)
2022-06-14 12:35:59 +02:00
Beniamino Galvani
d799d29027 device: ensure DHCP is restarted every time the link goes up
Currently we call nm_device_update_dynamic_ip_setup() in
carrier_changed() every time the carrier goes up again and the device
is activating, to kick a restart of DHCP.

Since we process link events in a idle handler, it can happen that the
handler is called only once for different events; in particular
device_link_changed() might be called once for a link-down/link-up
sequence.

carrier_changed() is "level-triggered" - it cares only about the
current carrier state. nm_device_update_dynamic_ip_setup() should
instead be "edge-triggered" - invoked every time the link goes from
down to up. We have a mechanism for that in device_link_changed(), use
it.

Fixes-test: @ipv4_spurious_leftover_route

https://bugzilla.redhat.com/show_bug.cgi?id=2079406
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1250
(cherry picked from commit d6429d3ddb)
(cherry picked from commit 1c158a5f37)
2022-06-11 18:31:02 +02:00
Beniamino Galvani
e7ad8a8b42 ppp: merge branch 'ppp-ip6-dns'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1254

(cherry picked from commit 31d7131126)

(cherry picked from commit 0c89c3a7bd)
2022-06-09 16:29:31 +02:00
Dominique Martinet
168496db34 ppp-manager: ip6: set interface mtu based on ppp config
impl_ppp_manager_set_ip4_config always has been setting interface mtu
based on ppp configuration: do the same for ip6 in case it matters.

(cherry picked from commit 4d7b494eb3)
(cherry picked from commit 423e5e5011)
2022-06-09 16:29:31 +02:00
Dominique Martinet
945bffddc5 ppp-manager: ip6: fix dns not being used
ipv6 DNS received on ppp interface were being ignored because their
priority was not set.
Fix this by using default priority in impl_ppp_manager_set_ip6_config(),
as was done for ip4_config in b2e559fab2 ("core: initialize l3cd
dns-priority for ppp and wwan")

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1022
(cherry picked from commit 6991333bc0)
(cherry picked from commit d04eba0c40)
2022-06-09 16:29:31 +02:00
Beniamino Galvani
a0f34b3f92 device: fix memory leak
l3cd instances must be removed from the old l3cfg before calling
_cleanup_ip_pre(). Otherwise, _cleanup_ip_pre() unregisters them from
the device, and later _dev_l3_register_l3cds(self, l3cfg_old, FALSE,
FALSE) does nothing because the device doesn't have any l3cd.

Previously the l3cds would linger in the l3cfg, keeping a reference to
it and causing a memory leak; the leak was not detected by valgrind
because the l3cfg was still referenced by the NMNetns.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
Fixes-test: @stable_mem_consumption2

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1252
(cherry picked from commit f69a1cc874)
(cherry picked from commit 83ee0f0779)
2022-06-09 09:40:44 +02:00
Thomas Haller
b0a7dda2ea
dhcp/dhclient: fix setting "src" attribute for certain routes
Fixes: 2dc7a3d9f9 ('dhcp: set "src" for DHCPv4 routes')
(cherry picked from commit 197e73ac7c)
(cherry picked from commit 0c6d242dc0)
2022-05-26 10:38:41 +02:00
Thomas Haller
f2942d11a7
dhcp: set "src" for DHCPv4 routes
Let's set the "src" (RTA_PREFSRC) of DHCP routes.
This helps with source address selection.

This can matter if the interface also has static addresses
configured.

Systemd-networkd also does this ([1], [2]).

[1] ac2dce5f36
[2] 5b89bff55f/src/network/networkd-dhcp4.c (L395)

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1173
(cherry picked from commit 2dc7a3d9f9)
(cherry picked from commit 10b9e07bfc)
2022-05-26 10:38:13 +02:00
Beniamino Galvani
7b68a153d2 release: bump version to 1.36.7 (development) 2022-05-19 17:33:55 +02:00
Beniamino Galvani
2090a918b5 release: bump version to 1.36.6 2022-05-19 17:33:55 +02:00
Beniamino Galvani
4770bdbc52 NEWS: update 2022-05-19 13:49:45 +02:00
David Rheinsberg
958bdf6954
c-rbtree: fix alignment assertion on m64k
We want to assert that our alignment-guarantees do not exceed the
guarantees of the system-linker or system-allocator on the target
platform. Hence, we check against max_align_t. This is a lower bound,
but not the exact check we actually want. And as it turns out, on m64k
it is too low. Add a static check against 4-byte alignment for m64k as
a workaround.

Reported-by: Michael Biebl
Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>

https://github.com/c-util/c-rbtree/issues/9
eb778d3969
(cherry picked from commit 78831d127f)
(cherry picked from commit a83c884fb6)
2022-05-18 12:01:38 +02:00
Beniamino Galvani
55321055e2 device: don't require a hardware address for DHCPv6
DHCPv4 requires a hardware address, while DHCPv6 does not.

Anyway, the DHCP manager already checks that an address is available
when needed, so drop the check here.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1228
(cherry picked from commit 9bc7278da3)
(cherry picked from commit 1dbcc1c441)
2022-05-17 18:23:39 +02:00
Thomas Haller
c6c363554f
ndisc/tests: relex check in test_dns_solicit_loop()
Dunno why this happens. Just silence it.

  nm:ERROR:../src/core/ndisc/tests/test-ndisc-fake.c:649:test_dns_solicit_loop: assertion failed (data.counter == 3): (2 == 3)

(cherry picked from commit cb98616e02)
(cherry picked from commit 9858c34afb)
2022-05-17 12:53:18 +02:00
Thomas Haller
97f437ca45
libnm: merge branch 'th/libnm-8021x-empty-strings'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/973

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

(cherry picked from commit 8df79f60d6)
2022-05-17 11:59:07 +02:00
Thomas Haller
3634b7457a
libnm: normalize empty strings in 802-1x setting
Supplicant does not allow setting certain properties to empty values.
It also does not make sense.

Also, ifcfg-rh writer uses svSetValueStr() for these properties, so
the ifcfg plugin would always loose having hte values set to "".

Also, you couldn't enter these strings in nmcli.

It's fair to assume that it makes no sense to have these values set to
an empty value. Since we cannot just tighten up verification to reject
them, normalize them.

It also seems that some GUI now starts setting domain_suffix_match to an
empty string. Or maybe it was always doing it, and ifcfg plugin just hid
the problem? Anyway, we have users out there who set these properties to
"".

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/973
(cherry picked from commit 915e923928)
2022-05-17 11:59:06 +02:00
Thomas Haller
d813d42359
libnm: fix printing NULL value in NMSetting8021x.verify()
(cherry picked from commit 445e783771)
2022-05-17 11:59:05 +02:00
Thomas Haller
ef2f185167
ifcfg-rh: move code around in write_8021x_setting()
Makes more sense, to not interrupt the construction of the
phase2_auth string.

(cherry picked from commit 91cbbd99b9)
2022-05-17 11:59:05 +02:00
Thomas Haller
13af01d972
ifcfg-rh/trivial: add fixme comments about lossy write/read of properties
(cherry picked from commit 5f5641d304)
2022-05-17 11:59:05 +02:00
Thomas Haller
7b27189098
core: merge branch 'th/fix-clear-ip6-temp-addrs'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1209

(cherry picked from commit 452158a036)
(cherry picked from commit 22affb0a16)
2022-05-13 15:19:20 +02:00
Thomas Haller
d785233fcc
l3cfg: refresh platform cache before creating prune list during L3Cfg commit
It seems, we should make decisions based on the latest state.
Make sure to process all pending netlink events.

(cherry picked from commit 9a69bc8d84)
(cherry picked from commit 1b9dfd3001)
2022-05-13 15:18:35 +02:00
Thomas Haller
75c87d18ec
l3cfg: fix clearing IPv6 temporary addresses to avoid stale addresses
IPv6 temporary addresses are configured by kernel, with the
"ipv6.ip6-privacy" setting ("use_tempaddr" sysctl) and the
IFA_F_MANAGETEMPADDR flag.

As such, the idea was that during reapply we would not remove them.
However, that is wrong.

The only case when we want to keep those addresses, is if during reapply
we are going to configure the same primary address (with mngtmpaddr
flag) again. Otherwise, theses addresses must always go away.

This is quite serious. This not only affects Reapply. Also during disconnect
we clear IP configuration via l3cfg.
Have an ethernet profile active with "ipv6.ip6-privacy". Unplug
the cable, the device disconnects but the temporary IPv6 address is not
cleared. As such, nm_device_generate_connection() will now generate
an external profile (with "ipv6.method=disabled" and no manual IP addresses).
The result is, that the device cannot properly autoconnect again,
once you replug the cable.

This is serious for disconnect. But I could not actually reproduce the
problem using reapply. That is, because during reapply we usually
toggle ipv6_disable sysctl, which drops all IPv6 addresses. I still
went through the effort of trying to preserve addresses that we still
want to have, because I am not sure whether there are cases where we
don't toggle ipv6_disable. Also, doing ipv6_disable during reapply is
bad anyway, and we might want to avoid that in the future.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 518f6124c6)
(cherry picked from commit 3bd210a8f1)
2022-05-13 15:17:27 +02:00
Thomas Haller
618f9c1426
glib-aux: add nm_g_array_data() helper
It's annoying to do

  (arr ? arr->data : NULL)

Especially, because usually you'd need to cast the above
(which would have type (char *)).

(cherry picked from commit 5ff08fbbea)
(cherry picked from commit 281b3e6473)
2022-05-13 15:15:04 +02:00
Thomas Haller
40988fbeee
libnm: fix crash validating infiniband profiles for interface-name
A virtual infiniband profile (with p-key>=0) can also contain a
"connection.interface-name". But it is required to match the
f"{parent}.{p-key}" format.

However, such a profile can also set "mac_address" instead of "parent".
In that case, the validation code was crashing.

  nmcli connection add type infiniband \
     infiniband.p-key 6 \
     infiniband.mac-address 52:54:00:86:f4:eb:aa:aa:aa:aa:52:54:00:86:f4:eb:aa:aa:aa:aa \
     connection.interface-name aaaa

The crash was introduced by commit 99d898cf1f ('libnm: rework caching
of virtual-iface-name for infiniband setting'). Previously, it would not
have crashed, because we just called

  g_strdup_printf("%s.%04x", priv->parent, priv->p_key)

with a NULL string. It would still not have validated the connection
and passing NULL as string to printf is wrong. But in practice, it
would have worked mostly fine for users.

Fixes: 99d898cf1f ('libnm: rework caching of virtual-iface-name for infiniband setting')
(cherry picked from commit fd5945b408)
(cherry picked from commit d476851ee7)
2022-05-13 13:12:27 +02:00
Thomas Haller
b1c0fb04d1
dhcp: merge branch 'th/dhcpv6-otherconf-ignore-addr'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1220

(cherry picked from commit 19a96f64ed)

(cherry picked from commit fb5f2f25bc)
2022-05-13 13:09:55 +02:00
Thomas Haller
a5dda0e9bc
dhcp: fix ignoring addresses with DHCPv6 otherconf (O flag)
With O flag (otherconf mode), don't add the IPv6 addresses to the
collected lease.

An alternative would be to add it initially, but ignore it when
merging the configuration in NML3Cfg. The idea of that would be that if
the mode switches from otherconf to managed, that we already have the
address. However, depending on the mode we made a different DHCPv6
request. That means, if the mode changes we anyway cannot just use the
previous lease, because it might not contain all the information. So
it seems better to ignore the address early.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://bugzilla.redhat.com/show_bug.cgi?id=2083968
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/953

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1220
(cherry picked from commit 2875ad7e50)
(cherry picked from commit 476e007d04)
2022-05-13 13:09:54 +02:00
Thomas Haller
fc93c6b127
dhcp: fix setting "-S" flag for dhclient info-only requests
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 41df480fdd)
(cherry picked from commit 29e90e4722)
2022-05-13 13:09:53 +02:00
Thomas Haller
b285231a8e
dhcp: always explicitly set request/information-request flags for internal DHCPv6 client
It seems clearer to explicitly set this always, and not rely on the
defaults.

(cherry picked from commit bacd3e1482)
(cherry picked from commit 6ad3694fc5)
2022-05-13 13:09:53 +02:00