From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 17 06:40:16 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2273A37B585 for ; Thu, 17 Jul 2003 06:40:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 90E1C43FAF for ; Thu, 17 Jul 2003 06:40:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h6HDeFUp030999 for ; Thu, 17 Jul 2003 06:40:15 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6HDeFbg030998; Thu, 17 Jul 2003 06:40:15 -0700 (PDT) Date: Thu, 17 Jul 2003 06:40:15 -0700 (PDT) Message-Id: <200307171340.h6HDeFbg030998@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Yar Tikhiy Subject: Re: bin/54151: [PATCH] -i (restrict to one interface) patch from arp(8) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Yar Tikhiy List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2003 13:40:16 -0000 The following reply was made to PR bin/54151; it has been noted by GNATS. From: Yar Tikhiy To: freebsd-gnats-submit@FreeBSD.org, marck@rinet.ru Cc: Subject: Re: bin/54151: [PATCH] -i (restrict to one interface) patch from arp(8) Date: Thu, 17 Jul 2003 17:35:56 +0400 The feature you've proposed looks really juicy to me so long as there's a router between numerous VLANs under my management, too. I've introduced some changes into your patch to improve its style and language. One of my points is using if_nametoindex(3) to check if an interface does exist, instead of all that code around sysctl(2). Could you please confirm my version of the patch works for you? -- Yar Index: arp.8 =================================================================== RCS file: /home/ncvs/src/usr.sbin/arp/arp.8,v retrieving revision 1.20 diff -u -p -r1.20 arp.8 --- arp.8 27 Dec 2002 10:09:04 -0000 1.20 +++ arp.8 17 Jul 2003 13:30:20 -0000 @@ -41,9 +41,11 @@ .Sh SYNOPSIS .Nm .Op Fl n +.Op Fl i Ar interface .Ar hostname .Nm .Op Fl n +.Op Fl i Ar interface .Fl a .Nm .Fl d Ar hostname @@ -99,6 +101,12 @@ Alternatively, the flag may be combined with the .Fl a flag to delete all entries. +.It Fl i Ar interface +Limit the operation scope to the +.Tn ARP +entries on +.Ar interface . +Applicable to the display operations only. .It Fl n Show network addresses as numbers (normally .Nm Index: arp.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/arp/arp.c,v retrieving revision 1.45 diff -u -p -r1.45 arp.c --- arp.c 3 May 2003 21:06:35 -0000 1.45 +++ arp.c 17 Jul 2003 13:30:20 -0000 @@ -104,6 +104,7 @@ static pid_t pid; static int nflag; /* no reverse dns lookups */ static int aflag; /* do it for all entries */ static int s = -1; +static char *rifname; struct sockaddr_in so_mask; struct sockaddr_inarp blank_sin, sin_m; @@ -132,7 +133,7 @@ main(int argc, char *argv[]) int rtn = 0; pid = getpid(); - while ((ch = getopt(argc, argv, "andfsS")) != -1) + while ((ch = getopt(argc, argv, "andfsSi:")) != -1) switch((char)ch) { case 'a': aflag = 1; @@ -152,6 +153,9 @@ main(int argc, char *argv[]) case 'f' : SETFUNC(F_FILESET); break; + case 'i': + rifname = optarg; + break; case '?': default: usage(); @@ -171,6 +175,16 @@ main(int argc, char *argv[]) if (!func) func = F_GET; + if (rifname) { + if (func != F_GET) + errx(1, "-i not applicable to this operation"); + if (if_nametoindex(rifname) == 0) { + if (errno == ENXIO) + errx(1, "interface %s does not exist", rifname); + else + err(1, "if_nametoindex(%s)", rifname); + } + } switch (func) { case F_GET: if (aflag) { @@ -376,8 +390,11 @@ get(char *host) } search(addr->sin_addr.s_addr, print_entry); if (found_entry == 0) { - printf("%s (%s) -- no entry\n", + printf("%s (%s) -- no entry", host, inet_ntoa(addr->sin_addr)); + if (rifname) + printf(" on %s", rifname); + printf("\n"); return(1); } return(0); @@ -459,6 +476,7 @@ search(u_long addr, void (*action)(struc struct rt_msghdr *rtm; struct sockaddr_inarp *sin2; struct sockaddr_dl *sdl; + char ifname[IFNAMSIZ]; mib[0] = CTL_NET; mib[1] = PF_ROUTE; @@ -477,6 +495,9 @@ search(u_long addr, void (*action)(struc rtm = (struct rt_msghdr *)next; sin2 = (struct sockaddr_inarp *)(rtm + 1); (char *)sdl = (char *)sin2 + ROUNDUP(sin2->sin_len); + if (rifname && if_indextoname(sdl->sdl_index, ifname) != NULL && + strcmp(ifname, rifname)) + continue; if (addr) { if (addr != sin2->sin_addr.s_addr) continue; @@ -593,8 +614,8 @@ void usage(void) { fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: arp [-n] hostname", - " arp [-n] -a", + "usage: arp [-n] [-i ifname] hostname", + " arp [-n] [-i ifname] -a", " arp -d hostname [pub]", " arp -d -a", " arp -s hostname ether_addr [temp] [pub]",