Deleted Added
full compact
nd6.c (74093) nd6.c (78064)
1/* $FreeBSD: head/sys/netinet6/nd6.c 74093 2001-03-11 05:31:45Z bmilekic $ */
2/* $KAME: nd6.c,v 1.68 2000/07/02 14:48:02 itojun Exp $ */
1/* $FreeBSD: head/sys/netinet6/nd6.c 78064 2001-06-11 12:39:29Z ume $ */
2/* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 27 unchanged lines hidden (view full) ---

38 * I left the code mostly as it was in 970310. -- itojun
39 */
40
41#include "opt_inet.h"
42#include "opt_inet6.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
3
4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 27 unchanged lines hidden (view full) ---

38 * I left the code mostly as it was in 970310. -- itojun
39 */
40
41#include "opt_inet.h"
42#include "opt_inet6.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/callout.h>
46#include <sys/malloc.h>
47#include <sys/mbuf.h>
48#include <sys/socket.h>
49#include <sys/sockio.h>
50#include <sys/time.h>
51#include <sys/kernel.h>
52#include <sys/protosw.h>
53#include <sys/errno.h>
54#include <sys/syslog.h>
55#include <sys/queue.h>
47#include <sys/malloc.h>
48#include <sys/mbuf.h>
49#include <sys/socket.h>
50#include <sys/sockio.h>
51#include <sys/time.h>
52#include <sys/kernel.h>
53#include <sys/protosw.h>
54#include <sys/errno.h>
55#include <sys/syslog.h>
56#include <sys/queue.h>
57#include <sys/sysctl.h>
56
57#include <net/if.h>
58#include <net/if_dl.h>
59#include <net/if_types.h>
60#include <net/if_atm.h>
61#include <net/route.h>
62
63#include <netinet/in.h>

--- 15 unchanged lines hidden (view full) ---

79#define SDL(s) ((struct sockaddr_dl *)s)
80
81/* timer values */
82int nd6_prune = 1; /* walk list every 1 seconds */
83int nd6_delay = 5; /* delay first probe time 5 second */
84int nd6_umaxtries = 3; /* maximum unicast query */
85int nd6_mmaxtries = 3; /* maximum multicast query */
86int nd6_useloopback = 1; /* use loopback interface for local traffic */
58
59#include <net/if.h>
60#include <net/if_dl.h>
61#include <net/if_types.h>
62#include <net/if_atm.h>
63#include <net/route.h>
64
65#include <netinet/in.h>

--- 15 unchanged lines hidden (view full) ---

