From 94560e4ad2e2bc4b54714e37b5668b198ec06bbb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Aug 2017 10:15:25 +0200 Subject: [PATCH] platform: cleanup nmp_lookup_init_route_visible() lookup helper nmp_lookup_init_route_visible() was originally named this way, to only return routes that are nmp_object_is_visible(). However, all routes are visible (as long as they are nmp_object_is_alive()). Hence, this is a historic misnomer. Also, passing @only_default FALSE is identical to the nmp_lookup_init_addrroute() lookup. So, rename the function to indicate it is a lookup for default routes only. Also, get rid of the unsupported ifindex argument for which there is no index. --- src/devices/nm-device.c | 6 ++---- src/nm-default-route-manager.c | 8 ++------ src/nm-ip4-config.c | 7 +++---- src/nm-ip6-config.c | 7 +++---- src/nm-route-manager.c | 15 +++++++------- src/platform/nmp-object.c | 18 ++-------------- src/platform/nmp-object.h | 35 +++++++++++++++++++------------- src/platform/tests/test-common.h | 22 +++++++++----------- src/tests/test-route-manager.c | 7 +++---- 9 files changed, 53 insertions(+), 72 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3934c18f3c..006d4e9227 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5453,12 +5453,10 @@ _device_get_default_route_from_platform (NMDevice *self, int addr_family, NMPlat const NMPlatformIPRoute *route = NULL; guint32 route_metric = G_MAXUINT32; - pl_head_entry = nm_platform_lookup_route_visible (nm_device_get_platform (self), + pl_head_entry = nm_platform_lookup_route_default (nm_device_get_platform (self), addr_family == AF_INET ? NMP_OBJECT_TYPE_IP4_ROUTE - : NMP_OBJECT_TYPE_IP6_ROUTE, - 0, - TRUE); + : NMP_OBJECT_TYPE_IP6_ROUTE); nmp_cache_iter_for_each (&iter, pl_head_entry, &plobj) { guint32 m; const NMPlatformIPRoute *r = NMP_OBJECT_CAST_IP_ROUTE (plobj); diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index d80d39450f..66a94a05a4 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -332,10 +332,8 @@ _platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self, /* prune all other default routes from this device. */ - routes = nm_platform_lookup_route_visible_clone (priv->platform, + routes = nm_platform_lookup_route_default_clone (priv->platform, vtable->vt->obj_type, - 0, - TRUE, nm_platform_lookup_predicate_routes_skip_rtprot_kernel, NULL); if (!routes) @@ -515,10 +513,8 @@ _resync_all (const VTableIP *vtable, NMDefaultRouteManager *self, const Entry *c entries = vtable->get_entries (priv); - routes = nm_platform_lookup_route_visible_clone (priv->platform, + routes = nm_platform_lookup_route_default_clone (priv->platform, vtable->vt->obj_type, - 0, - TRUE, nm_platform_lookup_predicate_routes_skip_rtprot_kernel, NULL); diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index ea2f03bd08..20e2d2f946 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -590,10 +590,9 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i has_addresses = TRUE; } - head_entry = nm_platform_lookup_route_visible (platform, - NMP_OBJECT_TYPE_IP4_ROUTE, - ifindex, - FALSE); + head_entry = nm_platform_lookup_addrroute (platform, + NMP_OBJECT_TYPE_IP4_ROUTE, + ifindex); /* Extract gateway from default route */ old_gateway = priv->gateway; diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 2197e96dc2..dc45acc18d 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -449,10 +449,9 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i GINT_TO_POINTER (use_temporary)); } - head_entry = nm_platform_lookup_route_visible (platform, - NMP_OBJECT_TYPE_IP6_ROUTE, - ifindex, - FALSE); + head_entry = nm_platform_lookup_addrroute (platform, + NMP_OBJECT_TYPE_IP6_ROUTE, + ifindex); /* Extract gateway from default route */ old_gateway = priv->gateway; diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index ebd0594fb5..12583e5c06 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -320,14 +320,13 @@ _route_index_create_from_platform (const VTableIP *vtable, nm_assert (out_storage && !*out_storage); - storage = nm_platform_lookup_route_visible_clone (platform, - vtable->vt->obj_type, - ifindex, - FALSE, - ignore_kernel_routes - ? nm_platform_lookup_predicate_routes_skip_rtprot_kernel - : NULL, - NULL); + storage = nm_platform_lookup_addrroute_clone (platform, + vtable->vt->obj_type, + ifindex, + ignore_kernel_routes + ? nm_platform_lookup_predicate_routes_skip_rtprot_kernel + : NULL, + NULL); if (!storage) return _route_index_create (vtable, NULL); diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 477ea62149..b51172b54b 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -1556,10 +1556,8 @@ nmp_lookup_init_addrroute (NMPLookup *lookup, } const NMPLookup * -nmp_lookup_init_route_visible (NMPLookup *lookup, - NMPObjectType obj_type, - int ifindex, - gboolean only_default) +nmp_lookup_init_route_default (NMPLookup *lookup, + NMPObjectType obj_type) { NMPObject *o; @@ -1567,18 +1565,6 @@ nmp_lookup_init_route_visible (NMPLookup *lookup, nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); - if (!only_default) { - return nmp_lookup_init_addrroute (lookup, - obj_type, - ifindex); - } - - if (ifindex > 0) { - /* there is no index to lookup a default-route by ifindex. - * You have to lookup all default-routes, and filter yourself */ - g_return_val_if_reached (NULL); - } - o = _nmp_object_stackinit_from_type (&lookup->selector_obj, obj_type); o->object.ifindex = 1; lookup->cache_id_type = NMP_CACHE_ID_TYPE_DEFAULT_ROUTES; diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 32a2a36dfd..8bb6e96877 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -523,10 +523,8 @@ const NMPLookup *nmp_lookup_init_link_by_ifname (NMPLookup *lookup, const NMPLookup *nmp_lookup_init_addrroute (NMPLookup *lookup, NMPObjectType obj_type, int ifindex); -const NMPLookup *nmp_lookup_init_route_visible (NMPLookup *lookup, - NMPObjectType obj_type, - int ifindex, - gboolean only_default); +const NMPLookup *nmp_lookup_init_route_default (NMPLookup *lookup, + NMPObjectType obj_type); const NMPLookup *nmp_lookup_init_route_by_weak_id (NMPLookup *lookup, const NMPObject *obj); const NMPLookup *nmp_lookup_init_ip4_route_by_weak_id (NMPLookup *lookup, @@ -715,29 +713,38 @@ nm_platform_lookup_addrroute (NMPlatform *platform, return nm_platform_lookup (platform, &lookup); } -static inline const NMDedupMultiHeadEntry * -nm_platform_lookup_route_visible (NMPlatform *platform, - NMPObjectType obj_type, - int ifindex, - gboolean only_default) +static inline GPtrArray * +nm_platform_lookup_addrroute_clone (NMPlatform *platform, + NMPObjectType obj_type, + int ifindex, + gboolean (*predicate) (const NMPObject *obj, gpointer user_data), + gpointer user_data) { NMPLookup lookup; - nmp_lookup_init_route_visible (&lookup, obj_type, ifindex, only_default); + nmp_lookup_init_addrroute (&lookup, obj_type, ifindex); + return nm_platform_lookup_clone (platform, &lookup, predicate, user_data); +} + +static inline const NMDedupMultiHeadEntry * +nm_platform_lookup_route_default (NMPlatform *platform, + NMPObjectType obj_type) +{ + NMPLookup lookup; + + nmp_lookup_init_route_default (&lookup, obj_type); return nm_platform_lookup (platform, &lookup); } static inline GPtrArray * -nm_platform_lookup_route_visible_clone (NMPlatform *platform, +nm_platform_lookup_route_default_clone (NMPlatform *platform, NMPObjectType obj_type, - int ifindex, - gboolean only_default, gboolean (*predicate) (const NMPObject *obj, gpointer user_data), gpointer user_data) { NMPLookup lookup; - nmp_lookup_init_route_visible (&lookup, obj_type, ifindex, only_default); + nmp_lookup_init_route_default (&lookup, obj_type); return nm_platform_lookup_clone (platform, &lookup, predicate, user_data); } diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index 8ec9c7e84a..ad58e141a9 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -227,24 +227,22 @@ static inline GPtrArray * nmtstp_ip4_route_get_all (NMPlatform *platform, int ifindex) { - return nm_platform_lookup_route_visible_clone (platform, - NMP_OBJECT_TYPE_IP4_ROUTE, - ifindex, - FALSE, - nm_platform_lookup_predicate_routes_skip_rtprot_kernel, - NULL); + return nm_platform_lookup_addrroute_clone (platform, + NMP_OBJECT_TYPE_IP4_ROUTE, + ifindex, + nm_platform_lookup_predicate_routes_skip_rtprot_kernel, + NULL); } static inline GPtrArray * nmtstp_ip6_route_get_all (NMPlatform *platform, int ifindex) { - return nm_platform_lookup_route_visible_clone (platform, - NMP_OBJECT_TYPE_IP6_ROUTE, - ifindex, - FALSE, - nm_platform_lookup_predicate_routes_skip_rtprot_kernel, - NULL); + return nm_platform_lookup_addrroute_clone (platform, + NMP_OBJECT_TYPE_IP6_ROUTE, + ifindex, + nm_platform_lookup_predicate_routes_skip_rtprot_kernel, + NULL); } /*****************************************************************************/ diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index 68e1f31b8a..2778cfcc82 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -166,10 +166,9 @@ ip_routes (test_fixture *fixture, NMPObjectType obj_type) else ifindex = fixture->ifindex1; - pl_head_entry = nm_platform_lookup_route_visible (NM_PLATFORM_GET, - obj_type, - ifindex, - FALSE); + pl_head_entry = nm_platform_lookup_addrroute (NM_PLATFORM_GET, + obj_type, + ifindex); nmp_cache_iter_for_each (&iter, pl_head_entry, &plobj) { const NMPlatformIPRoute *r = NMP_OBJECT_CAST_IP_ROUTE (plobj);