Commit graph

29904 commits

Author SHA1 Message Date
Thomas Haller
7d8e43df94
device: fix reapply for lldp/mdns/llmnr/dns-over-tls settings
When only one of those connection.{lldp,mdns,llmnr,dns-over-tls}
settings changes, we still need to do a full restart of the IP
configuration to reapply the changes.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit f4b128c63b)
(cherry picked from commit 6eaee2b13f)
2022-09-29 10:53:02 +02:00
Thomas Haller
1999fa9650
glib-aux: add nm_g_hash_table_contains_any() helper
(cherry picked from commit e0fc8a11d5)
(cherry picked from commit dced08e3b0)
2022-09-29 10:53:01 +02:00
avery
3e260357b4
nmcli-completion: fix support for embedded quote characters
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/455

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

Fixes: 9d2290135c ('cli: make nmcli do its own command completion')
(cherry picked from commit ebdf3bd376)
(cherry picked from commit 40870dd6d0)
2022-09-29 10:40:22 +02:00
Beniamino Galvani
0b20519260 device: don't emit recheck-assume if there is a queued activation request
The @dracut_NM_vlan_over_team_no_boot sometimes fails, among other
things, because it fails to assume an indicated connection after a
restart.

That seems to happen because after the decision to activate the
indicated connection, the device does not move from DISCONNECTED state
quickly enough. Another assumption recheck runs in between and decides
to generate a connection, because the assume state was already reset
in between.

First start, creates and activates b3a61b68-f744-4a4c-a513-61399c154a67
on vlan0017:

  NetworkManager (version 1.41.1-30921.55767cf5.el9) is starting...
      (asserts:10000, boot:caf7301a-19cd-498b-b5ba-5d36ee939ffe)
  ...
  settings: update[b3a61b68-f744-4a4c-a513-61399c154a67]: adding connection "vlan0017"
      (45113870df0a4cfb/keyfile)

Second start:

  NetworkManager (version 1.41.1-30921.55767cf5.el9) is starting...
      (after a restart, asserts:10000, boot:caf7301a-19cd-498b-b5ba-5d36ee939ffe)

Assumption attempt successfully picks the right connection and thus
proceeds to reset the assume state:

  manager: (vlan0017): assume: will attempt to assume matching connection 'vlan0017'
      (b3a61b68-f744-4a4c-a513-61399c154a67) (indicated)
  device[c7c5101cf0b73f5f] (vlan0017): assume-state: set guess-assume=0, connection=(null)

Everything great so far, activation of the right connection is enqueued
and the device moves away from unavailable state. However, the
activation can't proceed immediately:

  device (vlan0017): state change: unmanaged -> unavailable
      (reason 'connection-assumed', sys-iface-state: 'assume')
  device (vlan0017): state change: unavailable -> disconnected
      (reason 'connection-assumed', sys-iface-state: 'assume')
  active-connection[0x55ba1162f1c0]: set device "vlan0017" [0x55ba1163c4f0]
  device[c7c5101cf0b73f5f] (vlan0017): queue activation request waiting for carrier

Now another assumption attempt is done. The original assume state is
gone, so a connection is generated:

  platform-linux: UDEV event: action 'add' subsys 'net' device 'vlan0017' (6); seqnum=1959
  device[c7c5101cf0b73f5f] (vlan0017): queued link change for ifindex 6
  manager: (vlan0017): assume: generated connection 'vlan0017' (57627119-8c20-4f9e-bf4d-4fc427b4a6a9)
  keyfile: commit: 57627119-8c20-4f9e-bf4d-4fc427b4a6a9 (vlan0017) added as
      "/run/NetworkManager/system-connections/vlan0017-57627119-8c20-4f9e-bf4d-4fc427b4a6a9.nmconnection"
      (nm-generated,volatile,external)

I think this shouldn't have happened. We've picked the correct
connection already and it's enqueued for activation!

Change the check in nm_device_emit_recheck_assume() to also consider
any queued activation.

Fixes-test: @dracut_NM_vlan_over_team_no_boot

Co-authored-by: Lubomir Rintel <lkundrak@v3.sk>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1351
(cherry picked from commit 9eb8cbca76)
(cherry picked from commit bdaba47a68)
(cherry picked from commit f2925801f2)
2022-09-05 09:36:39 +02:00
Thomas Haller
8b9a12e109 dhcp: merge branch 'bg/restart-dhcp-on-mac-change'
https://bugzilla.redhat.com/show_bug.cgi?id=2110000

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