81#define SDL(s) ((struct sockaddr_dl *)s)
82
83/* timer values */
84int nd6_prune = 1; /* walk list every 1 seconds */
85int nd6_delay = 5; /* delay first probe time 5 second */
86int nd6_umaxtries = 3; /* maximum unicast query */
87int nd6_mmaxtries = 3; /* maximum multicast query */
88int nd6_useloopback = 1; /* use loopback interface for local traffic */
89int nd6_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */
87
88/* preventing too many loops in ND option parsing */
89int nd6_maxndopt = 10; /* max # of ND options allowed */
90
91int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */
92
90
91/* preventing too many loops in ND option parsing */
92int nd6_maxndopt = 10; /* max # of ND options allowed */
93
94int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */
95
96#ifdef ND6_DEBUG
97int nd6_debug = 1;
98#else
99int nd6_debug = 0;
100#endif
101
93/* for debugging? */
94static int nd6_inuse, nd6_allocated;
95
96struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6};
97static size_t nd_ifinfo_indexlim = 8;
98struct nd_ifinfo *nd_ifinfo = NULL;
99struct nd_drhead nd_defrouter;
100struct nd_prhead nd_prefix = { 0 };
101
102int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
103static struct sockaddr_in6 all1_sa;
104
105static void nd6_slowtimo __P((void *));
102/* for debugging? */
103static int nd6_inuse, nd6_allocated;
104
105struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6};
106static size_t nd_ifinfo_indexlim = 8;
107struct nd_ifinfo *nd_ifinfo = NULL;
108struct nd_drhead nd_defrouter;
109struct nd_prhead nd_prefix = { 0 };
110
111int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
112static struct sockaddr_in6 all1_sa;
113
114static void nd6_slowtimo __P((void *));
115static int regen_tmpaddr __P((struct in6_ifaddr *));
106
116
117struct callout nd6_slowtimo_ch;
118struct callout nd6_timer_ch;
119extern struct callout in6_tmpaddrtimer_ch;
120
107void
108nd6_init()
109{
110 static int nd6_init_done = 0;
111 int i;
112
113 if (nd6_init_done) {
114 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n");

--- 6 unchanged lines hidden (view full) ---

121 all1_sa.sin6_addr.s6_addr[i] = 0xff;
122
123 /* initialization of the default router list */
124 TAILQ_INIT(&nd_defrouter);
125
126 nd6_init_done = 1;
127
128 /* start timer */
121void
122nd6_init()
123{
124 static int nd6_init_done = 0;
125 int i;
126
127 if (nd6_init_done) {
128 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n");

--- 6 unchanged lines hidden (view full) ---

135 all1_sa.sin6_addr.s6_addr[i] = 0xff;
136
137 /* initialization of the default router list */
138 TAILQ_INIT(&nd_defrouter);
139
140 nd6_init_done = 1;
141
142 /* start timer */
129 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
143 callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz,
144 nd6_slowtimo, NULL);
130}
131
132void
133nd6_ifattach(ifp)
134 struct ifnet *ifp;
135{
136
137 /*

--- 49 unchanged lines hidden (view full) ---

187nd6_setmtu(ifp)
188 struct ifnet *ifp;
189{
190#define MIN(a,b) ((a) < (b) ? (a) : (b))
191 struct nd_ifinfo *ndi = &nd_ifinfo[ifp->if_index];
192 u_long oldmaxmtu = ndi->maxmtu;
193 u_long oldlinkmtu = ndi->linkmtu;
194
145}
146
147void
148nd6_ifattach(ifp)
149 struct ifnet *ifp;
150{
151
152 /*

--- 49 unchanged lines hidden (view full) ---

202nd6_setmtu(ifp)
203 struct ifnet *ifp;
204{
205#define MIN(a,b) ((a) < (b) ? (a) : (b))
206 struct nd_ifinfo *ndi = &nd_ifinfo[ifp->if_index];
207 u_long oldmaxmtu = ndi->maxmtu;
208 u_long oldlinkmtu = ndi->linkmtu;
209
195 switch(ifp->if_type) {
196 case IFT_ARCNET: /* XXX MTU handling needs more work */
197 ndi->maxmtu = MIN(60480, ifp->if_mtu);
198 break;
199 case IFT_ETHER:
200 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
201 break;
202 case IFT_FDDI:
203 ndi->maxmtu = MIN(FDDIIPMTU, ifp->if_mtu);
204 break;
205 case IFT_ATM:
206 ndi->maxmtu = MIN(ATMMTU, ifp->if_mtu);
207 break;
208 default:
209 ndi->maxmtu = ifp->if_mtu;
210 break;
210 switch (ifp->if_type) {
211 case IFT_ARCNET: /* XXX MTU handling needs more work */
212 ndi->maxmtu = MIN(60480, ifp->if_mtu);
213 break;
214 case IFT_ETHER:
215 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
216 break;
217 case IFT_FDDI:
218 ndi->maxmtu = MIN(FDDIIPMTU, ifp->if_mtu);
219 break;
220 case IFT_ATM:
221 ndi->maxmtu = MIN(ATMMTU, ifp->if_mtu);
222 break;
223 case IFT_IEEE1394: /* XXX should be IEEE1394MTU(1500) */
224 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
225 break;
226#ifdef IFT_IEEE80211
227 case IFT_IEEE80211: /* XXX should be IEEE80211MTU(1500) */
228 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
229 break;
230#endif
231 default:
232 ndi->maxmtu = ifp->if_mtu;
233 break;
211 }
212
213 if (oldmaxmtu != ndi->maxmtu) {
214 /*
215 * If the ND level MTU is not set yet, or if the maxmtu
216 * is reset to a smaller value than the ND level MTU,
217 * also reset the ND level MTU.
218 */

--- 105 unchanged lines hidden (view full) ---

324
325 while (1) {
326 nd_opt = nd6_option(ndopts);
327 if (!nd_opt && !ndopts->nd_opts_last) {
328 /*
329 * Message validation requires that all included
330 * options have a length that is greater than zero.
331 */
234 }
235
236 if (oldmaxmtu != ndi->maxmtu) {
237 /*
238 * If the ND level MTU is not set yet, or if the maxmtu
239 * is reset to a smaller value than the ND level MTU,
240 * also reset the ND level MTU.
241 */

--- 105 unchanged lines hidden (view full) ---

347
348 while (1) {
349 nd_opt = nd6_option(ndopts);
350 if (!nd_opt && !ndopts->nd_opts_last) {
351 /*
352 * Message validation requires that all included
353 * options have a length that is greater than zero.
354 */
355 icmp6stat.icp6s_nd_badopt++;
332 bzero(ndopts, sizeof(*ndopts));
333 return -1;
334 }
335
336 if (!nd_opt)
337 goto skip1;
338
339 switch (nd_opt->nd_opt_type) {
340 case ND_OPT_SOURCE_LINKADDR:
341 case ND_OPT_TARGET_LINKADDR:
342 case ND_OPT_MTU:
343 case ND_OPT_REDIRECTED_HEADER:
344 if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) {
356 bzero(ndopts, sizeof(*ndopts));
357 return -1;
358 }
359
360 if (!nd_opt)
361 goto skip1;
362
363 switch (nd_opt->nd_opt_type) {
364 case ND_OPT_SOURCE_LINKADDR:
365 case ND_OPT_TARGET_LINKADDR:
366 case ND_OPT_MTU:
367 case ND_OPT_REDIRECTED_HEADER:
368 if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) {
345 printf("duplicated ND6 option found "
346 "(type=%d)\n", nd_opt->nd_opt_type);
369 nd6log((LOG_INFO,
370 "duplicated ND6 option found (type=%d)\n",
371 nd_opt->nd_opt_type));
347 /* XXX bark? */
348 } else {
349 ndopts->nd_opt_array[nd_opt->nd_opt_type]
350 = nd_opt;
351 }
352 break;
353 case ND_OPT_PREFIX_INFORMATION:
354 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) {
355 ndopts->nd_opt_array[nd_opt->nd_opt_type]
356 = nd_opt;
357 }
358 ndopts->nd_opts_pi_end =
359 (struct nd_opt_prefix_info *)nd_opt;
360 break;
361 default:
362 /*
363 * Unknown options must be silently ignored,
364 * to accomodate future extension to the protocol.
365 */
372 /* XXX bark? */
373 } else {
374 ndopts->nd_opt_array[nd_opt->nd_opt_type]
375 = nd_opt;
376 }
377 break;
378 case ND_OPT_PREFIX_INFORMATION:
379 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) {
380 ndopts->nd_opt_array[nd_opt->nd_opt_type]
381 = nd_opt;
382 }
383 ndopts->nd_opts_pi_end =
384 (struct nd_opt_prefix_info *)nd_opt;
385 break;
386 default:
387 /*
388 * Unknown options must be silently ignored,
389 * to accomodate future extension to the protocol.
390 */
366 log(LOG_DEBUG,
391 nd6log((LOG_DEBUG,
367 "nd6_options: unsupported option %d - "
392 "nd6_options: unsupported option %d - "
368 "option ignored\n", nd_opt->nd_opt_type);
393 "option ignored\n", nd_opt->nd_opt_type));
369 }
370
371skip1:
372 i++;
373 if (i > nd6_maxndopt) {
374 icmp6stat.icp6s_nd_toomanyopt++;
394 }
395
396skip1:
397 i++;
398 if (i > nd6_maxndopt) {
399 icmp6stat.icp6s_nd_toomanyopt++;
375 printf("too many loop in nd opt\n");
400 nd6log((LOG_INFO, "too many loop in nd opt\n"));
376 break;
377 }
378
379 if (ndopts->nd_opts_done)
380 break;
381 }
382
383 return 0;
384}
385
386/*
387 * ND6 timer routine to expire default route list and prefix list
388 */
389void
390nd6_timer(ignored_arg)
391 void *ignored_arg;
392{
393 int s;
401 break;
402 }
403
404 if (ndopts->nd_opts_done)
405 break;
406 }
407
408 return 0;
409}
410
411/*
412 * ND6 timer routine to expire default route list and prefix list
413 */
414void
415nd6_timer(ignored_arg)
416 void *ignored_arg;
417{
418 int s;
394 register struct llinfo_nd6 *ln;
395 register struct nd_defrouter *dr;
396 register struct nd_prefix *pr;
419 struct llinfo_nd6 *ln;
420 struct nd_defrouter *dr;
421 struct nd_prefix *pr;
422 struct ifnet *ifp;
423 struct in6_ifaddr *ia6, *nia6;
424 struct in6_addrlifetime *lt6;
397
398 s = splnet();
425
426 s = splnet();
399 timeout(nd6_timer, (caddr_t)0, nd6_prune * hz);
427 callout_reset(&nd6_timer_ch, nd6_prune * hz,
428 nd6_timer, NULL);
400
401 ln = llinfo_nd6.ln_next;
402 /* XXX BSD/OS separates this code -- itojun */
403 while (ln && ln != &llinfo_nd6) {
404 struct rtentry *rt;
429
430 ln = llinfo_nd6.ln_next;
431 /* XXX BSD/OS separates this code -- itojun */
432 while (ln && ln != &llinfo_nd6) {
433 struct rtentry *rt;
405 struct ifnet *ifp;
406 struct sockaddr_in6 *dst;
407 struct llinfo_nd6 *next = ln->ln_next;
408 /* XXX: used for the DELAY case only: */
409 struct nd_ifinfo *ndi = NULL;
410
411 if ((rt = ln->ln_rt) == NULL) {
412 ln = next;
413 continue;

--- 39 unchanged lines hidden (view full) ---

453 * older rcvif?
454 */
455 m->m_pkthdr.rcvif = rt->rt_ifp;
456 }
457 icmp6_error(m, ICMP6_DST_UNREACH,
458 ICMP6_DST_UNREACH_ADDR, 0);
459 ln->ln_hold = NULL;
460 }
434 struct sockaddr_in6 *dst;
435 struct llinfo_nd6 *next = ln->ln_next;
436 /* XXX: used for the DELAY case only: */
437 struct nd_ifinfo *ndi = NULL;
438
439 if ((rt = ln->ln_rt) == NULL) {
440 ln = next;
441 continue;

--- 39 unchanged lines hidden (view full) ---

481 * older rcvif?
482 */
483 m->m_pkthdr.rcvif = rt->rt_ifp;
484 }
485 icmp6_error(m, ICMP6_DST_UNREACH,
486 ICMP6_DST_UNREACH_ADDR, 0);
487 ln->ln_hold = NULL;
488 }
461 nd6_free(rt);
489 next = nd6_free(rt);
462 }
463 break;
464 case ND6_LLINFO_REACHABLE:
490 }
491 break;
492 case ND6_LLINFO_REACHABLE:
465 if (ln->ln_expire)
493 if (ln->ln_expire) {
466 ln->ln_state = ND6_LLINFO_STALE;
494 ln->ln_state = ND6_LLINFO_STALE;
495 ln->ln_expire = time_second + nd6_gctimer;
496 }
467 break;
497 break;
468 /*
469 * ND6_LLINFO_STALE state requires nothing for timer
470 * routine.
471 */
498
499 case ND6_LLINFO_STALE:
500 /* Garbage Collection(RFC 2461 5.3) */
501 if (ln->ln_expire)
502 next = nd6_free(rt);
503 break;
504
472 case ND6_LLINFO_DELAY:
473 if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) {
474 /* We need NUD */
475 ln->ln_asked = 1;
476 ln->ln_state = ND6_LLINFO_PROBE;
477 ln->ln_expire = time_second +
478 ndi->retrans / 1000;
479 nd6_ns_output(ifp, &dst->sin6_addr,
480 &dst->sin6_addr,
481 ln, 0);
505 case ND6_LLINFO_DELAY:
506 if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) {
507 /* We need NUD */
508 ln->ln_asked = 1;
509 ln->ln_state = ND6_LLINFO_PROBE;
510 ln->ln_expire = time_second +
511 ndi->retrans / 1000;
512 nd6_ns_output(ifp, &dst->sin6_addr,
513 &dst->sin6_addr,
514 ln, 0);
482 } else
515 } else {
483 ln->ln_state = ND6_LLINFO_STALE; /* XXX */
516 ln->ln_state = ND6_LLINFO_STALE; /* XXX */
517 ln->ln_expire = time_second + nd6_gctimer;
518 }
484 break;
485 case ND6_LLINFO_PROBE:
486 if (ln->ln_asked < nd6_umaxtries) {
487 ln->ln_asked++;
488 ln->ln_expire = time_second +
489 nd_ifinfo[ifp->if_index].retrans / 1000;
490 nd6_ns_output(ifp, &dst->sin6_addr,
491 &dst->sin6_addr, ln, 0);
492 } else {
519 break;
520 case ND6_LLINFO_PROBE:
521 if (ln->ln_asked < nd6_umaxtries) {
522 ln->ln_asked++;
523 ln->ln_expire = time_second +
524 nd_ifinfo[ifp->if_index].retrans / 1000;
525 nd6_ns_output(ifp, &dst->sin6_addr,
526 &dst->sin6_addr, ln, 0);
527 } else {
493 nd6_free(rt);
528 next = nd6_free(rt);
494 }
495 break;
529 }
530 break;
496 case ND6_LLINFO_WAITDELETE:
497 nd6_free(rt);
498 break;
499 }
500 ln = next;
501 }
502
531 }
532 ln = next;
533 }
534
503 /* expire */
535 /* expire default router list */
504 dr = TAILQ_FIRST(&nd_defrouter);
505 while (dr) {
506 if (dr->expire && dr->expire < time_second) {
507 struct nd_defrouter *t;
508 t = TAILQ_NEXT(dr, dr_entry);
509 defrtrlist_del(dr);
510 dr = t;
511 } else {
512 dr = TAILQ_NEXT(dr, dr_entry);
513 }
514 }
536 dr = TAILQ_FIRST(&nd_defrouter);
537 while (dr) {
538 if (dr->expire && dr->expire < time_second) {
539 struct nd_defrouter *t;
540 t = TAILQ_NEXT(dr, dr_entry);
541 defrtrlist_del(dr);
542 dr = t;
543 } else {
544 dr = TAILQ_NEXT(dr, dr_entry);
545 }
546 }
515 pr = nd_prefix.lh_first;
516 while (pr) {
517 struct in6_ifaddr *ia6;
518 struct in6_addrlifetime *lt6;
519
547
520 if (IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
521 ia6 = NULL;
522 else
523 ia6 = in6ifa_ifpwithaddr(pr->ndpr_ifp, &pr->ndpr_addr);
548 /*
549 * expire interface addresses.
550 * in the past the loop was inside prefix expiry processing.
551 * However, from a stricter speci-confrmance standpoint, we should
552 * rather separate address lifetimes and prefix lifetimes.
553 */
554 addrloop:
555 for (ia6 = in6_ifaddr; ia6; ia6 = nia6) {
556 nia6 = ia6->ia_next;
557 /* check address lifetime */
558 lt6 = &ia6->ia6_lifetime;
559 if (IFA6_IS_INVALID(ia6)) {
560 int regen = 0;
524
561
525 if (ia6) {
526 /* check address lifetime */
527 lt6 = &ia6->ia6_lifetime;
528 if (lt6->ia6t_preferred && lt6->ia6t_preferred < time_second)
529 ia6->ia6_flags |= IN6_IFF_DEPRECATED;
530 if (lt6->ia6t_expire && lt6->ia6t_expire < time_second) {
531 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
532 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
533 /* xxx ND_OPT_PI_FLAG_ONLINK processing */
562 /*
563 * If the expiring address is temporary, try
564 * regenerating a new one. This would be useful when
565 * we suspended a laptop PC, then turned on after a
566 * period that could invalidate all temporary
567 * addresses. Although we may have to restart the
568 * loop (see below), it must be after purging the
569 * address. Otherwise, we'd see an infinite loop of
570 * regeneration.
571 */
572 if (ip6_use_tempaddr &&
573 (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) {
574 if (regen_tmpaddr(ia6) == 0)
575 regen = 1;
534 }
576 }
577
578 in6_purgeaddr(&ia6->ia_ifa);
579
580 if (regen)
581 goto addrloop; /* XXX: see below */
582 } else if (IFA6_IS_DEPRECATED(ia6)) {
583 int oldflags = ia6->ia6_flags;
584
585 ia6->ia6_flags |= IN6_IFF_DEPRECATED;
586
587 /*
588 * If a temporary address has just become deprecated,
589 * regenerate a new one if possible.
590 */
591 if (ip6_use_tempaddr &&
592 (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0 &&
593 (oldflags & IN6_IFF_DEPRECATED) == 0) {
594
595 if (regen_tmpaddr(ia6) == 0) {
596 /*
597 * A new temporary address is
598 * generated.
599 * XXX: this means the address chain
600 * has changed while we are still in
601 * the loop. Although the change
602 * would not cause disaster (because
603 * it's not an addition, but a
604 * deletion,) we'd rather restart the
605 * loop just for safety. Or does this
606 * significantly reduce performance??
607 */
608 goto addrloop;
609 }
610 }
611 } else if (IFA6_IS_DEPRECATED(ia6)) {
612 /*
613 * A new RA might have made a deprecated address
614 * preferred.
615 */
616 ia6->ia6_flags &= ~IN6_IFF_DEPRECATED;
535 }
617 }
618 }
536
619
620 /* expire prefix list */
621 pr = nd_prefix.lh_first;
622 while (pr) {
537 /*
538 * check prefix lifetime.
539 * since pltime is just for autoconf, pltime processing for
540 * prefix is not necessary.
541 *
542 * we offset expire time by NDPR_KEEP_EXPIRE, so that we
543 * can use the old prefix information to validate the
544 * next prefix information to come. See prelist_update()
545 * for actual validation.
623 /*
624 * check prefix lifetime.
625 * since pltime is just for autoconf, pltime processing for
626 * prefix is not necessary.
627 *
628 * we offset expire time by NDPR_KEEP_EXPIRE, so that we
629 * can use the old prefix information to validate the
630 * next prefix information to come. See prelist_update()
631 * for actual validation.
632 *
633 * I don't think such an offset is necessary.
634 * (jinmei@kame.net, 20010130).
546 */
635 */
547 if (pr->ndpr_expire
548 && pr->ndpr_expire + NDPR_KEEP_EXPIRED < time_second) {
636 if (pr->ndpr_expire && pr->ndpr_expire < time_second) {
549 struct nd_prefix *t;
550 t = pr->ndpr_next;
551
552 /*
553 * address expiration and prefix expiration are
637 struct nd_prefix *t;
638 t = pr->ndpr_next;
639
640 /*
641 * address expiration and prefix expiration are
554 * separate. NEVER perform in6_ifdel here.
642 * separate. NEVER perform in6_purgeaddr here.
555 */
556
557 prelist_remove(pr);
558 pr = t;
559 } else
560 pr = pr->ndpr_next;
561 }
562 splx(s);
563}
564
643 */
644
645 prelist_remove(pr);
646 pr = t;
647 } else
648 pr = pr->ndpr_next;
649 }
650 splx(s);
651}
652
653static int
654regen_tmpaddr(ia6)
655 struct in6_ifaddr *ia6; /* deprecated/invalidated temporary address */
656{
657 struct ifaddr *ifa;
658 struct ifnet *ifp;
659 struct in6_ifaddr *public_ifa6 = NULL;
660
661 ifp = ia6->ia_ifa.ifa_ifp;
662 for (ifa = ifp->if_addrlist.tqh_first; ifa;
663 ifa = ifa->ifa_list.tqe_next)
664 {
665 struct in6_ifaddr *it6;
666
667 if (ifa->ifa_addr->sa_family != AF_INET6)
668 continue;
669
670 it6 = (struct in6_ifaddr *)ifa;
671
672 /* ignore no autoconf addresses. */
673 if ((it6->ia6_flags & IN6_IFF_AUTOCONF) == 0)
674 continue;
675
676 /* ignore autoconf addresses with different prefixes. */
677 if (it6->ia6_ndpr == NULL || it6->ia6_ndpr != ia6->ia6_ndpr)
678 continue;
679
680 /*
681 * Now we are looking at an autoconf address with the same
682 * prefix as ours. If the address is temporary and is still
683 * preferred, do not create another one. It would be rare, but
684 * could happen, for example, when we resume a laptop PC after
685 * a long period.
686 */
687 if ((it6->ia6_flags & IN6_IFF_TEMPORARY) != 0 &&
688 !IFA6_IS_DEPRECATED(it6)) {
689 public_ifa6 = NULL;
690 break;
691 }
692
693 /*
694 * This is a public autoconf address that has the same prefix
695 * as ours. If it is preferred, keep it. We can't break the
696 * loop here, because there may be a still-preferred temporary
697 * address with the prefix.
698 */
699 if (!IFA6_IS_DEPRECATED(it6))
700 public_ifa6 = it6;
701 }
702
703 if (public_ifa6 != NULL) {
704 int e;
705
706 if ((e = in6_tmpifadd(public_ifa6, 0)) != 0) {
707 log(LOG_NOTICE, "regen_tmpaddr: failed to create a new"
708 " tmp addr,errno=%d\n", e);
709 return(-1);
710 }
711 return(0);
712 }
713
714 return(-1);
715}
716
565/*
566 * Nuke neighbor cache/prefix/default router management table, right before
567 * ifp goes away.
568 */
569void
570nd6_purge(ifp)
571 struct ifnet *ifp;
572{

--- 16 unchanged lines hidden (view full) ---

589 if (dr->ifp == ifp)
590 defrtrlist_del(dr);
591 }
592
593 /* Nuke prefix list entries toward ifp */
594 for (pr = nd_prefix.lh_first; pr; pr = npr) {
595 npr = pr->ndpr_next;
596 if (pr->ndpr_ifp == ifp) {
717/*
718 * Nuke neighbor cache/prefix/default router management table, right before
719 * ifp goes away.
720 */
721void
722nd6_purge(ifp)
723 struct ifnet *ifp;
724{

--- 16 unchanged lines hidden (view full) ---

741 if (dr->ifp == ifp)
742 defrtrlist_del(dr);
743 }
744
745 /* Nuke prefix list entries toward ifp */
746 for (pr = nd_prefix.lh_first; pr; pr = npr) {
747 npr = pr->ndpr_next;
748 if (pr->ndpr_ifp == ifp) {
597 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
598 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
749 /*
750 * Previously, pr->ndpr_addr is removed as well,
751 * but I strongly believe we don't have to do it.
752 * nd6_purge() is only called from in6_ifdetach(),
753 * which removes all the associated interface addresses
754 * by itself.
755 * (jinmei@kame.net 20010129)
756 */
599 prelist_remove(pr);
600 }
601 }
602
603 /* cancel default outgoing interface setting */
604 if (nd6_defifindex == ifp->if_index)
605 nd6_setdefaultiface(0);
606

--- 14 unchanged lines hidden (view full) ---

621 struct sockaddr_dl *sdl;
622
623 nln = ln->ln_next;
624 rt = ln->ln_rt;
625 if (rt && rt->rt_gateway &&
626 rt->rt_gateway->sa_family == AF_LINK) {
627 sdl = (struct sockaddr_dl *)rt->rt_gateway;
628 if (sdl->sdl_index == ifp->if_index)
757 prelist_remove(pr);
758 }
759 }
760
761 /* cancel default outgoing interface setting */
762 if (nd6_defifindex == ifp->if_index)
763 nd6_setdefaultiface(0);
764

--- 14 unchanged lines hidden (view full) ---

779 struct sockaddr_dl *sdl;
780
781 nln = ln->ln_next;
782 rt = ln->ln_rt;
783 if (rt && rt->rt_gateway &&
784 rt->rt_gateway->sa_family == AF_LINK) {
785 sdl = (struct sockaddr_dl *)rt->rt_gateway;
786 if (sdl->sdl_index == ifp->if_index)
629 nd6_free(rt);
787 nln = nd6_free(rt);
630 }
631 ln = nln;
632 }
788 }
789 ln = nln;
790 }
633
634 /*
635 * Neighbor cache entry for interface route will be retained
636 * with ND6_LLINFO_WAITDELETE state, by nd6_free(). Nuke it.
637 */
638 ln = llinfo_nd6.ln_next;
639 while (ln && ln != &llinfo_nd6) {
640 struct rtentry *rt;
641 struct sockaddr_dl *sdl;
642
643 nln = ln->ln_next;
644 rt = ln->ln_rt;
645 if (rt && rt->rt_gateway &&
646 rt->rt_gateway->sa_family == AF_LINK) {
647 sdl = (struct sockaddr_dl *)rt->rt_gateway;
648 if (sdl->sdl_index == ifp->if_index) {
649 rtrequest(RTM_DELETE, rt_key(rt),
650 (struct sockaddr *)0, rt_mask(rt), 0,
651 (struct rtentry **)0);
652 }
653 }
654 ln = nln;
655 }
656}
657
658struct rtentry *
659nd6_lookup(addr6, create, ifp)
660 struct in6_addr *addr6;
661 int create;
662 struct ifnet *ifp;
663{

--- 88 unchanged lines hidden (view full) ---

752 * Detect if a given IPv6 address identifies a neighbor on a given link.
753 * XXX: should take care of the destination of a p2p link?
754 */
755int
756nd6_is_addr_neighbor(addr, ifp)
757 struct sockaddr_in6 *addr;
758 struct ifnet *ifp;
759{
791}
792
793struct rtentry *
794nd6_lookup(addr6, create, ifp)
795 struct in6_addr *addr6;
796 int create;
797 struct ifnet *ifp;
798{

--- 88 unchanged lines hidden (view full) ---

887 * Detect if a given IPv6 address identifies a neighbor on a given link.
888 * XXX: should take care of the destination of a p2p link?
889 */
890int
891nd6_is_addr_neighbor(addr, ifp)
892 struct sockaddr_in6 *addr;
893 struct ifnet *ifp;
894{
760 register struct ifaddr *ifa;
895 struct ifaddr *ifa;
761 int i;
762
763#define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
764#define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
765
766 /*
767 * A link-local address is always a neighbor.
768 * XXX: we should use the sin6_scope_id field rather than the embedded

--- 33 unchanged lines hidden (view full) ---

802 return(0);
803#undef IFADDR6
804#undef IFMASK6
805}
806
807/*
808 * Free an nd6 llinfo entry.
809 */
896 int i;
897
898#define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
899#define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
900
901 /*
902 * A link-local address is always a neighbor.
903 * XXX: we should use the sin6_scope_id field rather than the embedded

--- 33 unchanged lines hidden (view full) ---

937 return(0);
938#undef IFADDR6
939#undef IFMASK6
940}
941
942/*
943 * Free an nd6 llinfo entry.
944 */
810void
945struct llinfo_nd6 *
811nd6_free(rt)
812 struct rtentry *rt;
813{
946nd6_free(rt)
947 struct rtentry *rt;
948{
814 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
815 struct sockaddr_dl *sdl;
949 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo, *next;
816 struct in6_addr in6 = ((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
817 struct nd_defrouter *dr;
818
819 /*
950 struct in6_addr in6 = ((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
951 struct nd_defrouter *dr;
952
953 /*
820 * Clear all destination cache entries for the neighbor.
821 * XXX: is it better to restrict this to hosts?
954 * we used to have pfctlinput(PRC_HOSTDEAD) here.
955 * even though it is not harmful, it was not really necessary.
822 */
956 */
823 pfctlinput(PRC_HOSTDEAD, rt_key(rt));
824
825 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */
826 int s;
827 s = splnet();
828 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->sin6_addr,
829 rt->rt_ifp);
957
958 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */
959 int s;
960 s = splnet();
961 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->sin6_addr,
962 rt->rt_ifp);
963
830 if (ln->ln_router || dr) {
831 /*
832 * rt6_flush must be called whether or not the neighbor
833 * is in the Default Router List.
834 * See a corresponding comment in nd6_na_input().
835 */
836 rt6_flush(&in6, rt->rt_ifp);
837 }

--- 9 unchanged lines hidden (view full) ---

847 * Temporarily fake the state to choose a new default
848 * router and to perform on-link determination of
849 * prefixes coreectly.
850 * Below the state will be set correctly,
851 * or the entry itself will be deleted.
852 */
853 ln->ln_state = ND6_LLINFO_INCOMPLETE;
854
964 if (ln->ln_router || dr) {
965 /*
966 * rt6_flush must be called whether or not the neighbor
967 * is in the Default Router List.
968 * See a corresponding comment in nd6_na_input().
969 */
970 rt6_flush(&in6, rt->rt_ifp);
971 }

--- 9 unchanged lines hidden (view full) ---

981 * Temporarily fake the state to choose a new default
982 * router and to perform on-link determination of
983 * prefixes coreectly.
984 * Below the state will be set correctly,
985 * or the entry itself will be deleted.
986 */
987 ln->ln_state = ND6_LLINFO_INCOMPLETE;
988
989 /*
990 * Since defrouter_select() does not affect the
991 * on-link determination and MIP6 needs the check
992 * before the default router selection, we perform
993 * the check now.
994 */
995 pfxlist_onlink_check();
996
855 if (dr == TAILQ_FIRST(&nd_defrouter)) {
856 /*
857 * It is used as the current default router,
858 * so we have to move it to the end of the
859 * list and choose a new one.
860 * XXX: it is not very efficient if this is
861 * the only router.
862 */
863 TAILQ_REMOVE(&nd_defrouter, dr, dr_entry);
864 TAILQ_INSERT_TAIL(&nd_defrouter, dr, dr_entry);
865
866 defrouter_select();
867 }
997 if (dr == TAILQ_FIRST(&nd_defrouter)) {
998 /*
999 * It is used as the current default router,
1000 * so we have to move it to the end of the
1001 * list and choose a new one.
1002 * XXX: it is not very efficient if this is
1003 * the only router.
1004 */
1005 TAILQ_REMOVE(&nd_defrouter, dr, dr_entry);
1006 TAILQ_INSERT_TAIL(&nd_defrouter, dr, dr_entry);
1007
1008 defrouter_select();
1009 }
868 pfxlist_onlink_check();
869 }
870 splx(s);
871 }
872
1010 }
1011 splx(s);
1012 }
1013
873 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
874 sdl->sdl_family == AF_LINK) {
875 sdl->sdl_alen = 0;
876 ln->ln_state = ND6_LLINFO_WAITDELETE;
877 ln->ln_asked = 0;
878 rt->rt_flags &= ~RTF_REJECT;
879 return;
880 }
1014 /*
1015 * Before deleting the entry, remember the next entry as the
1016 * return value. We need this because pfxlist_onlink_check() above
1017 * might have freed other entries (particularly the old next entry) as
1018 * a side effect (XXX).
1019 */
1020 next = ln->ln_next;
881
1021
1022 /*
1023 * Detach the route from the routing tree and the list of neighbor
1024 * caches, and disable the route entry not to be used in already
1025 * cached routes.
1026 */
882 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
883 rt_mask(rt), 0, (struct rtentry **)0);
1027 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
1028 rt_mask(rt), 0, (struct rtentry **)0);
1029
1030 return(next);
884}
885
886/*
887 * Upper-layer reachability hint for Neighbor Unreachability Detection.
888 *
889 * XXX cost-effective metods?
890 */
891void

