about summary refs log tree commit diff
path: root/src/platform/nm-platform.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-06-04 00:08:31 +0200
committerMichael Biebl <biebl@debian.org>2018-06-04 00:08:31 +0200
commit0dd9df69fdbd475c48a0c8d5b0a1882550fe7321 (patch)
tree249cf25643b1fe408e10679bb61613bc6540e894 /src/platform/nm-platform.c
parent2e94a3b93171ab3fb95bf689aab1664d23988809 (diff)
parent04bc9e1cd3544445d883ad29ea108c1645c8e7b7 (diff)
Update upstream source from tag 'upstream/1.11.4'
Update to upstream version '1.11.4'
with Debian dir d0638aa2e32d5bae4e8daa021b9a66b7c4d6647e
Diffstat (limited to 'src/platform/nm-platform.c')
-rw-r--r--src/platform/nm-platform.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 84d862d2..1a94ce28 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -2396,7 +2396,6 @@ nm_platform_link_infiniband_delete (NMPlatform *self,
 	return _infiniband_add_add_or_delete (self, parent, p_key, FALSE, NULL);
 }
 
-
 gboolean
 nm_platform_link_infiniband_get_properties (NMPlatform *self,
                                             int ifindex,
@@ -3596,6 +3595,25 @@ delete_and_next2:
 	return TRUE;
 }
 
+static guint
+ip6_address_scope_priority (const struct in6_addr *addr)
+{
+	if (IN6_IS_ADDR_LINKLOCAL (addr))
+		return 1;
+	if (IN6_IS_ADDR_SITELOCAL (addr))
+		return 2;
+	return 3;
+}
+
+static gint
+ip6_address_scope_cmp (gconstpointer a, gconstpointer b)
+{
+	const NMPlatformIP6Address *x = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) a);
+	const NMPlatformIP6Address *y = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) b);
+
+	return ip6_address_scope_priority (&x->address) - ip6_address_scope_priority (&y->address);
+}
+
 /**
  * nm_platform_ip6_address_sync:
  * @self: platform instance
@@ -3629,6 +3647,13 @@ nm_platform_ip6_address_sync (NMPlatform *self,
 	NMPLookup lookup;
 	guint32 ifa_flags;
 
+	/* The order we want to enforce is only among addresses with the same
+	 * scope, as the kernel keeps addresses sorted by scope. Therefore,
+	 * 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);
+
 	if (!_addr_array_clean_expired (AF_INET6, ifindex, known_addresses, now, &known_addresses_idx))
 		known_addresses = NULL;
 
@@ -4019,6 +4044,7 @@ sync_route_add:
 						nmp_object_stackinit (&oo,
 						                      NMP_OBJECT_TYPE_IP4_ROUTE,
 						                      &((NMPlatformIP4Route) {
+						                          .ifindex = r->ifindex,
 						                          .network = r->gateway,
 						                          .plen = 32,
 						                          .metric = r->metric,
@@ -4031,6 +4057,7 @@ sync_route_add:
 						nmp_object_stackinit (&oo,
 						                      NMP_OBJECT_TYPE_IP6_ROUTE,
 						                      &((NMPlatformIP6Route) {
+						                          .ifindex = r->ifindex,
 						                          .network = r->gateway,
 						                          .plen = 128,
 						                          .metric = r->metric,
@@ -4651,7 +4678,6 @@ nm_platform_qdisc_sync (NMPlatform *self,
 	                                                                ifindex),
 	                                        NULL, NULL);
 
-
 	if (plat_qdiscs) {
 		for (i = 0; i < plat_qdiscs->len; i++) {
 			const NMPObject *q = g_ptr_array_index (plat_qdiscs, i);
@@ -4717,7 +4743,6 @@ nm_platform_tfilter_sync (NMPlatform *self,
 	                                                                  ifindex),
 	                                          NULL, NULL);
 
-
 	if (plat_tfilters) {
 		for (i = 0; i < plat_tfilters->len; i++) {
 			const NMPObject *q = g_ptr_array_index (plat_tfilters, i);
@@ -4786,7 +4811,6 @@ _lifetime_to_string (guint32 timestamp, guint32 lifetime, gint32 now, char *buf,
 	return buf;
 }
 
-
 static const char *
 _lifetime_summary_to_string (gint32 now, guint32 timestamp, guint32 preferred, guint32 lifetime, char *buf, size_t buf_size)
 {
@@ -4884,11 +4908,11 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
 	            link->inet6_addr_gen_mode_inv ? " addrgenmode " : "",
 	            link->inet6_addr_gen_mode_inv ? nm_platform_link_inet6_addrgenmode2str (_nm_platform_uint8_inv (link->inet6_addr_gen_mode_inv), str_addrmode, sizeof (str_addrmode)) : "",
 	            str_addr ? " addr " : "",
-	            str_addr ? str_addr : "",
+	            str_addr ?: "",
 	            link->inet6_token.id ? " inet6token " : "",
 	            link->inet6_token.id ? nm_utils_inet6_interface_identifier_to_token (link->inet6_token, str_inet6_token) : "",
 	            link->driver ? " driver " : "",
-	            link->driver ? link->driver : "",
+	            link->driver ?: "",
 	            link->rx_packets, link->rx_bytes,
 	            link->tx_packets, link->tx_bytes);
 	g_string_free (str_flags, TRUE);
@@ -5300,7 +5324,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu
 		str_label[0] = 0;
 
 	str_lft_p = _lifetime_to_string (address->timestamp,
-	                                 address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
+	                                 address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT,
 	                                 now, str_lft, sizeof (str_lft)),
 	str_pref_p = (address->lifetime == address->preferred)
 	             ? str_lft_p
@@ -5312,7 +5336,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu
 	g_snprintf (buf, len,
 	            "%s/%d lft %s pref %s%s%s%s%s%s src %s",
 	            s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
-	            str_peer ? str_peer : "",
+	            str_peer ?: "",
 	            str_dev,
 	            _to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
 	            str_label,
@@ -5407,7 +5431,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu
 	_to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev));
 
 	str_lft_p = _lifetime_to_string (address->timestamp,
-	                                 address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
+	                                 address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT,
 	                                 now, str_lft, sizeof (str_lft)),
 	str_pref_p = (address->lifetime == address->preferred)
 	             ? str_lft_p
@@ -5419,7 +5443,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu
 	g_snprintf (buf, len,
 	            "%s/%d lft %s pref %s%s%s%s%s src %s",
 	            s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
-	            str_peer ? str_peer : "",
+	            str_peer ?: "",
 	            str_dev,
 	            _to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
 	            nmp_utils_ip_config_source_to_string (address->addr_source, s_source, sizeof (s_source)));
@@ -5492,7 +5516,6 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsi
 
 	_to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev));
 
-
 	g_snprintf (buf, len,
 	            "%s" /* table */
 	            "%s/%d"