From 4fba2260f3e14a13f37499bd46ffcb220fdc5a4c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 2 Dec 2013 16:24:06 -0600 Subject: [PATCH] core: ignore gateway host route during connection generation When a gateway is not in the prefix of any of the interface's IP addresses, NetworkManager adds a static host route to the gateway through the interface to ensure the gateway can be reached. That route will not be part of the persistent connection (since it was added automatically) but would normally be picked up by connection generation. This would cause the generated connection not to match with the persistent connection, because the persistent connection does not have the host route. Ignore the gateway host route when capturing the interface's existing IP configuration. --- src/nm-ip4-config.c | 16 ++++++++++++++++ src/nm-ip6-config.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 640a1e1bfe..f7c3e07466 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -210,6 +210,22 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) } } + /* If there is a host route to the gateway, ignore that route. It is + * automatically added by NetworkManager when needed. + */ + if (has_gateway) { + for (i = 0; i < priv->routes->len; i++) { + const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i); + + if ( (route->plen == 32) + && (route->network == priv->gateway) + && (route->gateway == 0)) { + g_array_remove_index (priv->routes, i); + i--; + } + } + } + /* If the interface has the default route, and has IPv4 addresses, capture * nameservers from /etc/resolv.conf. */ diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 6319dbf316..083f215810 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -212,6 +212,22 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf) } } + /* If there is a host route to the gateway, ignore that route. It is + * automatically added by NetworkManager when needed. + */ + if (has_gateway) { + for (i = 0; i < priv->routes->len; i++) { + const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i); + + if ( route->plen == 128 + && IN6_ARE_ADDR_EQUAL (&route->network, &priv->gateway) + && IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) { + g_array_remove_index (priv->routes, i); + i--; + } + } + } + /* If the interface has the default route, and has IPv4 addresses, capture * nameservers from /etc/resolv.conf. */