--- 38 unchanged lines hidden (view full) ---

930 }
931
932 ln->ln_state = ND6_LLINFO_REACHABLE;
933 if (ln->ln_expire)
934 ln->ln_expire = time_second +
935 nd_ifinfo[rt->rt_ifp->if_index].reachable;
936}
937
1031}
1032
1033/*
1034 * Upper-layer reachability hint for Neighbor Unreachability Detection.
1035 *
1036 * XXX cost-effective metods?
1037 */
1038void

--- 38 unchanged lines hidden (view full) ---

1077 }
1078
1079 ln->ln_state = ND6_LLINFO_REACHABLE;
1080 if (ln->ln_expire)
1081 ln->ln_expire = time_second +
1082 nd_ifinfo[rt->rt_ifp->if_index].reachable;
1083}
1084
938#ifdef OLDIP6OUTPUT
939/*
940 * Resolve an IP6 address into an ethernet address. If success,
941 * desten is filled in. If there is no entry in ndptab,
942 * set one up and multicast a solicitation for the IP6 address.
943 * Hold onto this mbuf and resend it once the address
944 * is finally resolved. A return value of 1 indicates
945 * that desten has been filled in and the packet should be sent
946 * normally; a 0 return indicates that the packet has been
947 * taken over here, either now or for later transmission.
948 */
949int
950nd6_resolve(ifp, rt, m, dst, desten)
951 struct ifnet *ifp;
952 struct rtentry *rt;
953 struct mbuf *m;
954 struct sockaddr *dst;
955 u_char *desten;
956{
957 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)NULL;
958 struct sockaddr_dl *sdl;
959
960 if (m->m_flags & M_MCAST) {
961 switch (ifp->if_type) {
962 case IFT_ETHER:
963 case IFT_FDDI:
964 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr,
965 desten);
966 return(1);
967 break;
968 case IFT_ARCNET:
969 *desten = 0;
970 return(1);
971 break;
972 default:
973 m_freem(m);
974 return(0);
975 }
976 }
977 if (rt && (rt->rt_flags & RTF_LLINFO) != 0)
978 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
979 else {
980 if ((rt = nd6_lookup(&(SIN6(dst)->sin6_addr), 1, ifp)) != NULL)
981 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
982 }
983 if (!ln || !rt) {
984 log(LOG_DEBUG, "nd6_resolve: can't allocate llinfo for %s\n",
985 ip6_sprintf(&(SIN6(dst)->sin6_addr)));
986 m_freem(m);
987 return(0);
988 }
989 sdl = SDL(rt->rt_gateway);
990 /*
991 * Ckeck the address family and length is valid, the address
992 * is resolved; otherwise, try to resolve.
993 */
994 if (ln->ln_state >= ND6_LLINFO_REACHABLE
995 && sdl->sdl_family == AF_LINK
996 && sdl->sdl_alen != 0) {
997 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
998 if (ln->ln_state == ND6_LLINFO_STALE) {
999 ln->ln_asked = 0;
1000 ln->ln_state = ND6_LLINFO_DELAY;
1001 ln->ln_expire = time_second + nd6_delay;
1002 }
1003 return(1);
1004 }
1005 /*
1006 * There is an ndp entry, but no ethernet address
1007 * response yet. Replace the held mbuf with this
1008 * latest one.
1009 *
1010 * XXX Does the code conform to rate-limiting rule?
1011 * (RFC 2461 7.2.2)
1012 */
1013 if (ln->ln_state == ND6_LLINFO_WAITDELETE ||
1014 ln->ln_state == ND6_LLINFO_NOSTATE)
1015 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1016 if (ln->ln_hold)
1017 m_freem(ln->ln_hold);
1018 ln->ln_hold = m;
1019 if (ln->ln_expire) {
1020 rt->rt_flags &= ~RTF_REJECT;
1021 if (ln->ln_asked < nd6_mmaxtries &&
1022 ln->ln_expire < time_second) {
1023 ln->ln_asked++;
1024 ln->ln_expire = time_second +
1025 nd_ifinfo[ifp->if_index].retrans / 1000;
1026 nd6_ns_output(ifp, NULL, &(SIN6(dst)->sin6_addr),
1027 ln, 0);
1028 }
1029 }
1030 /* Do not free mbuf chain here as it is queued in llinfo_nd6 */
1031 return(0);
1032}
1033#endif /* OLDIP6OUTPUT */
1034
1035void
1036nd6_rtrequest(req, rt, sa)
1037 int req;
1038 struct rtentry *rt;
1039 struct sockaddr *sa; /* xxx unused */
1040{
1041 struct sockaddr *gate = rt->rt_gateway;
1042 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1043 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
1044 struct ifnet *ifp = rt->rt_ifp;
1045 struct ifaddr *ifa;
1046
1047 if (rt->rt_flags & RTF_GATEWAY)
1048 return;
1049
1085void
1086nd6_rtrequest(req, rt, sa)
1087 int req;
1088 struct rtentry *rt;
1089 struct sockaddr *sa; /* xxx unused */
1090{
1091 struct sockaddr *gate = rt->rt_gateway;
1092 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1093 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
1094 struct ifnet *ifp = rt->rt_ifp;
1095 struct ifaddr *ifa;
1096
1097 if (rt->rt_flags & RTF_GATEWAY)
1098 return;
1099
1100 if (nd6_need_cache(ifp) == 0 && (rt->rt_flags & RTF_HOST) == 0) {
1101 /*
1102 * This is probably an interface direct route for a link
1103 * which does not need neighbor caches (e.g. fe80::%lo0/64).
1104 * We do not need special treatment below for such a route.
1105 * Moreover, the RTF_LLINFO flag which would be set below
1106 * would annoy the ndp(8) command.
1107 */
1108 return;
1109 }
1110
1050 switch (req) {
1051 case RTM_ADD:
1052 /*
1053 * There is no backward compatibility :)
1054 *
1055 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1056 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1057 * rt->rt_flags |= RTF_CLONING;

--- 9 unchanged lines hidden (view full) ---

1067 (struct sockaddr *)&null_sdl);
1068 gate = rt->rt_gateway;
1069 SDL(gate)->sdl_type = ifp->if_type;
1070 SDL(gate)->sdl_index = ifp->if_index;
1071 if (ln)
1072 ln->ln_expire = time_second;
1073#if 1
1074 if (ln && ln->ln_expire == 0) {
1111 switch (req) {
1112 case RTM_ADD:
1113 /*
1114 * There is no backward compatibility :)
1115 *
1116 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1117 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1118 * rt->rt_flags |= RTF_CLONING;

--- 9 unchanged lines hidden (view full) ---

1128 (struct sockaddr *)&null_sdl);
1129 gate = rt->rt_gateway;
1130 SDL(gate)->sdl_type = ifp->if_type;
1131 SDL(gate)->sdl_index = ifp->if_index;
1132 if (ln)
1133 ln->ln_expire = time_second;
1134#if 1
1135 if (ln && ln->ln_expire == 0) {
1075 /* cludge for desktops */
1136 /* kludge for desktops */
1076#if 0
1077 printf("nd6_request: time.tv_sec is zero; "
1078 "treat it as 1\n");
1079#endif
1080 ln->ln_expire = 1;
1081 }
1082#endif
1083 if (rt->rt_flags & RTF_CLONING)

--- 4 unchanged lines hidden (view full) ---

1088 * We don't do that here since llinfo is not ready yet.
1089 *
1090 * There are also couple of other things to be discussed:
1091 * - unsolicited NA code needs improvement beforehand
1092 * - RFC2461 says we MAY send multicast unsolicited NA
1093 * (7.2.6 paragraph 4), however, it also says that we
1094 * SHOULD provide a mechanism to prevent multicast NA storm.
1095 * we don't have anything like it right now.
1137#if 0
1138 printf("nd6_request: time.tv_sec is zero; "
1139 "treat it as 1\n");
1140#endif
1141 ln->ln_expire = 1;
1142 }
1143#endif
1144 if (rt->rt_flags & RTF_CLONING)

--- 4 unchanged lines hidden (view full) ---

1149 * We don't do that here since llinfo is not ready yet.
1150 *
1151 * There are also couple of other things to be discussed:
1152 * - unsolicited NA code needs improvement beforehand
1153 * - RFC2461 says we MAY send multicast unsolicited NA
1154 * (7.2.6 paragraph 4), however, it also says that we
1155 * SHOULD provide a mechanism to prevent multicast NA storm.
1156 * we don't have anything like it right now.
1096 * note that the mechanism need a mutual agreement
1157 * note that the mechanism needs a mutual agreement
1097 * between proxies, which means that we need to implement
1158 * between proxies, which means that we need to implement
1098 * a new protocol, or new kludge.
1099 * - from RFC2461 6.2.4, host MUST NOT send unsolicited NA.
1159 * a new protocol, or a new kludge.
1160 * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA.
1100 * we need to check ip6forwarding before sending it.
1101 * (or should we allow proxy ND configuration only for
1102 * routers? there's no mention about proxy ND from hosts)
1103 */
1104#if 0
1105 /* XXX it does not work */
1106 if (rt->rt_flags & RTF_ANNOUNCE)
1107 nd6_na_output(ifp,
1108 &SIN6(rt_key(rt))->sin6_addr,
1109 &SIN6(rt_key(rt))->sin6_addr,
1110 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1111 1, NULL);
1112#endif
1113 /* FALLTHROUGH */
1114 case RTM_RESOLVE:
1161 * we need to check ip6forwarding before sending it.
1162 * (or should we allow proxy ND configuration only for
1163 * routers? there's no mention about proxy ND from hosts)
1164 */
1165#if 0
1166 /* XXX it does not work */
1167 if (rt->rt_flags & RTF_ANNOUNCE)
1168 nd6_na_output(ifp,
1169 &SIN6(rt_key(rt))->sin6_addr,
1170 &SIN6(rt_key(rt))->sin6_addr,
1171 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1172 1, NULL);
1173#endif
1174 /* FALLTHROUGH */
1175 case RTM_RESOLVE:
1115 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
1176 if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) {
1116 /*
1117 * Address resolution isn't necessary for a point to
1118 * point link, so we can skip this test for a p2p link.
1119 */
1120 if (gate->sa_family != AF_LINK ||
1121 gate->sa_len < sizeof(null_sdl)) {
1122 log(LOG_DEBUG,
1177 /*
1178 * Address resolution isn't necessary for a point to
1179 * point link, so we can skip this test for a p2p link.
1180 */
1181 if (gate->sa_family != AF_LINK ||
1182 gate->sa_len < sizeof(null_sdl)) {
1183 log(LOG_DEBUG,
1123 "nd6_rtrequest: bad gateway value\n");
1184 "nd6_rtrequest: bad gateway value: %s\n",
1185 if_name(ifp));
1124 break;
1125 }
1126 SDL(gate)->sdl_type = ifp->if_type;
1127 SDL(gate)->sdl_index = ifp->if_index;
1128 }
1129 if (ln != NULL)
1130 break; /* This happens on a route change */
1131 /*

--- 55 unchanged lines hidden (view full) ---

1187 * corresponding to the address.
1188 * We need this because when we refer
1189 * rt_ifa->ia6_flags in ip6_input, we assume
1190 * that the rt_ifa points to the address instead
1191 * of the loopback address.
1192 */
1193 if (ifa != rt->rt_ifa) {
1194 IFAFREE(rt->rt_ifa);
1186 break;
1187 }
1188 SDL(gate)->sdl_type = ifp->if_type;
1189 SDL(gate)->sdl_index = ifp->if_index;
1190 }
1191 if (ln != NULL)
1192 break; /* This happens on a route change */
1193 /*

--- 55 unchanged lines hidden (view full) ---

1249 * corresponding to the address.
1250 * We need this because when we refer
1251 * rt_ifa->ia6_flags in ip6_input, we assume
1252 * that the rt_ifa points to the address instead
1253 * of the loopback address.
1254 */
1255 if (ifa != rt->rt_ifa) {
1256 IFAFREE(rt->rt_ifa);
1195 ifa->ifa_refcnt++;
1257 IFAREF(ifa);
1196 rt->rt_ifa = ifa;
1197 }
1198 }
1199 } else if (rt->rt_flags & RTF_ANNOUNCE) {
1200 ln->ln_expire = 0;
1201 ln->ln_state = ND6_LLINFO_REACHABLE;
1202 ln->ln_byhint = 0;
1203

--- 4 unchanged lines hidden (view full) ---

1208
1209 llsol = SIN6(rt_key(rt))->sin6_addr;
1210 llsol.s6_addr16[0] = htons(0xff02);
1211 llsol.s6_addr16[1] = htons(ifp->if_index);
1212 llsol.s6_addr32[1] = 0;
1213 llsol.s6_addr32[2] = htonl(1);
1214 llsol.s6_addr8[12] = 0xff;
1215
1258 rt->rt_ifa = ifa;
1259 }
1260 }
1261 } else if (rt->rt_flags & RTF_ANNOUNCE) {
1262 ln->ln_expire = 0;
1263 ln->ln_state = ND6_LLINFO_REACHABLE;
1264 ln->ln_byhint = 0;
1265

--- 4 unchanged lines hidden (view full) ---

1270
1271 llsol = SIN6(rt_key(rt))->sin6_addr;
1272 llsol.s6_addr16[0] = htons(0xff02);
1273 llsol.s6_addr16[1] = htons(ifp->if_index);
1274 llsol.s6_addr32[1] = 0;
1275 llsol.s6_addr32[2] = htonl(1);
1276 llsol.s6_addr8[12] = 0xff;
1277
1216 (void)in6_addmulti(&llsol, ifp, &error);
1217 if (error)
1218 printf(
1219"nd6_rtrequest: could not join solicited node multicast (errno=%d)\n", error);
1278 if (!in6_addmulti(&llsol, ifp, &error)) {
1279 nd6log((LOG_ERR, "%s: failed to join "
1280 "%s (errno=%d)\n", if_name(ifp),
1281 ip6_sprintf(&llsol), error));
1282 }
1220 }
1221 }
1222 break;
1223
1224 case RTM_DELETE:
1225 if (!ln)
1226 break;
1227 /* leave from solicited node multicast for proxy ND */

