summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-11-29 12:19:15 +0100
committerThomas Haller <thaller@redhat.com>2018-11-30 14:34:54 +0100
commitef4fc79eae187e415643bdabdc672b60239cff19 (patch)
treedd0500b3c3ccfa9d14aa3b1a01e299ee1be5925c /src
parent7f74c66a64e32b866e72fec40a4e2373aca14525 (diff)
downloadNetworkManager-ef4fc79eae187e415643bdabdc672b60239cff19.tar.gz
platform: let nmp_cache_lookup_link_full() prefer visible links
In nmp_cache_lookup_link_full(), we may have multiple candidates that match. Continue searching, until we find a visible one. That way, visible results are preferred. Note that for links, nmp_object_is_visible() checks whether the link is visible in netlink (instead of only udev).
Diffstat (limited to 'src')
-rw-r--r--src/platform/nmp-object.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c
index 5e1ebb56e2..fd505282e2 100644
--- a/src/platform/nmp-object.c
+++ b/src/platform/nmp-object.c
@@ -1976,6 +1976,8 @@ nmp_cache_lookup_link_full (const NMPCache *cache,
} else if (!ifname && !match_fn)
return NULL;
else {
+ const NMPObject *obj_best = NULL;
+
if (ifname) {
if (strlen (ifname) >= IFNAMSIZ)
return NULL;
@@ -1987,16 +1989,21 @@ nmp_cache_lookup_link_full (const NMPCache *cache,
nmp_cache_iter_for_each_link (&iter, head_entry, &link) {
obj = NMP_OBJECT_UP_CAST (link);
- if (visible_only && !nmp_object_is_visible (obj))
- continue;
if (link_type != NM_LINK_TYPE_NONE && obj->link.type != link_type)
continue;
+ if (visible_only && !nmp_object_is_visible (obj))
+ continue;
if (match_fn && !match_fn (obj, user_data))
continue;
- return obj;
+ /* if there are multiple candidates, prefer the visible ones. */
+ if ( visible_only
+ || nmp_object_is_visible (obj))
+ return obj;
+ if (!obj_best)
+ obj_best = obj;
}
- return NULL;
+ return obj_best;
}
}