summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-03-18 18:03:03 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2020-03-25 16:31:50 +0100
commit73a71fb9b7e2bc728cf676ee54ac7f95d2e6fb43 (patch)
tree2c71fb7a9a16c958feb107397deb46549da503c3
parent74b9a9bf999198860e7027cfe22f299365b0b654 (diff)
downloadNetworkManager-73a71fb9b7e2bc728cf676ee54ac7f95d2e6fb43.tar.gz
platform: sort IPv6 addresses from platform during sync
There is no guarantee that addresses returned from the cache are in scope-priority order. Sort them.
-rw-r--r--src/platform/nm-platform.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 699c8902fa..c19a6e2da5 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3842,12 +3842,15 @@ ip6_address_scope_priority (const struct in6_addr *addr)
}
static int
-ip6_address_scope_cmp (gconstpointer a, gconstpointer b)
+ip6_address_scope_cmp (gconstpointer a, gconstpointer b, gpointer increasing)
{
const NMPlatformIP6Address *x = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) a);
const NMPlatformIP6Address *y = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) b);
+ int ret;
- return ip6_address_scope_priority (&x->address) - ip6_address_scope_priority (&y->address);
+ ret = ip6_address_scope_priority (&x->address) - ip6_address_scope_priority (&y->address);
+
+ return GPOINTER_TO_INT (increasing) ? ret : -ret;
}
/**
@@ -3888,7 +3891,7 @@ nm_platform_ip6_address_sync (NMPlatform *self,
* apply the same sorting to known addresses, so that we don't try to
* unnecessary change the order of addresses with different scopes. */
if (known_addresses)
- g_ptr_array_sort (known_addresses, ip6_address_scope_cmp);
+ g_ptr_array_sort_with_data (known_addresses, ip6_address_scope_cmp, GINT_TO_POINTER (TRUE));
if (!_addr_array_clean_expired (AF_INET6, ifindex, known_addresses, now, &known_addresses_idx))
known_addresses = NULL;
@@ -3904,6 +3907,8 @@ nm_platform_ip6_address_sync (NMPlatform *self,
if (plat_addresses) {
guint known_addresses_len;
+ g_ptr_array_sort_with_data (plat_addresses, ip6_address_scope_cmp, GINT_TO_POINTER (FALSE));
+
known_addresses_len = known_addresses ? known_addresses->len : 0;
/* First, compare every address whether it is still a "known address", that is, whether