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.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user