Cache the last result from if_indextoname for printing. This speeds up
"arp -an" when using a lot of aliases (on a single interface). A better fix would include a better interface for if_indextoname than getting the whole address list from the kernel just to find the one index->name mapping. Reported & analyzed by: Nick Rogers MFC after: 3 days
This commit is contained in:
parent
1bdfff2252
commit
e78c7a0a9a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=209063
@ -555,6 +555,9 @@ 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,
|
||||||
struct sockaddr_inarp *addr, struct rt_msghdr *rtm)
|
struct sockaddr_inarp *addr, struct rt_msghdr *rtm)
|
||||||
@ -562,7 +565,6 @@ 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;
|
||||||
char ifname[IF_NAMESIZE];
|
|
||||||
int seg;
|
int seg;
|
||||||
|
|
||||||
if (nflag == 0)
|
if (nflag == 0)
|
||||||
@ -591,8 +593,12 @@ print_entry(struct sockaddr_dl *sdl,
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
printf("(incomplete)");
|
printf("(incomplete)");
|
||||||
if (if_indextoname(sdl->sdl_index, ifname) != NULL)
|
if (sdl->sdl_index != lifindex &&
|
||||||
printf(" on %s", ifname);
|
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);
|
||||||
if (rtm->rtm_rmx.rmx_expire == 0)
|
if (rtm->rtm_rmx.rmx_expire == 0)
|
||||||
printf(" permanent");
|
printf(" permanent");
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user