Commit graph

34212 commits

Author SHA1 Message Date
Yi Zhao
53952446a7
build/meson: add dependency libnm_client_public_dep for "libnm-client-test"
Fix parallel build error:
| In file included from ../NetworkManager-1.36.0/src/libnm-client-test/nm-test-utils-impl.c:10:
| ../NetworkManager-1.36.0/src/libnm-client-public/NetworkManager.h:47:10: fatal error: nm-enum-types.h: No such file or directory
|    47 | #include "nm-enum-types.h"
|       |          ^~~~~~~~~~~~~~~~~

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>

Fixes: a03a03fbe9 ('libnm/tests: add static helper library "src/libnm-client-test/"')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1206
2022-05-04 08:56:58 +02:00
Beniamino Galvani
e8d6ad9d12
ovsdb: fix memory leak
@error was leaked when created inside the function.

While at it, remove the goto.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
(cherry picked from commit 6f6c044739)
2022-05-03 22:18:02 +02:00
Thomas Haller
fd1d0a79dc
platform: log skipped addresses in nm_platform_ip_address_sync()
This is generally useful. Don't only log with more logging.

(cherry picked from commit 4c67970e4c)
2022-05-03 22:17:01 +02:00
Thomas Haller
e92639d89c
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)
2022-05-03 22:16:29 +02:00
Beniamino Galvani
3fff6770f8 device: merge branch 'bg/enslave-async'
https://bugzilla.redhat.com/show_bug.cgi?id=2052441
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1202
2022-05-03 13:20:27 +02:00
Beniamino Galvani
af9ed3eb2f ovs: add FIXME about cancellable operations 2022-05-03 13:19:24 +02:00
Beniamino Galvani
c503f5b214 ovs: attach port asynchronously
The attach operation needs to be asynchronous as we should wait the
result from ovsdb.

https://bugzilla.redhat.com/show_bug.cgi?id=2052441
2022-05-03 13:19:24 +02:00
Beniamino Galvani
9fcbc6b37d device: make attach_port() asynchronous
For some device types the attach-port operation doesn't complete
immediately. NMDevice needs to wait that the operation completes
before proceeding (for example, before starting stage3 for the port).

Change attach_port() so that it can return TERNARY_DEFAULT to indicate
that the operation will complete asynchronously. Most of devices are
not affected by this and can continue returning TRUE/FALSE as before
without callback.
2022-05-03 13:19:24 +02:00
Beniamino Galvani
bcc958c411 device: rename {enslave,release}_slave() to {attach,detach}_port()
Rename the enslave_slave() and release_slave() device methods to
attach_port() and detach_port().
2022-05-03 13:19:23 +02:00
Beniamino Galvani
6f6c044739 ovsdb: fix memory leak
@error was leaked when created inside the function.

While at it, remove the goto.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
2022-05-03 13:19:23 +02:00
Thomas Haller
f3db8049b7
NEWS: update
Resync latest changes from nm-1-38 branch.
2022-05-03 12:30:00 +02:00
Thomas Haller
202657c5d2
NEWS: update 2022-05-03 12:27:04 +02:00
Thomas Haller
508c677f0c
build/meson: avoid compiler warning generating "NM-1.0.gir"
In glib_dep we specify

  "-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_40 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_40"

which is the dependency we use almost everywhere. With g-ir-scanner
this causes compiler warnings:

    [xxx] Generating NM-1.0.gir with a custom command
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c: In function ‘dump_object_type’:
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c:252:13: warning: Not available before 2.70
      252 |   if (G_TYPE_IS_FINAL (type))
          |             ^~~~~~~~~~~~~~~~~
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c: In function ‘dump_fundamental_type’:
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c:370:13: warning: Not available before 2.70
      370 |   if (G_TYPE_IS_FINAL (type))
          |             ^~~~~~~~~~~~~~~~~
    g-ir-scanner: link: gcc -o /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0 /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.o -L. -Wl,-rpath,. -Wl,--no-as-needed -L/src/NetworkManager/build/src/libnm-client-impl -Wl,-rpath,/src/NetworkManager/build/src/libnm-client-impl -lnm -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lgmodule-2.0 -ludev -lgirepository-1.0 -lgio-2.0 -lgobject-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lglib-2.0