--- 20 unchanged lines hidden (view full) ---

1248 rt->rt_llinfo = 0;
1249 rt->rt_flags &= ~RTF_LLINFO;
1250 if (ln->ln_hold)
1251 m_freem(ln->ln_hold);
1252 Free((caddr_t)ln);
1253 }
1254}
1255
1283 }
1284 }
1285 break;
1286
1287 case RTM_DELETE:
1288 if (!ln)
1289 break;
1290 /* leave from solicited node multicast for proxy ND */

--- 20 unchanged lines hidden (view full) ---

1311 rt->rt_llinfo = 0;
1312 rt->rt_flags &= ~RTF_LLINFO;
1313 if (ln->ln_hold)
1314 m_freem(ln->ln_hold);
1315 Free((caddr_t)ln);
1316 }
1317}
1318
1256void
1257nd6_p2p_rtrequest(req, rt, sa)
1258 int req;
1259 struct rtentry *rt;
1260 struct sockaddr *sa; /* xxx unused */
1261{
1262 struct sockaddr *gate = rt->rt_gateway;
1263 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
1264 struct ifnet *ifp = rt->rt_ifp;
1265 struct ifaddr *ifa;
1266
1267 if (rt->rt_flags & RTF_GATEWAY)
1268 return;
1269
1270 switch (req) {
1271 case RTM_ADD:
1272 /*
1273 * There is no backward compatibility :)
1274 *
1275 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1276 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1277 * rt->rt_flags |= RTF_CLONING;
1278 */
1279 if (rt->rt_flags & RTF_CLONING) {
1280 /*
1281 * Case 1: This route should come from
1282 * a route to interface.
1283 */
1284 rt_setgate(rt, rt_key(rt),
1285 (struct sockaddr *)&null_sdl);
1286 gate = rt->rt_gateway;
1287 SDL(gate)->sdl_type = ifp->if_type;
1288 SDL(gate)->sdl_index = ifp->if_index;
1289 break;
1290 }
1291 /* Announce a new entry if requested. */
1292 if (rt->rt_flags & RTF_ANNOUNCE)
1293 nd6_na_output(ifp,
1294 &SIN6(rt_key(rt))->sin6_addr,
1295 &SIN6(rt_key(rt))->sin6_addr,
1296 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1297 1, NULL);
1298 /* FALLTHROUGH */
1299 case RTM_RESOLVE:
1300 /*
1301 * check if rt_key(rt) is one of my address assigned
1302 * to the interface.
1303 */
1304 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp,
1305 &SIN6(rt_key(rt))->sin6_addr);
1306 if (ifa) {
1307 if (nd6_useloopback) {
1308 rt->rt_ifp = &loif[0]; /*XXX*/
1309 }
1310 }
1311 break;
1312 }
1313}
1314
1315int
1316nd6_ioctl(cmd, data, ifp)
1317 u_long cmd;
1318 caddr_t data;
1319 struct ifnet *ifp;
1320{
1321 struct in6_drlist *drl = (struct in6_drlist *)data;
1322 struct in6_prlist *prl = (struct in6_prlist *)data;
1323 struct in6_ndireq *ndi = (struct in6_ndireq *)data;
1324 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data;
1325 struct in6_ndifreq *ndif = (struct in6_ndifreq *)data;
1326 struct nd_defrouter *dr, any;
1327 struct nd_prefix *pr;
1328 struct rtentry *rt;
1329 int i = 0, error = 0;
1330 int s;
1331
1332 switch (cmd) {
1333 case SIOCGDRLST_IN6:
1319int
1320nd6_ioctl(cmd, data, ifp)
1321 u_long cmd;
1322 caddr_t data;
1323 struct ifnet *ifp;
1324{
1325 struct in6_drlist *drl = (struct in6_drlist *)data;
1326 struct in6_prlist *prl = (struct in6_prlist *)data;
1327 struct in6_ndireq *ndi = (struct in6_ndireq *)data;
1328 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data;
1329 struct in6_ndifreq *ndif = (struct in6_ndifreq *)data;
1330 struct nd_defrouter *dr, any;
1331 struct nd_prefix *pr;
1332 struct rtentry *rt;
1333 int i = 0, error = 0;
1334 int s;
1335
1336 switch (cmd) {
1337 case SIOCGDRLST_IN6:
1338 /*
1339 * obsolete API, use sysctl under net.inet6.icmp6
1340 */
1334 bzero(drl, sizeof(*drl));
1335 s = splnet();
1336 dr = TAILQ_FIRST(&nd_defrouter);
1337 while (dr && i < DRLSTSIZ) {
1338 drl->defrouter[i].rtaddr = dr->rtaddr;
1339 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
1340 /* XXX: need to this hack for KAME stack */
1341 drl->defrouter[i].rtaddr.s6_addr16[1] = 0;

--- 9 unchanged lines hidden (view full) ---

1351 drl->defrouter[i].if_index = dr->ifp->if_index;
1352 i++;
1353 dr = TAILQ_NEXT(dr, dr_entry);
1354 }
1355 splx(s);
1356 break;
1357 case SIOCGPRLST_IN6:
1358 /*
1341 bzero(drl, sizeof(*drl));
1342 s = splnet();
1343 dr = TAILQ_FIRST(&nd_defrouter);
1344 while (dr && i < DRLSTSIZ) {
1345 drl->defrouter[i].rtaddr = dr->rtaddr;
1346 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
1347 /* XXX: need to this hack for KAME stack */
1348 drl->defrouter[i].rtaddr.s6_addr16[1] = 0;

--- 9 unchanged lines hidden (view full) ---

1358 drl->defrouter[i].if_index = dr->ifp->if_index;
1359 i++;
1360 dr = TAILQ_NEXT(dr, dr_entry);
1361 }
1362 splx(s);
1363 break;
1364 case SIOCGPRLST_IN6:
1365 /*
1366 * obsolete API, use sysctl under net.inet6.icmp6
1367 */
1368 /*
1359 * XXX meaning of fields, especialy "raflags", is very
1360 * differnet between RA prefix list and RR/static prefix list.
1361 * how about separating ioctls into two?
1362 */
1363 bzero(prl, sizeof(*prl));
1364 s = splnet();
1365 pr = nd_prefix.lh_first;
1366 while (pr && i < PRLSTSIZ) {
1367 struct nd_pfxrouter *pfr;
1368 int j;
1369
1369 * XXX meaning of fields, especialy "raflags", is very
1370 * differnet between RA prefix list and RR/static prefix list.
1371 * how about separating ioctls into two?
1372 */
1373 bzero(prl, sizeof(*prl));
1374 s = splnet();
1375 pr = nd_prefix.lh_first;
1376 while (pr && i < PRLSTSIZ) {
1377 struct nd_pfxrouter *pfr;
1378 int j;
1379
1370 prl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr;
1380 (void)in6_embedscope(&prl->prefix[i].prefix,
1381 &pr->ndpr_prefix, NULL, NULL);
1371 prl->prefix[i].raflags = pr->ndpr_raf;
1372 prl->prefix[i].prefixlen = pr->ndpr_plen;
1373 prl->prefix[i].vltime = pr->ndpr_vltime;
1374 prl->prefix[i].pltime = pr->ndpr_pltime;
1375 prl->prefix[i].if_index = pr->ndpr_ifp->if_index;
1376 prl->prefix[i].expire = pr->ndpr_expire;
1377
1378 pfr = pr->ndpr_advrtrs.lh_first;
1379 j = 0;
1382 prl->prefix[i].raflags = pr->ndpr_raf;
1383 prl->prefix[i].prefixlen = pr->ndpr_plen;
1384 prl->prefix[i].vltime = pr->ndpr_vltime;
1385 prl->prefix[i].pltime = pr->ndpr_pltime;
1386 prl->prefix[i].if_index = pr->ndpr_ifp->if_index;
1387 prl->prefix[i].expire = pr->ndpr_expire;
1388
1389 pfr = pr->ndpr_advrtrs.lh_first;
1390 j = 0;
1380 while(pfr) {
1391 while (pfr) {
1381 if (j < DRLSTSIZ) {
1382#define RTRADDR prl->prefix[i].advrtr[j]
1383 RTRADDR = pfr->router->rtaddr;
1384 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) {
1385 /* XXX: hack for KAME */
1386 RTRADDR.s6_addr16[1] = 0;
1387 } else
1388 log(LOG_ERR,

--- 14 unchanged lines hidden (view full) ---

1403 }
1404 {
1405 struct rr_prefix *rpp;
1406
1407 for (rpp = LIST_FIRST(&rr_prefix); rpp;
1408 rpp = LIST_NEXT(rpp, rp_entry)) {
1409 if (i >= PRLSTSIZ)
1410 break;
1392 if (j < DRLSTSIZ) {
1393#define RTRADDR prl->prefix[i].advrtr[j]
1394 RTRADDR = pfr->router->rtaddr;
1395 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) {
1396 /* XXX: hack for KAME */
1397 RTRADDR.s6_addr16[1] = 0;
1398 } else
1399 log(LOG_ERR,

--- 14 unchanged lines hidden (view full) ---

1414 }
1415 {
1416 struct rr_prefix *rpp;
1417
1418 for (rpp = LIST_FIRST(&rr_prefix); rpp;
1419 rpp = LIST_NEXT(rpp, rp_entry)) {
1420 if (i >= PRLSTSIZ)
1421 break;
1411 prl->prefix[i].prefix = rpp->rp_prefix.sin6_addr;
1422 (void)in6_embedscope(&prl->prefix[i].prefix,
1423 &pr->ndpr_prefix, NULL, NULL);
1412 prl->prefix[i].raflags = rpp->rp_raf;
1413 prl->prefix[i].prefixlen = rpp->rp_plen;
1414 prl->prefix[i].vltime = rpp->rp_vltime;
1415 prl->prefix[i].pltime = rpp->rp_pltime;
1416 prl->prefix[i].if_index = rpp->rp_ifp->if_index;
1417 prl->prefix[i].expire = rpp->rp_expire;
1418 prl->prefix[i].advrtrs = 0;
1419 prl->prefix[i].origin = rpp->rp_origin;
1420 i++;
1421 }
1422 }
1423 splx(s);
1424
1425 break;
1424 prl->prefix[i].raflags = rpp->rp_raf;
1425 prl->prefix[i].prefixlen = rpp->rp_plen;
1426 prl->prefix[i].vltime = rpp->rp_vltime;
1427 prl->prefix[i].pltime = rpp->rp_pltime;
1428 prl->prefix[i].if_index = rpp->rp_ifp->if_index;
1429 prl->prefix[i].expire = rpp->rp_expire;
1430 prl->prefix[i].advrtrs = 0;
1431 prl->prefix[i].origin = rpp->rp_origin;
1432 i++;
1433 }
1434 }
1435 splx(s);
1436
1437 break;
1438 case OSIOCGIFINFO_IN6:
1439 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1440 error = EINVAL;
1441 break;
1442 }
1443 ndi->ndi.linkmtu = nd_ifinfo[ifp->if_index].linkmtu;
1444 ndi->ndi.maxmtu = nd_ifinfo[ifp->if_index].maxmtu;
1445 ndi->ndi.basereachable =
1446 nd_ifinfo[ifp->if_index].basereachable;
1447 ndi->ndi.reachable = nd_ifinfo[ifp->if_index].reachable;
1448 ndi->ndi.retrans = nd_ifinfo[ifp->if_index].retrans;
1449 ndi->ndi.flags = nd_ifinfo[ifp->if_index].flags;
1450 ndi->ndi.recalctm = nd_ifinfo[ifp->if_index].recalctm;
1451 ndi->ndi.chlim = nd_ifinfo[ifp->if_index].chlim;
1452 ndi->ndi.receivedra = nd_ifinfo[ifp->if_index].receivedra;
1453 break;
1426 case SIOCGIFINFO_IN6:
1427 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1428 error = EINVAL;
1429 break;
1430 }
1431 ndi->ndi = nd_ifinfo[ifp->if_index];
1432 break;
1433 case SIOCSIFINFO_FLAGS:

--- 17 unchanged lines hidden (view full) ---

1451 break;
1452 case SIOCSPFXFLUSH_IN6:
1453 {
1454 /* flush all the prefix advertised by routers */
1455 struct nd_prefix *pr, *next;
1456
1457 s = splnet();
1458 for (pr = nd_prefix.lh_first; pr; pr = next) {
1454 case SIOCGIFINFO_IN6:
1455 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1456 error = EINVAL;
1457 break;
1458 }
1459 ndi->ndi = nd_ifinfo[ifp->if_index];
1460 break;
1461 case SIOCSIFINFO_FLAGS:

--- 17 unchanged lines hidden (view full) ---

1479 break;
1480 case SIOCSPFXFLUSH_IN6:
1481 {
1482 /* flush all the prefix advertised by routers */
1483 struct nd_prefix *pr, *next;
1484
1485 s = splnet();
1486 for (pr = nd_prefix.lh_first; pr; pr = next) {
1487 struct in6_ifaddr *ia, *ia_next;
1488
1459 next = pr->ndpr_next;
1489 next = pr->ndpr_next;
1460 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
1461 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
1490
1491 if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
1492 continue; /* XXX */
1493
1494 /* do we really have to remove addresses as well? */
1495 for (ia = in6_ifaddr; ia; ia = ia_next) {
1496 /* ia might be removed. keep the next ptr. */
1497 ia_next = ia->ia_next;
1498
1499 if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0)
1500 continue;
1501
1502 if (ia->ia6_ndpr == pr)
1503 in6_purgeaddr(&ia->ia_ifa);
1504 }
1462 prelist_remove(pr);
1463 }
1464 splx(s);
1465 break;
1466 }
1467 case SIOCSRTRFLUSH_IN6:
1468 {
1469 /* flush all the default routers */

--- 102 unchanged lines hidden (view full) ---

1572#if 0
1573 /* nothing must be done if there's no lladdr */
1574 if (!lladdr || !lladdrlen)
1575 return NULL;
1576#endif
1577
1578 rt = nd6_lookup(from, 1, ifp);
1579 is_newentry = 1;
1505 prelist_remove(pr);
1506 }
1507 splx(s);
1508 break;
1509 }
1510 case SIOCSRTRFLUSH_IN6:
1511 {
1512 /* flush all the default routers */

--- 102 unchanged lines hidden (view full) ---

1615#if 0
1616 /* nothing must be done if there's no lladdr */
1617 if (!lladdr || !lladdrlen)
1618 return NULL;
1619#endif
1620
1621 rt = nd6_lookup(from, 1, ifp);
1622 is_newentry = 1;
1580 } else
1623 } else {
1624 /* do nothing if static ndp is set */
1625 if (rt->rt_flags & RTF_STATIC)
1626 return NULL;
1581 is_newentry = 0;
1627 is_newentry = 0;
1628 }
1582
1583 if (!rt)
1584 return NULL;
1585 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {
1586fail:
1629
1630 if (!rt)
1631 return NULL;
1632 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {
1633fail:
1587 nd6_free(rt);
1634 (void)nd6_free(rt);
1588 return NULL;
1589 }
1590 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1591 if (!ln)
1592 goto fail;
1593 if (!rt->rt_gateway)
1594 goto fail;
1595 if (rt->rt_gateway->sa_family != AF_LINK)

--- 46 unchanged lines hidden (view full) ---

1642
1643 if (do_update) {
1644 /*
1645 * Update the state of the neighbor cache.
1646 */
1647 ln->ln_state = newstate;
1648
1649 if (ln->ln_state == ND6_LLINFO_STALE) {
1635 return NULL;
1636 }
1637 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1638 if (!ln)
1639 goto fail;
1640 if (!rt->rt_gateway)
1641 goto fail;
1642 if (rt->rt_gateway->sa_family != AF_LINK)

--- 46 unchanged lines hidden (view full) ---

1689
1690 if (do_update) {
1691 /*
1692 * Update the state of the neighbor cache.
1693 */
1694 ln->ln_state = newstate;
1695
1696 if (ln->ln_state == ND6_LLINFO_STALE) {
1650 rt->rt_flags &= ~RTF_REJECT;
1697 /*
1698 * XXX: since nd6_output() below will cause
1699 * state tansition to DELAY and reset the timer,
1700 * we must set the timer now, although it is actually
1701 * meaningless.
1702 */
1703 ln->ln_expire = time_second + nd6_gctimer;
1704
1651 if (ln->ln_hold) {
1705 if (ln->ln_hold) {
1652#ifdef OLDIP6OUTPUT
1653 (*ifp->if_output)(ifp, ln->ln_hold,
1654 rt_key(rt), rt);
1655#else
1656 /*
1657 * we assume ifp is not a p2p here, so just
1658 * set the 2nd argument as the 1st one.
1659 */
1660 nd6_output(ifp, ifp, ln->ln_hold,
1661 (struct sockaddr_in6 *)rt_key(rt),
1662 rt);
1706 /*
1707 * we assume ifp is not a p2p here, so just
1708 * set the 2nd argument as the 1st one.
1709 */
1710 nd6_output(ifp, ifp, ln->ln_hold,
1711 (struct sockaddr_in6 *)rt_key(rt),
1712 rt);
1663#endif
1664 ln->ln_hold = 0;
1713 ln->ln_hold = NULL;
1665 }
1666 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
1667 /* probe right away */
1668 ln->ln_expire = time_second;
1669 }
1670 }
1671
1672 /*

--- 64 unchanged lines hidden (view full) ---

1737 return rt;
1738}
1739
1740static void
1741nd6_slowtimo(ignored_arg)
1742 void *ignored_arg;
1743{
1744 int s = splnet();
1714 }
1715 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
1716 /* probe right away */
1717 ln->ln_expire = time_second;
1718 }
1719 }
1720
1721 /*

--- 64 unchanged lines hidden (view full) ---

1786 return rt;
1787}
1788
1789static void
1790nd6_slowtimo(ignored_arg)
1791 void *ignored_arg;
1792{
1793 int s = splnet();
1745 register int i;
1746 register struct nd_ifinfo *nd6if;
1794 int i;
1795 struct nd_ifinfo *nd6if;
1747
1796
1748 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
1797 callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz,
1798 nd6_slowtimo, NULL);
1749 for (i = 1; i < if_index + 1; i++) {
1750 if (!nd_ifinfo || i >= nd_ifinfo_indexlim)
1751 continue;
1752 nd6if = &nd_ifinfo[i];
1753 if (nd6if->basereachable && /* already initialized */
1754 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) {
1755 /*
1756 * Since reachable time rarely changes by router

--- 6 unchanged lines hidden (view full) ---

1763 }
1764 }
1765 splx(s);
1766}
1767
1768#define senderr(e) { error = (e); goto bad;}
1769int
1770nd6_output(ifp, origifp, m0, dst, rt0)
1799 for (i = 1; i < if_index + 1; i++) {
1800 if (!nd_ifinfo || i >= nd_ifinfo_indexlim)
1801 continue;
1802 nd6if = &nd_ifinfo[i];
1803 if (nd6if->basereachable && /* already initialized */
1804 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) {
1805 /*
1806 * Since reachable time rarely changes by router

--- 6 unchanged lines hidden (view full) ---

1813 }
1814 }
1815 splx(s);
1816}
1817
1818#define senderr(e) { error = (e); goto bad;}
1819int
1820nd6_output(ifp, origifp, m0, dst, rt0)
1771 register struct ifnet *ifp;
1821 struct ifnet *ifp;
1772 struct ifnet *origifp;
1773 struct mbuf *m0;
1774 struct sockaddr_in6 *dst;
1775 struct rtentry *rt0;
1776{
1822 struct ifnet *origifp;
1823 struct mbuf *m0;
1824 struct sockaddr_in6 *dst;
1825 struct rtentry *rt0;
1826{
1777 register struct mbuf *m = m0;
1778 register struct rtentry *rt = rt0;
1827 struct mbuf *m = m0;
1828 struct rtentry *rt = rt0;
1779 struct sockaddr_in6 *gw6 = NULL;
1780 struct llinfo_nd6 *ln = NULL;
1781 int error = 0;
1782
1783 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
1784 goto sendpkt;
1785
1829 struct sockaddr_in6 *gw6 = NULL;
1830 struct llinfo_nd6 *ln = NULL;
1831 int error = 0;
1832
1833 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
1834 goto sendpkt;
1835
1786 /*
1787 * XXX: we currently do not make neighbor cache on any interface
1788 * other than ARCnet, Ethernet, FDDI and GIF.
1789 *
1790 * draft-ietf-ngtrans-mech-06.txt says:
1791 * - unidirectional tunnels needs no ND
1792 */
1793 switch (ifp->if_type) {
1794 case IFT_ARCNET:
1795 case IFT_ETHER:
1796 case IFT_FDDI:
1797 case IFT_GIF: /* XXX need more cases? */
1798 break;
1799 default:
1836 if (nd6_need_cache(ifp) == 0)
1800 goto sendpkt;
1837 goto sendpkt;
1801 }
1802
1803 /*
1804 * next hop determination. This routine is derived from ether_outpout.
1805 */
1806 if (rt) {
1807 if ((rt->rt_flags & RTF_UP) == 0) {
1808 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) !=
1809 NULL)

--- 9 unchanged lines hidden (view full) ---

1819 }
1820
1821 if (rt->rt_flags & RTF_GATEWAY) {
1822 gw6 = (struct sockaddr_in6 *)rt->rt_gateway;
1823
1824 /*
1825 * We skip link-layer address resolution and NUD
1826 * if the gateway is not a neighbor from ND point
1838
1839 /*
1840 * next hop determination. This routine is derived from ether_outpout.
1841 */
1842 if (rt) {
1843 if ((rt->rt_flags & RTF_UP) == 0) {
1844 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) !=
1845 NULL)

--- 9 unchanged lines hidden (view full) ---

1855 }
1856
1857 if (rt->rt_flags & RTF_GATEWAY) {
1858 gw6 = (struct sockaddr_in6 *)rt->rt_gateway;
1859
1860 /*
1861 * We skip link-layer address resolution and NUD
1862 * if the gateway is not a neighbor from ND point
1827 * of view, regardless the value of the value of
1863 * of view, regardless the value of the
1828 * nd_ifinfo.flags.
1829 * The second condition is a bit tricky: we skip
1830 * if the gateway is our own address, which is
1831 * sometimes used to install a route to a p2p link.
1832 */
1833 if (!nd6_is_addr_neighbor(gw6, ifp) ||
1834 in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) {
1864 * nd_ifinfo.flags.
1865 * The second condition is a bit tricky: we skip
1866 * if the gateway is our own address, which is
1867 * sometimes used to install a route to a p2p link.
1868 */
1869 if (!nd6_is_addr_neighbor(gw6, ifp) ||
1870 in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) {
1835 if (rt->rt_flags & RTF_REJECT)
1836 senderr(EHOSTDOWN);
1837
1838 /*
1839 * We allow this kind of tricky route only
1840 * when the outgoing interface is p2p.
1841 * XXX: we may need a more generic rule here.
1842 */
1843 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
1844 senderr(EHOSTUNREACH);
1845

--- 4 unchanged lines hidden (view full) ---

1850 goto lookup;
1851 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
1852 rtfree(rt); rt = rt0;
1853 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL);
1854 if ((rt = rt->rt_gwroute) == 0)
1855 senderr(EHOSTUNREACH);
1856 }
1857 }
1871 /*
1872 * We allow this kind of tricky route only
1873 * when the outgoing interface is p2p.
1874 * XXX: we may need a more generic rule here.
1875 */
1876 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
1877 senderr(EHOSTUNREACH);
1878

--- 4 unchanged lines hidden (view full) ---

1883 goto lookup;
1884 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
1885 rtfree(rt); rt = rt0;
1886 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL);
1887 if ((rt = rt->rt_gwroute) == 0)
1888 senderr(EHOSTUNREACH);
1889 }
1890 }
1858 if (rt->rt_flags & RTF_REJECT)
1859 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
1860 }
1861
1862 /*
1863 * Address resolution or Neighbor Unreachability Detection
1864 * for the next hop.
1865 * At this point, the destination of the packet must be a unicast
1866 * or an anycast address(i.e. not a multicast).
1867 */

