diff options
author | gnn <gnn@FreeBSD.org> | 2014-04-05 22:13:32 +0000 |
---|---|---|
committer | gnn <gnn@FreeBSD.org> | 2014-04-05 22:13:32 +0000 |
commit | d1d0c789012efc4677f6b17c22123297875113ff (patch) | |
tree | 4c4fb6d38f2f3546767ece9f65c3e52ab353432e /usr.sbin | |
parent | e62844041e1cc501a851c12d335d5bf77e02f898 (diff) | |
download | FreeBSD-src-d1d0c789012efc4677f6b17c22123297875113ff.zip FreeBSD-src-d1d0c789012efc4677f6b17c22123297875113ff.tar.gz |
Speed up the lookup of interfaces when there are a large number
of them, such in a system with a large number of VLANs.
Submitted by: Nick Rogers
MFC after: 2 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/arp/arp.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c index 25fbb23..932ac95 100644 --- a/usr.sbin/arp/arp.c +++ b/usr.sbin/arp/arp.c @@ -104,6 +104,8 @@ static char *rifname; static time_t expire_time; static int flags, doing_proxy; +struct if_nameindex *ifnameindex; + /* which function we're supposed to do */ #define F_GET 1 #define F_SET 2 @@ -200,6 +202,9 @@ main(int argc, char *argv[]) break; } + if (ifnameindex != NULL) + if_freenameindex(ifnameindex); + return (rtn); } @@ -558,8 +563,6 @@ search(u_long addr, action_fn *action) /* * Display an arp entry */ -static char lifname[IF_NAMESIZE]; -static int64_t lifindex = -1; static void print_entry(struct sockaddr_dl *sdl, @@ -568,8 +571,13 @@ print_entry(struct sockaddr_dl *sdl, const char *host; struct hostent *hp; struct iso88025_sockaddr_dl_data *trld; + struct if_nameindex *p; int seg; + if (ifnameindex == NULL) + if ((ifnameindex = if_nameindex()) == NULL) + err(1, "cannot retrieve interface names"); + if (nflag == 0) hp = gethostbyaddr((caddr_t)&(addr->sin_addr), sizeof addr->sin_addr, AF_INET); @@ -596,12 +604,15 @@ print_entry(struct sockaddr_dl *sdl, } } else printf("(incomplete)"); - if (sdl->sdl_index != lifindex && - if_indextoname(sdl->sdl_index, lifname) != NULL) { - lifindex = sdl->sdl_index; - printf(" on %s", lifname); - } else if (sdl->sdl_index == lifindex) - printf(" on %s", lifname); + + for (p = ifnameindex; p && ifnameindex->if_index && + ifnameindex->if_name; p++) { + if (p->if_index == sdl->sdl_index) { + printf(" on %s", p->if_name); + break; + } + } + if (rtm->rtm_rmx.rmx_expire == 0) printf(" permanent"); else { |