Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2010 23:21:05 +0200
From:      Max Laier <max@love2party.net>
To:        freebsd-hackers@freebsd.org
Cc:        Nick Rogers <ncrogers@gmail.com>
Subject:   Re: arp(8) performance w/ many aliases assigned to an interface
Message-ID:  <201006092321.05453.max@love2party.net>
In-Reply-To: <AANLkTikLZCREKNUdon_kRHtzvPkk-XbbXF9ghUuBjoGw@mail.gmail.com>
References:  <AANLkTikLZCREKNUdon_kRHtzvPkk-XbbXF9ghUuBjoGw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--Boundary-00=_BXAEMBK+l1397lG
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello Nick,

On Wednesday 09 June 2010 20:17:43 Nick Rogers wrote:
> Is there something that can be done to speedup the call to
> if_indextoname(), or would it be worthwhile for me to submit a patch that
> adds the ability to skip the interface lookup as an arp(8) option?

how about the attached:

# time arp -an > /dev/null
0.171u 0.462s 0:00.63 100.0%    21+1538k 0+0io 0pf+0w
# time arp.patched -an > /dev/null
0.005u 0.000s 0:00.00 0.0%      0+0k 0+0io 0pf+0w

# arp -an | wc -l
    1095

I'll commit this soon unless somebody objects.

Thanks for your report.
  Max

--Boundary-00=_BXAEMBK+l1397lG
Content-Type: text/x-patch; charset="ISO-8859-1"; name="arp_cache_ifname.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="arp_cache_ifname.diff"

diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
index a0e228c..cc4d383 100644
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -555,6 +555,9 @@ search(u_long addr, action_fn *action)
 /*
  * Display an arp entry
  */
+static char lifname[IF_NAMESIZE];
+static long lifindex = -1;
+
 static void
 print_entry(struct sockaddr_dl *sdl,
 	struct sockaddr_inarp *addr, struct rt_msghdr *rtm)
@@ -562,7 +565,6 @@ print_entry(struct sockaddr_dl *sdl,
 	const char *host;
 	struct hostent *hp;
 	struct iso88025_sockaddr_dl_data *trld;
-	char ifname[IF_NAMESIZE];
 	int seg;
 
 	if (nflag == 0)
@@ -591,8 +593,12 @@ print_entry(struct sockaddr_dl *sdl,
 		}
 	} else
 		printf("(incomplete)");
-	if (if_indextoname(sdl->sdl_index, ifname) != NULL)
-		printf(" on %s", ifname);
+	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);
 	if (rtm->rtm_rmx.rmx_expire == 0)
 		printf(" permanent");
 	else {

--Boundary-00=_BXAEMBK+l1397lG--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006092321.05453.max>