Enforce device name only after choosing loopback in route_dst_generic.

Nping calls route_dst at least twice: once with a NULL device, and again
with the device learned from the first time. This interfered with the
code that automatically chooses a loopback interface for dests that are
the same as an interface address. For example, if you are 192.168.0.1,
and you are scanning 192.168.0.1, route_dst will tell you to use
interface "lo0" even though the interface of 192.168.0.1 may be "eth0".
route_dst was returning failure because the device name check was being
done before "eth0" got changed to "lo0".

This problem didn't show up on Linux because Linux uses
route_dst_netlink, which delegates the work to the kernel. But I could
reproduce on Linux by forcing the use of route_dst_generic.
This commit is contained in:
david 2013-02-09 18:55:46 +00:00
parent 9e74850e6e
commit 66bd9d1993

View file

@ -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. */