From 75faf5bb77706267feb0438803c2b318130c9916 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 16 Mar 2017 13:55:14 +0000 Subject: [PATCH] route-manager: add routine to query route shadowing for a link If a route is shadowed by another route to the same network it's a good indication we're multihoming and want to disable the Strict RP filtering. --- src/nm-route-manager.c | 27 +++++++++++++++++++++++++++ src/nm-route-manager.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index a8778e2a7d..13cb032724 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -967,6 +967,33 @@ nm_route_manager_route_flush (NMRouteManager *self, int ifindex) return success; } +/** + * nm_route_manager_ip4_routes_shadowed: + * @ifindex: Interface index + * + * Returns: %TRUE if some other link has a route to the same destination + * with a lower metric. + */ +gboolean +nm_route_manager_ip4_routes_shadowed (NMRouteManager *self, int ifindex) +{ + NMRouteManagerPrivate *priv = NM_ROUTE_MANAGER_GET_PRIVATE (self); + RouteIndex *index = priv->ip4_routes.index; + const NMPlatformIP4Route *route; + guint i; + + for (i = 1; i < index->len; i++) { + route = (const NMPlatformIP4Route *) index->entries[i]; + + if (route->ifindex != ifindex) + continue; + if (_v4_route_dest_cmp (route, (const NMPlatformIP4Route *) index->entries[i - 1]) == 0) + return TRUE; + } + + return FALSE; +} + /*****************************************************************************/ static gboolean diff --git a/src/nm-route-manager.h b/src/nm-route-manager.h index d12f025603..181d794ee5 100644 --- a/src/nm-route-manager.h +++ b/src/nm-route-manager.h @@ -38,6 +38,7 @@ gboolean nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, con gboolean nm_route_manager_ip6_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes, gboolean full_sync); gboolean nm_route_manager_route_flush (NMRouteManager *self, int ifindex); +gboolean nm_route_manager_ip4_routes_shadowed (NMRouteManager *self, int ifindex); void nm_route_manager_ip4_route_register_device_route_purge_list (NMRouteManager *self, GArray *device_route_purge_list); NMRouteManager *nm_route_manager_get (void);