diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-10-22 16:52:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-10-22 16:52:38 +0200 |
commit | a5f035960006556beab51c42e6948985635e261a (patch) | |
tree | bee22c1c99904edcc348117d784b2352a018a4b3 /src/resolve/resolved-manager.c | |
parent | 91c40d86120f3bf033539a53c971d99f5dd70708 (diff) |
resolved: simplify detection of packets from the loopback device
We can simplify our code quite a bit if we explicitly check for the
ifindex being 1 on Linux as a loopback check. Apparently, this is
hardcoded on Linux on the kernel, and effectively exported to userspace
via rtnl and such, hence we should be able to rely on it.
Diffstat (limited to 'src/resolve/resolved-manager.c')
-rw-r--r-- | src/resolve/resolved-manager.c | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 74f4ad5dba..c4a5b08773 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -960,7 +960,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { * device if the packet came from the local host since it * avoids the routing table in such a case. Let's unset the * interface index in such a case. */ - if (p->ifindex > 0 && manager_ifindex_is_loopback(m, p->ifindex) != 0) + if (p->ifindex == LOOPBACK_IFINDEX) p->ifindex = 0; /* If we don't know the interface index still, we look for the @@ -1695,26 +1695,6 @@ 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); - - if (ifindex <= 0) - return -EINVAL; - - l = hashmap_get(m->links, INT_TO_PTR(ifindex)); - 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; -} - int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr) { LinkAddress *a; |