From 8532b83f46fac73d3a19c7b77a68de8fb237fdff Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 24 Jun 2015 11:21:43 +0200 Subject: [PATCH] route-manager: add argument @ignore_kernel_routes to route_sync() Will be used later, no behavioral change yet. (cherry picked from commit 347555795f405263fb117b0472ca916f0b79b486) --- src/nm-ip4-config.c | 2 +- src/nm-ip6-config.c | 2 +- src/nm-route-manager.c | 21 +++++++++++++-------- src/nm-route-manager.h | 4 ++-- src/tests/test-route-manager.c | 12 ++++++------ 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 0efc30babe..e5fd25df06 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -284,7 +284,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, guint32 default_ro g_array_append_vals (routes, route, 1); } - success = nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes); + success = nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_unref (routes); if (!success) return FALSE; diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 65cd711bc6..2f3dc3f487 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -398,7 +398,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex) g_array_append_vals (routes, route, 1); } - success = nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes); + success = nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_unref (routes); } diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index ac8ded374a..5986196fc5 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -345,7 +345,7 @@ _sort_indexes_cmp (guint *a, guint *b) /*********************************************************************************************/ static gboolean -_vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const GArray *known_routes) +_vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes) { NMRouteManagerPrivate *priv = NM_ROUTE_MANAGER_GET_PRIVATE (self); GArray *plat_routes; @@ -362,7 +362,10 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const nm_platform_process_events (priv->platform); ipx_routes = vtable->vt->is_ip4 ? &priv->ip4_routes : &priv->ip6_routes; - plat_routes = vtable->vt->route_get_all (priv->platform, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT); + plat_routes = vtable->vt->route_get_all (priv->platform, ifindex, + ignore_kernel_routes + ? NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT + : NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_RTPROT_KERNEL); plat_routes_idx = _route_index_create (vtable, plat_routes); known_routes_idx = _route_index_create (vtable, known_routes); @@ -590,6 +593,7 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const * nm_route_manager_ip4_route_sync: * @ifindex: Interface index * @known_routes: List of routes + * @ignore_kernel_routes: if %TRUE, ignore kernel routes. * * A convenience function to synchronize routes for a specific interface * with the least possible disturbance. It simply removes routes that are @@ -600,15 +604,16 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const * Returns: %TRUE on success. */ gboolean -nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes) +nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes) { - return _vx_route_sync (&vtable_v4, self, ifindex, known_routes); + return _vx_route_sync (&vtable_v4, self, ifindex, known_routes, ignore_kernel_routes); } /** * nm_route_manager_ip6_route_sync: * @ifindex: Interface index * @known_routes: List of routes + * @ignore_kernel_routes: if %TRUE, ignore kernel routes. * * A convenience function to synchronize routes for a specific interface * with the least possible disturbance. It simply removes routes that are @@ -619,16 +624,16 @@ nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, const GArray * Returns: %TRUE on success. */ gboolean -nm_route_manager_ip6_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes) +nm_route_manager_ip6_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes) { - return _vx_route_sync (&vtable_v6, self, ifindex, known_routes); + return _vx_route_sync (&vtable_v6, self, ifindex, known_routes, ignore_kernel_routes); } gboolean nm_route_manager_route_flush (NMRouteManager *self, int ifindex) { - return nm_route_manager_ip4_route_sync (self, ifindex, NULL) - && nm_route_manager_ip6_route_sync (self, ifindex, NULL); + return nm_route_manager_ip4_route_sync (self, ifindex, NULL, TRUE) + && nm_route_manager_ip6_route_sync (self, ifindex, NULL, TRUE); } /*********************************************************************************************/ diff --git a/src/nm-route-manager.h b/src/nm-route-manager.h index 4c66ffcd94..7b2d16f756 100644 --- a/src/nm-route-manager.h +++ b/src/nm-route-manager.h @@ -42,8 +42,8 @@ typedef struct { GType nm_route_manager_get_type (void); -gboolean nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes); -gboolean nm_route_manager_ip6_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes); +gboolean nm_route_manager_ip4_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes); +gboolean nm_route_manager_ip6_route_sync (NMRouteManager *self, int ifindex, const GArray *known_routes, gboolean ignore_kernel_routes); gboolean nm_route_manager_route_flush (NMRouteManager *self, int ifindex); NMRouteManager *nm_route_manager_get (void); diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index bcc5f3f1be..6b0a86ca3b 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -61,7 +61,7 @@ setup_dev0_ip4 (int ifindex, guint mss_of_first_route, guint32 metric_of_second_ route.mss = 0; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); } @@ -107,7 +107,7 @@ setup_dev1_ip4 (int ifindex) route.metric = 22; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); } @@ -134,7 +134,7 @@ update_dev0_ip4 (int ifindex) route.metric = 21; g_array_append_val (routes, route); - nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); } @@ -346,7 +346,7 @@ setup_dev0_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); } @@ -403,7 +403,7 @@ setup_dev1_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); } @@ -450,7 +450,7 @@ update_dev0_ip6 (int ifindex) 0); g_array_append_val (routes, *route); - nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes); + nm_route_manager_ip6_route_sync (nm_route_manager_get (), ifindex, routes, TRUE); g_array_free (routes, TRUE); }