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
This commit is contained in:
George V. Neville-Neil 2014-04-05 22:13:32 +00:00
parent 14fcb4b4f8
commit c1ed96c2bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264174

View File

@ -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 {