Work around that.

Meson's gnome.generate_gir() is not very flexibly in allowing to
pass extra `--cflags-begin {} --cflags-end` parameters.
Hack around by adding a pseudo dependency that resets
these defines.

See-also: https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/331
See-also: 1234e5583a ('build/autotools: avoid compiler warning generating "NM-1.0.gir"')
(cherry picked from commit e5d4194673)
2022-05-03 12:18:51 +02:00
Thomas Haller
14a23494f0
platform: merge branch 'th/platform-address-sync-one-by-one'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1200

(cherry picked from commit 7dda0b94bc)
2022-05-03 12:18:48 +02:00
Thomas Haller
555891fe8d
platform: simplify loop for IPv6 addresses in nm_platform_ip_address_sync()
(cherry picked from commit 9b930cd962)
2022-05-03 12:18:45 +02:00
Thomas Haller
169d74b2e4
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)
2022-05-03 12:18:43 +02:00
Thomas Haller
a1835c2c05
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)
2022-05-03 12:18:40 +02:00
Thomas Haller
9fe4695ab6
platform: merge branch 'th/ipv6-address-order-rh2073032'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1185

(cherry picked from commit c3b7ec5b42)
2022-05-03 12:18:38 +02:00
Thomas Haller
257221d198
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)
2022-05-03 12:18:35 +02:00
Thomas Haller
171d70bbf7
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)
2022-05-03 12:18:33 +02:00
Thomas Haller
f3a84483f7
platform: merge branch 'th/platform-address-order' (part 2)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1168

(cherry picked from commit 0119d56dca)
2022-05-03 12:18:30 +02:00
Thomas Haller
0180a9fca5
glib-aux: add assertions for valid prefix length
(cherry picked from commit 9ce4a16523)
2022-05-03 12:18:28 +02:00
Thomas Haller
fee1d627e9
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)
2022-05-03 12:18:26 +02:00
Thomas Haller
fb6e912810
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)
2022-05-03 12:18:24 +02:00
Thomas Haller
e5fa1a30c2
glib-aux: move nm_utils_ip4_address_clear_host_address() to header so it can be inlined
(cherry picked from commit b5a06dedd4)
2022-05-03 12:18:22 +02:00
Thomas Haller
04d982e278
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)
2022-05-03 12:18:20 +02:00
Thomas Haller
09832c5639
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)
2022-05-03 12:18:18 +02:00
Thomas Haller
57065cc50d
platform: guard logging statements with check whether logging is enabled
(cherry picked from commit 4fc25d523a)
2022-05-03 12:18:17 +02:00
Thomas Haller
3b56f33aa2
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)
2022-05-03 12:18:15 +02:00
Thomas Haller
14b920d3cf
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)
2022-05-03 12:18:13 +02:00
Thomas Haller
c21034f494
all: use "NM_UTILS_TO_STRING_BUFFER_SIZE" macro
(cherry picked from commit 02a8d21e4e)
2022-05-03 12:18:12 +02:00
Thomas Haller
e13c2426c8
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)
2022-05-03 12:18:11 +02:00
Thomas Haller
429540a6b7
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)
2022-05-03 12:18:10 +02:00
Thomas Haller
aa764f5fcc
platform: add nm_platform_ip_address_get() helper
(cherry picked from commit a815212214)
2022-05-03 12:18:09 +02:00
Thomas Haller
07c4b3ec71
platform: avoid duplicated code in _nmp_object_stackinit_from_type()
(cherry picked from commit 3bd5d2bca9)
2022-05-03 12:18:09 +02:00
Thomas Haller
e38dac5226
platform: rename local variable in nm_platform_ip_address_sync()
(cherry picked from commit 31299473cd)
2022-05-03 12:18:08 +02:00
Thomas Haller
1f05866821
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)
2022-05-03 12:18:08 +02:00
Thomas Haller
2e6d45cb4e
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)
2022-05-03 12:18:07 +02:00
Thomas Haller
e9d3ba66df
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)
2022-05-03 12:18:07 +02:00
Thomas Haller
d361bfc945
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)
2022-05-03 12:18:07 +02:00
Thomas Haller
032757a02d
trivial: fix code format
(cherry picked from commit 0ddc664526)
2022-05-03 10:28:52 +02:00
Thomas Haller
7dda0b94bc
platform: merge branch 'th/platform-address-sync-one-by-one'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1200
2022-05-03 10:01:06 +02:00
Thomas Haller
9b930cd962
platform: simplify loop for IPv6 addresses in nm_platform_ip_address_sync() 2022-05-03 09:45:33 +02:00
Thomas Haller
b52941ac34
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')
2022-05-03 09:45:32 +02:00
Thomas Haller
a6fd641634
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.
2022-05-03 09:45:32 +02:00
Beniamino Galvani
ee7240783a dhcp: merge branch 'bg/dhcp-lease-rundir'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1190
2022-05-03 09:14:06 +02:00
Beniamino Galvani
6ab5c4e578 core: save DHCP lease information in state file in /run
DHCP leases for a given interface are already exported on D-Bus
through DHCP4Config and DHCP6Config objects. It is useful to have the
same information also available on the filesystem so that it can be
easily used by scripts.