--- 21 unchanged lines hidden (view full) ---

1889 senderr(EIO); /* XXX: good error? */
1890 }
1891
1892 goto sendpkt; /* send anyway */
1893 }
1894
1895 /* We don't have to do link-layer address resolution on a p2p link. */
1896 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 &&
1891 }
1892
1893 /*
1894 * Address resolution or Neighbor Unreachability Detection
1895 * for the next hop.
1896 * At this point, the destination of the packet must be a unicast
1897 * or an anycast address(i.e. not a multicast).
1898 */

--- 21 unchanged lines hidden (view full) ---

1920 senderr(EIO); /* XXX: good error? */
1921 }
1922
1923 goto sendpkt; /* send anyway */
1924 }
1925
1926 /* We don't have to do link-layer address resolution on a p2p link. */
1927 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 &&
1897 ln->ln_state < ND6_LLINFO_REACHABLE)
1928 ln->ln_state < ND6_LLINFO_REACHABLE) {
1898 ln->ln_state = ND6_LLINFO_STALE;
1929 ln->ln_state = ND6_LLINFO_STALE;
1930 ln->ln_expire = time_second + nd6_gctimer;
1931 }
1899
1900 /*
1901 * The first time we send a packet to a neighbor whose entry is
1902 * STALE, we have to change the state to DELAY and a sets a timer to
1903 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
1904 * neighbor unreachability detection on expiration.
1905 * (RFC 2461 7.3.3)
1906 */

