diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index be5ee8c61..fef42801c 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -3344,8 +3344,6 @@ static int route_dst_generic(const struct sockaddr_storage *dst, if (!sockaddr_equal(dst, &ifaces[i].addr)) continue; - if (iface != NULL && strcmp(ifaces[i].devname, iface->devname) != 0) - continue; if (ifaces[i].device_type == devt_loopback) loopback = &ifaces[i]; @@ -3355,6 +3353,9 @@ static int route_dst_generic(const struct sockaddr_storage *dst, /* Hmmm ... no localhost -- move on to the routing table. */ break; + if (iface != NULL && strcmp(loopback->devname, iface->devname) != 0) + continue; + rnfo->ii = *loopback; rnfo->direct_connect = 1; /* But the source address we want to use is the target address. */