if_arp.c revision 1.77 1 /* $NetBSD: if_arp.c,v 1.77 2001/08/17 21:47:57 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Public Access Networks Corporation ("Panix"). It was developed under
9 * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1982, 1986, 1988, 1993
42 * The Regents of the University of California. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by the University of
55 * California, Berkeley and its contributors.
56 * 4. Neither the name of the University nor the names of its contributors
57 * may be used to endorse or promote products derived from this software
58 * without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 * @(#)if_ether.c 8.2 (Berkeley) 9/26/94
73 */
74
75 /*
76 * Ethernet address resolution protocol.
77 * TODO:
78 * add "inuse/lock" bit (or ref. count) along with valid bit
79 */
80
81 #include "opt_ddb.h"
82 #include "opt_inet.h"
83
84 #ifdef INET
85
86 #include "bridge.h"
87
88 #include <sys/param.h>
89 #include <sys/systm.h>
90 #include <sys/callout.h>
91 #include <sys/malloc.h>
92 #include <sys/mbuf.h>
93 #include <sys/socket.h>
94 #include <sys/time.h>
95 #include <sys/kernel.h>
96 #include <sys/errno.h>
97 #include <sys/ioctl.h>
98 #include <sys/syslog.h>
99 #include <sys/proc.h>
100 #include <sys/protosw.h>
101 #include <sys/domain.h>
102
103 #include <net/ethertypes.h>
104 #include <net/if.h>
105 #include <net/if_dl.h>
106 #include <net/if_token.h>
107 #include <net/if_types.h>
108 #include <net/route.h>
109
110
111 #include <netinet/in.h>
112 #include <netinet/in_systm.h>
113 #include <netinet/in_var.h>
114 #include <netinet/ip.h>
115 #include <netinet/if_inarp.h>
116
117 #include "loop.h"
118 #include "arc.h"
119 #if NARC > 0
120 #include <net/if_arc.h>
121 #endif
122 #include "fddi.h"
123 #if NFDDI > 0
124 #include <net/if_fddi.h>
125 #endif
126 #include "token.h"
127 #include "token.h"
128
129 #define SIN(s) ((struct sockaddr_in *)s)
130 #define SDL(s) ((struct sockaddr_dl *)s)
131 #define SRP(s) ((struct sockaddr_inarp *)s)
132
133 /*
134 * ARP trailer negotiation. Trailer protocol is not IP specific,
135 * but ARP request/response use IP addresses.
136 */
137 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
138
139 /* timer values */
140 int arpt_prune = (5*60*1); /* walk list every 5 minutes */
141 int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
142 int arpt_down = 20; /* once declared down, don't send for 20 secs */
143 #define rt_expire rt_rmx.rmx_expire
144
145 static void arprequest __P((struct ifnet *,
146 struct in_addr *, struct in_addr *, u_int8_t *));
147 static void arptfree __P((struct llinfo_arp *));
148 static void arptimer __P((void *));
149 static struct llinfo_arp *arplookup __P((struct mbuf *, struct in_addr *,
150 int, int));
151 static void in_arpinput __P((struct mbuf *));
152
153 #if NLOOP > 0
154 extern struct ifnet loif[NLOOP];
155 #endif
156 LIST_HEAD(, llinfo_arp) llinfo_arp;
157 struct ifqueue arpintrq = {0, 0, 0, 50};
158 int arp_inuse, arp_allocated, arp_intimer;
159 int arp_maxtries = 5;
160 int useloopback = 1; /* use loopback interface for local traffic */
161 int arpinit_done = 0;
162
163 struct arpstat arpstat;
164 struct callout arptimer_ch;
165
166
167 /* revarp state */
168 static struct in_addr myip, srv_ip;
169 static int myip_initialized = 0;
170 static int revarp_in_progress = 0;
171 static struct ifnet *myip_ifp = NULL;
172
173 #ifdef DDB
174 static void db_print_sa __P((struct sockaddr *));
175 static void db_print_ifa __P((struct ifaddr *));
176 static void db_print_llinfo __P((caddr_t));
177 static int db_show_radix_node __P((struct radix_node *, void *));
178 #endif
179
180 /*
181 * this should be elsewhere.
182 */
183
184 static char *
185 lla_snprintf __P((u_int8_t *, int));
186
187 static char *
188 lla_snprintf(adrp, len)
189 u_int8_t *adrp;
190 int len;
191 {
192 #define NUMBUFS 3
193 static char buf[NUMBUFS][16*3];
194 static int bnum = 0;
195 static const char hexdigits[] = {
196 '0','1','2','3','4','5','6','7',
197 '8','9','a','b','c','d','e','f'
198 };
199
200 int i;
201 char *p;
202
203 p = buf[bnum];
204
205 *p++ = hexdigits[(*adrp)>>4];
206 *p++ = hexdigits[(*adrp++)&0xf];
207
208 for (i=1; i<len && i<16; i++) {
209 *p++ = ':';
210 *p++ = hexdigits[(*adrp)>>4];
211 *p++ = hexdigits[(*adrp++)&0xf];
212 }
213
214 *p = 0;
215 p = buf[bnum];
216 bnum = (bnum + 1) % NUMBUFS;
217 return p;
218 }
219
220 struct protosw arpsw[] = {
221 { 0, 0, 0, 0,
222 0, 0, 0, 0,
223 0,
224 0, 0, 0, arp_drain,
225 }
226 };
227
228
229 struct domain arpdomain =
230 { PF_ARP, "arp", 0, 0, 0,
231 arpsw, &arpsw[sizeof(arpsw)/sizeof(arpsw[0])]
232 };
233
234 /*
235 * ARP table locking.
236 *
237 * to prevent lossage vs. the arp_drain routine (which may be called at
238 * any time, including in a device driver context), we do two things:
239 *
240 * 1) manipulation of la->la_hold is done at splnet() (for all of
241 * about two instructions).
242 *
243 * 2) manipulation of the arp table's linked list is done under the
244 * protection of the ARP_LOCK; if arp_drain() or arptimer is called
245 * while the arp table is locked, we punt and try again later.
246 */
247
248 int arp_locked;
249
250 static __inline int arp_lock_try __P((int));
251 static __inline void arp_unlock __P((void));
252
253 static __inline int
254 arp_lock_try(int recurse)
255 {
256 int s;
257
258 /*
259 * Use splvm() -- we're blocking things that would cause
260 * mbuf allocation.
261 */
262 s = splvm();
263 if (!recurse && arp_locked) {
264 splx(s);
265 return (0);
266 }
267 arp_locked++;
268 splx(s);
269 return (1);
270 }
271
272 static __inline void
273 arp_unlock()
274 {
275 int s;
276
277 s = splvm();
278 arp_locked--;
279 splx(s);
280 }
281
282 #ifdef DIAGNOSTIC
283 #define ARP_LOCK(recurse) \
284 do { \
285 if (arp_lock_try(recurse) == 0) { \
286 printf("%s:%d: arp already locked\n", __FILE__, __LINE__); \
287 panic("arp_lock"); \
288 } \
289 } while (0)
290 #define ARP_LOCK_CHECK() \
291 do { \
292 if (arp_locked == 0) { \
293 printf("%s:%d: arp lock not held\n", __FILE__, __LINE__); \
294 panic("arp lock check"); \
295 } \
296 } while (0)
297 #else
298 #define ARP_LOCK(x) (void) arp_lock_try(x)
299 #define ARP_LOCK_CHECK() /* nothing */
300 #endif
301
302 #define ARP_UNLOCK() arp_unlock()
303
304 /*
305 * ARP protocol drain routine. Called when memory is in short supply.
306 * Called at splvm();
307 */
308
309 void
310 arp_drain()
311 {
312 struct llinfo_arp *la, *nla;
313 int count = 0;
314 struct mbuf *mold;
315
316 if (arp_lock_try(0) == 0) {
317 printf("arp_drain: locked; punting\n");
318 return;
319 }
320
321 for (la = LIST_FIRST(&llinfo_arp); la != 0; la = nla) {
322 nla = LIST_NEXT(la, la_list);
323
324 mold = la->la_hold;
325 la->la_hold = 0;
326
327 if (mold) {
328 m_freem(mold);
329 count++;
330 }
331 }
332 ARP_UNLOCK();
333 arpstat.as_dfrdropped += count;
334 }
335
336
337 /*
338 * Timeout routine. Age arp_tab entries periodically.
339 */
340 /* ARGSUSED */
341 static void
342 arptimer(arg)
343 void *arg;
344 {
345 int s;
346 struct llinfo_arp *la, *nla;
347
348 s = splsoftnet();
349
350 if (arp_lock_try(0) == 0) {
351 /* get it later.. */
352 splx(s);
353 return;
354 }
355
356 callout_reset(&arptimer_ch, arpt_prune * hz, arptimer, NULL);
357 for (la = LIST_FIRST(&llinfo_arp); la != 0; la = nla) {
358 struct rtentry *rt = la->la_rt;
359
360 nla = LIST_NEXT(la, la_list);
361 if (rt->rt_expire && rt->rt_expire <= time.tv_sec)
362 arptfree(la); /* timer has expired; clear */
363 }
364
365 ARP_UNLOCK();
366
367 splx(s);
368 }
369
370 /*
371 * Parallel to llc_rtrequest.
372 */
373 void
374 arp_rtrequest(req, rt, info)
375 int req;
376 struct rtentry *rt;
377 struct rt_addrinfo *info;
378 {
379 struct sockaddr *gate = rt->rt_gateway;
380 struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
381 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
382 size_t allocsize;
383 struct mbuf *mold;
384 int s;
385 struct in_ifaddr *ia;
386 struct ifaddr *ifa;
387
388 if (!arpinit_done) {
389 arpinit_done = 1;
390 /*
391 * We generate expiration times from time.tv_sec
392 * so avoid accidently creating permanent routes.
393 */
394 if (time.tv_sec == 0) {
395 time.tv_sec++;
396 }
397 callout_init(&arptimer_ch);
398 callout_reset(&arptimer_ch, hz, arptimer, NULL);
399 }
400 if (rt->rt_flags & RTF_GATEWAY)
401 return;
402
403 ARP_LOCK(1); /* we may already be locked here. */
404
405 switch (req) {
406
407 case RTM_ADD:
408 /*
409 * XXX: If this is a manually added route to interface
410 * such as older version of routed or gated might provide,
411 * restore cloning bit.
412 */
413 if ((rt->rt_flags & RTF_HOST) == 0 &&
414 SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
415 rt->rt_flags |= RTF_CLONING;
416 if (rt->rt_flags & RTF_CLONING) {
417 /*
418 * Case 1: This route should come from a route to iface.
419 */
420 rt_setgate(rt, rt_key(rt),
421 (struct sockaddr *)&null_sdl);
422 gate = rt->rt_gateway;
423 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
424 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
425 /*
426 * Give this route an expiration time, even though
427 * it's a "permanent" route, so that routes cloned
428 * from it do not need their expiration time set.
429 */
430 rt->rt_expire = time.tv_sec;
431 #if NFDDI > 0
432 if (rt->rt_ifp->if_type == IFT_FDDI
433 && (rt->rt_rmx.rmx_mtu > FDDIIPMTU
434 || (rt->rt_rmx.rmx_mtu == 0
435 && rt->rt_ifp->if_mtu > FDDIIPMTU))) {
436 rt->rt_rmx.rmx_mtu = FDDIIPMTU;
437 }
438 #endif
439 #if NARC > 0
440 if (rt->rt_ifp->if_type == IFT_ARCNET) {
441 int arcipifmtu;
442
443 if (rt->rt_ifp->if_flags & IFF_LINK0)
444 arcipifmtu = arc_ipmtu;
445 else
446 arcipifmtu = ARCMTU;
447
448 if (rt->rt_rmx.rmx_mtu > arcipifmtu ||
449 (rt->rt_rmx.rmx_mtu == 0 &&
450 rt->rt_ifp->if_mtu > arcipifmtu))
451
452 rt->rt_rmx.rmx_mtu = arcipifmtu;
453 }
454 #endif
455 break;
456 }
457 /* Announce a new entry if requested. */
458 if (rt->rt_flags & RTF_ANNOUNCE)
459 arprequest(rt->rt_ifp,
460 &SIN(rt_key(rt))->sin_addr,
461 &SIN(rt_key(rt))->sin_addr,
462 (u_char *)LLADDR(SDL(gate)));
463 /*FALLTHROUGH*/
464 case RTM_RESOLVE:
465 if (gate->sa_family != AF_LINK ||
466 gate->sa_len < sizeof(null_sdl)) {
467 log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
468 break;
469 }
470 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
471 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
472 if (la != 0)
473 break; /* This happens on a route change */
474 /*
475 * Case 2: This route may come from cloning, or a manual route
476 * add with a LL address.
477 */
478 switch (SDL(gate)->sdl_type) {
479 #if NTOKEN > 0
480 case IFT_ISO88025:
481 allocsize = sizeof(*la) + sizeof(struct token_rif);
482 break;
483 #endif /* NTOKEN > 0 */
484 default:
485 allocsize = sizeof(*la);
486 }
487 R_Malloc(la, struct llinfo_arp *, allocsize);
488 rt->rt_llinfo = (caddr_t)la;
489 if (la == 0) {
490 log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
491 break;
492 }
493 arp_inuse++, arp_allocated++;
494 Bzero(la, allocsize);
495 la->la_rt = rt;
496 rt->rt_flags |= RTF_LLINFO;
497 LIST_INSERT_HEAD(&llinfo_arp, la, la_list);
498
499 INADDR_TO_IA(SIN(rt_key(rt))->sin_addr, ia);
500 while (ia && ia->ia_ifp != rt->rt_ifp)
501 NEXT_IA_WITH_SAME_ADDR(ia);
502 if (ia) {
503 /*
504 * This test used to be
505 * if (loif.if_flags & IFF_UP)
506 * It allowed local traffic to be forced through
507 * the hardware by configuring the loopback down.
508 * However, it causes problems during network
509 * configuration for boards that can't receive
510 * packets they send. It is now necessary to clear
511 * "useloopback" and remove the route to force
512 * traffic out to the hardware.
513 *
514 * In 4.4BSD, the above "if" statement checked
515 * rt->rt_ifa against rt_key(rt). It was changed
516 * to the current form so that we can provide a
517 * better support for multiple IPv4 addresses on a
518 * interface.
519 */
520 rt->rt_expire = 0;
521 Bcopy(LLADDR(rt->rt_ifp->if_sadl),
522 LLADDR(SDL(gate)),
523 SDL(gate)->sdl_alen =
524 rt->rt_ifp->if_data.ifi_addrlen);
525 #if NLOOP > 0
526 if (useloopback)
527 rt->rt_ifp = &loif[0];
528 #endif
529 /*
530 * make sure to set rt->rt_ifa to the interface
531 * address we are using, otherwise we will have trouble
532 * with source address selection.
533 */
534 ifa = &ia->ia_ifa;
535 if (ifa != rt->rt_ifa) {
536 IFAFREE(rt->rt_ifa);
537 IFAREF(ifa);
538 rt->rt_ifa = ifa;
539 }
540 }
541 break;
542
543 case RTM_DELETE:
544 if (la == 0)
545 break;
546 arp_inuse--;
547 LIST_REMOVE(la, la_list);
548 rt->rt_llinfo = 0;
549 rt->rt_flags &= ~RTF_LLINFO;
550
551 s = splnet();
552 mold = la->la_hold;
553 la->la_hold = 0;
554 splx(s);
555
556 if (mold)
557 m_freem(mold);
558
559 Free((caddr_t)la);
560 }
561 ARP_UNLOCK();
562 }
563
564 /*
565 * Broadcast an ARP request. Caller specifies:
566 * - arp header source ip address
567 * - arp header target ip address
568 * - arp header source ethernet address
569 */
570 static void
571 arprequest(ifp, sip, tip, enaddr)
572 struct ifnet *ifp;
573 struct in_addr *sip, *tip;
574 u_int8_t *enaddr;
575 {
576 struct mbuf *m;
577 struct arphdr *ah;
578 struct sockaddr sa;
579
580 if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
581 return;
582 m->m_len = sizeof(*ah) + 2*sizeof(struct in_addr) +
583 2*ifp->if_data.ifi_addrlen;
584 m->m_pkthdr.len = m->m_len;
585 MH_ALIGN(m, m->m_len);
586 ah = mtod(m, struct arphdr *);
587 bzero((caddr_t)ah, m->m_len);
588 ah->ar_pro = htons(ETHERTYPE_IP);
589 ah->ar_hln = ifp->if_data.ifi_addrlen; /* hardware address length */
590 ah->ar_pln = sizeof(struct in_addr); /* protocol address length */
591 ah->ar_op = htons(ARPOP_REQUEST);
592 bcopy((caddr_t)enaddr, (caddr_t)ar_sha(ah), ah->ar_hln);
593 bcopy((caddr_t)sip, (caddr_t)ar_spa(ah), ah->ar_pln);
594 bcopy((caddr_t)tip, (caddr_t)ar_tpa(ah), ah->ar_pln);
595 sa.sa_family = AF_ARP;
596 sa.sa_len = 2;
597 m->m_flags |= M_BCAST;
598 arpstat.as_sndtotal++;
599 arpstat.as_sndrequest++;
600 (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
601 }
602
603 /*
604 * Resolve an IP address into an ethernet address. If success,
605 * desten is filled in. If there is no entry in arptab,
606 * set one up and broadcast a request for the IP address.
607 * Hold onto this mbuf and resend it once the address
608 * is finally resolved. A return value of 1 indicates
609 * that desten has been filled in and the packet should be sent
610 * normally; a 0 return indicates that the packet has been
611 * taken over here, either now or for later transmission.
612 */
613 int
614 arpresolve(ifp, rt, m, dst, desten)
615 struct ifnet *ifp;
616 struct rtentry *rt;
617 struct mbuf *m;
618 struct sockaddr *dst;
619 u_char *desten;
620 {
621 struct llinfo_arp *la;
622 struct sockaddr_dl *sdl;
623 struct mbuf *mold;
624 int s;
625
626 if (rt)
627 la = (struct llinfo_arp *)rt->rt_llinfo;
628 else {
629 if ((la = arplookup(m, &SIN(dst)->sin_addr, 1, 0)) != NULL)
630 rt = la->la_rt;
631 }
632 if (la == 0 || rt == 0) {
633 arpstat.as_allocfail++;
634 log(LOG_DEBUG,
635 "arpresolve: can't allocate llinfo on %s for %s\n",
636 ifp->if_xname, in_fmtaddr(SIN(dst)->sin_addr));
637 m_freem(m);
638 return (0);
639 }
640 sdl = SDL(rt->rt_gateway);
641 /*
642 * Check the address family and length is valid, the address
643 * is resolved; otherwise, try to resolve.
644 */
645 if ((rt->rt_expire == 0 || rt->rt_expire > time.tv_sec) &&
646 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
647 bcopy(LLADDR(sdl), desten,
648 min(sdl->sdl_alen, ifp->if_data.ifi_addrlen));
649 return 1;
650 }
651 /*
652 * There is an arptab entry, but no ethernet address
653 * response yet. Replace the held mbuf with this
654 * latest one.
655 */
656
657 arpstat.as_dfrtotal++;
658 s = splnet();
659 mold = la->la_hold;
660 la->la_hold = m;
661 splx(s);
662
663 if (mold) {
664 arpstat.as_dfrdropped++;
665 m_freem(mold);
666 }
667
668 /*
669 * Re-send the ARP request when appropriate.
670 */
671 #ifdef DIAGNOSTIC
672 if (rt->rt_expire == 0) {
673 /* This should never happen. (Should it? -gwr) */
674 printf("arpresolve: unresolved and rt_expire == 0\n");
675 /* Set expiration time to now (expired). */
676 rt->rt_expire = time.tv_sec;
677 }
678 #endif
679 if (rt->rt_expire) {
680 rt->rt_flags &= ~RTF_REJECT;
681 if (la->la_asked == 0 || rt->rt_expire != time.tv_sec) {
682 rt->rt_expire = time.tv_sec;
683 if (la->la_asked++ < arp_maxtries)
684 arprequest(ifp,
685 &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
686 &SIN(dst)->sin_addr,
687 LLADDR(ifp->if_sadl));
688 else {
689 rt->rt_flags |= RTF_REJECT;
690 rt->rt_expire += arpt_down;
691 la->la_asked = 0;
692 }
693 }
694 }
695 return (0);
696 }
697
698 /*
699 * Common length and type checks are done here,
700 * then the protocol-specific routine is called.
701 */
702 void
703 arpintr()
704 {
705 struct mbuf *m;
706 struct arphdr *ar;
707 int s;
708
709 while (arpintrq.ifq_head) {
710 s = splnet();
711 IF_DEQUEUE(&arpintrq, m);
712 splx(s);
713 if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
714 panic("arpintr");
715
716 arpstat.as_rcvtotal++;
717
718 if (m->m_len >= sizeof(struct arphdr) &&
719 (ar = mtod(m, struct arphdr *)) &&
720 /* XXX ntohs(ar->ar_hrd) == ARPHRD_ETHER && */
721 m->m_len >=
722 sizeof(struct arphdr) + 2 * (ar->ar_hln + ar->ar_pln))
723 switch (ntohs(ar->ar_pro)) {
724
725 case ETHERTYPE_IP:
726 case ETHERTYPE_IPTRAILERS:
727 in_arpinput(m);
728 continue;
729 default:
730 arpstat.as_rcvbadproto++;
731 }
732 else
733 arpstat.as_rcvbadlen++;
734 m_freem(m);
735 }
736 }
737
738 /*
739 * ARP for Internet protocols on 10 Mb/s Ethernet.
740 * Algorithm is that given in RFC 826.
741 * In addition, a sanity check is performed on the sender
742 * protocol address, to catch impersonators.
743 * We no longer handle negotiations for use of trailer protocol:
744 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
745 * along with IP replies if we wanted trailers sent to us,
746 * and also sent them in response to IP replies.
747 * This allowed either end to announce the desire to receive
748 * trailer packets.
749 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
750 * but formerly didn't normally send requests.
751 */
752 static void
753 in_arpinput(m)
754 struct mbuf *m;
755 {
756 struct arphdr *ah;
757 struct ifnet *ifp = m->m_pkthdr.rcvif;
758 struct llinfo_arp *la = 0;
759 struct rtentry *rt;
760 struct in_ifaddr *ia;
761 #if NBRIDGE > 0
762 struct in_ifaddr *bridge_ia = NULL;
763 #endif
764 struct sockaddr_dl *sdl;
765 struct sockaddr sa;
766 struct in_addr isaddr, itaddr, myaddr;
767 int op;
768 struct mbuf *mold;
769 int s;
770
771 ah = mtod(m, struct arphdr *);
772 op = ntohs(ah->ar_op);
773 bcopy((caddr_t)ar_spa(ah), (caddr_t)&isaddr, sizeof (isaddr));
774 bcopy((caddr_t)ar_tpa(ah), (caddr_t)&itaddr, sizeof (itaddr));
775
776 if (m->m_flags & (M_BCAST|M_MCAST))
777 arpstat.as_rcvmcast++;
778
779 /*
780 * If the target IP address is zero, ignore the packet.
781 * This prevents the code below from tring to answer
782 * when we are using IP address zero (booting).
783 */
784 if (in_nullhost(itaddr)) {
785 arpstat.as_rcvzerotpa++;
786 goto out;
787 }
788
789 /*
790 * If the source IP address is zero, this is most likely a
791 * confused host trying to use IP address zero. (Windoze?)
792 * XXX: Should we bother trying to reply to these?
793 */
794 if (in_nullhost(isaddr)) {
795 arpstat.as_rcvzerospa++;
796 goto out;
797 }
798
799 /*
800 * Search for a matching interface address
801 * or any address on the interface to use
802 * as a dummy address in the rest of this function
803 */
804 INADDR_TO_IA(itaddr, ia);
805 while (ia != NULL) {
806 if (ia->ia_ifp == m->m_pkthdr.rcvif)
807 break;
808
809 #if NBRIDGE > 0
810 /*
811 * If the interface we received the packet on
812 * is part of a bridge, check to see if we need
813 * to "bridge" the packet to ourselves at this
814 * layer. Note we still prefer a perfect match,
815 * but allow this weaker match if necessary.
816 */
817 if (m->m_pkthdr.rcvif->if_bridge != NULL &&
818 m->m_pkthdr.rcvif->if_bridge == ia->ia_ifp->if_bridge)
819 bridge_ia = ia;
820 #endif /* NBRIDGE > 0 */
821
822 NEXT_IA_WITH_SAME_ADDR(ia);
823 }
824
825 #if NBRIDGE > 0
826 if (ia == NULL)
827 ia = bridge_ia;
828 #endif
829
830 if (ia == NULL) {
831 INADDR_TO_IA(isaddr, ia);
832 while ((ia != NULL) && ia->ia_ifp != m->m_pkthdr.rcvif)
833 NEXT_IA_WITH_SAME_ADDR(ia);
834
835 if (ia == NULL) {
836 IFP_TO_IA(ifp, ia);
837 if (ia == NULL) {
838 arpstat.as_rcvnoint++;
839 goto out;
840 }
841 }
842 }
843
844 myaddr = ia->ia_addr.sin_addr;
845
846 if (!bcmp((caddr_t)ar_sha(ah), LLADDR(ifp->if_sadl),
847 ifp->if_data.ifi_addrlen)) {
848 arpstat.as_rcvlocalsha++;
849 goto out; /* it's from me, ignore it. */
850 }
851
852 if (!bcmp((caddr_t)ar_sha(ah), (caddr_t)ifp->if_broadcastaddr,
853 ifp->if_data.ifi_addrlen)) {
854 arpstat.as_rcvbcastsha++;
855 log(LOG_ERR,
856 "%s: arp: link address is broadcast for IP address %s!\n",
857 ifp->if_xname, in_fmtaddr(isaddr));
858 goto out;
859 }
860
861 if (in_hosteq(isaddr, myaddr)) {
862 arpstat.as_rcvlocalspa++;
863 log(LOG_ERR,
864 "duplicate IP address %s sent from link address %s\n",
865 in_fmtaddr(isaddr), lla_snprintf(ar_sha(ah), ah->ar_hln));
866 itaddr = myaddr;
867 goto reply;
868 }
869 la = arplookup(m, &isaddr, in_hosteq(itaddr, myaddr), 0);
870 if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
871 if (sdl->sdl_alen &&
872 bcmp((caddr_t)ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) {
873 if (rt->rt_flags & RTF_STATIC) {
874 arpstat.as_rcvoverperm++;
875 log(LOG_INFO,
876 "%s tried to overwrite permanent arp info"
877 " for %s\n",
878 lla_snprintf(ar_sha(ah), ah->ar_hln),
879 in_fmtaddr(isaddr));
880 goto out;
881 } else if (rt->rt_ifp != ifp) {
882 arpstat.as_rcvoverint++;
883 log(LOG_INFO,
884 "%s on %s tried to overwrite "
885 "arp info for %s on %s\n",
886 lla_snprintf(ar_sha(ah), ah->ar_hln),
887 ifp->if_xname, in_fmtaddr(isaddr),
888 rt->rt_ifp->if_xname);
889 goto out;
890 } else {
891 arpstat.as_rcvover++;
892 log(LOG_INFO,
893 "arp info overwritten for %s by %s\n",
894 in_fmtaddr(isaddr),
895 lla_snprintf(ar_sha(ah), ah->ar_hln));
896 }
897 }
898 /*
899 * sanity check for the address length.
900 * XXX this does not work for protocols with variable address
901 * length. -is
902 */
903 if (sdl->sdl_alen &&
904 sdl->sdl_alen != ah->ar_hln) {
905 arpstat.as_rcvlenchg++;
906 log(LOG_WARNING,
907 "arp from %s: new addr len %d, was %d",
908 in_fmtaddr(isaddr), ah->ar_hln, sdl->sdl_alen);
909 }
910 if (ifp->if_data.ifi_addrlen != ah->ar_hln) {
911 arpstat.as_rcvbadlen++;
912 log(LOG_WARNING,
913 "arp from %s: addr len: new %d, i/f %d (ignored)",
914 in_fmtaddr(isaddr), ah->ar_hln,
915 ifp->if_data.ifi_addrlen);
916 goto reply;
917 }
918 #if NTOKEN > 0
919 /*
920 * XXX uses m_data and assumes the complete answer including
921 * XXX token-ring headers is in the same buf
922 */
923 if (ifp->if_type == IFT_ISO88025) {
924 struct token_header *trh;
925
926 trh = (struct token_header *)M_TRHSTART(m);
927 if (trh->token_shost[0] & TOKEN_RI_PRESENT) {
928 struct token_rif *rif;
929 size_t riflen;
930
931 rif = TOKEN_RIF(trh);
932 riflen = (ntohs(rif->tr_rcf) &
933 TOKEN_RCF_LEN_MASK) >> 8;
934
935 if (riflen > 2 &&
936 riflen < sizeof(struct token_rif) &&
937 (riflen & 1) == 0) {
938 rif->tr_rcf ^= htons(TOKEN_RCF_DIRECTION);
939 rif->tr_rcf &= htons(~TOKEN_RCF_BROADCAST_MASK);
940 bcopy(rif, TOKEN_RIF(la), riflen);
941 }
942 }
943 }
944 #endif /* NTOKEN > 0 */
945 bcopy((caddr_t)ar_sha(ah), LLADDR(sdl),
946 sdl->sdl_alen = ah->ar_hln);
947 if (rt->rt_expire)
948 rt->rt_expire = time.tv_sec + arpt_keep;
949 rt->rt_flags &= ~RTF_REJECT;
950 la->la_asked = 0;
951
952 s = splnet();
953 mold = la->la_hold;
954 la->la_hold = 0;
955 splx(s);
956
957 if (mold) {
958 arpstat.as_dfrsent++;
959 (*ifp->if_output)(ifp, mold, rt_key(rt), rt);
960 }
961 }
962 reply:
963 if (op != ARPOP_REQUEST) {
964 if (op == ARPOP_REPLY)
965 arpstat.as_rcvreply++;
966 out:
967 m_freem(m);
968 return;
969 }
970 arpstat.as_rcvrequest++;
971 if (in_hosteq(itaddr, myaddr)) {
972 /* I am the target */
973 bcopy((caddr_t)ar_sha(ah), (caddr_t)ar_tha(ah), ah->ar_hln);
974 bcopy(LLADDR(ifp->if_sadl), (caddr_t)ar_sha(ah), ah->ar_hln);
975 } else {
976 la = arplookup(m, &itaddr, 0, SIN_PROXY);
977 if (la == 0)
978 goto out;
979 rt = la->la_rt;
980 bcopy((caddr_t)ar_sha(ah), (caddr_t)ar_tha(ah), ah->ar_hln);
981 sdl = SDL(rt->rt_gateway);
982 bcopy(LLADDR(sdl), (caddr_t)ar_sha(ah), ah->ar_hln);
983 }
984
985 bcopy((caddr_t)ar_spa(ah), (caddr_t)ar_tpa(ah), ah->ar_pln);
986 bcopy((caddr_t)&itaddr, (caddr_t)ar_spa(ah), ah->ar_pln);
987 ah->ar_op = htons(ARPOP_REPLY);
988 ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */
989 m->m_flags &= ~(M_BCAST|M_MCAST); /* never reply by broadcast */
990 m->m_len = sizeof(*ah) + (2 * ah->ar_pln) + (2 * ah->ar_hln);
991 m->m_pkthdr.len = m->m_len;
992 sa.sa_family = AF_ARP;
993 sa.sa_len = 2;
994 arpstat.as_sndtotal++;
995 arpstat.as_sndreply++;
996 (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
997 return;
998 }
999
1000 /*
1001 * Free an arp entry.
1002 */
1003 static void
1004 arptfree(la)
1005 struct llinfo_arp *la;
1006 {
1007 struct rtentry *rt = la->la_rt;
1008 struct sockaddr_dl *sdl;
1009
1010 ARP_LOCK_CHECK();
1011
1012 if (rt == 0)
1013 panic("arptfree");
1014 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
1015 sdl->sdl_family == AF_LINK) {
1016 sdl->sdl_alen = 0;
1017 la->la_asked = 0;
1018 rt->rt_flags &= ~RTF_REJECT;
1019 return;
1020 }
1021 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
1022 0, (struct rtentry **)0);
1023 }
1024
1025 /*
1026 * Lookup or enter a new address in arptab.
1027 */
1028 static struct llinfo_arp *
1029 arplookup(m, addr, create, proxy)
1030 struct mbuf *m;
1031 struct in_addr *addr;
1032 int create, proxy;
1033 {
1034 struct arphdr *ah;
1035 struct ifnet *ifp = m->m_pkthdr.rcvif;
1036 struct rtentry *rt;
1037 static struct sockaddr_inarp sin;
1038 const char *why = 0;
1039
1040 ah = mtod(m, struct arphdr *);
1041 sin.sin_len = sizeof(sin);
1042 sin.sin_family = AF_INET;
1043 sin.sin_addr = *addr;
1044 sin.sin_other = proxy ? SIN_PROXY : 0;
1045 rt = rtalloc1(sintosa(&sin), create);
1046 if (rt == 0)
1047 return (0);
1048 rt->rt_refcnt--;
1049
1050 if (rt->rt_flags & RTF_GATEWAY)
1051 why = "host is not on local network";
1052 else if ((rt->rt_flags & RTF_LLINFO) == 0) {
1053 arpstat.as_allocfail++;
1054 why = "could not allocate llinfo";
1055 } else if (rt->rt_gateway->sa_family != AF_LINK)
1056 why = "gateway route is not ours";
1057 else
1058 return ((struct llinfo_arp *)rt->rt_llinfo);
1059
1060 if (create)
1061 log(LOG_DEBUG, "arplookup: unable to enter address"
1062 " for %s@%s on %s (%s)\n",
1063 in_fmtaddr(*addr), lla_snprintf(ar_sha(ah), ah->ar_hln),
1064 ifp->if_xname, why);
1065 return (0);
1066 }
1067
1068 int
1069 arpioctl(cmd, data)
1070 u_long cmd;
1071 caddr_t data;
1072 {
1073
1074 return (EOPNOTSUPP);
1075 }
1076
1077 void
1078 arp_ifinit(ifp, ifa)
1079 struct ifnet *ifp;
1080 struct ifaddr *ifa;
1081 {
1082 struct in_addr *ip;
1083
1084 /*
1085 * Warn the user if another station has this IP address,
1086 * but only if the interface IP address is not zero.
1087 */
1088 ip = &IA_SIN(ifa)->sin_addr;
1089 if (!in_nullhost(*ip))
1090 arprequest(ifp, ip, ip, LLADDR(ifp->if_sadl));
1091
1092 ifa->ifa_rtrequest = arp_rtrequest;
1093 ifa->ifa_flags |= RTF_CLONING;
1094 }
1095
1096 /*
1097 * Called from 10 Mb/s Ethernet interrupt handlers
1098 * when ether packet type ETHERTYPE_REVARP
1099 * is received. Common length and type checks are done here,
1100 * then the protocol-specific routine is called.
1101 */
1102 void
1103 revarpinput(m)
1104 struct mbuf *m;
1105 {
1106 struct arphdr *ar;
1107
1108 if (m->m_len < sizeof(struct arphdr))
1109 goto out;
1110 ar = mtod(m, struct arphdr *);
1111 #if 0 /* XXX I don't think we need this... and it will prevent other LL */
1112 if (ntohs(ar->ar_hrd) != ARPHRD_ETHER)
1113 goto out;
1114 #endif
1115 if (m->m_len < sizeof(struct arphdr) + 2 * (ar->ar_hln + ar->ar_pln))
1116 goto out;
1117 switch (ntohs(ar->ar_pro)) {
1118
1119 case ETHERTYPE_IP:
1120 case ETHERTYPE_IPTRAILERS:
1121 in_revarpinput(m);
1122 return;
1123
1124 default:
1125 break;
1126 }
1127 out:
1128 m_freem(m);
1129 }
1130
1131 /*
1132 * RARP for Internet protocols on 10 Mb/s Ethernet.
1133 * Algorithm is that given in RFC 903.
1134 * We are only using for bootstrap purposes to get an ip address for one of
1135 * our interfaces. Thus we support no user-interface.
1136 *
1137 * Since the contents of the RARP reply are specific to the interface that
1138 * sent the request, this code must ensure that they are properly associated.
1139 *
1140 * Note: also supports ARP via RARP packets, per the RFC.
1141 */
1142 void
1143 in_revarpinput(m)
1144 struct mbuf *m;
1145 {
1146 struct ifnet *ifp;
1147 struct arphdr *ah;
1148 int op;
1149
1150 ah = mtod(m, struct arphdr *);
1151 op = ntohs(ah->ar_op);
1152 switch (op) {
1153 case ARPOP_REQUEST:
1154 case ARPOP_REPLY: /* per RFC */
1155 in_arpinput(m);
1156 return;
1157 case ARPOP_REVREPLY:
1158 break;
1159 case ARPOP_REVREQUEST: /* handled by rarpd(8) */
1160 default:
1161 goto out;
1162 }
1163 if (!revarp_in_progress)
1164 goto out;
1165 ifp = m->m_pkthdr.rcvif;
1166 if (ifp != myip_ifp) /* !same interface */
1167 goto out;
1168 if (myip_initialized)
1169 goto wake;
1170 if (bcmp(ar_tha(ah), LLADDR(ifp->if_sadl), ifp->if_sadl->sdl_alen))
1171 goto out;
1172 bcopy((caddr_t)ar_spa(ah), (caddr_t)&srv_ip, sizeof(srv_ip));
1173 bcopy((caddr_t)ar_tpa(ah), (caddr_t)&myip, sizeof(myip));
1174 myip_initialized = 1;
1175 wake: /* Do wakeup every time in case it was missed. */
1176 wakeup((caddr_t)&myip);
1177
1178 out:
1179 m_freem(m);
1180 }
1181
1182 /*
1183 * Send a RARP request for the ip address of the specified interface.
1184 * The request should be RFC 903-compliant.
1185 */
1186 void
1187 revarprequest(ifp)
1188 struct ifnet *ifp;
1189 {
1190 struct sockaddr sa;
1191 struct mbuf *m;
1192 struct arphdr *ah;
1193
1194 if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
1195 return;
1196 m->m_len = sizeof(*ah) + 2*sizeof(struct in_addr) +
1197 2*ifp->if_data.ifi_addrlen;
1198 m->m_pkthdr.len = m->m_len;
1199 MH_ALIGN(m, m->m_len);
1200 ah = mtod(m, struct arphdr *);
1201 bzero((caddr_t)ah, m->m_len);
1202 ah->ar_pro = htons(ETHERTYPE_IP);
1203 ah->ar_hln = ifp->if_data.ifi_addrlen; /* hardware address length */
1204 ah->ar_pln = sizeof(struct in_addr); /* protocol address length */
1205 ah->ar_op = htons(ARPOP_REVREQUEST);
1206
1207 bcopy(LLADDR(ifp->if_sadl), (caddr_t)ar_sha(ah), ah->ar_hln);
1208 bcopy(LLADDR(ifp->if_sadl), (caddr_t)ar_tha(ah), ah->ar_hln);
1209
1210 sa.sa_family = AF_ARP;
1211 sa.sa_len = 2;
1212 m->m_flags |= M_BCAST;
1213 (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
1214
1215 }
1216
1217 /*
1218 * RARP for the ip address of the specified interface, but also
1219 * save the ip address of the server that sent the answer.
1220 * Timeout if no response is received.
1221 */
1222 int
1223 revarpwhoarewe(ifp, serv_in, clnt_in)
1224 struct ifnet *ifp;
1225 struct in_addr *serv_in;
1226 struct in_addr *clnt_in;
1227 {
1228 int result, count = 20;
1229
1230 myip_initialized = 0;
1231 myip_ifp = ifp;
1232
1233 revarp_in_progress = 1;
1234 while (count--) {
1235 revarprequest(ifp);
1236 result = tsleep((caddr_t)&myip, PSOCK, "revarp", hz/2);
1237 if (result != EWOULDBLOCK)
1238 break;
1239 }
1240 revarp_in_progress = 0;
1241
1242 if (!myip_initialized)
1243 return ENETUNREACH;
1244
1245 bcopy((caddr_t)&srv_ip, serv_in, sizeof(*serv_in));
1246 bcopy((caddr_t)&myip, clnt_in, sizeof(*clnt_in));
1247 return 0;
1248 }
1249
1250
1251
1253 #ifdef DDB
1254
1255 #include <machine/db_machdep.h>
1256 #include <ddb/db_interface.h>
1257 #include <ddb/db_output.h>
1258 static void
1259 db_print_sa(sa)
1260 struct sockaddr *sa;
1261 {
1262 int len;
1263 u_char *p;
1264
1265 if (sa == 0) {
1266 db_printf("[NULL]");
1267 return;
1268 }
1269
1270 p = (u_char*)sa;
1271 len = sa->sa_len;
1272 db_printf("[");
1273 while (len > 0) {
1274 db_printf("%d", *p);
1275 p++; len--;
1276 if (len) db_printf(",");
1277 }
1278 db_printf("]\n");
1279 }
1280 static void
1281 db_print_ifa(ifa)
1282 struct ifaddr *ifa;
1283 {
1284 if (ifa == 0)
1285 return;
1286 db_printf(" ifa_addr=");
1287 db_print_sa(ifa->ifa_addr);
1288 db_printf(" ifa_dsta=");
1289 db_print_sa(ifa->ifa_dstaddr);
1290 db_printf(" ifa_mask=");
1291 db_print_sa(ifa->ifa_netmask);
1292 db_printf(" flags=0x%x,refcnt=%d,metric=%d\n",
1293 ifa->ifa_flags,
1294 ifa->ifa_refcnt,
1295 ifa->ifa_metric);
1296 }
1297 static void
1298 db_print_llinfo(li)
1299 caddr_t li;
1300 {
1301 struct llinfo_arp *la;
1302
1303 if (li == 0)
1304 return;
1305 la = (struct llinfo_arp *)li;
1306 db_printf(" la_rt=%p la_hold=%p, la_asked=0x%lx\n",
1307 la->la_rt, la->la_hold, la->la_asked);
1308 }
1309 /*
1310 * Function to pass to rn_walktree().
1311 * Return non-zero error to abort walk.
1312 */
1313 static int
1314 db_show_radix_node(rn, w)
1315 struct radix_node *rn;
1316 void *w;
1317 {
1318 struct rtentry *rt = (struct rtentry *)rn;
1319
1320 db_printf("rtentry=%p", rt);
1321
1322 db_printf(" flags=0x%x refcnt=%d use=%ld expire=%ld\n",
1323 rt->rt_flags, rt->rt_refcnt,
1324 rt->rt_use, rt->rt_expire);
1325
1326 db_printf(" key="); db_print_sa(rt_key(rt));
1327 db_printf(" mask="); db_print_sa(rt_mask(rt));
1328 db_printf(" gw="); db_print_sa(rt->rt_gateway);
1329
1330 db_printf(" ifp=%p ", rt->rt_ifp);
1331 if (rt->rt_ifp)
1332 db_printf("(%s)", rt->rt_ifp->if_xname);
1333 else
1334 db_printf("(NULL)");
1335
1336 db_printf(" ifa=%p\n", rt->rt_ifa);
1337 db_print_ifa(rt->rt_ifa);
1338
1339 db_printf(" genmask="); db_print_sa(rt->rt_genmask);
1340
1341 db_printf(" gwroute=%p llinfo=%p\n",
1342 rt->rt_gwroute, rt->rt_llinfo);
1343 db_print_llinfo(rt->rt_llinfo);
1344
1345 return (0);
1346 }
1347 /*
1348 * Function to print all the route trees.
1349 * Use this from ddb: "show arptab"
1350 */
1351 void
1352 db_show_arptab(addr, have_addr, count, modif)
1353 db_expr_t addr;
1354 int have_addr;
1355 db_expr_t count;
1356 char * modif;
1357 {
1358 struct radix_node_head *rnh;
1359 rnh = rt_tables[AF_INET];
1360 db_printf("Route tree for AF_INET\n");
1361 if (rnh == NULL) {
1362 db_printf(" (not initialized)\n");
1363 return;
1364 }
1365 rn_walktree(rnh, db_show_radix_node, NULL);
1366 return;
1367 }
1368 #endif
1369 #endif /* INET */
1370
1371