summary refs log tree commit diff
path: root/src/nm-ip6-config.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-04-12 17:33:05 +0200
committerMichael Biebl <biebl@debian.org>2016-04-12 17:33:05 +0200
commit288a08a3672a89a9bfdb8354b6863cc039759fc2 (patch)
tree351ac159de25507ba7eeab003153dabb1c6652a2 /src/nm-ip6-config.c
parent2bfb3eb7d0323e69affca154395f51d8b577414d (diff)
Imported Upstream version 1.1.94 upstream/1.1.94
Diffstat (limited to 'src/nm-ip6-config.c')
-rw-r--r--src/nm-ip6-config.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index 6d83bd53..8e7bd22c 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -95,24 +95,6 @@ nm_ip6_config_get_ifindex (const NMIP6Config *config)
 
 /******************************************************************/
 
-static gboolean
-same_prefix (const struct in6_addr *address1, const struct in6_addr *address2, int plen)
-{
-	const guint8 *bytes1 = (const guint8 *) address1;
-	const guint8 *bytes2 = (const guint8 *) address2;
-	int nbytes = plen / 8;
-	int nbits = plen % 8;
-	int masked1 = bytes1[nbytes] >> (8 - nbits);
-	int masked2 = bytes2[nbytes] >> (8 - nbits);
-
-	if (nbytes && memcmp (bytes1, bytes2, nbytes))
-		return FALSE;
-
-	return masked1 == masked2;
-}
-
-/******************************************************************/
-
 /**
  * nm_ip6_config_capture_resolv_conf():
  * @nameservers: array of struct in6_addr
@@ -472,6 +454,7 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu
 		memset (&address, 0, sizeof (address));
 		nm_ip_address_get_address_binary (s_addr, &address.address);
 		address.plen = nm_ip_address_get_prefix (s_addr);
+		nm_assert (address.plen <= 128);
 		address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT;
 		address.preferred = NM_PLATFORM_LIFETIME_PERMANENT;
 		address.source = NM_IP_CONFIG_SOURCE_USER;
@@ -488,7 +471,12 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu
 
 		memset (&route, 0, sizeof (route));
 		nm_ip_route_get_dest_binary (s_route, &route.network);
+
 		route.plen = nm_ip_route_get_prefix (s_route);
+		nm_assert (route.plen <= 128);
+		if (route.plen == 0)
+			continue;
+
 		nm_ip_route_get_next_hop_binary (s_route, &route.gateway);
 		if (nm_ip_route_get_metric (s_route) == -1)
 			route.metric = default_route_metric;
@@ -496,8 +484,6 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu
 			route.metric = nm_ip_route_get_metric (s_route);
 		route.source = NM_IP_CONFIG_SOURCE_USER;
 
-		g_assert (route.plen > 0);
-
 		nm_ip6_config_add_route (config, &route);
 	}
 
@@ -708,16 +694,20 @@ nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFl
 }
 
 gboolean
-nm_ip6_config_destination_is_direct (const NMIP6Config *config, const struct in6_addr *network, int plen)
+nm_ip6_config_destination_is_direct (const NMIP6Config *config, const struct in6_addr *network, guint8 plen)
 {
 	int num = nm_ip6_config_get_num_addresses (config);
 	int i;
 
+	nm_assert (network);
+	nm_assert (plen <= 128);
+
 	for (i = 0; i < num; i++) {
 		const NMPlatformIP6Address *item = nm_ip6_config_get_address (config, i);
 
-		if (item->plen <= plen && same_prefix (&item->address, network, item->plen) &&
-		    !(item->n_ifa_flags & IFA_F_NOPREFIXROUTE))
+		if (   item->plen <= plen
+		    && !NM_FLAGS_HAS (item->n_ifa_flags, IFA_F_NOPREFIXROUTE)
+		    && nm_utils_ip6_address_same_prefix (&item->address, network, item->plen))
 			return TRUE;
 	}
 
@@ -1415,7 +1405,7 @@ nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *new)
 	int i;
 
 	g_return_if_fail (new != NULL);
-	g_return_if_fail (new->plen > 0);
+	g_return_if_fail (new->plen > 0 && new->plen <= 128);
 	g_assert (priv->ifindex);
 
 	for (i = 0; i < priv->routes->len; i++ ) {
@@ -1473,7 +1463,6 @@ nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct
 {
 	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
 	guint i;
-	struct in6_addr network2, host2;
 	NMPlatformIP6Route *best_route = NULL;
 
 	g_return_val_if_fail (host && !IN6_IS_ADDR_UNSPECIFIED (host), NULL);
@@ -1487,10 +1476,7 @@ nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct
 		if (best_route && best_route->plen > item->plen)
 			continue;
 
-		nm_utils_ip6_address_clear_host_address (&host2, host, item->plen);
-		nm_utils_ip6_address_clear_host_address (&network2, &item->network, item->plen);
-
-		if (!IN6_ARE_ADDR_EQUAL (&network2, &host2))
+		if (!nm_utils_ip6_address_same_prefix (host, &item->network, item->plen))
 			continue;
 
 		if (best_route &&