--- 14 unchanged lines hidden (view full) ---

1921 /*
1922 * There is a neighbor cache entry, but no ethernet address
1923 * response yet. Replace the held mbuf (if any) with this
1924 * latest one.
1925 *
1926 * XXX Does the code conform to rate-limiting rule?
1927 * (RFC 2461 7.2.2)
1928 */
1932
1933 /*
1934 * The first time we send a packet to a neighbor whose entry is
1935 * STALE, we have to change the state to DELAY and a sets a timer to
1936 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
1937 * neighbor unreachability detection on expiration.
1938 * (RFC 2461 7.3.3)
1939 */

--- 14 unchanged lines hidden (view full) ---

1954 /*
1955 * There is a neighbor cache entry, but no ethernet address
1956 * response yet. Replace the held mbuf (if any) with this
1957 * latest one.
1958 *
1959 * XXX Does the code conform to rate-limiting rule?
1960 * (RFC 2461 7.2.2)
1961 */
1929 if (ln->ln_state == ND6_LLINFO_WAITDELETE ||
1930 ln->ln_state == ND6_LLINFO_NOSTATE)
1962 if (ln->ln_state == ND6_LLINFO_NOSTATE)
1931 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1932 if (ln->ln_hold)
1933 m_freem(ln->ln_hold);
1934 ln->ln_hold = m;
1935 if (ln->ln_expire) {
1963 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1964 if (ln->ln_hold)
1965 m_freem(ln->ln_hold);
1966 ln->ln_hold = m;
1967 if (ln->ln_expire) {
1936 rt->rt_flags &= ~RTF_REJECT;
1937 if (ln->ln_asked < nd6_mmaxtries &&
1938 ln->ln_expire < time_second) {
1939 ln->ln_asked++;
1940 ln->ln_expire = time_second +
1941 nd_ifinfo[ifp->if_index].retrans / 1000;
1942 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
1943 }
1944 }
1945 return(0);
1946
1947 sendpkt:
1948
1968 if (ln->ln_asked < nd6_mmaxtries &&
1969 ln->ln_expire < time_second) {
1970 ln->ln_asked++;
1971 ln->ln_expire = time_second +
1972 nd_ifinfo[ifp->if_index].retrans / 1000;
1973 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
1974 }
1975 }
1976 return(0);
1977
1978 sendpkt:
1979
1949#ifdef FAKE_LOOPBACK_IF
1950 if (ifp->if_flags & IFF_LOOPBACK) {
1980 if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
1951 return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
1952 rt));
1953 }
1981 return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
1982 rt));
1983 }
1954#endif
1955 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt));
1956
1957 bad:
1958 if (m)
1959 m_freem(m);
1960 return (error);
1961}
1962#undef senderr
1963
1964int
1984 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt));
1985
1986 bad:
1987 if (m)
1988 m_freem(m);
1989 return (error);
1990}
1991#undef senderr
1992
1993int
1994nd6_need_cache(ifp)
1995 struct ifnet *ifp;
1996{
1997 /*
1998 * XXX: we currently do not make neighbor cache on any interface
1999 * other than ARCnet, Ethernet, FDDI and GIF.
2000 *
2001 * RFC2893 says:
2002 * - unidirectional tunnels needs no ND
2003 */
2004 switch (ifp->if_type) {
2005 case IFT_ARCNET:
2006 case IFT_ETHER:
2007 case IFT_FDDI:
2008 case IFT_IEEE1394:
2009#ifdef IFT_IEEE80211
2010 case IFT_IEEE80211:
2011#endif
2012 case IFT_GIF: /* XXX need more cases? */
2013 return(1);
2014 default:
2015 return(0);
2016 }
2017}
2018
2019int
1965nd6_storelladdr(ifp, rt, m, dst, desten)
1966 struct ifnet *ifp;
1967 struct rtentry *rt;
1968 struct mbuf *m;
1969 struct sockaddr *dst;
1970 u_char *desten;
1971{
2020nd6_storelladdr(ifp, rt, m, dst, desten)
2021 struct ifnet *ifp;
2022 struct rtentry *rt;
2023 struct mbuf *m;
2024 struct sockaddr *dst;
2025 u_char *desten;
2026{
2027 int i;
1972 struct sockaddr_dl *sdl;
1973
1974 if (m->m_flags & M_MCAST) {
1975 switch (ifp->if_type) {
1976 case IFT_ETHER:
2028 struct sockaddr_dl *sdl;
2029
2030 if (m->m_flags & M_MCAST) {
2031 switch (ifp->if_type) {
2032 case IFT_ETHER:
1977 case IFT_FDDI:
2033 case IFT_FDDI:
2034#ifdef IFT_IEEE80211
2035 case IFT_IEEE80211:
2036#endif
1978 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr,
1979 desten);
1980 return(1);
2037 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr,
2038 desten);
2039 return(1);
1981 break;
2040 case IFT_IEEE1394:
2041 for (i = 0; i < ifp->if_addrlen; i++)
2042 desten[i] = ~0;
2043 return(1);
1982 case IFT_ARCNET:
1983 *desten = 0;
1984 return(1);
1985 default:
1986 m_freem(m);
1987 return(0);
1988 }
1989 }
1990
1991 if (rt == NULL) {
2044 case IFT_ARCNET:
2045 *desten = 0;
2046 return(1);
2047 default:
2048 m_freem(m);
2049 return(0);
2050 }
2051 }
2052
2053 if (rt == NULL) {
1992 /* This could happen if we could not allocate memory */
2054 /* this could happen, if we could not allocate memory */
1993 m_freem(m);
1994 return(0);
1995 }
1996 if (rt->rt_gateway->sa_family != AF_LINK) {
2055 m_freem(m);
2056 return(0);
2057 }
2058 if (rt->rt_gateway->sa_family != AF_LINK) {
1997 printf("nd6_storelladdr: something odd happened\n");
2059 printf("nd6_storelladdr: something odd happens\n");
1998 m_freem(m);
1999 return(0);
2000 }
2001 sdl = SDL(rt->rt_gateway);
2002 if (sdl->sdl_alen == 0) {
2003 /* this should be impossible, but we bark here for debugging */
2004 printf("nd6_storelladdr: sdl_alen == 0\n");
2005 m_freem(m);
2006 return(0);
2007 }
2008
2009 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
2010 return(1);
2011}
2060 m_freem(m);
2061 return(0);
2062 }
2063 sdl = SDL(rt->rt_gateway);
2064 if (sdl->sdl_alen == 0) {
2065 /* this should be impossible, but we bark here for debugging */
2066 printf("nd6_storelladdr: sdl_alen == 0\n");
2067 m_freem(m);
2068 return(0);
2069 }
2070
2071 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
2072 return(1);
2073}
2074
2075static int nd6_sysctl_drlist(SYSCTL_HANDLER_ARGS);
2076static int nd6_sysctl_prlist(SYSCTL_HANDLER_ARGS);
2077#ifdef SYSCTL_DECL
2078SYSCTL_DECL(_net_inet6_icmp6);
2079#endif
2080SYSCTL_NODE(_net_inet6_icmp6, ICMPV6CTL_ND6_DRLIST, nd6_drlist,
2081 CTLFLAG_RD, nd6_sysctl_drlist, "");
2082SYSCTL_NODE(_net_inet6_icmp6, ICMPV6CTL_ND6_PRLIST, nd6_prlist,
2083 CTLFLAG_RD, nd6_sysctl_prlist, "");
2084
2085static int
2086nd6_sysctl_drlist(SYSCTL_HANDLER_ARGS)
2087{
2088 int error;
2089 char buf[1024];
2090 struct in6_defrouter *d, *de;
2091 struct nd_defrouter *dr;
2092
2093 if (req->newptr)
2094 return EPERM;
2095 error = 0;
2096
2097 for (dr = TAILQ_FIRST(&nd_defrouter);
2098 dr;
2099 dr = TAILQ_NEXT(dr, dr_entry)) {
2100 d = (struct in6_defrouter *)buf;
2101 de = (struct in6_defrouter *)(buf + sizeof(buf));
2102
2103 if (d + 1 <= de) {
2104 bzero(d, sizeof(*d));
2105 d->rtaddr.sin6_family = AF_INET6;
2106 d->rtaddr.sin6_len = sizeof(d->rtaddr);
2107 if (in6_recoverscope(&d->rtaddr, &dr->rtaddr,
2108 dr->ifp) != 0)
2109 log(LOG_ERR,
2110 "scope error in "
2111 "default router list (%s)\n",
2112 ip6_sprintf(&dr->rtaddr));
2113 d->flags = dr->flags;
2114 d->rtlifetime = dr->rtlifetime;
2115 d->expire = dr->expire;
2116 d->if_index = dr->ifp->if_index;
2117 } else
2118 panic("buffer too short");
2119
2120 error = SYSCTL_OUT(req, buf, sizeof(*d));
2121 if (error)
2122 break;
2123 }
2124 return error;
2125}
2126
2127static int
2128nd6_sysctl_prlist(SYSCTL_HANDLER_ARGS)
2129{
2130 int error;
2131 char buf[1024];
2132 struct in6_prefix *p, *pe;
2133 struct nd_prefix *pr;
2134
2135 if (req->newptr)
2136 return EPERM;
2137 error = 0;
2138
2139 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
2140 u_short advrtrs;
2141 size_t advance;
2142 struct sockaddr_in6 *sin6, *s6;
2143 struct nd_pfxrouter *pfr;
2144
2145 p = (struct in6_prefix *)buf;
2146 pe = (struct in6_prefix *)(buf + sizeof(buf));
2147
2148 if (p + 1 <= pe) {
2149 bzero(p, sizeof(*p));
2150 sin6 = (struct sockaddr_in6 *)(p + 1);
2151
2152 p->prefix = pr->ndpr_prefix;
2153 if (in6_recoverscope(&p->prefix,
2154 &p->prefix.sin6_addr, pr->ndpr_ifp) != 0)
2155 log(LOG_ERR,
2156 "scope error in prefix list (%s)\n",
2157 ip6_sprintf(&p->prefix.sin6_addr));
2158 p->raflags = pr->ndpr_raf;
2159 p->prefixlen = pr->ndpr_plen;
2160 p->vltime = pr->ndpr_vltime;
2161 p->pltime = pr->ndpr_pltime;
2162 p->if_index = pr->ndpr_ifp->if_index;
2163 p->expire = pr->ndpr_expire;
2164 p->refcnt = pr->ndpr_refcnt;
2165 p->flags = pr->ndpr_stateflags;
2166 p->origin = PR_ORIG_RA;
2167 advrtrs = 0;
2168 for (pfr = pr->ndpr_advrtrs.lh_first;
2169 pfr;
2170 pfr = pfr->pfr_next) {
2171 if ((void *)&sin6[advrtrs + 1] >
2172 (void *)pe) {
2173 advrtrs++;
2174 continue;
2175 }
2176 s6 = &sin6[advrtrs];
2177 bzero(s6, sizeof(*s6));
2178 s6->sin6_family = AF_INET6;
2179 s6->sin6_len = sizeof(*sin6);
2180 if (in6_recoverscope(s6,
2181 &pfr->router->rtaddr,
2182 pfr->router->ifp) != 0)
2183 log(LOG_ERR,
2184 "scope error in "
2185 "prefix list (%s)\n",
2186 ip6_sprintf(&pfr->router->rtaddr));
2187 advrtrs++;
2188 }
2189 p->advrtrs = advrtrs;
2190 } else
2191 panic("buffer too short");
2192
2193 advance = sizeof(*p) + sizeof(*sin6) * advrtrs;
2194 error = SYSCTL_OUT(req, buf, advance);
2195 if (error)
2196 break;
2197 }
2198 return error;
2199}