1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-14 15:21:37 +03:00

resolved: fall back to hardcoded ifindex when checking if a link is the loopback

Reported by Philippe De Swert <philippedeswert@gmail.com>.

Coverity CID#1237656
This commit is contained in:
Tom Gundersen 2014-09-13 20:41:35 +02:00
parent 124f09e812
commit d1c457badf

View File

@ -1687,6 +1687,9 @@ fail:
return r; return r;
} }
/* lo having ifindex 1 is hardcoded in the kernel */
#define LOOPBACK_IFINDEX 1
int manager_ifindex_is_loopback(Manager *m, int ifindex) { int manager_ifindex_is_loopback(Manager *m, int ifindex) {
Link *l; Link *l;
assert(m); assert(m);
@ -1695,7 +1698,10 @@ int manager_ifindex_is_loopback(Manager *m, int ifindex) {
return -EINVAL; return -EINVAL;
l = hashmap_get(m->links, INT_TO_PTR(ifindex)); l = hashmap_get(m->links, INT_TO_PTR(ifindex));
if (l->flags & IFF_LOOPBACK) if (!l)
/* in case we don't yet track the link, rely on the hardcoded value */
return ifindex == LOOPBACK_IFINDEX;
else if (l->flags & IFF_LOOPBACK)
return 1; return 1;
return 0; return 0;