summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-06-13 14:44:22 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2017-06-13 14:52:00 +0200
commitb1da7a8285b4ea3bf08c00e9acf33db809bbaf79 (patch)
treeaf1492b006b2c34710f0604b21920ac9b64d90a3
parent73e664e3b15e47b20dcdc92d4cde7f8492069f17 (diff)
downloadNetworkManager-bg/rh1459813.tar.gz
core: sort addresses in captured IPv4 configurationbg/rh1459813
When IPv4 addresses are synchronized to platform, the order of IPv4 addresses matters because the first address is considered the primary one. Thus, nm_ip4_config_capture() should put the primary address as first, otherwise during synchronization addresses will be removed and added back with a different primary/secondary role.
-rw-r--r--src/nm-ip4-config.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 20532e8607..ae6af9c350 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -248,6 +248,16 @@ notify_addresses (NMIP4Config *self)
_notify (self, PROP_ADDRESSES);
}
+static gint
+sort_captured_addresses (gconstpointer a, gconstpointer b)
+{
+ const NMPlatformIP4Address *addr_a = a, *addr_b = b;
+
+ /* Primary addresses first */
+ return NM_FLAGS_HAS (addr_a->n_ifa_flags, IFA_F_SECONDARY) -
+ NM_FLAGS_HAS (addr_b->n_ifa_flags, IFA_F_SECONDARY);
+}
+
NMIP4Config *
nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf)
{
@@ -269,6 +279,8 @@ nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resol
g_array_unref (priv->routes);
priv->addresses = nm_platform_ip4_address_get_all (platform, ifindex);
+ g_array_sort (priv->addresses, sort_captured_addresses);
+
priv->routes = nm_platform_ip4_route_get_all (platform, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT);
/* Extract gateway from default route */