(cherry picked from commit 7f40eb1b04)

(cherry picked from commit 14633422e2)

(cherry picked from commit c8341aa3f2)
2022-08-31 10:11:37 +02:00
Beniamino Galvani
59a52510f3 device: restart DHCP when the MAC changes
If the MAC changes there is the possibility that the DHCP client will
not be able to renew the address because it uses the old MAC as
CHADDR. Depending on the implementation, the DHCP server might use
CHADDR (so, the old address) as the destination MAC for DHCP replies,
and those packets will be lost.

To avoid this problem, restart the DHCP client when the MAC changes.

https://bugzilla.redhat.com/show_bug.cgi?id=2110000
(cherry picked from commit 905adabdba)
(cherry picked from commit 5a49a2f6b2)
(cherry picked from commit d0fb3fbf8e)
2022-08-31 10:11:37 +02:00
Beniamino Galvani
3d02df8061 core: log when dynamic IP configuration is restarted and why
(cherry picked from commit 6cd69fde33)
(cherry picked from commit 2f8e4e2b06)
(cherry picked from commit 8011d0b32b)
2022-08-31 10:11:37 +02:00
Fernando Fernandez Mancera
45c0cde9eb ovsdb: do not set the device as DEACTIVATING if it is DISCONNECTED
During the deactivation of ovs interfaces, ovsdb receives the command to
remove the interface but for OVS system ports the device won't
disappear.

When reconnecting, ovsdb will update first the status and it will notice
that the OVS system interface was removed and it will set the status as
DEACTIVATING. This is incorrect if the status is already DEACTIVATING,
DISCONNECTED, UNMANAGED or UNAVAILABLE because it will block the
activation of the interface.

https://bugzilla.redhat.com/show_bug.cgi?id=2080236
(cherry picked from commit bc6e28e585)
(cherry picked from commit 19613a8d81)
2022-08-29 16:01:34 +02:00
Beniamino Galvani
7f614dc88b bridge: don't reset vlan filtering parameters on external connections
Fixes: 96fab7b462 ('all: add vlan-filtering and vlan-default-pvid bridge properties')

https://bugzilla.redhat.com/show_bug.cgi?id=2107647
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1305
(cherry picked from commit 2c70fef12e)
(cherry picked from commit 4430e663c6)
2022-07-26 09:10:31 +02:00
Beniamino Galvani
b43503b67b ovs: fail device only when it's activating
It doesn't make sense to fail a device that is not activating.

Especially, if the device was in state UNMANAGED, it would enter state
FAILED (and then DISCONNECTED) or ACTIVATED (when external or
assumed); both are wrong.

https://bugzilla.redhat.com/show_bug.cgi?id=2077950
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1302
(cherry picked from commit 93372e8100)
(cherry picked from commit 562239779c)
2022-07-19 14:16:01 +02:00
Beniamino Galvani
36cbca83e7 core: merge branch 'bg/l3cd-dns-priority'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1045
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1298

(cherry picked from commit e122df6005)

(cherry picked from commit 6fbb1c282e)
2022-07-18 08:15:15 +02:00
Beniamino Galvani
36f2cfc434 ppp,wwan: remove explicit initialization of DNS priority
It's no longer necessary, as modem devices get the priority from the
ipmanual configuration created from the profile.

(cherry picked from commit 8c17760f62)
(cherry picked from commit 6a83fad831)
2022-07-18 08:15:15 +02:00
Beniamino Galvani
2c919477c6 wwan: enable manual IP configuration
Before 1.36, manual addresses from the profile were assigned to the
interface; restore that behavior.

The manual IP configuration also contains the DNS priority from the
profile; so this change ensures that the merged l3cd has a DNS
priority and that dynamically discovered DNS servers are not ignored
by the DNS manager.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
(cherry picked from commit 0717589972)
(cherry picked from commit 2ddb643319)
2022-07-18 08:15:15 +02:00
Beniamino Galvani
8388f67d3d device: add "is_manual" argument to ready_for_ip_config() device method
Some device types might want to run manual ip configuration while
skipping other methods.

