From eac15cb9198f123b29807c3294005ddc8d168f89 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 27 Jul 2009 19:01:58 +0000 Subject: [PATCH] Apply a patch by Dmitry Levin that uses a network interface's full name, including alias extension, in several places to avoid this error message when an alias has an IP address but the primary interface doesn't: Failed to lookup subnet/netmask for device (venet0): venet0: no IPv4 address assigned The patch also considers an interface alias if the primary interface does not appear in the list of interfaces (perhaps because it does not have an IP address assigned) when building the table of routes. --- CHANGELOG | 7 +++++++ idle_scan.cc | 2 +- osscan2.cc | 2 +- scan_engine.cc | 2 +- tcpip.cc | 15 +++++++++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index af2894603..f269f8050 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,12 @@ # Nmap Changelog ($Id$); -*-text-*- +o Nmap now handles the case when a primary network interface (venet0) + does not have an address assigned but its aliases do (venet0:1 + etc.). This could result in the error messages + Failed to find device venet0 which was referenced in /proc/net/route + Failed to lookup subnet/netmask for device (venet0): venet0: no IPv4 address assigned + This was observed particularly under OpenVZ. [Dmitry Levin] + o [Ncat] The --ssl-cert, --ssl-key, and --ssl-trustfile options now automatically turn on SSL mode. Previously they were ignored if --ssl was not also used. [David] diff --git a/idle_scan.cc b/idle_scan.cc index ededdf2cc..83d1ba3aa 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -406,7 +406,7 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, Snprintf(filter, sizeof(filter), "tcp and src host %s and dst host %s and src port %hu", p, q, proxy->probe_port); free(p); free(q); - set_pcap_filter(proxy->host.deviceName(), proxy->pd, filter); + set_pcap_filter(proxy->host.deviceFullName(), proxy->pd, filter); /* Windows nonsense -- I am not sure why this is needed, but I should get rid of it at sometime */ diff --git a/osscan2.cc b/osscan2.cc index a05d54c36..f89d771d2 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -3266,7 +3266,7 @@ static void begin_sniffer(HostOsScan *HOS, vector &Targets) { filterlen = len; if (o.debugging > 2) log_write(LOG_PLAIN, "Pcap filter: %s\n", pcap_filter); - set_pcap_filter(Targets[0]->deviceName(), HOS->pd, pcap_filter); + set_pcap_filter(Targets[0]->deviceFullName(), HOS->pd, pcap_filter); return; } diff --git a/scan_engine.cc b/scan_engine.cc index 1f8bd5118..5a0936bec 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -5071,7 +5071,7 @@ static void begin_sniffer(UltraScanInfo *USI, vector &Targets) { } }else assert(0); if (o.debugging > 2) log_write(LOG_PLAIN, "Pcap filter: %s\n", pcap_filter.c_str()); - set_pcap_filter(Targets[0]->deviceName(), USI->pd, pcap_filter.c_str()); + set_pcap_filter(Targets[0]->deviceFullName(), USI->pd, pcap_filter.c_str()); /* pcap_setnonblock(USI->pd, 1, NULL); */ return; } diff --git a/tcpip.cc b/tcpip.cc index aba8551d8..03035b17b 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -2721,8 +2721,8 @@ bool setTargetNextHopMAC(Target *target) { /* OK, the last choice is to send our own damn ARP request (and retransmissions if necessary) to determine the MAC */ target->SourceSockAddr(&srcss, NULL); - if (doArp(target->deviceName(), target->SrcMACAddress(), &srcss, &targetss, - mac)) { + if (doArp(target->deviceFullName(), target->SrcMACAddress(), + &srcss, &targetss, mac)) { NmapArpCache(ARPCACHE_SET, &targetss, mac); target->setNextHopMACAddress(mac); return true; @@ -3202,6 +3202,17 @@ static struct sys_route *getsysroutes_proc(FILE *routefp, int *howmany) { break; } } + /* If device name in the route file does not match the full name (including + alias extension) of any interface, then try to find at least an alias of + the proper interface. */ + if (i == numifaces) { + for(i=0; i < numifaces; i++) { + if (!strcmp(iface, ifaces[i].devname)) { + routes[numroutes].device = &ifaces[i]; + break; + } + } + } if (i == numifaces) { error("Failed to find device %s which was referenced in /proc/net/route", iface); continue;