From owner-svn-src-all@FreeBSD.ORG Fri Jun 11 19:35:05 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6A2891065673; Fri, 11 Jun 2010 19:35:05 +0000 (UTC) (envelope-from mlaier@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5A29D8FC0A; Fri, 11 Jun 2010 19:35:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o5BJZ5vv069574; Fri, 11 Jun 2010 19:35:05 GMT (envelope-from mlaier@svn.freebsd.org) Received: (from mlaier@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o5BJZ55T069572; Fri, 11 Jun 2010 19:35:05 GMT (envelope-from mlaier@svn.freebsd.org) Message-Id: <201006111935.o5BJZ55T069572@svn.freebsd.org> From: Max Laier Date: Fri, 11 Jun 2010 19:35:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209063 - head/usr.sbin/arp X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jun 2010 19:35:05 -0000 Author: mlaier Date: Fri Jun 11 19:35:05 2010 New Revision: 209063 URL: http://svn.freebsd.org/changeset/base/209063 Log: 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 Modified: head/usr.sbin/arp/arp.c Modified: head/usr.sbin/arp/arp.c ============================================================================== --- head/usr.sbin/arp/arp.c Fri Jun 11 19:27:21 2010 (r209062) +++ head/usr.sbin/arp/arp.c Fri Jun 11 19:35:05 2010 (r209063) @@ -555,6 +555,9 @@ 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, 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 {