(cherry picked from commit 2ae8433520)
(cherry picked from commit 2128e4542e)
2022-07-18 08:15:15 +02:00
Beniamino Galvani
ace95e5113 core: update DNS when the device enters IP_CONFIG state
Update DNS information when the device enters the IP_CONFIG state. In
this way, when dispatcher events "dhcp4-change,dhcp6-change" are
emitted resolv.conf already contains the information received from
the DHCP lease.

https://bugzilla.redhat.com/show_bug.cgi?id=2100456
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1283
(cherry picked from commit 1784fc9fa1)
(cherry picked from commit 95df70112f)
2022-07-13 09:40:38 +02:00
Thomas Haller
ab4c9539f7
release: bump version to 1.36.9 (development) 2022-07-12 16:56:08 +02:00
Thomas Haller
08bb0a8023
release: bump version to 1.36.8 2022-07-12 16:56:08 +02:00
Thomas Haller
03175cbc3f
NEWS: update 2022-07-12 15:31:26 +02:00
Thomas Haller
6732138ffe
libnm: fix timestamp in LIBNM_CLIENT_DEBUG debug logging
Fixes: 9c01d6ca67 ('libnm: print timestamp in LIBNM_CLIENT_DEBUG debug logging')
(cherry picked from commit 287a34990a)
(cherry picked from commit 2946192217)
2022-07-04 17:31:36 +02:00
Thomas Haller
da166edc3f
libnm: fix "parameters" argument in nm_client_dbus_call() to be optional
It was documented to be an optional parameter. That is also in line
with g_dbus_connection_call(), which is essentially wrapped by nm_client_dbus_call().

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
(cherry picked from commit ea85f6dfa3)
(cherry picked from commit ce629741f1)
2022-07-04 17:31:36 +02:00
Slava Monich
864e1748aa
supplicant: fix a memory leak
==30980== 8 bytes in 1 blocks are definitely lost in loss record 1,117 of 6,137
==30980==    at 0x4841C38: malloc (vg_replace_malloc.c:309)
==30980==    by 0x4A246C7: g_malloc (gmem.c:106)
==30980==    by 0x4A4A4BB: g_variant_get_strv (gvariant.c:1607)
==30980==    by 0x4A4CA73: g_variant_valist_get_nnp (gvariant.c:4901)
==30980==    by 0x4A4CA73: g_variant_valist_get_leaf (gvariant.c:5058)
==30980==    by 0x4A4CA73: g_variant_valist_get (gvariant.c:5239)
==30980==    by 0x4A4D11D: g_variant_get_va (gvariant.c:5502)
==30980==    by 0x4A4D1BD: g_variant_lookup (gvariant.c:989)
==30980==    by 0xE9389: parse_capabilities (nm-supplicant-interface.c:1241)
==30980==    by 0xEBF99: _properties_changed_main (nm-supplicant-interface.c:1941)
==30980==    by 0xEF549: _properties_changed (nm-supplicant-interface.c:2867)
==30980==    by 0xEF7ED: _get_all_main_cb (nm-supplicant-interface.c:2972)
==30980==    by 0x262057: _nm_dbus_connection_call_default_cb (nm-dbus-aux.c:70)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DBF43: g_task_return.part.3 (gtask.c:1285)
==30980==    by 0x4918885: g_dbus_connection_call_done (gdbusconnection.c:5765)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DB6D7: complete_in_idle_cb (gtask.c:1229)
==30980==    by 0x4A20981: g_main_dispatch (gmain.c:3325)
==30980==    by 0x4A20981: g_main_context_dispatch (gmain.c:4016)
==30980==    by 0x4A20BEF: g_main_context_iterate.isra.23 (gmain.c:4092)
==30980==    by 0x4A20E33: g_main_loop_run (gmain.c:4290)
==30980==    by 0x2C5C9: main (main.c:509)

Fixes: cd1e0193ab ('supplicant: add BIP interface capability')
(cherry picked from commit 8c5356cec6)
(cherry picked from commit 25f41811c5)
2022-07-04 17:31:35 +02:00
Beniamino Galvani
313e666431 wifi: wait supplicant to settle before renewing DHCP after roam
After roaming to a different AP, if we trigger a DHCP renewal while
the supplicant is still reauthenticating the REQUEST will be lost and
the client will fall back to sending a DISCOVER, potentially getting a
different address.

