summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-02-02 21:17:48 +0100
committerThomas Haller <thaller@redhat.com>2022-02-09 19:13:03 +0100
commitd4ad9666bd4b94c1186bb2dc3f81e4efa5d0e94c (patch)
treeee1de1847a4d1a78e090067b5c5a9da1b19024e7
parent1123d3a5fb3b1f1a36809d1ea55e1c21c99c35c4 (diff)
downloadNetworkManager-d4ad9666bd4b94c1186bb2dc3f81e4efa5d0e94c.tar.gz
platform: don't treat ifindex zero special in nmp_lookup_init_object()
So far, certain NMObject types could not have an ifindex of zero. Hence, nmp_lookup_init_object() took such an ifindex to mean lookup all objects of that type. Soon, we will support blackhole/unreachable/prohibit route types, which have their ifindex set to zero. It is still useful to lookup those routes types via nmp_lookup_init_object(). Change behaviour how to interpret the ifindex. Note that this also affects various callers of nmp_lookup_init_object(). If somebody was relying on the previous behavior, it would need fixing.
-rw-r--r--src/core/platform/nm-fake-platform.c11
-rw-r--r--src/core/platform/tests/test-common.c6
-rw-r--r--src/libnm-platform/nmp-object.c10
3 files changed, 19 insertions, 8 deletions
diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c
index ebb6a795b9..7d8986d764 100644
--- a/src/core/platform/nm-fake-platform.c
+++ b/src/core/platform/nm-fake-platform.c
@@ -957,11 +957,10 @@ ipx_address_delete(NMPlatform *platform,
peer_addr_i = peer_addr ? *((guint32 *) peer_addr) : 0;
nmp_cache_iter_for_each (&iter,
- nm_platform_lookup_object(platform,
- addr_family == AF_INET
- ? NMP_OBJECT_TYPE_IP4_ADDRESS
- : NMP_OBJECT_TYPE_IP6_ADDRESS,
- 0),
+ nm_platform_lookup_obj_type(platform,
+ addr_family == AF_INET
+ ? NMP_OBJECT_TYPE_IP4_ADDRESS
+ : NMP_OBJECT_TYPE_IP6_ADDRESS),
&o) {
const NMPObject *obj_old = NULL;
@@ -1139,7 +1138,7 @@ ip_route_add(NMPlatform *platform,
gboolean has_route_to_gw = FALSE;
nmp_cache_iter_for_each (&iter,
- nm_platform_lookup_object(platform, NMP_OBJECT_GET_TYPE(obj), 0),
+ nm_platform_lookup_obj_type(platform, NMP_OBJECT_GET_TYPE(obj)),
&o) {
if (addr_family == AF_INET) {
const NMPlatformIP4Route *item = NMP_OBJECT_CAST_IP4_ROUTE(o);
diff --git a/src/core/platform/tests/test-common.c b/src/core/platform/tests/test-common.c
index 24426a5414..9053d35173 100644
--- a/src/core/platform/tests/test-common.c
+++ b/src/core/platform/tests/test-common.c
@@ -102,7 +102,11 @@ nmtstp_platform_ip_address_find(NMPlatform *self, int ifindex, int addr_family,
nm_assert_addr_family(addr_family);
nm_assert(addr);
- nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex);
+ if (ifindex > 0)
+ nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex);
+ else
+ nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4));
+
nm_platform_iter_obj_for_each (&iter, self, &lookup, &obj) {
const NMPlatformIPAddress *a = NMP_OBJECT_CAST_IP_ADDRESS(obj);
diff --git a/src/libnm-platform/nmp-object.c b/src/libnm-platform/nmp-object.c
index 3154a23e80..8bd43ef0e5 100644
--- a/src/libnm-platform/nmp-object.c
+++ b/src/libnm-platform/nmp-object.c
@@ -2142,7 +2142,15 @@ nmp_lookup_init_object(NMPLookup *lookup, NMPObjectType obj_type, int ifindex)
NMP_OBJECT_TYPE_QDISC,
NMP_OBJECT_TYPE_TFILTER));
- if (ifindex <= 0) {
+ if (G_UNLIKELY(
+ (ifindex < 0)
+ || (ifindex == 0
+ && !NM_IN_SET(obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)))) {
+ /* This function used to have a fallback that meant to lookup all objects, if
+ * ifindex is non-positive. As routes can have a zero ifindex, that fallback is
+ * confusing and no longer supported. Only have this code, to catch accidental bugs
+ * after the API change. */
+ nm_assert_not_reached();
return nmp_lookup_init_obj_type(lookup, obj_type);
}