mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 22:49:01 +00:00
Add intf_name to the route_entry struct.
This is set to an empty string in all functions yielding routes, particularly route_loop. The code to get the interface pertaining to a route is different on different platforms, so must be added one by one. The code setting the intf_name to an empty string is only tested on Linux.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
* Routing table entry
|
||||
*/
|
||||
struct route_entry {
|
||||
char intf_name[INTF_NAME_LEN]; /* interface name */
|
||||
struct addr route_dst; /* destination address */
|
||||
struct addr route_gw; /* gateway address */
|
||||
};
|
||||
|
||||
@@ -212,6 +212,7 @@ route_get(route_t *r, struct route_entry *entry)
|
||||
{
|
||||
if (route_msg(r, RTM_GET, &entry->route_dst, &entry->route_gw) < 0)
|
||||
return (-1);
|
||||
entry->intf_name[0] = '\0';
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -318,6 +319,8 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
rtm = (struct rt_msghdr *)next;
|
||||
sa = (struct sockaddr *)(rtm + 1);
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
if ((rtm->rtm_addrs & RTA_DST) == 0)
|
||||
/* Need a destination. */
|
||||
continue;
|
||||
@@ -443,6 +446,8 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
rt->ipRouteNextHop == IP_ADDR_ANY)
|
||||
continue;
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
sin.sin_addr.s_addr = rt->ipRouteNextHop;
|
||||
addr_ston((struct sockaddr *)&sin,
|
||||
&entry.route_gw);
|
||||
@@ -535,6 +540,8 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
memcmp(&rt->ipv6RouteNextHop, IP6_ADDR_UNSPEC, IP6_ADDR_LEN) == 0)
|
||||
continue;
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
sin6.sin6_addr = rt->ipv6RouteNextHop;
|
||||
addr_ston((struct sockaddr *)&sin6,
|
||||
&entry.route_gw);
|
||||
@@ -576,6 +583,7 @@ _radix_walk(int fd, struct radix_node *rn, route_handler callback, void *arg)
|
||||
_kread(fd, rn, &rnode, sizeof(rnode));
|
||||
if (rnode.rn_b < 0) {
|
||||
if (!(rnode.rn_flags & RNF_ROOT)) {
|
||||
entry.intf_name[0] = '\0';
|
||||
_kread(fd, rn, &rt, sizeof(rt));
|
||||
_kread(fd, rt_key(&rt), &sin, sizeof(sin));
|
||||
addr_ston((struct sockaddr *)&sin, &entry.route_dst);
|
||||
|
||||
@@ -116,6 +116,7 @@ route_get(route_t *r, struct route_entry *entry)
|
||||
errno = ESRCH;
|
||||
return (-1);
|
||||
}
|
||||
entry->intf_name[0] = '\0';
|
||||
entry->route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry->route_gw.addr_bits = IP_ADDR_BITS;
|
||||
memcpy(&entry->route_gw.addr_ip, &rtr.rtr_gwayaddr, IP_ADDR_LEN);
|
||||
@@ -147,8 +148,6 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
}
|
||||
close_mib(fd);
|
||||
|
||||
entry.route_dst.addr_type = entry.route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_dst.addr_bits = entry.route_gw.addr_bits = IP_ADDR_BITS;
|
||||
n /= sizeof(*rtentries);
|
||||
ret = 0;
|
||||
|
||||
@@ -157,6 +156,9 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
rtentries[i].Type != NMREMOTE)
|
||||
continue;
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
entry.route_dst.addr_type = entry.route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_dst.addr_bits = entry.route_gw.addr_bits = IP_ADDR_BITS;
|
||||
entry.route_dst.addr_ip = rtentries[i].Dest;
|
||||
addr_mtob(&rtentries[i].Mask, IP_ADDR_LEN,
|
||||
&entry.route_dst.addr_bits);
|
||||
|
||||
@@ -194,6 +194,7 @@ route_get(route_t *r, struct route_entry *entry)
|
||||
|
||||
while (RTA_OK(rta, i)) {
|
||||
if (rta->rta_type == RTA_GATEWAY) {
|
||||
entry->intf_name[0] = '\0';
|
||||
entry->route_gw.addr_type = entry->route_dst.addr_type;
|
||||
memcpy(entry->route_gw.addr_data8, RTA_DATA(rta), alen);
|
||||
entry->route_gw.addr_bits = alen * 8;
|
||||
@@ -228,6 +229,8 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
if (i < 11 || !(iflags & RTF_UP))
|
||||
continue;
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
entry.route_dst.addr_type = entry.route_gw.addr_type =
|
||||
ADDR_TYPE_IP;
|
||||
|
||||
@@ -259,6 +262,8 @@ route_loop(route_t *r, route_handler callback, void *arg)
|
||||
if (i < 21 || !(iflags & RTF_UP))
|
||||
continue;
|
||||
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s:%s:%s:%s:%s:%s:%s:%s/%d",
|
||||
d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
|
||||
dlen);
|
||||
|
||||
@@ -115,6 +115,7 @@ route_get(route_t *route, struct route_entry *entry)
|
||||
}
|
||||
addr_btom(entry->route_dst.addr_bits, &mask, IP_ADDR_LEN);
|
||||
|
||||
entry->intf_name[0] = '\0';
|
||||
entry->route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry->route_gw.addr_bits = IP_ADDR_BITS;
|
||||
entry->route_gw.addr_ip = ipfrow.dwForwardNextHop;
|
||||
@@ -139,13 +140,16 @@ route_loop_getipforwardtable(route_t *r, route_handler callback, void *arg)
|
||||
else if (ret != ERROR_INSUFFICIENT_BUFFER)
|
||||
return (-1);
|
||||
}
|
||||
entry.route_dst.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_dst.addr_bits = IP_ADDR_BITS;
|
||||
|
||||
entry.route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_gw.addr_bits = IP_ADDR_BITS;
|
||||
|
||||
for (i = 0; i < (int)r->ipftable->dwNumEntries; i++) {
|
||||
entry.intf_name[0] = '\0';
|
||||
|
||||
entry.route_dst.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_dst.addr_bits = IP_ADDR_BITS;
|
||||
|
||||
entry.route_gw.addr_type = ADDR_TYPE_IP;
|
||||
entry.route_gw.addr_bits = IP_ADDR_BITS;
|
||||
|
||||
entry.route_dst.addr_ip = r->ipftable->table[i].dwForwardDest;
|
||||
addr_mtob(&r->ipftable->table[i].dwForwardMask, IP_ADDR_LEN,
|
||||
&entry.route_dst.addr_bits);
|
||||
@@ -174,6 +178,7 @@ route_loop_getipforwardtable2(GETIPFORWARDTABLE2 GetIpForwardTable2,
|
||||
MIB_IPFORWARD_ROW2 *row;
|
||||
|
||||
row = &r->ipftable2->Table[i];
|
||||
entry.intf_name[0] = '\0';
|
||||
addr_ston((struct sockaddr *) &row->DestinationPrefix.Prefix, &entry.route_dst);
|
||||
entry.route_dst.addr_bits = row->DestinationPrefix.PrefixLength;
|
||||
addr_ston((struct sockaddr *) &row->NextHop, &entry.route_gw);
|
||||
|
||||
Reference in New Issue
Block a user