summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2016-11-18 11:53:06 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2016-11-18 11:56:36 +0100
commitfc95811b93ae15bc86febe34e6431f77ec60842f (patch)
tree5338cf42ebe4ce93517024eb06b59b12121ef04e
parent09cec798a80a67e24fc7b745985dbd7b62bac517 (diff)
downloadNetworkManager-bg/ipv4-order-rh1394500.tar.gz
fixup! platform: fix the order of addition of primary and secondary IPv4 addressesbg/ipv4-order-rh1394500
-rw-r--r--src/platform/nm-platform.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index e23744c1e0..01d30ed42c 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -2712,6 +2712,23 @@ _ptr_inside_ip4_addr_array (const GArray *array, gconstpointer needle)
&& needle < (gconstpointer) &g_array_index (array, const NMPlatformIP4Address, array->len);
}
+static void
+ip4_addr_subnets_destroy_index (GHashTable *ht, const GArray *addresses)
+{
+ GHashTableIter iter;
+ gpointer p;
+
+ g_hash_table_iter_init (&iter, ht);
+
+ while (g_hash_table_iter_next (&iter, NULL, &p)) {
+ if (!_ptr_inside_ip4_addr_array (addresses, p)) {
+ g_ptr_array_free ((GPtrArray *) p, TRUE);
+ }
+ }
+
+ g_hash_table_unref (ht);
+}
+
static GHashTable *
ip4_addr_subnets_build_index (const GArray *addresses, gboolean consider_flags)
{
@@ -2729,7 +2746,7 @@ ip4_addr_subnets_build_index (const GArray *addresses, gboolean consider_flags)
subnets = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
- (GDestroyNotify) g_ptr_array_unref);
+ NULL);
/* Build a hash table of all addresses per subnet */
for (i = 0; i < addresses->len; i++) {
@@ -2770,12 +2787,12 @@ ip4_addr_subnets_is_secondary (const NMPlatformIP4Address *address, GHashTable *
if (!_ptr_inside_ip4_addr_array (addresses, p)) {
addr_list = p;
if (addr_list->pdata[0] != address) {
- *out_addr_list = addr_list;
+ NM_SET_OUT (out_addr_list, addr_list);
return TRUE;
}
} else
nm_assert ((gconstpointer) address == p);
- *out_addr_list = NULL;
+ NM_SET_OUT (out_addr_list, NULL);
return FALSE;
}
@@ -2802,8 +2819,8 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
NMPlatformIP4Address *address;
const NMPlatformIP4Address *known_address;
gint32 now = nm_utils_get_monotonic_timestamp_s ();
- gs_unref_hashtable GHashTable *plat_subnets = NULL;
- gs_unref_hashtable GHashTable *known_subnets = NULL;
+ GHashTable *plat_subnets;
+ GHashTable *known_subnets;
GPtrArray *ptr;
int i, j;
@@ -2857,6 +2874,7 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
}
}
}
+ ip4_addr_subnets_destroy_index (plat_subnets, addresses);
g_array_free (addresses, TRUE);
if (out_added_addresses)
@@ -2877,8 +2895,10 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen,
known_address->peer_address, lifetime, preferred,
- 0, known_address->label))
+ 0, known_address->label)) {
+ ip4_addr_subnets_destroy_index (known_subnets, known_addresses);
return FALSE;
+ }
if (out_added_addresses) {
if (!*out_added_addresses)
@@ -2887,6 +2907,8 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
}
}
+ ip4_addr_subnets_destroy_index (known_subnets, known_addresses);
+
return TRUE;
}