platform: track routes in NMFakePlatform via NMPCache
NMPlatform's cache should be directly accessible to the users, at least the NMPLookup part and the fact that the cache contains ref-counted, immutable NMPObjects. This allows users to inspect the cache with zero overhead. Meaning, they can obtain an NMDedupMultiHeadEntry and iterate the objects themself. It also means, the are free to take and keep references of the NMPObject instances (of course, without modifying them!). NMFakePlatform will use the very same cache. The fake platform should only differ when modifying the objects. Another reason why this makes sense is because NMFakePlatform is for one a test-stup but also tests behavior of platform itself. Using a separate internal implementation for the caching is a pointless excecise, because only the real NMPCache's implementation really matters for production. So, either NMFakePlatform behaves idential, or it is buggy. Reuse it. Port fake platform's tracking of routes to NMPCache and move duplicate code from NMLinuxPlatform to the base class. This commit only ports IP routes, eventually also addresses and links should be tracked via the NMPCache instance.
This commit is contained in:
@@ -5889,58 +5889,6 @@ ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static GArray *
|
||||
ipx_route_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type, NMPlatformGetRouteFlags flags)
|
||||
{
|
||||
NMDedupMultiIter iter;
|
||||
NMPLookup lookup;
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
GArray *array;
|
||||
const NMPClass *klass;
|
||||
const NMPObject *o;
|
||||
gboolean with_rtprot_kernel;
|
||||
|
||||
nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE));
|
||||
|
||||
if (!NM_FLAGS_ANY (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT))
|
||||
flags |= NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT;
|
||||
|
||||
klass = nmp_class_from_type (obj_type);
|
||||
|
||||
head_entry = nmp_cache_lookup (nm_platform_get_cache (platform),
|
||||
nmp_lookup_init_route_visible (&lookup,
|
||||
obj_type,
|
||||
ifindex,
|
||||
NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT),
|
||||
NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT)));
|
||||
|
||||
array = g_array_sized_new (FALSE, FALSE, klass->sizeof_public, head_entry ? head_entry->len : 0);
|
||||
|
||||
with_rtprot_kernel = NM_FLAGS_HAS (flags, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_RTPROT_KERNEL);
|
||||
|
||||
nmp_cache_iter_for_each (&iter,
|
||||
head_entry,
|
||||
&o) {
|
||||
nm_assert (NMP_OBJECT_GET_CLASS (o) == klass);
|
||||
if ( with_rtprot_kernel
|
||||
|| o->ip_route.rt_source != NM_IP_CONFIG_SOURCE_RTPROT_KERNEL)
|
||||
g_array_append_vals (array, &o->ip_route, 1);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static GArray *
|
||||
ip4_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteFlags flags)
|
||||
{
|
||||
return ipx_route_get_all (platform, ifindex, NMP_OBJECT_TYPE_IP4_ROUTE, flags);
|
||||
}
|
||||
|
||||
static GArray *
|
||||
ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteFlags flags)
|
||||
{
|
||||
return ipx_route_get_all (platform, ifindex, NMP_OBJECT_TYPE_IP6_ROUTE, flags);
|
||||
}
|
||||
|
||||
static guint32
|
||||
ip_route_get_lock_flag (NMPlatformIPRoute *route)
|
||||
{
|
||||
@@ -6130,34 +6078,6 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, gu
|
||||
return do_delete_object (platform, &obj_id, nlmsg);
|
||||
}
|
||||
|
||||
static const NMPlatformIP4Route *
|
||||
ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
|
||||
{
|
||||
NMPObject obj_id;
|
||||
const NMPObject *obj;
|
||||
|
||||
nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric);
|
||||
obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
|
||||
if (nmp_object_is_visible (obj))
|
||||
return &obj->ip4_route;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const NMPlatformIP6Route *
|
||||
ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
|
||||
{
|
||||
NMPObject obj_id;
|
||||
const NMPObject *obj;
|
||||
|
||||
metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||
|
||||
nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric);
|
||||
obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
|
||||
if (nmp_object_is_visible (obj))
|
||||
return &obj->ip6_route;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define EVENT_CONDITIONS ((GIOCondition) (G_IO_IN | G_IO_PRI))
|
||||
@@ -6898,10 +6818,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
platform_class->ip4_address_delete = ip4_address_delete;
|
||||
platform_class->ip6_address_delete = ip6_address_delete;
|
||||
|
||||
platform_class->ip4_route_get = ip4_route_get;
|
||||
platform_class->ip6_route_get = ip6_route_get;
|
||||
platform_class->ip4_route_get_all = ip4_route_get_all;
|
||||
platform_class->ip6_route_get_all = ip6_route_get_all;
|
||||
platform_class->ip4_route_add = ip4_route_add;
|
||||
platform_class->ip6_route_add = ip6_route_add;
|
||||
platform_class->ip4_route_delete = ip4_route_delete;
|
||||
|
Reference in New Issue
Block a user