Commit graph

30163 commits

Author SHA1 Message Date
Thomas Haller
1b9dfd3001
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)
2022-05-09 19:27:07 +02:00
Thomas Haller
3bd210a8f1
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)
2022-05-09 19:27:06 +02:00
Thomas Haller
281b3e6473
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)
2022-05-09 19:27:06 +02:00
Beniamino Galvani
b596ad1058 device: commit l3cfg on link change only when the device is activating
On link change, the configuration should be reapplied only when the
device is activating.

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

https://bugzilla.redhat.com/show_bug.cgi?id=2079054
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1216
(cherry picked from commit 77c8b2960a)
2022-05-09 15:01:09 +02:00
Beniamino Galvani
e056a68d21
n-dhcp4/probe: forget lease after a NAK
If we have a lease and we get a NAK renewing/rebinding it, the lease
is lost.

Without this, probe->current_lease remains set and after the next
DISCOVER/OFFER round, any call to n_dhcp4_client_lease_select() will
fail at:

        if (lease->probe->current_lease)
                return -ENOTRECOVERABLE;

As in:

 [5325.1313] dhcp4 (veth0): send REQUEST of 172.25.1.200 to 255.255.255.255
 [5325.1434] dhcp4 (veth0): received NACK from 172.25.1.1
 [5325.1435] dhcp4 (veth0): client event 3 (RETRACTED)
 [5325.1436] dhcp4 (veth0): send DISCOVER to 255.255.255.255
 [5325.1641] dhcp4 (veth0): received OFFER of 172.25.1.200 from 172.25.1.1
 [5325.1641] dhcp4 (veth0): client event (OFFER)
 [5325.1641] dhcp4 (veth0): selecting lease failed: -131 (ENOTRECOVERABLE)

Upstream: https://github.com/nettools/n-dhcp4/pull/33
Upstream: e4af93228e

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

Fixes: e43b1791a3 ('Merge commit 'e23b3c9c3ac86b065eef002fa5c4321cc4a87df2' as 'shared/n-dhcp4'')

(cherry picked from commit e141cd45d6)
2022-05-06 13:54:19 +02:00
Thomas Haller
341bf7dedf
cloud-setup: merge branch 'th/cloud-setup-aliyun-primary-ip'
https://bugzilla.redhat.com/show_bug.cgi?id=2079849

(cherry picked from commit ebe8a9b292)
2022-05-05 08:37:30 +02:00
Thomas Haller
a1d9fce147
cloud-setup: only pass config-iface-data as user-data for async functions
From config_iface_data->get_config_data we have access to the other pointer
already. No need to allocate a user data.

(cherry picked from commit 7d71aff247)
2022-05-05 08:37:29 +02:00
Thomas Haller
16ba58cfb1
cloud-setup: use union for NMCSProviderGetConfigIfaceData.priv
Use a union, it makes more sense.

Note that with union, C's struct initialization might not sufficiently
set all fields to the default. In practice yes, but theoretically in C
a NULL pointer and floats must not have all zero bits, so the following
is not guaranteed to work:

    struct {
        int some_field;
        union {
             void *v_ptr;
             int v_int;
        };
    } variable = {
        .some_field = 24,
    };

    assert(variable.union.v_ptr == 0);
    assert(variable.union.v_int == 0);

When initializing the variable, we should not rely on automatically
initialize all union members correctly. It cannot at the same time
set NULL pointers and zero integers -- well, on our architectures it
probably can, but not as far as guaranteed by C language.
We need to know which union field we are going to use and initialize
it explicitly.
As we know the provider type, we can do that.

Also, maybe in the future we need special free/unref calls when
destroying the type specific data in NMCSProviderGetConfigIfaceData.
As we know the provider, we can.

Note that having type specific data in NMCSProviderGetConfigIfaceData.priv
is a layering violation. But it is still simpler than implementing
type specific handlers (callbacks) or tracking the data somewhere else.
After all, we know at compile time all the existing provider types.

(cherry picked from commit 1e696c7e93)
2022-05-05 08:37:29 +02:00
Thomas Haller
061c05ca39
cloud-setup: track config-task-data in iface-data
Let NMCSProviderGetConfigIfaceData.get_config_data have a pointer to the
NMCSProviderGetConfigTaskData. This will allow two things:

- at several places we pass on `nm_utils_user_data_pack(get_config_data,
  config_iface_data)` as user data. We can avoid that, by just letting
  config_iface_data have a pointer to get_config_data.

- NMCSProviderGetConfigIfaceData contains a provider specific field
  "priv". That may also require special initialization or destruction,
  depending on the type. We thus need access to the provider type,
  which we have via iface_data->get_config_data->self.

