mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 11:30:15 +01:00
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.
This commit is contained in:
parent
3ec110b67e
commit
94560e4ad2
9 changed files with 53 additions and 72 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue