diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-07-31 17:28:08 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-08-29 10:46:49 +0200 |
commit | bc9269ffcb8d44d6fb54c9c1d7c5fa5637d04bac (patch) | |
tree | 3e5993e970f8e7a8c345851d487697e696ed9ed2 | |
parent | fb5834c3c1e4bcdf9003b50382f920959a8447b4 (diff) | |
download | NetworkManager-bc9269ffcb8d44d6fb54c9c1d7c5fa5637d04bac.tar.gz |
default-route: skip addition when the route already exists
Re-adding the default route has side-effects, as it also prunes the
cloned routes from the kernel FIB.
https://bugzilla.redhat.com/show_bug.cgi?id=1470930
(cherry picked from commit bea6d05c1d3a92a14fd62267584e99b15f88687d)
-rw-r--r-- | src/nm-default-route-manager.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index 9ac6d552c0..1ab8f02d61 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -28,6 +28,7 @@ #include "devices/nm-device.h" #include "vpn/nm-vpn-connection.h" #include "platform/nm-platform.h" +#include "platform/nm-platform-utils.h" #include "nm-manager.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" @@ -266,6 +267,8 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g { NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self); GPtrArray *entries = vtable->get_entries (priv); + char buf1[sizeof (_nm_utils_to_string_buffer)]; + char buf2[sizeof (_nm_utils_to_string_buffer)]; guint i; Entry *entry_unsynced = NULL; Entry *entry = NULL; @@ -304,21 +307,64 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g if (vtable->vt->is_ip4) { NMPlatformIP4Route rt = entry->route.r4; + const NMPlatformIP4Route *plat_rt; rt.network = 0; rt.plen = 0; rt.metric = entry->effective_metric; + rt.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (rt.rt_source); + + plat_rt = nm_platform_ip4_route_get (priv->platform, + entry->route.r4.ifindex, + 0, + 0, + entry->effective_metric); + if (plat_rt && nm_platform_ip4_route_cmp (plat_rt, &rt) == 0) { + _LOGt (AF_INET, "already exists: %s", + nm_platform_ip4_route_to_string (&rt, NULL, 0)); + return FALSE; + } + + rt.rt_source = entry->route.r4.rt_source; + + if (plat_rt) { + _LOGt (AF_INET, "update platform route: %s; with route: %s", + nm_platform_ip4_route_to_string (plat_rt, buf1, sizeof (buf1)), + nm_platform_ip4_route_to_string (&rt, buf2, sizeof (buf2))); + } success = nm_platform_ip4_route_add (priv->platform, &rt); } else { NMPlatformIP6Route rt = entry->route.r6; + const NMPlatformIP6Route *plat_rt; rt.network = in6addr_any; rt.plen = 0; rt.metric = entry->effective_metric; + rt.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (rt.rt_source); + + plat_rt = nm_platform_ip6_route_get (priv->platform, + entry->route.r6.ifindex, + in6addr_any, + 0, + entry->effective_metric); + if (plat_rt && nm_platform_ip6_route_cmp (plat_rt, &rt) == 0) { + _LOGt (AF_INET6, "already exists: %s", + nm_platform_ip6_route_to_string (&rt, NULL, 0)); + return FALSE; + } + + rt.rt_source = entry->route.r6.rt_source; + + if (plat_rt) { + _LOGt (AF_INET, "update platform route: %s; with route: %s", + nm_platform_ip6_route_to_string (plat_rt, buf1, sizeof (buf1)), + nm_platform_ip6_route_to_string (&rt, buf2, sizeof (buf2))); + } success = nm_platform_ip6_route_add (priv->platform, &rt); } + if (!success) { _LOGW (vtable->vt->addr_family, "failed to add default route %s with effective metric %u", vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) entry->effective_metric); |