Date: Sat, 5 Apr 2014 22:13:32 +0000 (UTC) From: "George V. Neville-Neil" <gnn@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264174 - head/usr.sbin/arp Message-ID: <201404052213.s35MDWoE015677@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gnn Date: Sat Apr 5 22:13:32 2014 New Revision: 264174 URL: http://svnweb.freebsd.org/changeset/base/264174 Log: 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 Modified: head/usr.sbin/arp/arp.c Modified: head/usr.sbin/arp/arp.c ============================================================================== --- head/usr.sbin/arp/arp.c Sat Apr 5 20:44:52 2014 (r264173) +++ head/usr.sbin/arp/arp.c Sat Apr 5 22:13:32 2014 (r264174) @@ -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 {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404052213.s35MDWoE015677>