NM already saves some information about DHCP leases in /var, however
that directory can only be accessed by root, for good reasons.

Append lease options to the existing state file
/run/NetworkManager/devices/$ifindex. Contrary to /var this directory
is not persistent, but it seems more correct to expose the lease only
when it is active and not after it expired or after a reboot.

Since the file is in keyfile format, we add new [dhcp4] and [dhcp6]
sections; however, since some options have the same name for DHCPv4
and DHCPv6, we add a "dhcp4." or "dhcp6." prefix to make the parsing
by scripts (e.g. via "grep") easier.

The option name is the same we use on D-Bus. Since some DHCPv6 options
also have a "dhcp6_" prefix, the key name can contain "dhcp6" twice.

The new sections look like this:

  [dhcp4]
  dhcp4.broadcast_address=172.25.1.255
  dhcp4.dhcp_lease_time=120
  dhcp4.dhcp_server_identifier=172.25.1.4
  dhcp4.domain_name_servers=172.25.1.4
  dhcp4.domain_search=example.com
  dhcp4.expiry=1641214444
  dhcp4.ip_address=172.25.1.182
  dhcp4.next_server=172.25.1.4
  dhcp4.routers=172.25.1.4
  dhcp4.subnet_mask=255.255.255.0

  [dhcp6]
  dhcp6.dhcp6_name_servers=fd01::1
  dhcp6.dhcp6_ntp_servers=ntp.example.com
  dhcp6.ip6_address=fd01::1aa
2022-05-03 09:12:12 +02:00
Beniamino Galvani
96d8637ced core: add nm_dhcp_config_get_option_values()
Introduce a function to return an array of name-value tuples for DHCP
options.
2022-05-03 09:08:16 +02:00
Beniamino Galvani
15a4211303 dhcp: fix logging domain
Fix wrong domain when logging a lease:

  dhcp6 (veth0):   valid_lft 7200
  dhcp6 (veth0):   preferred_lft 5400
  dhcp6 (veth0):   address fd00:db8:db8::11:2233:4455
  dhcp (veth0):   domain search 'domain'
2022-05-03 09:07:29 +02:00
Beniamino Galvani
f20ac6bdc7 dhcp: improve logging for DHCPv6 merged leases
Instead of logging the event-id, which is composed from options that
are already visible in the log, it's more interesting to log that the
lease was merged.
2022-05-03 09:07:29 +02:00