summary refs log tree commit diff
path: root/src/platform
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2017-07-12 17:57:30 +0200
committerMichael Biebl <biebl@debian.org>2017-07-12 17:57:30 +0200
commitb9f0451fa35393ceedf6d9d20b78c43578ebea5d (patch)
tree417afcdd717020ad44e25fadee4b89de23316e83 /src/platform
parentc333f062ddcba9b35330647bf6cbd0a07f2d786e (diff)
New upstream version 1.8.2 upstream/1.8.2
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/nm-linux-platform.c20
-rw-r--r--src/platform/nm-platform.c26
-rw-r--r--src/platform/nm-platform.h2
-rw-r--r--src/platform/tests/test-common.c2
-rw-r--r--src/platform/tests/test-general.c2
5 files changed, 35 insertions, 17 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 252f054d..487725e4 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -1529,6 +1529,23 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
 	if (!obj->link.name[0])
 		goto errout;
 
+	if (!tb[IFLA_MTU]) {
+		/* Kernel has two places that send RTM_GETLINK messages:
+		 * net/core/rtnetlink.c and net/wireless/ext-core.c.
+		 * Unfotunatelly ext-core.c sets only IFLA_WIRELESS and
+		 * IFLA_IFNAME. This confuses code in this function, because
+		 * it cannot get complete set of data for the interface and
+		 * later incomplete object this function creates is used to
+		 * overwrite existing data in NM's cache.
+		 * Since ext-core.c doesn't set IFLA_MTU we can use it as a
+		 * signal to ignore incoming message.
+		 * To some extent this is a hack and correct approach is to
+		 * merge objects per-field.
+		 */
+		goto errout;
+	}
+	obj->link.mtu = nla_get_u32 (tb[IFLA_MTU]);
+
 	if (tb[IFLA_LINKINFO]) {
 		err = nla_parse_nested (li, IFLA_INFO_MAX, tb[IFLA_LINKINFO], policy_link_info);
 		if (err < 0)
@@ -1609,9 +1626,6 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
 		}
 	}
 
-	if (tb[IFLA_MTU])
-		obj->link.mtu = nla_get_u32 (tb[IFLA_MTU]);
-
 	switch (obj->link.type) {
 	case NM_LINK_TYPE_GRE:
 		lnk_data = _parse_lnk_gre (nl_info_kind, nl_info_data);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 767187d9..a244ff39 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -437,7 +437,8 @@ nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *pathid, int di
 
 static int
 _link_get_all_presort (gconstpointer  p_a,
-                       gconstpointer  p_b)
+                       gconstpointer  p_b,
+                       gpointer       sort_by_name)
 {
 	const NMPlatformLink *a = p_a;
 	const NMPlatformLink *b = p_b;
@@ -448,13 +449,16 @@ _link_get_all_presort (gconstpointer  p_a,
 	if (b->ifindex == 1)
 		return 1;
 
-	/* Initialized links first */
-	if (a->initialized > b->initialized)
-		return -1;
-	if (a->initialized < b->initialized)
-		return 1;
+	if (GPOINTER_TO_INT (sort_by_name)) {
+		/* Initialized links first */
+		if (a->initialized > b->initialized)
+			return -1;
+		if (a->initialized < b->initialized)
+			return 1;
 
-	return strcmp (a->name, b->name);
+		return strcmp (a->name, b->name);
+	} else
+		return a->ifindex - b->ifindex;
 }
 
 /**
@@ -465,7 +469,7 @@ _link_get_all_presort (gconstpointer  p_a,
  * owned by the caller and should be freed with g_array_unref().
  */
 GArray *
-nm_platform_link_get_all (NMPlatform *self)
+nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name)
 {
 	GArray *links, *result;
 	guint i, j, nresult;
@@ -479,9 +483,9 @@ nm_platform_link_get_all (NMPlatform *self)
 	if (!links || links->len == 0)
 		return links;
 
-	/* first sort the links by their ifindex. Below we will sort further by moving
-	 * children/slaves to the end. */
-	g_array_sort (links, _link_get_all_presort);
+	/* first sort the links by their ifindex or name. Below we will sort
+	 * further by moving children/slaves to the end. */
+	g_array_sort_with_data (links, _link_get_all_presort, GINT_TO_POINTER (sort_by_name));
 
 	unseen = g_hash_table_new (g_direct_hash, g_direct_equal);
 	for (i = 0; i < links->len; i++) {
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 43be17fa..1b8fa133 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -763,7 +763,7 @@ const NMPlatformLink *nm_platform_link_get (NMPlatform *self, int ifindex);
 const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname);
 const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);
 
-GArray *nm_platform_link_get_all (NMPlatform *self);
+GArray *nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name);
 NMPlatformError nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
 NMPlatformError nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
 NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 04db862d..a9d0694d 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -185,7 +185,7 @@ link_callback (NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink
 
 	/* Check the data */
 	g_assert (received->ifindex > 0);
-	links = nm_platform_link_get_all (NM_PLATFORM_GET);
+	links = nm_platform_link_get_all (NM_PLATFORM_GET, TRUE);
 	for (i = 0; i < links->len; i++) {
 		cached = &g_array_index (links, NMPlatformLink, i);
 		if (cached->ifindex == received->ifindex) {
diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c
index 2ccfac7d..e772662c 100644
--- a/src/platform/tests/test-general.c
+++ b/src/platform/tests/test-general.c
@@ -48,7 +48,7 @@ test_link_get_all (void)
 
 	platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
 
-	links = nm_platform_link_get_all (platform);
+	links = nm_platform_link_get_all (platform, TRUE);
 }
 
 /*****************************************************************************/