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:
parent
14fcb4b4f8
commit
c1ed96c2bb
@ -104,6 +104,8 @@ static char *rifname;
|
|||||||
static time_t expire_time;
|
static time_t expire_time;
|
||||||
static int flags, doing_proxy;
|
static int flags, doing_proxy;
|
||||||
|
|
||||||
|
struct if_nameindex *ifnameindex;
|
||||||
|
|
||||||
/* which function we're supposed to do */
|
/* which function we're supposed to do */
|
||||||
#define F_GET 1
|
#define F_GET 1
|
||||||
#define F_SET 2
|
#define F_SET 2
|
||||||
@ -200,6 +202,9 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ifnameindex != NULL)
|
||||||
|
if_freenameindex(ifnameindex);
|
||||||
|
|
||||||
return (rtn);
|
return (rtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,8 +563,6 @@ search(u_long addr, action_fn *action)
|
|||||||
/*
|
/*
|
||||||
* Display an arp entry
|
* Display an arp entry
|
||||||
*/
|
*/
|
||||||
static char lifname[IF_NAMESIZE];
|
|
||||||
static int64_t lifindex = -1;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_entry(struct sockaddr_dl *sdl,
|
print_entry(struct sockaddr_dl *sdl,
|
||||||
@ -568,8 +571,13 @@ print_entry(struct sockaddr_dl *sdl,
|
|||||||
const char *host;
|
const char *host;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct iso88025_sockaddr_dl_data *trld;
|
struct iso88025_sockaddr_dl_data *trld;
|
||||||
|
struct if_nameindex *p;
|
||||||
int seg;
|
int seg;
|
||||||
|
|
||||||
|
if (ifnameindex == NULL)
|
||||||
|
if ((ifnameindex = if_nameindex()) == NULL)
|
||||||
|
err(1, "cannot retrieve interface names");
|
||||||
|
|
||||||
if (nflag == 0)
|
if (nflag == 0)
|
||||||
hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
|
hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
|
||||||
sizeof addr->sin_addr, AF_INET);
|
sizeof addr->sin_addr, AF_INET);
|
||||||
@ -596,12 +604,15 @@ print_entry(struct sockaddr_dl *sdl,
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
printf("(incomplete)");
|
printf("(incomplete)");
|
||||||
if (sdl->sdl_index != lifindex &&
|
|
||||||
if_indextoname(sdl->sdl_index, lifname) != NULL) {
|
for (p = ifnameindex; p && ifnameindex->if_index &&
|
||||||
lifindex = sdl->sdl_index;
|
ifnameindex->if_name; p++) {
|
||||||
printf(" on %s", lifname);
|
if (p->if_index == sdl->sdl_index) {
|
||||||
} else if (sdl->sdl_index == lifindex)
|
printf(" on %s", p->if_name);
|
||||||
printf(" on %s", lifname);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (rtm->rtm_rmx.rmx_expire == 0)
|
if (rtm->rtm_rmx.rmx_expire == 0)
|
||||||
printf(" permanent");
|
printf(" permanent");
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user