Subject: Re: Bad things with NetBSD and IP
To: gabriel rosenkoetter <gr@eclipsed.net>
From: Andrew Brown <atatat@atatdot.net>
List: current-users
Date: 04/13/2001 15:37:36
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
>> How do you flush the ARP tables???
>
>Presuming a Bourne-derived shell:
>
># for i in `arp -a | awk '{ print $1 }'`; do arp -d ${i} ; done
>
>(Yes, arp really ought to have a flush. No, it doesn't seem to. Note
>the hash above. Yes, you must be root to use arp -d.)
# arp -na | awk '{gsub("[()]","",$2);print$2}' | xargs -n1 arp -vd
for something less shell-centric.
for arp(8), i add the -D option with the attached patch. anyone mind
if it gets committed?
(-D because -f is already taken)
--
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org * "ah! i see you have the internet
twofsonet@graffiti.com (Andrew Brown) that goes *ping*!"
andrew@crossbar.com * "information is power -- share the wealth."
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="arp.patch"
Index: arp.8
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/arp/arp.8,v
retrieving revision 1.11
diff -u -r1.11 arp.8
--- arp.8 1999/03/22 18:43:48 1.11
+++ arp.8 2001/04/13 19:32:49
@@ -50,6 +50,9 @@
.Op Fl v
.Fl d Ar hostname
.Nm ""
+.Op Fl v
+.Fl D
+.Nm ""
.Fl s Ar hostname ether_addr
.Op Ar temp
.Op Ar pub
@@ -80,6 +83,8 @@
with the
.Fl d
flag.
+.It Fl D
+A super-user may delete all entries from the arp table.
.It Fl n
Show network addresses as numbers (normally
.Nm
Index: arp.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/arp/arp.c,v
retrieving revision 1.29
diff -u -r1.29 arp.c
--- arp.c 2001/03/19 19:49:30 1.29
+++ arp.c 2001/04/13 19:32:50
@@ -85,6 +85,7 @@
int delete __P((const char *, const char *));
void dump __P((u_long));
+void delete_all __P((void));
void sdl_print __P((const struct sockaddr_dl *));
int getifname __P((u_int16_t, char *));
int atosdl __P((const char *s, struct sockaddr_dl *sdl));
@@ -117,12 +118,13 @@
pid = getpid();
progname = ((progname = strrchr(argv[0], '/')) ? progname + 1 : argv[0]);
- while ((ch = getopt(argc, argv, "andsfv")) != -1)
+ while ((ch = getopt(argc, argv, "andsfvD")) != -1)
switch((char)ch) {
case 'a':
case 'd':
case 's':
case 'f':
+ case 'D':
if (op)
usage();
op = ch;
@@ -156,6 +158,11 @@
if (argc != 1)
usage();
return (file(argv[0]));
+ case 'D':
+ if (argc != 0)
+ usage();
+ delete_all();
+ break;
default:
if (argc != 1)
usage();
@@ -455,6 +462,45 @@
(void)printf("(weird)");
}
(void)printf("\n");
+ }
+}
+
+/*
+ * Delete the entire arp table
+ */
+void
+delete_all(void)
+{
+ int mib[6];
+ size_t needed;
+ char addr[sizeof("000.000.000.000\0")];
+ char *lim, *buf, *next;
+ struct rt_msghdr *rtm;
+ struct sockaddr_inarp *sin;
+ struct sockaddr_dl *sdl;
+
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_INET;
+ mib[4] = NET_RT_FLAGS;
+ mib[5] = RTF_LLINFO;
+ if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ err(1, "route-sysctl-estimate");
+ if (needed == 0)
+ return;
+ if ((buf = malloc(needed)) == NULL)
+ err(1, "malloc");
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ err(1, "actual retrieval of routing table");
+ lim = buf + needed;
+ for (next = buf; next < lim; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)next;
+ sin = (struct sockaddr_inarp *)(rtm + 1);
+ sdl = (struct sockaddr_dl *)
+ (ROUNDUP(sin->sin_len) + (char *)sin);
+ snprintf(addr, sizeof(addr), "%s", inet_ntoa(sin->sin_addr));
+ delete(addr, NULL);
}
}
--X1bOJ3K7DJ5YkBrT--