From 05a82a948877c62fb624c3b681fa95c9f26c26e4 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 19 Nov 2013 22:51:29 -0600 Subject: [PATCH 3/3] core: don't leave additional default routes in captured IP config There can be multiple defualt routes for an interface with different metrics. Only accept the first one, otherwise the rest get left in the IPv4 config and could be applied at random times. --- src/nm-ip4-config.c | 4 ++-- src/nm-ip6-config.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index e27a557..aa4bfd5 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -147,21 +147,21 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) priv->routes = nm_platform_ip4_route_get_all (ifindex, TRUE); /* Extract gateway from default route */ for (i = 0; i < priv->routes->len; i++) { const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i); if (route->network == 0) { - if (priv->gateway != route->gateway) { + if (!gateway_changed && (priv->gateway != route->gateway)) { priv->gateway = route->gateway; gateway_changed = TRUE; } /* Remove the default route from the list */ g_array_remove_index (priv->routes, i); - break; + i--; } } /* If the interface has the default route, and has IPv4 addresses, capture * nameservers from /etc/resolv.conf. */ if (priv->addresses->len && priv->gateway && capture_resolv_conf) { diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 726e658..08ac43a 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -147,21 +147,21 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf) priv->routes = nm_platform_ip6_route_get_all (ifindex, TRUE); /* Extract gateway from default route */ for (i = 0; i < priv->routes->len; i++) { const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i); if (IN6_IS_ADDR_UNSPECIFIED (&route->network)) { - if (!IN6_ARE_ADDR_EQUAL (&priv->gateway, &route->gateway)) { + if (!gateway_changed && !IN6_ARE_ADDR_EQUAL (&priv->gateway, &route->gateway)) { priv->gateway = route->gateway; gateway_changed = TRUE; } /* Remove the default route from the list */ g_array_remove_index (priv->routes, i); - break; + i--; } } /* If the interface has the default route, and has IPv4 addresses, capture * nameservers from /etc/resolv.conf. */ if (priv->addresses->len && !IN6_IS_ADDR_UNSPECIFIED (&priv->gateway) && capture_resolv_conf) { -- 1.8.3.1