Also let NMCSProviderGetConfigTaskData have a pointer "self" to the
NMCSProvider. While there was already the "task", which contains the
provider as source-object, this is more convenient.

(cherry picked from commit 069946cda1)
2022-05-05 08:37:29 +02:00
Thomas Haller
3a9ec3c5a3
cloud-setup: reorder addresses to honor "primary_ip_address"
The order of IPv4 addresses matters, in particular if they are in
the same subnet. Kernel will mark all but the first one as "secondary".
In NetworkManager's ipv4.addresses, the first address is the primary.

It seems that on aliyun cloud, "private-ipv4s" URL may give the
addresses in arbitrary order. The primary can be fetched from
"primary-ip-address".

Fix that by also fetching "primary-ip-address". Then, resort the array
so that the primary is the first one in the list.

https://bugzilla.redhat.com/show_bug.cgi?id=2079849
(cherry picked from commit 191baf84e2)
2022-05-05 08:37:29 +02:00
Thomas Haller
a845a3425f
release: bump version to 1.37.92 (1.38-rc3) (development) 2022-05-04 14:33:32 +02:00
Yi Zhao
5c3d538d6d
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
(cherry picked from commit 53952446a7)
2022-05-04 09:07:46 +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
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
Fernando Fernandez Mancera
a494c00901 l3cfg: drop NM_L3_CFG_COMMIT_TYPE_ASSUME and assume_config_once
ASSUME is causing more troubles than benefits it provides. This patch is
dropping NM_L3_CFG_COMMIT_TYPE_ASSUME and assume_config_once. NM3LCfg
will commit as if the sys-iface-state is MANAGED.

This patch is part of the effort to remove ASSUME from NetworkManager.
After ASSUME is dropped when starting NetworkManager it will take full
control of the interface, re-configuring it. The interface will be
managed from the start instead of assumed and then managed.

This will solve the situations where an interface is half-up and then a
restart happens. When NetworkManager is back it won't add the missing
addresses (which is what assume does) so the interface will fail during
the activation and will require a full activation.

https://bugzilla.redhat.com/show_bug.cgi?id=2050216
https://bugzilla.redhat.com/show_bug.cgi?id=2077605
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1196
(cherry picked from commit bf5927b978)
2022-04-28 12:03:46 +02:00
Thomas Haller
ea6625ce97 platform: add semantic comparison for IP addresses and add "nm_platform_vtable_address"
We already have a comparison of NMPlatformIPXAddress with the modes
"full" and "id". The former is needed to fully compare two addresses,
the latter as identity for tracking addresses in the cache.

In NetworkManager we also use the NMPlatformIP[46]Address structure to
track the addresses we want to configure. When we add them in kernel,
we will later see them in the platform cache. However, some fields
will be slightly different. For example, "addr_source" address will
always be "kernel", because that one is not a field we configure in
kernel. Also, the "n_ifa_flags" probably differ (getting "permanent"
and "secondary" flags).

Add a compare function that can ignore such differences.

Also add nm_platform_vtable_address for accessing the IPv4 and IPv6
methods generically (based on an "IS_IPv4" variable).

(cherry picked from commit ef1b60c061)
2022-04-28 12:03:41 +02:00
Thomas Haller
3a98ecfa0e platform: make NMPlatformVTableAddress struct smaller and pack NMPObjectType
(cherry picked from commit 7c92663f8d)
2022-04-28 12:03:35 +02:00
Thomas Haller
9e40474c71 platform: make "now" timestamp an in/out parameter to nmp_utils_lifetime_get()
nmp_utils_lifetime_get() calculates the lifetime of addresses,
and it bases the result on a "now" timestamp.

If you have two addresses and calculate their expiry, then we want to
base it on top of the same "now" timestamp, meaning, we should
only call nm_utils_get_monotonic_timestamp_sec() once. This is also a
performance optimization. But much more importantly, when we make a
comparison at a certain moment, we need that all sides have the same
understanding of the current timestamp.

But nmp_utils_lifetime_get() does not always require the now timestamp.
And the caller doesn't know, whether it will need it (short of knowing
how nmp_utils_lifetime_get() is implemented). So, make the now parameter
an in/out argument. If we pass in an already valid now timestamp, use
that. Otherwise, fetch the current time and also return it.

(cherry picked from commit deb37401e9)
2022-04-28 12:03:30 +02:00
Thomas Haller
66237888e7 glib-aux: add nm_utils_get_monotonic_timestamp_sec_cached() helper
(cherry picked from commit 3f4586532f)
2022-04-28 12:03:25 +02:00