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).
This commit is contained in:
Thomas Haller 2018-11-29 12:19:15 +01:00
parent f411dea585
commit f47f9e3956

View file

@ -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;
}
}