Wait that the supplicant state settles before renewing.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1024
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1263
(cherry picked from commit fb4ac007ba)
(cherry picked from commit b3036782dd)
2022-07-04 13:26:25 +02:00
Ana Cabral
592a78a583
rpm: move ifcfg scripts directory to the NetworkManager package
NetworkManager does not support by default legacy ifcfg configuration
files anymore, this support is now provided in a separate package
(https://fedoramagazine.org/converting-networkmanager-from-ifcfg-to-keyfiles/).

ifcfg directory (/etc/sysconfig/network-scripts/) should always be present,
regardless of NetworkManager support for network scripts. This change makes the
directory always present, not only when the recently splitted ifcfg subpackage
is installed, and also make it persistent after the package removal.

Fixes: 50a6627fd7 ('rpm: split ifcfg-rh settings plugin into a separate package')
(cherry picked from commit 0415d904cb)
(cherry picked from commit 77b48a906e)
2022-06-29 09:36:41 +02:00
Thomas Haller
6a505fd400
l3cfg: fix comparing "has-dns-priority" flag in nm_l3_config_data_cmp_full()
Fixes: cb29244552 ('core: support compare flags in nm_l3_config_data_cmp_full()')
(cherry picked from commit 8e86cfb8ab)
(cherry picked from commit a9b0b269a6)
2022-06-29 09:34:29 +02:00
Beniamino Galvani
e1266b3b12 platform: fix routing rule test failure
Since kernel 5.18 there is a stricter validation [1][2] on the tos
field of routing rules, that must not include ECN bits.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f55fbb6afb8d701e3185e31e73f5ea9503a66744
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a410a0cf98854a698a519bfbeb604145da384c0e

Fixes the following failure:

  >>> src/core/platform/tests/test-route-linux
  >>> ...
  # NetworkManager-MESSAGE: <warn>  [1656321515.6604] platform-linux: do-add-rule: failure 22 (Invalid argument - Invalid dsfield (tos): ECN bits must be 0)
  >>> failing... errno=-22, rule=[routing-rule,0x13d6e80,1,+alive,+visible; [6] 0: from all tos 0xff fwmark 0x4/0 suppress_prefixlen -459579276 action-214 protocol 255]
  >>> existing rule: * [routing-rule,0x13d71e0,2,+alive,+visible; [6] 0: from all sport 65534 lookup 10009 suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d7280,2,+alive,+visible; [4] 0: from all fwmark 0/0x9a7e9992 ipproto 255 suppress_prefixlen 0 realms 0x00000008 none protocol 71]
  >>> existing rule:   [routing-rule,0x13d7320,2,+alive,+visible; [6] 598928157: from all suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d73c0,2,+alive,+visible; [4] 0: from 192.192.5.200/8 lookup 254 suppress_prefixlen 0 none protocol 9]
  >>> existing rule:   [routing-rule,0x13d7460,2,+alive,+visible; [4] 0: from all ipproto 3 suppress_prefixlen 0 realms 0xffffffff none protocol 5]
  >>> existing rule:   [routing-rule,0x13d7500,2,+alive,+visible; [4] 0: from all fwmark 0x1/0 lookup 254 suppress_prefixlen 0 action-124 protocol 4]
  >>> existing rule:   [routing-rule,0x13d75a0,2,+alive,+visible; [4] 0: from all suppress_prefixlen 0 action-109]
  0:      from all fwmark 0/0x9a7e9992 ipproto ipproto-255 realms 8 none proto 71
  0:      from 192.192.5.200/8 lookup main suppress_prefixlength 0 none proto ra
  0:      from all ipproto ggp realms 65535/65535 none proto 5
  0:      from all fwmark 0x1/0 lookup main suppress_prefixlength 0 124 proto static
  0:      from all 109
  0:      from all sport 65534 lookup 10009 suppress_prefixlength 0 none
  598928157:      from all none
  Bail out! nm:ERROR:../src/core/platform/tests/test-route.c:1787:test_rule: assertion failed (r == 0): (-22 == 0)

Fixes: 5ae2431b0f ('platform/tests: add tests for handling policy routing rules')
(cherry picked from commit bf9a2babb4)
(cherry picked from commit 09b0014a01)
2022-06-27 13:38:30 +02:00
Beniamino Galvani
bc980fc07c core: avoid stale entries in the DNS manager for non-virtual devices
_dev_l3_register_l3cds() schedules a commit, but if the device has
commit type NONE, that doesn't emit a l3cd-changed. Do it manually,
to ensure that entries are removed from the DNS manager.

Related: b86388bef3 ('core: avoid stale entries in the DNS manager')
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/995
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1268
(cherry picked from commit f8885d0724)
(cherry picked from commit 4baec297f4)
2022-06-24 13:39:45 +02:00
Beniamino Galvani
ce4ada62c7 device: stop ac6 grace time when ip6ll is ready in shared mode
The IPv6 shared mode starts IPv6 autoconf to send router
advertisements. IPv6 autoconf schedules a 30-second timeout waiting
for a link-local address to appear. When the link-local address
appears, we need to cancel the timeout.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1030
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1266
(cherry picked from commit a216739e09)
(cherry picked from commit 7368f322f8)
2022-06-22 18:08:49 +02:00
Thomas Haller
007d9ea265
NEWS: update 2022-06-14 12:55:46 +02:00
Thomas Haller
6920b6ceb1
merge branch 'th/addr-order-1.36' into nm-1-36
The behavior about IP address order was just too broken on 1.36.
Fix it, by backporting all relevant patches from nm-1-38. This
is a change in behavior.

The bug was that 1.36.0 would have an inverted notion of the correct
IPv6 address order. But it also had a bug so that the order was not
enforced. That second bug was fixed by commit cd4601802d ('platform: fix
address order in nm_platform_ip_address_sync()') in 1.36.6. Thereby
uncovering the wrong order.

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1977619
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1021

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1256
2022-06-14 12:55:46 +02:00
Thomas Haller
53ac352d10
platform: ensure the platform cache is up to date during nm_platform_ip_address_sync()
Since commit 528a63d9cc ('platform: avoid unnecessary configuration of
IP address in nm_platform_ip_address_sync()'), we no longer configure the
IP address if it is in the platform cache. But the cache might not be
up to date. Process any pending netlink events.

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

Fixes: 528a63d9cc ('platform: avoid unnecessary configuration of IP address in nm_platform_ip_address_sync()')
(cherry picked from commit 7f427ac4e6)
(cherry picked from commit e92639d89c)
2022-06-14 12:55:46 +02:00
Thomas Haller
c7382daa85
platform: merge branch 'th/platform-address-sync-one-by-one'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1200

(cherry picked from commit 7dda0b94bc)

(cherry picked from commit 14a23494f0)
2022-06-14 12:55:46 +02:00
Thomas Haller
fdc4207ab1
platform: simplify loop for IPv6 addresses in nm_platform_ip_address_sync()
(cherry picked from commit 9b930cd962)
(cherry picked from commit 555891fe8d)
2022-06-14 12:55:46 +02:00
Thomas Haller
1188942c75
platform: fix handling IPv6 address index in nm_platform_ip_address_sync()
Fixes: 4a548423b9 ('core: change order/priority of static IPv6 addresses relative to autoconf6/DHCPv6')
(cherry picked from commit b52941ac34)
(cherry picked from commit 169d74b2e4)
2022-06-14 12:55:46 +02:00
Thomas Haller
cab3e6d074
platform: merge branch 'th/ipv6-address-order-rh2073032'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1185

(cherry picked from commit c3b7ec5b42)
(cherry picked from commit 9fe4695ab6)
2022-06-14 12:55:45 +02:00
Thomas Haller
08884c53a9
platform: re-configure one address at a time in nm_platform_ip_address_sync()
Try to do one change at a time when reconfiguring addresses, to not
remove several/all addresses at once.

For IP addresses, kernel cares about the order in which they were added.
This mostly affects source address selection, and the "secondary" flag
for IPv4 addresses. The order is thus related to the priority of an
address.

There is no direct kernel API to change the order. Instead, we have to
add them in the correct order. During a sync, if an address already
exists in the wrong order, we need to remove it, and re-add it.
Btw, with IPv4 addresses added first via netlink are the primary
address, while with IPv6 it's reverse.

Previously, we would first iterate over all addresses and remove those
that had a conflicting order. This means, that we would potentially
remove all addresses for a short while, before readding them. That seems
problematic.

Instead, first track all addresses that are in the wrong order. And in
the step when we add/update the address, remove it. We now only remove
and address shortly before re-adding it. This way the time for which the
address on the interface is missing is shorter. More importantly, we will
never remove all addresses at the same time.

(cherry picked from commit a6fd641634)
(cherry picked from commit a1835c2c05)
2022-06-14 12:55:45 +02:00
Thomas Haller
a7b110db14
platform: merge branch 'th/platform-address-order' (part 2)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1168

(cherry picked from commit 0119d56dca)
(cherry picked from commit f3a84483f7)
2022-06-14 12:55:45 +02:00
Thomas Haller
bd933ae82b
core: change the priority order in static "ipv6.addresses"
The order of addresses matters. For "ipv4.addresses", the list
contains the primary address first. For "ipv6.addresses", the
order was reverted. This was also documented behavior.

The previous patch just changed behavior with respect to relative order
of static IPv6 addresses and autoconf6/DHCPv6. As we seem in the mood
for changing behavior, here is another one.

Now the addresses are interpreted in an order consistent with IPv4 and
how one might expect: preferred addresses first.

(cherry picked from commit 3d6b6aa317)
(cherry picked from commit 257221d198)
2022-06-14 12:55:45 +02:00
Thomas Haller
b7a5d41ffe
glib-aux: add assertions for valid prefix length
(cherry picked from commit 9ce4a16523)
(cherry picked from commit 0180a9fca5)
2022-06-14 12:55:45 +02:00
Thomas Haller
87cae4802b
core: change order/priority of static IPv6 addresses relative to autoconf6/DHCPv6
The order of addresses can matter for source address selection.
This is described in RFC 6724 section 5, but if the rules don't
determine a clear winner, the order matters.

Change the relative order of IPv6 addresses. Previously, we would prefer
autoconf6, over DHCPv6, over manual addresses. Now that got reverted
to make more sense and be consistent with IPv4.
Also, if we had multiple autoconf6 addresses (received at different
moments in time), then previously a newly received address would be
added with highest priority. Now, the older address will be preferred
and that order will be enforced (this can be a problem, see (*) below).

For IPv4, it's all simple and sensible. When we add addresses in kernel
via netlink, the first address (of a subnet) becomes the primary.
Note that we only control the order of addresses of the same subnet.
The addresses in ipv4.addresses" are sorted with primary address first.
In the same way is the order for addresses in NML3ConfigData and for
@known_addresses in nm_platform_ip_address_sync(), all primary-first.
Also, manual addresses are sorted with higher priority compared to DHCPv4
addresses (at least since NetworkManager 1.36). That means the way how we
merge NML3ConfigData makes sense (nm_l3_config_data_merge()) because we first
merge the static configuration, then the DHCPv4 configuration, where we just
append the lower priority DHCPv4 addresses.

For IPv6, the address priority is messed up. On netlink/kernel, the last added
address becomes the preferred one (we thus need to add them in the order of
lowest priority first). Consequently and historically, the IPv6 addresses in
@known_addresses parameter to nm_platform_ip_address_sync() were
lowest priority first. And so they were tracked in NML3ConfigData
and in the profile ("ipv6.addresses"). That is confusing.
Also, we usually want to merge NML3ConfigData with different priorities
(e.g. static configuration from the profile before autoconf6/DHCPv6),
as we do with IPv4. However, since internally IPv6 addresses are tracked in
reverse order, it means later NML3ConfigData would be appended and get effectively
a higher priority. That means, autoconf6 addresses were preferred over DHCPv6 and
over manual "ipv6.addresses", respectively. That seems undesirable and inconsistent
with IPv4. Change that. This is a change in behavior.

Note that changing the order of addresses means to remove and re-add
them in the right (inverse) order, with lease important first. This
means, when we add a new address with lower priority, we need to remove
all higher priority addresses temporarily, before readding them. That
is a problem(*).

Note that in the profile, "ipv6.addresses" is still tracked in reverse
order. This did not change, but might change later.

(cherry picked from commit 4a548423b9)
(cherry picked from commit 171d70bbf7)
2022-06-14 12:55:45 +02:00
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