diff options
author | Thomas Haller <thaller@redhat.com> | 2017-07-04 11:44:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-07-05 18:37:39 +0200 |
commit | 17f02318add85410ab8e75f982932633154e2a5e (patch) | |
tree | 49abe7a95e2438ef4c163ee9a5b112fc31b1e4a9 | |
parent | beb0b9b1ad98014bb83617513ba3dea25d6431f1 (diff) | |
download | NetworkManager-17f02318add85410ab8e75f982932633154e2a5e.tar.gz |
platform: drop separate index for visible objects
Routes and addresses don't implement cmd_obj_is_visible(),
hence they are always visible, and NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY
is identical to NMP_CACHE_ID_TYPE_OBJECT_TYPE.
Only link objects can be alive but invisible. Still, drop the index
for looking up visible links entirely. Let callers do the filtering,
if they care.
-rw-r--r-- | src/platform/nm-fake-platform.c | 6 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 22 | ||||
-rw-r--r-- | src/platform/nmp-object.c | 70 | ||||
-rw-r--r-- | src/platform/nmp-object.h | 41 | ||||
-rw-r--r-- | src/platform/tests/test-nmp-object.c | 13 |
5 files changed, 48 insertions, 104 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 028931c8c8..3f57afa789 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -1168,8 +1168,7 @@ ipx_route_delete (NMPlatform *platform, addr_family == AF_INET ? NMP_OBJECT_TYPE_IP4_ROUTE : NMP_OBJECT_TYPE_IP6_ROUTE, - 0, - FALSE), + 0), &o) { const NMPObject *obj_old = NULL; @@ -1266,8 +1265,7 @@ ipx_route_add (NMPlatform *platform, int addr_family, const NMPlatformObject *ro nmp_cache_iter_for_each (&iter, nm_platform_lookup_addrroute (platform, NMP_OBJECT_GET_TYPE (obj), - 0, - FALSE), + 0), &o) { if (addr_family == AF_INET) { const NMPlatformIP4Route *item = NMP_OBJECT_CAST_IP4_ROUTE (o); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index f4cd591771..5367bdc5ae 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3286,8 +3286,7 @@ cache_prune_one_type (NMPlatform *platform, NMPObjectType obj_type) NMPCache *cache = nm_platform_get_cache (platform); nmp_lookup_init_obj_type (&lookup, - obj_type, - FALSE); + obj_type); nm_dedup_multi_iter_init (&iter, nmp_cache_lookup (cache, &lookup)); @@ -3418,7 +3417,7 @@ cache_on_change (NMPlatform *platform, NMDedupMultiIter iter; const NMPlatformLink *l; - nmp_lookup_init_link (&lookup, FALSE); + nmp_lookup_init_obj_type (&lookup, NMP_OBJECT_TYPE_LINK); nmp_cache_iter_for_each_link (&iter, nmp_cache_lookup (cache, &lookup), &l) { @@ -3876,9 +3875,10 @@ link_get_all (NMPlatform *platform) { NMPLookup lookup; - nmp_lookup_init_link (&lookup, TRUE); + nmp_lookup_init_obj_type (&lookup, NMP_OBJECT_TYPE_LINK); return nmp_cache_lookup_to_array (nmp_cache_lookup (nm_platform_get_cache (platform), &lookup), - NMP_OBJECT_TYPE_LINK); + NMP_OBJECT_TYPE_LINK, + TRUE); } static const NMPlatformLink * @@ -5635,15 +5635,13 @@ link_can_assume (NMPlatform *platform, int ifindex) nmp_lookup_init_addrroute (&lookup, NMP_OBJECT_TYPE_IP4_ADDRESS, - ifindex, - TRUE); + ifindex); if (nmp_cache_lookup (cache, &lookup)) return TRUE; nmp_lookup_init_addrroute (&lookup, NMP_OBJECT_TYPE_IP6_ADDRESS, - ifindex, - TRUE); + ifindex); nmp_cache_iter_for_each (&iter, nmp_cache_lookup (cache, &lookup), &o) { @@ -5732,10 +5730,10 @@ ipx_address_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type) nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); nmp_lookup_init_addrroute (&lookup, obj_type, - ifindex, - TRUE); + ifindex); return nmp_cache_lookup_to_array (nmp_cache_lookup (nm_platform_get_cache (platform), &lookup), - obj_type); + obj_type, + FALSE /*addresses are always visible. */); } static GArray * diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index ac5ee20e1d..cf82514a50 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -177,20 +177,6 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, /* just return 1, to indicate that obj_a is partitionable by this idx_type. */ return 1; - case NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY: - if (!nmp_object_is_visible (obj_a)) - return 0; - if (obj_b) { - return NMP_OBJECT_GET_TYPE (obj_a) == NMP_OBJECT_GET_TYPE (obj_b) - && nmp_object_is_visible (obj_b); - } - if (request_hash) { - h = (guint) idx_type->cache_id_type; - h = NM_HASH_COMBINE (h, NMP_OBJECT_GET_TYPE (obj_a)); - return _HASH_NON_ZERO (h); - } - return 1; - case NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_BY_DEFAULT: if ( !NM_IN_SET (NMP_OBJECT_GET_TYPE (obj_a), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) @@ -1263,21 +1249,18 @@ _vt_cmd_obj_is_visible_link (const NMPObject *obj) static const guint8 _supported_cache_ids_link[] = { NMP_CACHE_ID_TYPE_OBJECT_TYPE, - NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY, NMP_CACHE_ID_TYPE_LINK_BY_IFNAME, 0, }; static const guint8 _supported_cache_ids_ipx_address[] = { NMP_CACHE_ID_TYPE_OBJECT_TYPE, - NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY, NMP_CACHE_ID_TYPE_ADDRROUTE_VISIBLE_BY_IFINDEX, 0, }; static const guint8 _supported_cache_ids_ipx_route[] = { NMP_CACHE_ID_TYPE_OBJECT_TYPE, - NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY, NMP_CACHE_ID_TYPE_ADDRROUTE_VISIBLE_BY_IFINDEX, NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_BY_DEFAULT, NMP_CACHE_ID_TYPE_ROUTES_BY_DESTINATION, @@ -1407,7 +1390,8 @@ nmp_cache_link_connected_needs_toggle (const NMPCache *cache, const NMPObject *m nmp_cache_iter_for_each_link (&iter, nmp_cache_lookup (cache, - nmp_lookup_init_link (&lookup, FALSE)), + nmp_lookup_init_obj_type (&lookup, + NMP_OBJECT_TYPE_LINK)), &link) { const NMPObject *obj = NMP_OBJECT_UP_CAST ((NMPlatformObject *) link); @@ -1540,8 +1524,7 @@ _L (const NMPLookup *lookup) const NMPLookup * nmp_lookup_init_obj_type (NMPLookup *lookup, - NMPObjectType obj_type, - gboolean visible_only) + NMPObjectType obj_type) { NMPObject *o; @@ -1554,16 +1537,7 @@ nmp_lookup_init_obj_type (NMPLookup *lookup, case NMP_OBJECT_TYPE_IP4_ROUTE: case NMP_OBJECT_TYPE_IP6_ROUTE: o = _nmp_object_stackinit_from_type (&lookup->selector_obj, obj_type); - if (visible_only) { - lookup->cache_id_type = NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY; - o->object.ifindex = 1; - if (obj_type == NMP_OBJECT_TYPE_LINK) { - o->_link.netlink.is_in_netlink = TRUE; - o->link.name[0] = 'x'; - } - } else { - lookup->cache_id_type = NMP_CACHE_ID_TYPE_OBJECT_TYPE; - } + lookup->cache_id_type = NMP_CACHE_ID_TYPE_OBJECT_TYPE; return _L (lookup); default: nm_assert_not_reached (); @@ -1572,15 +1546,6 @@ nmp_lookup_init_obj_type (NMPLookup *lookup, } const NMPLookup * -nmp_lookup_init_link (NMPLookup *lookup, - gboolean visible_only) -{ - return nmp_lookup_init_obj_type (lookup, - NMP_OBJECT_TYPE_LINK, - visible_only); -} - -const NMPLookup * nmp_lookup_init_link_by_ifname (NMPLookup *lookup, const char *ifname) { @@ -1600,8 +1565,7 @@ nmp_lookup_init_link_by_ifname (NMPLookup *lookup, const NMPLookup * nmp_lookup_init_addrroute (NMPLookup *lookup, NMPObjectType obj_type, - int ifindex, - gboolean visible_only) + int ifindex) { NMPObject *o; @@ -1613,14 +1577,7 @@ nmp_lookup_init_addrroute (NMPLookup *lookup, if (ifindex <= 0) { return nmp_lookup_init_obj_type (lookup, - obj_type, - visible_only); - } - - if (!visible_only) { - /* some match combinations are not implemented, as they would require - * an additional index which is expensive to maintain. */ - g_return_val_if_reached (NULL); + obj_type); } o = _nmp_object_stackinit_from_type (&lookup->selector_obj, obj_type); @@ -1644,8 +1601,7 @@ nmp_lookup_init_route_visible (NMPLookup *lookup, if (!only_default) { return nmp_lookup_init_addrroute (lookup, obj_type, - ifindex, - TRUE); + ifindex); } if (ifindex > 0) { @@ -1701,7 +1657,8 @@ nmp_lookup_init_route_by_dest (NMPLookup *lookup, GArray * nmp_cache_lookup_to_array (const NMDedupMultiHeadEntry *head_entry, - NMPObjectType obj_type) + NMPObjectType obj_type, + gboolean visible_only) { const NMPClass *klass = nmp_class_from_type (obj_type); NMDedupMultiIter iter; @@ -1717,6 +1674,9 @@ nmp_cache_lookup_to_array (const NMDedupMultiHeadEntry *head_entry, head_entry, &o) { nm_assert (NMP_OBJECT_GET_CLASS (o) == klass); + if ( visible_only + && !nmp_object_is_visible (o)) + continue; g_array_append_vals (array, &o->object, 1); } return array; @@ -1807,10 +1767,8 @@ nmp_cache_lookup_link_full (const NMPCache *cache, return NULL; nmp_lookup_init_link_by_ifname (&lookup, ifname); ifname = NULL; - } else { - nmp_lookup_init_link (&lookup, visible_only); - visible_only = FALSE; - } + } else + nmp_lookup_init_obj_type (&lookup, NMP_OBJECT_TYPE_LINK); head_entry = nmp_cache_lookup (cache, &lookup); nmp_cache_iter_for_each_link (&iter, head_entry, &link) { diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 1cff049555..605a131b3c 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -66,15 +66,17 @@ typedef enum { /*< skip >*/ * they don't track all objects. * * Hence, this index type is used when looking at all objects (still - * partitioned by type). */ + * partitioned by type). + * + * Also, note that links may be considered invisible. This index type + * expose all links, even invisible ones. For addresses/routes, this + * distiction doesn't exist, as all addresses/routes that are alive + * are visible as well. */ NMP_CACHE_ID_TYPE_OBJECT_TYPE, /* index for the link objects by ifname. */ NMP_CACHE_ID_TYPE_LINK_BY_IFNAME, - /* all the visible objects of a certain type */ - NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY, - /* indeces for the visible default-routes, ignoring ifindex. * This index only contains two partitions: all visible default-routes, * separate for IPv4 and IPv6. */ @@ -453,16 +455,12 @@ nmp_cache_lookup (const NMPCache *cache, } const NMPLookup *nmp_lookup_init_obj_type (NMPLookup *lookup, - NMPObjectType obj_type, - gboolean visible_only); -const NMPLookup *nmp_lookup_init_link (NMPLookup *lookup, - gboolean visible_only); + NMPObjectType obj_type); const NMPLookup *nmp_lookup_init_link_by_ifname (NMPLookup *lookup, const char *ifname); const NMPLookup *nmp_lookup_init_addrroute (NMPLookup *lookup, NMPObjectType obj_type, - int ifindex, - gboolean visible_only); + int ifindex); const NMPLookup *nmp_lookup_init_route_visible (NMPLookup *lookup, NMPObjectType obj_type, int ifindex, @@ -474,7 +472,8 @@ const NMPLookup *nmp_lookup_init_route_by_dest (NMPLookup *lookup, guint32 metric); GArray *nmp_cache_lookup_to_array (const NMDedupMultiHeadEntry *head_entry, - NMPObjectType obj_type); + NMPObjectType obj_type, + gboolean visible_only); static inline gboolean nmp_cache_iter_next (NMDedupMultiIter *iter, const NMPObject **out_obj) @@ -600,22 +599,11 @@ ASSERT_nmp_cache_ops (const NMPCache *cache, static inline const NMDedupMultiHeadEntry * nm_platform_lookup_obj_type (NMPlatform *platform, - NMPObjectType obj_type, - gboolean visible_only) -{ - NMPLookup lookup; - - nmp_lookup_init_obj_type (&lookup, obj_type, visible_only); - return nm_platform_lookup (platform, &lookup); -} - -static inline const NMDedupMultiHeadEntry * -nm_platform_lookup_link (NMPlatform *platform, - gboolean visible_only) + NMPObjectType obj_type) { NMPLookup lookup; - nmp_lookup_init_link (&lookup, visible_only); + nmp_lookup_init_obj_type (&lookup, obj_type); return nm_platform_lookup (platform, &lookup); } @@ -632,12 +620,11 @@ nm_platform_lookup_link_by_ifname (NMPlatform *platform, static inline const NMDedupMultiHeadEntry * nm_platform_lookup_addrroute (NMPlatform *platform, NMPObjectType obj_type, - int ifindex, - gboolean visible_only) + int ifindex) { NMPLookup lookup; - nmp_lookup_init_addrroute (&lookup, obj_type, ifindex, visible_only); + nmp_lookup_init_addrroute (&lookup, obj_type, ifindex); return nm_platform_lookup (platform, &lookup); } diff --git a/src/platform/tests/test-nmp-object.c b/src/platform/tests/test-nmp-object.c index 40d876a65b..11fc59e24b 100644 --- a/src/platform/tests/test-nmp-object.c +++ b/src/platform/tests/test-nmp-object.c @@ -110,7 +110,7 @@ _nmp_object_equal (const NMPObject *a, const NMPObject *b) /*****************************************************************************/ static void -_assert_cache_multi_lookup_contains (const NMPCache *cache, const NMDedupMultiHeadEntry *head_entry, const NMPObject *obj, gboolean contains) +_assert_cache_multi_lookup_contains (const NMPCache *cache, const NMDedupMultiHeadEntry *head_entry, const NMPObject *obj, gboolean visible_only, gboolean contains) { NMDedupMultiIter iter; gboolean found; @@ -131,8 +131,11 @@ _assert_cache_multi_lookup_contains (const NMPCache *cache, const NMDedupMultiHe &o) { g_assert (NMP_OBJECT_IS_VALID (o)); if (obj == o) { - g_assert (!found); - found = TRUE; + if ( !visible_only + || nmp_object_is_visible (o)) { + g_assert (!found); + found = TRUE; + } } i++; } @@ -152,9 +155,9 @@ _assert_cache_multi_lookup_contains_link (const NMPCache *cache, g_assert (cache); - nmp_lookup_init_link (&lookup, visible_only); + nmp_lookup_init_obj_type (&lookup, NMP_OBJECT_TYPE_LINK); head_entry = nmp_cache_lookup (cache, &lookup); - _assert_cache_multi_lookup_contains (cache, head_entry, obj, contains); + _assert_cache_multi_lookup_contains (cache, head_entry, obj, visible_only, contains); } /*****************************************************************************/ |