summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-13 20:41:35 +0200
committerTom Gundersen <teg@jklm.no>2014-09-13 21:10:59 +0200
commitd1c457badfce0dc86b54b2cac2c5eec99d7bc65e (patch)
tree4db548d82fee40439096a3e892f32317d8275322 /src
parent124f09e8125e1eae5b058b1f287e72c85a46d557 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/resolve/resolved-manager.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index f97989754d..00aaffe448 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -1687,6 +1687,9 @@ fail:
return r;
}
+/* lo having ifindex 1 is hardcoded in the kernel */
+#define LOOPBACK_IFINDEX 1
+
int manager_ifindex_is_loopback(Manager *m, int ifindex) {
Link *l;
assert(m);
@@ -1695,7 +1698,10 @@ int manager_ifindex_is_loopback(Manager *m, int ifindex) {
return -EINVAL;
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 0;