Deleted Added
full compact
nd6.c (59333) nd6.c (62587)
1/* $FreeBSD: head/sys/netinet6/nd6.c 62587 2000-07-04 16:35:15Z itojun $ */
2/* $KAME: nd6.c,v 1.68 2000/07/02 14:48:02 itojun Exp $ */
3
1/*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
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:
11 * 1. Redistributions of source code must retain the above copyright

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

23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/netinet6/nd6.c 59333 2000-04-17 20:24:06Z sumikawa $
30 */
31
32/*
33 * XXX
34 * KAME 970409 note:
35 * BSD/OS version heavily modifies this code, related to llinfo.
36 * Since we don't have BSD/OS version of net/route.c in our hand,
37 * I left the code mostly as it was in 970310. -- itojun
38 */
39
31 */
32
33/*
34 * XXX
35 * KAME 970409 note:
36 * BSD/OS version heavily modifies this code, related to llinfo.
37 * Since we don't have BSD/OS version of net/route.c in our hand,
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
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <sys/mbuf.h>
44#include <sys/socket.h>
45#include <sys/sockio.h>
46#include <sys/time.h>
47#include <sys/kernel.h>
44#include <sys/param.h>
45#include <sys/systm.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>
48#include <sys/errno.h>
49#include <sys/syslog.h>
50#include <sys/queue.h>
51
52#include <net/if.h>
53#include <net/if_dl.h>
54#include <net/if_types.h>
55#include <net/if_atm.h>
56#include <net/route.h>
57
58#include <netinet/in.h>
59#include <netinet/if_ether.h>
60#include <netinet/if_fddi.h>
61#include <netinet6/in6_var.h>
53#include <sys/errno.h>
54#include <sys/syslog.h>
55#include <sys/queue.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>
64#include <netinet/if_ether.h>
65#include <netinet/if_fddi.h>
66#include <netinet6/in6_var.h>
62#include <netinet6/ip6.h>
67#include
63#include <netinet6/ip6_var.h>
64#include <netinet6/nd6.h>
65#include <netinet6/in6_prefix.h>
68#include <netinet6/ip6_var.h>
69#include <netinet6/nd6.h>
70#include <netinet6/in6_prefix.h>
66#include <netinet6/icmp6.h>
71#include
67
68#include "loop.h"
69
70#include <net/net_osdep.h>
71
72
73#include "loop.h"
74
75#include <net/net_osdep.h>
76
72#define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */
73#define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */
77#define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */
78#define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */
74
79
75#define SIN6(s) ((struct sockaddr_in6 *)s)
76#define SDL(s) ((struct sockaddr_dl *)s)
80#define SIN6(s) ((struct sockaddr_in6 *)s)
81#define SDL(s) ((struct sockaddr_dl *)s)
77
78/* timer values */
79int nd6_prune = 1; /* walk list every 1 seconds */
80int nd6_delay = 5; /* delay first probe time 5 second */
81int nd6_umaxtries = 3; /* maximum unicast query */
82int nd6_mmaxtries = 3; /* maximum multicast query */
83int nd6_useloopback = 1; /* use loopback interface for local traffic */
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 */
84int nd6_proxyall = 0; /* enable Proxy Neighbor Advertisement */
85
89
90/* preventing too many loops in ND option parsing */
91int nd6_maxndopt = 10; /* max # of ND options allowed */
92
93int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */
94
86/* for debugging? */
95/* for debugging? */
87static int nd6_inuse, nd6_allocated;
96static int nd6_inuse, nd6_allocated;
88
97
89struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6};
90struct nd_ifinfo *nd_ifinfo = NULL;
91struct nd_drhead nd_defrouter = { 0 };
92struct nd_prhead nd_prefix = { 0 };
98struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6};
99static size_t nd_ifinfo_indexlim = 8;
100struct nd_ifinfo *nd_ifinfo = NULL;
101struct nd_drhead nd_defrouter;
102struct nd_prhead nd_prefix = { 0 };
93
103
94int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
95static struct sockaddr_in6 all1_sa;
104int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
105static struct sockaddr_in6 all1_sa;
96
106
97static void nd6_slowtimo __P((void *));
107static void nd6_slowtimo __P((void *));
98
99void
100nd6_init()
101{
102 static int nd6_init_done = 0;
103 int i;
104
105 if (nd6_init_done) {
106 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n");
107 return;
108 }
109
110 all1_sa.sin6_family = AF_INET6;
111 all1_sa.sin6_len = sizeof(struct sockaddr_in6);
112 for (i = 0; i < sizeof(all1_sa.sin6_addr); i++)
113 all1_sa.sin6_addr.s6_addr[i] = 0xff;
114
108
109void
110nd6_init()
111{
112 static int nd6_init_done = 0;
113 int i;
114
115 if (nd6_init_done) {
116 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n");
117 return;
118 }
119
120 all1_sa.sin6_family = AF_INET6;
121 all1_sa.sin6_len = sizeof(struct sockaddr_in6);
122 for (i = 0; i < sizeof(all1_sa.sin6_addr); i++)
123 all1_sa.sin6_addr.s6_addr[i] = 0xff;
124
125 /* initialization of the default router list */
126 TAILQ_INIT(&nd_defrouter);
127
115 nd6_init_done = 1;
116
117 /* start timer */
118 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
119}
120
121void
122nd6_ifattach(ifp)
123 struct ifnet *ifp;
124{
128 nd6_init_done = 1;
129
130 /* start timer */
131 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
132}
133
134void
135nd6_ifattach(ifp)
136 struct ifnet *ifp;
137{
125 static size_t if_indexlim = 8;
126
127 /*
128 * We have some arrays that should be indexed by if_index.
129 * since if_index will grow dynamically, they should grow too.
130 */
138
139 /*
140 * We have some arrays that should be indexed by if_index.
141 * since if_index will grow dynamically, they should grow too.
142 */
131 if (nd_ifinfo == NULL || if_index >= if_indexlim) {
143 if (nd_ifinfo == NULL || if_index >= nd_ifinfo_indexlim) {
132 size_t n;
133 caddr_t q;
134
144 size_t n;
145 caddr_t q;
146
135 while (if_index >= if_indexlim)
136 if_indexlim <<= 1;
147 while (if_index >= nd_ifinfo_indexlim)
148 nd_ifinfo_indexlim <<= 1;
137
138 /* grow nd_ifinfo */
149
150 /* grow nd_ifinfo */
139 n = if_indexlim * sizeof(struct nd_ifinfo);
151 n = nd_ifinfo_indexlim * sizeof(struct nd_ifinfo);
140 q = (caddr_t)malloc(n, M_IP6NDP, M_WAITOK);
141 bzero(q, n);
142 if (nd_ifinfo) {
143 bcopy((caddr_t)nd_ifinfo, q, n/2);
144 free((caddr_t)nd_ifinfo, M_IP6NDP);
145 }
146 nd_ifinfo = (struct nd_ifinfo *)q;
147 }
148
149#define ND nd_ifinfo[ifp->if_index]
152 q = (caddr_t)malloc(n, M_IP6NDP, M_WAITOK);
153 bzero(q, n);
154 if (nd_ifinfo) {
155 bcopy((caddr_t)nd_ifinfo, q, n/2);
156 free((caddr_t)nd_ifinfo, M_IP6NDP);
157 }
158 nd_ifinfo = (struct nd_ifinfo *)q;
159 }
160
161#define ND nd_ifinfo[ifp->if_index]
162
163 /* don't initialize if called twice */
164 if (ND.linkmtu)
165 return;
166
150 ND.linkmtu = ifindex2ifnet[ifp->if_index]->if_mtu;
151 ND.chlim = IPV6_DEFHLIM;
152 ND.basereachable = REACHABLE_TIME;
153 ND.reachable = ND_COMPUTE_RTIME(ND.basereachable);
154 ND.retrans = RETRANS_TIMER;
155 ND.receivedra = 0;
167 ND.linkmtu = ifindex2ifnet[ifp->if_index]->if_mtu;
168 ND.chlim = IPV6_DEFHLIM;
169 ND.basereachable = REACHABLE_TIME;
170 ND.reachable = ND_COMPUTE_RTIME(ND.basereachable);
171 ND.retrans = RETRANS_TIMER;
172 ND.receivedra = 0;
173 ND.flags = ND6_IFF_PERFORMNUD;
156 nd6_setmtu(ifp);
157#undef ND
158}
159
160/*
161 * Reset ND level link MTU. This function is called when the physical MTU
162 * changes, which means we might have to adjust the ND level MTU.
163 */

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

325 ndopts->nd_opts_pi_end =
326 (struct nd_opt_prefix_info *)nd_opt;
327 break;
328 default:
329 /*
330 * Unknown options must be silently ignored,
331 * to accomodate future extension to the protocol.
332 */
174 nd6_setmtu(ifp);
175#undef ND
176}
177
178/*
179 * Reset ND level link MTU. This function is called when the physical MTU
180 * changes, which means we might have to adjust the ND level MTU.
181 */

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

343 ndopts->nd_opts_pi_end =
344 (struct nd_opt_prefix_info *)nd_opt;
345 break;
346 default:
347 /*
348 * Unknown options must be silently ignored,
349 * to accomodate future extension to the protocol.
350 */
333 log(LOG_INFO,
351 log(LOG_DEBUG,
334 "nd6_options: unsupported option %d - "
335 "option ignored\n", nd_opt->nd_opt_type);
336 }
337
338skip1:
339 i++;
352 "nd6_options: unsupported option %d - "
353 "option ignored\n", nd_opt->nd_opt_type);
354 }
355
356skip1:
357 i++;
340 if (i > 10) {
358 if (i > nd6_maxndopt) {
359 icmp6stat.icp6s_nd_toomanyopt++;
341 printf("too many loop in nd opt\n");
342 break;
343 }
344
345 if (ndopts->nd_opts_done)
346 break;
347 }
348

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

366
367 ln = llinfo_nd6.ln_next;
368 /* XXX BSD/OS separates this code -- itojun */
369 while (ln && ln != &llinfo_nd6) {
370 struct rtentry *rt;
371 struct ifnet *ifp;
372 struct sockaddr_in6 *dst;
373 struct llinfo_nd6 *next = ln->ln_next;
360 printf("too many loop in nd opt\n");
361 break;
362 }
363
364 if (ndopts->nd_opts_done)
365 break;
366 }
367

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

385
386 ln = llinfo_nd6.ln_next;
387 /* XXX BSD/OS separates this code -- itojun */
388 while (ln && ln != &llinfo_nd6) {
389 struct rtentry *rt;
390 struct ifnet *ifp;
391 struct sockaddr_in6 *dst;
392 struct llinfo_nd6 *next = ln->ln_next;
393 /* XXX: used for the DELAY case only: */
394 struct nd_ifinfo *ndi = NULL;
374
375 if ((rt = ln->ln_rt) == NULL) {
376 ln = next;
377 continue;
378 }
379 if ((ifp = rt->rt_ifp) == NULL) {
380 ln = next;
381 continue;
382 }
395
396 if ((rt = ln->ln_rt) == NULL) {
397 ln = next;
398 continue;
399 }
400 if ((ifp = rt->rt_ifp) == NULL) {
401 ln = next;
402 continue;
403 }
404 ndi = &nd_ifinfo[ifp->if_index];
383 dst = (struct sockaddr_in6 *)rt_key(rt);
384
385 if (ln->ln_expire > time_second) {
386 ln = next;
387 continue;
388 }
389
390 /* sanity check */
391 if (!rt)
392 panic("rt=0 in nd6_timer(ln=%p)\n", ln);
405 dst = (struct sockaddr_in6 *)rt_key(rt);
406
407 if (ln->ln_expire > time_second) {
408 ln = next;
409 continue;
410 }
411
412 /* sanity check */
413 if (!rt)
414 panic("rt=0 in nd6_timer(ln=%p)\n", ln);
415 if (rt->rt_llinfo && (struct llinfo_nd6 *)rt->rt_llinfo != ln)
416 panic("rt_llinfo(%p) is not equal to ln(%p)\n",
417 rt->rt_llinfo, ln);
393 if (!dst)
394 panic("dst=0 in nd6_timer(ln=%p)\n", ln);
395
396 switch (ln->ln_state) {
397 case ND6_LLINFO_INCOMPLETE:
398 if (ln->ln_asked < nd6_mmaxtries) {
399 ln->ln_asked++;
400 ln->ln_expire = time_second +

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

417 icmp6_error(m, ICMP6_DST_UNREACH,
418 ICMP6_DST_UNREACH_ADDR, 0);
419 ln->ln_hold = NULL;
420 }
421 nd6_free(rt);
422 }
423 break;
424 case ND6_LLINFO_REACHABLE:
418 if (!dst)
419 panic("dst=0 in nd6_timer(ln=%p)\n", ln);
420
421 switch (ln->ln_state) {
422 case ND6_LLINFO_INCOMPLETE:
423 if (ln->ln_asked < nd6_mmaxtries) {
424 ln->ln_asked++;
425 ln->ln_expire = time_second +

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

442 icmp6_error(m, ICMP6_DST_UNREACH,
443 ICMP6_DST_UNREACH_ADDR, 0);
444 ln->ln_hold = NULL;
445 }
446 nd6_free(rt);
447 }
448 break;
449 case ND6_LLINFO_REACHABLE:
425 if (ln->ln_expire) {
450 if (ln->ln_expire)
426 ln->ln_state = ND6_LLINFO_STALE;
451 ln->ln_state = ND6_LLINFO_STALE;
427 }
428 break;
429 /*
430 * ND6_LLINFO_STALE state requires nothing for timer
431 * routine.
432 */
433 case ND6_LLINFO_DELAY:
452 break;
453 /*
454 * ND6_LLINFO_STALE state requires nothing for timer
455 * routine.
456 */
457 case ND6_LLINFO_DELAY:
434 ln->ln_asked = 1;
435 ln->ln_state = ND6_LLINFO_PROBE;
436 ln->ln_expire = time_second +
437 nd_ifinfo[ifp->if_index].retrans / 1000;
438 nd6_ns_output(ifp, &dst->sin6_addr, &dst->sin6_addr,
439 ln, 0);
458 if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) {
459 /* We need NUD */
460 ln->ln_asked = 1;
461 ln->ln_state = ND6_LLINFO_PROBE;
462 ln->ln_expire = time_second +
463 ndi->retrans / 1000;
464 nd6_ns_output(ifp, &dst->sin6_addr,
465 &dst->sin6_addr,
466 ln, 0);
467 } else
468 ln->ln_state = ND6_LLINFO_STALE; /* XXX */
440 break;
469 break;
441
442 case ND6_LLINFO_PROBE:
443 if (ln->ln_asked < nd6_umaxtries) {
444 ln->ln_asked++;
445 ln->ln_expire = time_second +
446 nd_ifinfo[ifp->if_index].retrans / 1000;
447 nd6_ns_output(ifp, &dst->sin6_addr,
448 &dst->sin6_addr, ln, 0);
449 } else {
450 nd6_free(rt);
451 }
452 break;
453 case ND6_LLINFO_WAITDELETE:
454 nd6_free(rt);
455 break;
456 }
457 ln = next;
458 }
459
460 /* expire */
470 case ND6_LLINFO_PROBE:
471 if (ln->ln_asked < nd6_umaxtries) {
472 ln->ln_asked++;
473 ln->ln_expire = time_second +
474 nd_ifinfo[ifp->if_index].retrans / 1000;
475 nd6_ns_output(ifp, &dst->sin6_addr,
476 &dst->sin6_addr, ln, 0);
477 } else {
478 nd6_free(rt);
479 }
480 break;
481 case ND6_LLINFO_WAITDELETE:
482 nd6_free(rt);
483 break;
484 }
485 ln = next;
486 }
487
488 /* expire */
461 dr = LIST_FIRST(&nd_defrouter);
489 dr = TAILQ_FIRST(&nd_defrouter);
462 while (dr) {
463 if (dr->expire && dr->expire < time_second) {
464 struct nd_defrouter *t;
490 while (dr) {
491 if (dr->expire && dr->expire < time_second) {
492 struct nd_defrouter *t;
465 t = LIST_NEXT(dr, dr_entry);
493 t = TAILQ_NEXT(dr, dr_entry);
466 defrtrlist_del(dr);
467 dr = t;
494 defrtrlist_del(dr);
495 dr = t;
468 } else
469 dr = LIST_NEXT(dr, dr_entry);
496 } else {
497 dr = TAILQ_NEXT(dr, dr_entry);
498 }
470 }
499 }
471 pr = LIST_FIRST(&nd_prefix);
500 pr = nd_prefix.lh_first;
472 while (pr) {
473 struct in6_ifaddr *ia6;
474 struct in6_addrlifetime *lt6;
475
476 if (IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
477 ia6 = NULL;
478 else
479 ia6 = in6ifa_ifpwithaddr(pr->ndpr_ifp, &pr->ndpr_addr);

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

498 * we offset expire time by NDPR_KEEP_EXPIRE, so that we
499 * can use the old prefix information to validate the
500 * next prefix information to come. See prelist_update()
501 * for actual validation.
502 */
503 if (pr->ndpr_expire
504 && pr->ndpr_expire + NDPR_KEEP_EXPIRED < time_second) {
505 struct nd_prefix *t;
501 while (pr) {
502 struct in6_ifaddr *ia6;
503 struct in6_addrlifetime *lt6;
504
505 if (IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
506 ia6 = NULL;
507 else
508 ia6 = in6ifa_ifpwithaddr(pr->ndpr_ifp, &pr->ndpr_addr);

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

527 * we offset expire time by NDPR_KEEP_EXPIRE, so that we
528 * can use the old prefix information to validate the
529 * next prefix information to come. See prelist_update()
530 * for actual validation.
531 */
532 if (pr->ndpr_expire
533 && pr->ndpr_expire + NDPR_KEEP_EXPIRED < time_second) {
534 struct nd_prefix *t;
506 t = LIST_NEXT(pr, ndpr_entry);
535 t = pr->ndpr_next;
507
508 /*
509 * address expiration and prefix expiration are
510 * separate. NEVER perform in6_ifdel here.
511 */
512
513 prelist_remove(pr);
514 pr = t;
515 } else
536
537 /*
538 * address expiration and prefix expiration are
539 * separate. NEVER perform in6_ifdel here.
540 */
541
542 prelist_remove(pr);
543 pr = t;
544 } else
516 pr = LIST_NEXT(pr, ndpr_entry);
545 pr = pr->ndpr_next;
517 }
518 splx(s);
519}
520
546 }
547 splx(s);
548}
549
550/*
551 * Nuke neighbor cache/prefix/default router management table, right before
552 * ifp goes away.
553 */
554void
555nd6_purge(ifp)
556 struct ifnet *ifp;
557{
558 struct llinfo_nd6 *ln, *nln;
559 struct nd_defrouter *dr, *ndr, drany;
560 struct nd_prefix *pr, *npr;
561
562 /* Nuke default router list entries toward ifp */
563 if ((dr = TAILQ_FIRST(&nd_defrouter)) != NULL) {
564 /*
565 * The first entry of the list may be stored in
566 * the routing table, so we'll delete it later.
567 */
568 for (dr = TAILQ_NEXT(dr, dr_entry); dr; dr = ndr) {
569 ndr = TAILQ_NEXT(dr, dr_entry);
570 if (dr->ifp == ifp)
571 defrtrlist_del(dr);
572 }
573 dr = TAILQ_FIRST(&nd_defrouter);
574 if (dr->ifp == ifp)
575 defrtrlist_del(dr);
576 }
577
578 /* Nuke prefix list entries toward ifp */
579 for (pr = nd_prefix.lh_first; pr; pr = npr) {
580 npr = pr->ndpr_next;
581 if (pr->ndpr_ifp == ifp) {
582 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
583 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
584 prelist_remove(pr);
585 }
586 }
587
588 /* cancel default outgoing interface setting */
589 if (nd6_defifindex == ifp->if_index)
590 nd6_setdefaultiface(0);
591
592 /* refresh default router list */
593 bzero(&drany, sizeof(drany));
594 defrouter_delreq(&drany, 0);
595 defrouter_select();
596
597 /*
598 * Nuke neighbor cache entries for the ifp.
599 * Note that rt->rt_ifp may not be the same as ifp,
600 * due to KAME goto ours hack. See RTM_RESOLVE case in
601 * nd6_rtrequest(), and ip6_input().
602 */
603 ln = llinfo_nd6.ln_next;
604 while (ln && ln != &llinfo_nd6) {
605 struct rtentry *rt;
606 struct sockaddr_dl *sdl;
607
608 nln = ln->ln_next;
609 rt = ln->ln_rt;
610 if (rt && rt->rt_gateway &&
611 rt->rt_gateway->sa_family == AF_LINK) {
612 sdl = (struct sockaddr_dl *)rt->rt_gateway;
613 if (sdl->sdl_index == ifp->if_index)
614 nd6_free(rt);
615 }
616 ln = nln;
617 }
618
619 /*
620 * Neighbor cache entry for interface route will be retained
621 * with ND6_LLINFO_WAITDELETE state, by nd6_free(). Nuke it.
622 */
623 ln = llinfo_nd6.ln_next;
624 while (ln && ln != &llinfo_nd6) {
625 struct rtentry *rt;
626 struct sockaddr_dl *sdl;
627
628 nln = ln->ln_next;
629 rt = ln->ln_rt;
630 if (rt && rt->rt_gateway &&
631 rt->rt_gateway->sa_family == AF_LINK) {
632 sdl = (struct sockaddr_dl *)rt->rt_gateway;
633 if (sdl->sdl_index == ifp->if_index) {
634 rtrequest(RTM_DELETE, rt_key(rt),
635 (struct sockaddr *)0, rt_mask(rt), 0,
636 (struct rtentry **)0);
637 }
638 }
639 ln = nln;
640 }
641}
642
521struct rtentry *
522nd6_lookup(addr6, create, ifp)
523 struct in6_addr *addr6;
524 int create;
525 struct ifnet *ifp;
526{
527 struct rtentry *rt;
528 struct sockaddr_in6 sin6;
529
530 bzero(&sin6, sizeof(sin6));
531 sin6.sin6_len = sizeof(struct sockaddr_in6);
532 sin6.sin6_family = AF_INET6;
533 sin6.sin6_addr = *addr6;
643struct rtentry *
644nd6_lookup(addr6, create, ifp)
645 struct in6_addr *addr6;
646 int create;
647 struct ifnet *ifp;
648{
649 struct rtentry *rt;
650 struct sockaddr_in6 sin6;
651
652 bzero(&sin6, sizeof(sin6));
653 sin6.sin6_len = sizeof(struct sockaddr_in6);
654 sin6.sin6_family = AF_INET6;
655 sin6.sin6_addr = *addr6;
656#ifdef SCOPEDROUTING
657 sin6.sin6_scope_id = in6_addr2scopeid(ifp, addr6);
658#endif
534 rt = rtalloc1((struct sockaddr *)&sin6, create, 0UL);
535 if (rt && (rt->rt_flags & RTF_LLINFO) == 0) {
536 /*
537 * This is the case for the default route.
538 * If we want to create a neighbor cache for the address, we
539 * should free the route for the destination and allocate an
540 * interface route.
541 */
542 if (create) {
543 RTFREE(rt);
544 rt = 0;
545 }
546 }
547 if (!rt) {
548 if (create && ifp) {
659 rt = rtalloc1((struct sockaddr *)&sin6, create, 0UL);
660 if (rt && (rt->rt_flags & RTF_LLINFO) == 0) {
661 /*
662 * This is the case for the default route.
663 * If we want to create a neighbor cache for the address, we
664 * should free the route for the destination and allocate an
665 * interface route.
666 */
667 if (create) {
668 RTFREE(rt);
669 rt = 0;
670 }
671 }
672 if (!rt) {
673 if (create && ifp) {
674 int e;
675
549 /*
550 * If no route is available and create is set,
551 * we allocate a host route for the destination
552 * and treat it like an interface route.
553 * This hack is necessary for a neighbor which can't
554 * be covered by our own prefix.
555 */
556 struct ifaddr *ifa =
557 ifaof_ifpforaddr((struct sockaddr *)&sin6, ifp);
558 if (ifa == NULL)
559 return(NULL);
560
561 /*
562 * Create a new route. RTF_LLINFO is necessary
563 * to create a Neighbor Cache entry for the
564 * destination in nd6_rtrequest which will be
565 * called in rtequest via ifa->ifa_rtrequest.
566 */
676 /*
677 * If no route is available and create is set,
678 * we allocate a host route for the destination
679 * and treat it like an interface route.
680 * This hack is necessary for a neighbor which can't
681 * be covered by our own prefix.
682 */
683 struct ifaddr *ifa =
684 ifaof_ifpforaddr((struct sockaddr *)&sin6, ifp);
685 if (ifa == NULL)
686 return(NULL);
687
688 /*
689 * Create a new route. RTF_LLINFO is necessary
690 * to create a Neighbor Cache entry for the
691 * destination in nd6_rtrequest which will be
692 * called in rtequest via ifa->ifa_rtrequest.
693 */
567 if (rtrequest(RTM_ADD, (struct sockaddr *)&sin6,
568 ifa->ifa_addr,
569 (struct sockaddr *)&all1_sa,
570 (ifa->ifa_flags |
571 RTF_HOST | RTF_LLINFO) & ~RTF_CLONING,
572 &rt))
694 if ((e = rtrequest(RTM_ADD, (struct sockaddr *)&sin6,
695 ifa->ifa_addr,
696 (struct sockaddr *)&all1_sa,
697 (ifa->ifa_flags |
698 RTF_HOST | RTF_LLINFO) &
699 ~RTF_CLONING,
700 &rt)) != 0)
573 log(LOG_ERR,
574 "nd6_lookup: failed to add route for a "
701 log(LOG_ERR,
702 "nd6_lookup: failed to add route for a "
575 "neighbor(%s)\n", ip6_sprintf(addr6));
703 "neighbor(%s), errno=%d\n",
704 ip6_sprintf(addr6), e);
576 if (rt == NULL)
577 return(NULL);
578 if (rt->rt_llinfo) {
579 struct llinfo_nd6 *ln =
580 (struct llinfo_nd6 *)rt->rt_llinfo;
581 ln->ln_state = ND6_LLINFO_NOSTATE;
582 }
583 } else

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

605}
606
607/*
608 * Detect if a given IPv6 address identifies a neighbor on a given link.
609 * XXX: should take care of the destination of a p2p link?
610 */
611int
612nd6_is_addr_neighbor(addr, ifp)
705 if (rt == NULL)
706 return(NULL);
707 if (rt->rt_llinfo) {
708 struct llinfo_nd6 *ln =
709 (struct llinfo_nd6 *)rt->rt_llinfo;
710 ln->ln_state = ND6_LLINFO_NOSTATE;
711 }
712 } else

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

734}
735
736/*
737 * Detect if a given IPv6 address identifies a neighbor on a given link.
738 * XXX: should take care of the destination of a p2p link?
739 */
740int
741nd6_is_addr_neighbor(addr, ifp)
613 struct in6_addr *addr;
742 struct sockaddr_in6 *addr;
614 struct ifnet *ifp;
615{
616 register struct ifaddr *ifa;
617 int i;
618
619#define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
620#define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
621
743 struct ifnet *ifp;
744{
745 register struct ifaddr *ifa;
746 int i;
747
748#define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
749#define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
750
622 /* A link-local address is always a neighbor. */
623 if (IN6_IS_ADDR_LINKLOCAL(addr))
751 /*
752 * A link-local address is always a neighbor.
753 * XXX: we should use the sin6_scope_id field rather than the embedded
754 * interface index.
755 */
756 if (IN6_IS_ADDR_LINKLOCAL(&addr->sin6_addr) &&
757 ntohs(*(u_int16_t *)&addr->sin6_addr.s6_addr[2]) == ifp->if_index)
624 return(1);
625
626 /*
627 * If the address matches one of our addresses,
628 * it should be a neighbor.
629 */
758 return(1);
759
760 /*
761 * If the address matches one of our addresses,
762 * it should be a neighbor.
763 */
630 TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list)
764 for (ifa = ifp->if_addrlist.tqh_first;
765 ifa;
766 ifa = ifa->ifa_list.tqe_next)
631 {
632 if (ifa->ifa_addr->sa_family != AF_INET6)
633 next: continue;
634
635 for (i = 0; i < 4; i++) {
767 {
768 if (ifa->ifa_addr->sa_family != AF_INET6)
769 next: continue;
770
771 for (i = 0; i < 4; i++) {
636 if ((IFADDR6(ifa).s6_addr32[i] ^ addr->s6_addr32[i]) &
772 if ((IFADDR6(ifa).s6_addr32[i] ^
773 addr->sin6_addr.s6_addr32[i]) &
637 IFMASK6(ifa).s6_addr32[i])
638 goto next;
639 }
640 return(1);
641 }
642
643 /*
644 * Even if the address matches none of our addresses, it might be
645 * in the neighbor cache.
646 */
774 IFMASK6(ifa).s6_addr32[i])
775 goto next;
776 }
777 return(1);
778 }
779
780 /*
781 * Even if the address matches none of our addresses, it might be
782 * in the neighbor cache.
783 */
647 if (nd6_lookup(addr, 0, ifp))
784 if (nd6_lookup(&addr->sin6_addr, 0, ifp))
648 return(1);
649
650 return(0);
651#undef IFADDR6
652#undef IFMASK6
653}
654
655/*
656 * Free an nd6 llinfo entry.
657 */
658void
659nd6_free(rt)
660 struct rtentry *rt;
661{
662 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
663 struct sockaddr_dl *sdl;
785 return(1);
786
787 return(0);
788#undef IFADDR6
789#undef IFMASK6
790}
791
792/*
793 * Free an nd6 llinfo entry.
794 */
795void
796nd6_free(rt)
797 struct rtentry *rt;
798{
799 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
800 struct sockaddr_dl *sdl;
801 struct in6_addr in6 = ((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
802 struct nd_defrouter *dr;
664
803
665 if (ln->ln_router) {
666 /* remove from default router list */
667 struct nd_defrouter *dr;
668 struct in6_addr *in6;
669 int s;
670 in6 = &((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
804 /*
805 * Clear all destination cache entries for the neighbor.
806 * XXX: is it better to restrict this to hosts?
807 */
808 pfctlinput(PRC_HOSTDEAD, rt_key(rt));
671
809
810 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */
811 int s;
672 s = splnet();
812 s = splnet();
673 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->
674 sin6_addr,
813 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->sin6_addr,
675 rt->rt_ifp);
814 rt->rt_ifp);
676 if (dr)
677 defrtrlist_del(dr);
678 else if (!ip6_forwarding && ip6_accept_rtadv) {
815 if (ln->ln_router || dr) {
679 /*
816 /*
680 * rt6_flush must be called in any case.
681 * see the comment in nd6_na_input().
817 * rt6_flush must be called whether or not the neighbor
818 * is in the Default Router List.
819 * See a corresponding comment in nd6_na_input().
682 */
820 */
683 rt6_flush(in6, rt->rt_ifp);
821 rt6_flush(&in6, rt->rt_ifp);
684 }
822 }
823
824 if (dr) {
825 /*
826 * Unreachablity of a router might affect the default
827 * router selection and on-link detection of advertised
828 * prefixes.
829 */
830
831 /*
832 * Temporarily fake the state to choose a new default
833 * router and to perform on-link determination of
834 * prefixes coreectly.
835 * Below the state will be set correctly,
836 * or the entry itself will be deleted.
837 */
838 ln->ln_state = ND6_LLINFO_INCOMPLETE;
839
840 if (dr == TAILQ_FIRST(&nd_defrouter)) {
841 /*
842 * It is used as the current default router,
843 * so we have to move it to the end of the
844 * list and choose a new one.
845 * XXX: it is not very efficient if this is
846 * the only router.
847 */
848 TAILQ_REMOVE(&nd_defrouter, dr, dr_entry);
849 TAILQ_INSERT_TAIL(&nd_defrouter, dr, dr_entry);
850
851 defrouter_select();
852 }
853 pfxlist_onlink_check();
854 }
685 splx(s);
686 }
855 splx(s);
856 }
687
857
688 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
858 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
689 sdl->sdl_family == AF_LINK) {
859 sdl->sdl_family == AF_LINK) {
690 sdl->sdl_alen = 0;
691 ln->ln_state = ND6_LLINFO_WAITDELETE;
692 ln->ln_asked = 0;
693 rt->rt_flags &= ~RTF_REJECT;
694 return;
695 }
860 sdl->sdl_alen = 0;
861 ln->ln_state = ND6_LLINFO_WAITDELETE;
862 ln->ln_asked = 0;
863 rt->rt_flags &= ~RTF_REJECT;
864 return;
865 }
696 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
697 0, (struct rtentry **)0);
866
867 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
868 rt_mask(rt), 0, (struct rtentry **)0);
698}
699
700/*
701 * Upper-layer reachability hint for Neighbor Unreachability Detection.
702 *
703 * XXX cost-effective metods?
704 */
705void
869}
870
871/*
872 * Upper-layer reachability hint for Neighbor Unreachability Detection.
873 *
874 * XXX cost-effective metods?
875 */
876void
706nd6_nud_hint(rt, dst6)
877nd6_nud_hint(rt, dst6, force)
707 struct rtentry *rt;
708 struct in6_addr *dst6;
878 struct rtentry *rt;
879 struct in6_addr *dst6;
880 int force;
709{
710 struct llinfo_nd6 *ln;
711
712 /*
713 * If the caller specified "rt", use that. Otherwise, resolve the
714 * routing table by supplied "dst6".
715 */
716 if (!rt) {
717 if (!dst6)
718 return;
719 if (!(rt = nd6_lookup(dst6, 0, NULL)))
720 return;
721 }
722
881{
882 struct llinfo_nd6 *ln;
883
884 /*
885 * If the caller specified "rt", use that. Otherwise, resolve the
886 * routing table by supplied "dst6".
887 */
888 if (!rt) {
889 if (!dst6)
890 return;
891 if (!(rt = nd6_lookup(dst6, 0, NULL)))
892 return;
893 }
894
723 if ((rt->rt_flags & RTF_GATEWAY)
724 || (rt->rt_flags & RTF_LLINFO) == 0
725 || !rt->rt_llinfo
726 || !rt->rt_gateway
727 || rt->rt_gateway->sa_family != AF_LINK) {
895 if ((rt->rt_flags & RTF_GATEWAY) != 0 ||
896 (rt->rt_flags & RTF_LLINFO) == 0 ||
897 !rt->rt_llinfo || !rt->rt_gateway ||
898 rt->rt_gateway->sa_family != AF_LINK) {
728 /* This is not a host route. */
729 return;
730 }
731
732 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
733 if (ln->ln_state < ND6_LLINFO_REACHABLE)
734 return;
735
899 /* This is not a host route. */
900 return;
901 }
902
903 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
904 if (ln->ln_state < ND6_LLINFO_REACHABLE)
905 return;
906
907 /*
908 * if we get upper-layer reachability confirmation many times,
909 * it is possible we have false information.
910 */
911 if (!force) {
912 ln->ln_byhint++;
913 if (ln->ln_byhint > nd6_maxnudhint)
914 return;
915 }
916
736 ln->ln_state = ND6_LLINFO_REACHABLE;
737 if (ln->ln_expire)
738 ln->ln_expire = time_second +
739 nd_ifinfo[rt->rt_ifp->if_index].reachable;
740}
741
917 ln->ln_state = ND6_LLINFO_REACHABLE;
918 if (ln->ln_expire)
919 ln->ln_expire = time_second +
920 nd_ifinfo[rt->rt_ifp->if_index].reachable;
921}
922
923#ifdef OLDIP6OUTPUT
924/*
925 * Resolve an IP6 address into an ethernet address. If success,
926 * desten is filled in. If there is no entry in ndptab,
927 * set one up and multicast a solicitation for the IP6 address.
928 * Hold onto this mbuf and resend it once the address
929 * is finally resolved. A return value of 1 indicates
930 * that desten has been filled in and the packet should be sent
931 * normally; a 0 return indicates that the packet has been
932 * taken over here, either now or for later transmission.
933 */
934int
935nd6_resolve(ifp, rt, m, dst, desten)
936 struct ifnet *ifp;
937 struct rtentry *rt;
938 struct mbuf *m;
939 struct sockaddr *dst;
940 u_char *desten;
941{
942 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)NULL;
943 struct sockaddr_dl *sdl;
944
945 if (m->m_flags & M_MCAST) {
946 switch (ifp->if_type) {
947 case IFT_ETHER:
948 case IFT_FDDI:
949 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr,
950 desten);
951 return(1);
952 break;
953 case IFT_ARCNET:
954 *desten = 0;
955 return(1);
956 break;
957 default:
958 return(0);
959 }
960 }
961 if (rt && (rt->rt_flags & RTF_LLINFO) != 0)
962 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
963 else {
964 if ((rt = nd6_lookup(&(SIN6(dst)->sin6_addr), 1, ifp)) != NULL)
965 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
966 }
967 if (!ln || !rt) {
968 log(LOG_DEBUG, "nd6_resolve: can't allocate llinfo for %s\n",
969 ip6_sprintf(&(SIN6(dst)->sin6_addr)));
970 m_freem(m);
971 return(0);
972 }
973 sdl = SDL(rt->rt_gateway);
974 /*
975 * Ckeck the address family and length is valid, the address
976 * is resolved; otherwise, try to resolve.
977 */
978 if (ln->ln_state >= ND6_LLINFO_REACHABLE
979 && sdl->sdl_family == AF_LINK
980 && sdl->sdl_alen != 0) {
981 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
982 if (ln->ln_state == ND6_LLINFO_STALE) {
983 ln->ln_asked = 0;
984 ln->ln_state = ND6_LLINFO_DELAY;
985 ln->ln_expire = time_second + nd6_delay;
986 }
987 return(1);
988 }
989 /*
990 * There is an ndp entry, but no ethernet address
991 * response yet. Replace the held mbuf with this
992 * latest one.
993 *
994 * XXX Does the code conform to rate-limiting rule?
995 * (RFC 2461 7.2.2)
996 */
997 if (ln->ln_state == ND6_LLINFO_WAITDELETE ||
998 ln->ln_state == ND6_LLINFO_NOSTATE)
999 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1000 if (ln->ln_hold)
1001 m_freem(ln->ln_hold);
1002 ln->ln_hold = m;
1003 if (ln->ln_expire) {
1004 rt->rt_flags &= ~RTF_REJECT;
1005 if (ln->ln_asked < nd6_mmaxtries &&
1006 ln->ln_expire < time_second) {
1007 ln->ln_asked++;
1008 ln->ln_expire = time_second +
1009 nd_ifinfo[ifp->if_index].retrans / 1000;
1010 nd6_ns_output(ifp, NULL, &(SIN6(dst)->sin6_addr),
1011 ln, 0);
1012 }
1013 }
1014 return(0);
1015}
1016#endif /* OLDIP6OUTPUT */
1017
742void
743nd6_rtrequest(req, rt, sa)
744 int req;
745 struct rtentry *rt;
746 struct sockaddr *sa; /* xxx unused */
747{
748 struct sockaddr *gate = rt->rt_gateway;
749 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;

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

758 case RTM_ADD:
759 /*
760 * There is no backward compatibility :)
761 *
762 * if ((rt->rt_flags & RTF_HOST) == 0 &&
763 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
764 * rt->rt_flags |= RTF_CLONING;
765 */
1018void
1019nd6_rtrequest(req, rt, sa)
1020 int req;
1021 struct rtentry *rt;
1022 struct sockaddr *sa; /* xxx unused */
1023{
1024 struct sockaddr *gate = rt->rt_gateway;
1025 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;

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

1034 case RTM_ADD:
1035 /*
1036 * There is no backward compatibility :)
1037 *
1038 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1039 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1040 * rt->rt_flags |= RTF_CLONING;
1041 */
766 if (rt->rt_flags & RTF_CLONING || rt->rt_flags & RTF_LLINFO) {
1042 if (rt->rt_flags & (RTF_CLONING | RTF_LLINFO)) {
767 /*
768 * Case 1: This route should come from
769 * a route to interface. RTF_LLINFO flag is set
770 * for a host route whose destination should be
771 * treated as on-link.
772 */
773 rt_setgate(rt, rt_key(rt),
774 (struct sockaddr *)&null_sdl);
775 gate = rt->rt_gateway;
776 SDL(gate)->sdl_type = ifp->if_type;
777 SDL(gate)->sdl_index = ifp->if_index;
778 if (ln)
779 ln->ln_expire = time_second;
1043 /*
1044 * Case 1: This route should come from
1045 * a route to interface. RTF_LLINFO flag is set
1046 * for a host route whose destination should be
1047 * treated as on-link.
1048 */
1049 rt_setgate(rt, rt_key(rt),
1050 (struct sockaddr *)&null_sdl);
1051 gate = rt->rt_gateway;
1052 SDL(gate)->sdl_type = ifp->if_type;
1053 SDL(gate)->sdl_index = ifp->if_index;
1054 if (ln)
1055 ln->ln_expire = time_second;
1056#if 1
780 if (ln && ln->ln_expire == 0) {
781 /* cludge for desktops */
1057 if (ln && ln->ln_expire == 0) {
1058 /* cludge for desktops */
1059#if 0
1060 printf("nd6_request: time.tv_sec is zero; "
1061 "treat it as 1\n");
1062#endif
782 ln->ln_expire = 1;
783 }
1063 ln->ln_expire = 1;
1064 }
1065#endif
784 if (rt->rt_flags & RTF_CLONING)
785 break;
786 }
1066 if (rt->rt_flags & RTF_CLONING)
1067 break;
1068 }
787 /* Announce a new entry if requested. */
1069 /*
1070 * In IPv4 code, we try to annonuce new RTF_ANNOUNCE entry here.
1071 * We don't do that here since llinfo is not ready yet.
1072 *
1073 * There are also couple of other things to be discussed:
1074 * - unsolicited NA code needs improvement beforehand
1075 * - RFC2461 says we MAY send multicast unsolicited NA
1076 * (7.2.6 paragraph 4), however, it also says that we
1077 * SHOULD provide a mechanism to prevent multicast NA storm.
1078 * we don't have anything like it right now.
1079 * note that the mechanism need a mutual agreement
1080 * between proxies, which means that we need to implement
1081 * a new protocol, or new kludge.
1082 * - from RFC2461 6.2.4, host MUST NOT send unsolicited NA.
1083 * we need to check ip6forwarding before sending it.
1084 * (or should we allow proxy ND configuration only for
1085 * routers? there's no mention about proxy ND from hosts)
1086 */
1087#if 0
1088 /* XXX it does not work */
788 if (rt->rt_flags & RTF_ANNOUNCE)
789 nd6_na_output(ifp,
1089 if (rt->rt_flags & RTF_ANNOUNCE)
1090 nd6_na_output(ifp,
790 &SIN6(rt_key(rt))->sin6_addr,
791 &SIN6(rt_key(rt))->sin6_addr,
792 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
793 1);
1091 &SIN6(rt_key(rt))->sin6_addr,
1092 &SIN6(rt_key(rt))->sin6_addr,
1093 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1094 1, NULL);
1095#endif
794 /* FALLTHROUGH */
795 case RTM_RESOLVE:
1096 /* FALLTHROUGH */
1097 case RTM_RESOLVE:
796 if (gate->sa_family != AF_LINK ||
797 gate->sa_len < sizeof(null_sdl)) {
798 log(LOG_DEBUG, "nd6_rtrequest: bad gateway value\n");
799 break;
1098 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
1099 /*
1100 * Address resolution isn't necessary for a point to
1101 * point link, so we can skip this test for a p2p link.
1102 */
1103 if (gate->sa_family != AF_LINK ||
1104 gate->sa_len < sizeof(null_sdl)) {
1105 log(LOG_DEBUG,
1106 "nd6_rtrequest: bad gateway value\n");
1107 break;
1108 }
1109 SDL(gate)->sdl_type = ifp->if_type;
1110 SDL(gate)->sdl_index = ifp->if_index;
800 }
1111 }
801 SDL(gate)->sdl_type = ifp->if_type;
802 SDL(gate)->sdl_index = ifp->if_index;
803 if (ln != 0)
1112 if (ln != NULL)
804 break; /* This happens on a route change */
805 /*
806 * Case 2: This route may come from cloning, or a manual route
807 * add with a LL address.
808 */
809 R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln));
810 rt->rt_llinfo = (caddr_t)ln;
811 if (!ln) {

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

819 /* this is required for "ndp" command. - shin */
820 if (req == RTM_ADD) {
821 /*
822 * gate should have some valid AF_LINK entry,
823 * and ln->ln_expire should have some lifetime
824 * which is specified by ndp command.
825 */
826 ln->ln_state = ND6_LLINFO_REACHABLE;
1113 break; /* This happens on a route change */
1114 /*
1115 * Case 2: This route may come from cloning, or a manual route
1116 * add with a LL address.
1117 */
1118 R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln));
1119 rt->rt_llinfo = (caddr_t)ln;
1120 if (!ln) {

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

1128 /* this is required for "ndp" command. - shin */
1129 if (req == RTM_ADD) {
1130 /*
1131 * gate should have some valid AF_LINK entry,
1132 * and ln->ln_expire should have some lifetime
1133 * which is specified by ndp command.
1134 */
1135 ln->ln_state = ND6_LLINFO_REACHABLE;
1136 ln->ln_byhint = 0;
827 } else {
828 /*
829 * When req == RTM_RESOLVE, rt is created and
830 * initialized in rtrequest(), so rt_expire is 0.
831 */
1137 } else {
1138 /*
1139 * When req == RTM_RESOLVE, rt is created and
1140 * initialized in rtrequest(), so rt_expire is 0.
1141 */
832 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1142 ln->ln_state = ND6_LLINFO_NOSTATE;
833 ln->ln_expire = time_second;
834 }
835 rt->rt_flags |= RTF_LLINFO;
836 ln->ln_next = llinfo_nd6.ln_next;
837 llinfo_nd6.ln_next = ln;
838 ln->ln_prev = &llinfo_nd6;
839 ln->ln_next->ln_prev = ln;
840
841 /*
842 * check if rt_key(rt) is one of my address assigned
843 * to the interface.
844 */
845 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp,
846 &SIN6(rt_key(rt))->sin6_addr);
847 if (ifa) {
848 caddr_t macp = nd6_ifptomac(ifp);
849 ln->ln_expire = 0;
850 ln->ln_state = ND6_LLINFO_REACHABLE;
1143 ln->ln_expire = time_second;
1144 }
1145 rt->rt_flags |= RTF_LLINFO;
1146 ln->ln_next = llinfo_nd6.ln_next;
1147 llinfo_nd6.ln_next = ln;
1148 ln->ln_prev = &llinfo_nd6;
1149 ln->ln_next->ln_prev = ln;
1150
1151 /*
1152 * check if rt_key(rt) is one of my address assigned
1153 * to the interface.
1154 */
1155 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp,
1156 &SIN6(rt_key(rt))->sin6_addr);
1157 if (ifa) {
1158 caddr_t macp = nd6_ifptomac(ifp);
1159 ln->ln_expire = 0;
1160 ln->ln_state = ND6_LLINFO_REACHABLE;
1161 ln->ln_byhint = 0;
851 if (macp) {
852 Bcopy(macp, LLADDR(SDL(gate)), ifp->if_addrlen);
853 SDL(gate)->sdl_alen = ifp->if_addrlen;
854 }
855 if (nd6_useloopback) {
856 rt->rt_ifp = &loif[0]; /*XXX*/
857 /*
858 * Make sure rt_ifa be equal to the ifaddr
859 * corresponding to the address.
860 * We need this because when we refer
861 * rt_ifa->ia6_flags in ip6_input, we assume
862 * that the rt_ifa points to the address instead
863 * of the loopback address.
864 */
865 if (ifa != rt->rt_ifa) {
1162 if (macp) {
1163 Bcopy(macp, LLADDR(SDL(gate)), ifp->if_addrlen);
1164 SDL(gate)->sdl_alen = ifp->if_addrlen;
1165 }
1166 if (nd6_useloopback) {
1167 rt->rt_ifp = &loif[0]; /*XXX*/
1168 /*
1169 * Make sure rt_ifa be equal to the ifaddr
1170 * corresponding to the address.
1171 * We need this because when we refer
1172 * rt_ifa->ia6_flags in ip6_input, we assume
1173 * that the rt_ifa points to the address instead
1174 * of the loopback address.
1175 */
1176 if (ifa != rt->rt_ifa) {
866 rt->rt_ifa->ifa_refcnt--;
1177 IFAFREE(rt->rt_ifa);
867 ifa->ifa_refcnt++;
868 rt->rt_ifa = ifa;
869 }
870 }
1178 ifa->ifa_refcnt++;
1179 rt->rt_ifa = ifa;
1180 }
1181 }
1182 } else if (rt->rt_flags & RTF_ANNOUNCE) {
1183 ln->ln_expire = 0;
1184 ln->ln_state = ND6_LLINFO_REACHABLE;
1185 ln->ln_byhint = 0;
1186
1187 /* join solicited node multicast for proxy ND */
1188 if (ifp->if_flags & IFF_MULTICAST) {
1189 struct in6_addr llsol;
1190 int error;
1191
1192 llsol = SIN6(rt_key(rt))->sin6_addr;
1193 llsol.s6_addr16[0] = htons(0xff02);
1194 llsol.s6_addr16[1] = htons(ifp->if_index);
1195 llsol.s6_addr32[1] = 0;
1196 llsol.s6_addr32[2] = htonl(1);
1197 llsol.s6_addr8[12] = 0xff;
1198
1199 (void)in6_addmulti(&llsol, ifp, &error);
1200 if (error)
1201 printf(
1202"nd6_rtrequest: could not join solicited node multicast (errno=%d)\n", error);
1203 }
871 }
872 break;
873
874 case RTM_DELETE:
875 if (!ln)
876 break;
1204 }
1205 break;
1206
1207 case RTM_DELETE:
1208 if (!ln)
1209 break;
1210 /* leave from solicited node multicast for proxy ND */
1211 if ((rt->rt_flags & RTF_ANNOUNCE) != 0 &&
1212 (ifp->if_flags & IFF_MULTICAST) != 0) {
1213 struct in6_addr llsol;
1214 struct in6_multi *in6m;
1215
1216 llsol = SIN6(rt_key(rt))->sin6_addr;
1217 llsol.s6_addr16[0] = htons(0xff02);
1218 llsol.s6_addr16[1] = htons(ifp->if_index);
1219 llsol.s6_addr32[1] = 0;
1220 llsol.s6_addr32[2] = htonl(1);
1221 llsol.s6_addr8[12] = 0xff;
1222
1223 IN6_LOOKUP_MULTI(llsol, ifp, in6m);
1224 if (in6m)
1225 in6_delmulti(in6m);
1226 }
877 nd6_inuse--;
878 ln->ln_next->ln_prev = ln->ln_prev;
879 ln->ln_prev->ln_next = ln->ln_next;
880 ln->ln_prev = NULL;
881 rt->rt_llinfo = 0;
882 rt->rt_flags &= ~RTF_LLINFO;
883 if (ln->ln_hold)
884 m_freem(ln->ln_hold);

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

922 break;
923 }
924 /* Announce a new entry if requested. */
925 if (rt->rt_flags & RTF_ANNOUNCE)
926 nd6_na_output(ifp,
927 &SIN6(rt_key(rt))->sin6_addr,
928 &SIN6(rt_key(rt))->sin6_addr,
929 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1227 nd6_inuse--;
1228 ln->ln_next->ln_prev = ln->ln_prev;
1229 ln->ln_prev->ln_next = ln->ln_next;
1230 ln->ln_prev = NULL;
1231 rt->rt_llinfo = 0;
1232 rt->rt_flags &= ~RTF_LLINFO;
1233 if (ln->ln_hold)
1234 m_freem(ln->ln_hold);

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

1272 break;
1273 }
1274 /* Announce a new entry if requested. */
1275 if (rt->rt_flags & RTF_ANNOUNCE)
1276 nd6_na_output(ifp,
1277 &SIN6(rt_key(rt))->sin6_addr,
1278 &SIN6(rt_key(rt))->sin6_addr,
1279 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
930 1);
1280 1, NULL);
931 /* FALLTHROUGH */
932 case RTM_RESOLVE:
933 /*
934 * check if rt_key(rt) is one of my address assigned
935 * to the interface.
936 */
937 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp,
938 &SIN6(rt_key(rt))->sin6_addr);

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

950 u_long cmd;
951 caddr_t data;
952 struct ifnet *ifp;
953{
954 struct in6_drlist *drl = (struct in6_drlist *)data;
955 struct in6_prlist *prl = (struct in6_prlist *)data;
956 struct in6_ndireq *ndi = (struct in6_ndireq *)data;
957 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data;
1281 /* FALLTHROUGH */
1282 case RTM_RESOLVE:
1283 /*
1284 * check if rt_key(rt) is one of my address assigned
1285 * to the interface.
1286 */
1287 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp,
1288 &SIN6(rt_key(rt))->sin6_addr);

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

1300 u_long cmd;
1301 caddr_t data;
1302 struct ifnet *ifp;
1303{
1304 struct in6_drlist *drl = (struct in6_drlist *)data;
1305 struct in6_prlist *prl = (struct in6_prlist *)data;
1306 struct in6_ndireq *ndi = (struct in6_ndireq *)data;
1307 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data;
1308 struct in6_ndifreq *ndif = (struct in6_ndifreq *)data;
958 struct nd_defrouter *dr, any;
959 struct nd_prefix *pr;
960 struct rtentry *rt;
961 int i = 0, error = 0;
962 int s;
963
964 switch (cmd) {
965 case SIOCGDRLST_IN6:
966 bzero(drl, sizeof(*drl));
967 s = splnet();
1309 struct nd_defrouter *dr, any;
1310 struct nd_prefix *pr;
1311 struct rtentry *rt;
1312 int i = 0, error = 0;
1313 int s;
1314
1315 switch (cmd) {
1316 case SIOCGDRLST_IN6:
1317 bzero(drl, sizeof(*drl));
1318 s = splnet();
968 dr = LIST_FIRST(&nd_defrouter);
1319 dr = TAILQ_FIRST(&nd_defrouter);
969 while (dr && i < DRLSTSIZ) {
970 drl->defrouter[i].rtaddr = dr->rtaddr;
971 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
972 /* XXX: need to this hack for KAME stack */
973 drl->defrouter[i].rtaddr.s6_addr16[1] = 0;
974 } else
975 log(LOG_ERR,
976 "default router list contains a "
977 "non-linklocal address(%s)\n",
978 ip6_sprintf(&drl->defrouter[i].rtaddr));
979
980 drl->defrouter[i].flags = dr->flags;
981 drl->defrouter[i].rtlifetime = dr->rtlifetime;
982 drl->defrouter[i].expire = dr->expire;
983 drl->defrouter[i].if_index = dr->ifp->if_index;
984 i++;
1320 while (dr && i < DRLSTSIZ) {
1321 drl->defrouter[i].rtaddr = dr->rtaddr;
1322 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
1323 /* XXX: need to this hack for KAME stack */
1324 drl->defrouter[i].rtaddr.s6_addr16[1] = 0;
1325 } else
1326 log(LOG_ERR,
1327 "default router list contains a "
1328 "non-linklocal address(%s)\n",
1329 ip6_sprintf(&drl->defrouter[i].rtaddr));
1330
1331 drl->defrouter[i].flags = dr->flags;
1332 drl->defrouter[i].rtlifetime = dr->rtlifetime;
1333 drl->defrouter[i].expire = dr->expire;
1334 drl->defrouter[i].if_index = dr->ifp->if_index;
1335 i++;
985 dr = LIST_NEXT(dr, dr_entry);
1336 dr = TAILQ_NEXT(dr, dr_entry);
986 }
987 splx(s);
988 break;
989 case SIOCGPRLST_IN6:
1337 }
1338 splx(s);
1339 break;
1340 case SIOCGPRLST_IN6:
1341 /*
1342 * XXX meaning of fields, especialy "raflags", is very
1343 * differnet between RA prefix list and RR/static prefix list.
1344 * how about separating ioctls into two?
1345 */
990 bzero(prl, sizeof(*prl));
991 s = splnet();
1346 bzero(prl, sizeof(*prl));
1347 s = splnet();
992 pr = LIST_FIRST(&nd_prefix);
1348 pr = nd_prefix.lh_first;
993 while (pr && i < PRLSTSIZ) {
994 struct nd_pfxrouter *pfr;
995 int j;
996
997 prl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr;
998 prl->prefix[i].raflags = pr->ndpr_raf;
999 prl->prefix[i].prefixlen = pr->ndpr_plen;
1000 prl->prefix[i].vltime = pr->ndpr_vltime;
1001 prl->prefix[i].pltime = pr->ndpr_pltime;
1002 prl->prefix[i].if_index = pr->ndpr_ifp->if_index;
1003 prl->prefix[i].expire = pr->ndpr_expire;
1004
1349 while (pr && i < PRLSTSIZ) {
1350 struct nd_pfxrouter *pfr;
1351 int j;
1352
1353 prl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr;
1354 prl->prefix[i].raflags = pr->ndpr_raf;
1355 prl->prefix[i].prefixlen = pr->ndpr_plen;
1356 prl->prefix[i].vltime = pr->ndpr_vltime;
1357 prl->prefix[i].pltime = pr->ndpr_pltime;
1358 prl->prefix[i].if_index = pr->ndpr_ifp->if_index;
1359 prl->prefix[i].expire = pr->ndpr_expire;
1360
1005 pfr = LIST_FIRST(&pr->ndpr_advrtrs);
1361 pfr = pr->ndpr_advrtrs.lh_first;
1006 j = 0;
1007 while(pfr) {
1008 if (j < DRLSTSIZ) {
1009#define RTRADDR prl->prefix[i].advrtr[j]
1010 RTRADDR = pfr->router->rtaddr;
1011 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) {
1012 /* XXX: hack for KAME */
1013 RTRADDR.s6_addr16[1] = 0;
1014 } else
1015 log(LOG_ERR,
1016 "a router(%s) advertises "
1017 "a prefix with "
1018 "non-link local address\n",
1019 ip6_sprintf(&RTRADDR));
1020#undef RTRADDR
1021 }
1022 j++;
1362 j = 0;
1363 while(pfr) {
1364 if (j < DRLSTSIZ) {
1365#define RTRADDR prl->prefix[i].advrtr[j]
1366 RTRADDR = pfr->router->rtaddr;
1367 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) {
1368 /* XXX: hack for KAME */
1369 RTRADDR.s6_addr16[1] = 0;
1370 } else
1371 log(LOG_ERR,
1372 "a router(%s) advertises "
1373 "a prefix with "
1374 "non-link local address\n",
1375 ip6_sprintf(&RTRADDR));
1376#undef RTRADDR
1377 }
1378 j++;
1023 pfr = LIST_NEXT(pfr, pfr_entry);
1379 pfr = pfr->pfr_next;
1024 }
1025 prl->prefix[i].advrtrs = j;
1380 }
1381 prl->prefix[i].advrtrs = j;
1382 prl->prefix[i].origin = PR_ORIG_RA;
1026
1027 i++;
1383
1384 i++;
1028 pr = LIST_NEXT(pr, ndpr_entry);
1385 pr = pr->ndpr_next;
1029 }
1386 }
1030 splx(s);
1031 {
1032 struct rr_prefix *rpp;
1033
1034 for (rpp = LIST_FIRST(&rr_prefix); rpp;
1035 rpp = LIST_NEXT(rpp, rp_entry)) {
1036 if (i >= PRLSTSIZ)
1037 break;
1038 prl->prefix[i].prefix = rpp->rp_prefix.sin6_addr;
1039 prl->prefix[i].raflags = rpp->rp_raf;
1040 prl->prefix[i].prefixlen = rpp->rp_plen;
1041 prl->prefix[i].vltime = rpp->rp_vltime;
1042 prl->prefix[i].pltime = rpp->rp_pltime;
1043 prl->prefix[i].if_index = rpp->rp_ifp->if_index;
1044 prl->prefix[i].expire = rpp->rp_expire;
1045 prl->prefix[i].advrtrs = 0;
1387 {
1388 struct rr_prefix *rpp;
1389
1390 for (rpp = LIST_FIRST(&rr_prefix); rpp;
1391 rpp = LIST_NEXT(rpp, rp_entry)) {
1392 if (i >= PRLSTSIZ)
1393 break;
1394 prl->prefix[i].prefix = rpp->rp_prefix.sin6_addr;
1395 prl->prefix[i].raflags = rpp->rp_raf;
1396 prl->prefix[i].prefixlen = rpp->rp_plen;
1397 prl->prefix[i].vltime = rpp->rp_vltime;
1398 prl->prefix[i].pltime = rpp->rp_pltime;
1399 prl->prefix[i].if_index = rpp->rp_ifp->if_index;
1400 prl->prefix[i].expire = rpp->rp_expire;
1401 prl->prefix[i].advrtrs = 0;
1402 prl->prefix[i].origin = rpp->rp_origin;
1046 i++;
1047 }
1048 }
1403 i++;
1404 }
1405 }
1406 splx(s);
1049
1050 break;
1051 case SIOCGIFINFO_IN6:
1407
1408 break;
1409 case SIOCGIFINFO_IN6:
1410 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1411 error = EINVAL;
1412 break;
1413 }
1052 ndi->ndi = nd_ifinfo[ifp->if_index];
1053 break;
1414 ndi->ndi = nd_ifinfo[ifp->if_index];
1415 break;
1054 case SIOCSNDFLUSH_IN6:
1416 case SIOCSIFINFO_FLAGS:
1417 /* XXX: almost all other fields of ndi->ndi is unused */
1418 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1419 error = EINVAL;
1420 break;
1421 }
1422 nd_ifinfo[ifp->if_index].flags = ndi->ndi.flags;
1423 break;
1424 case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */
1055 /* flush default router list */
1056 /*
1057 * xxx sumikawa: should not delete route if default
1058 * route equals to the top of default router list
1059 */
1060 bzero(&any, sizeof(any));
1061 defrouter_delreq(&any, 0);
1425 /* flush default router list */
1426 /*
1427 * xxx sumikawa: should not delete route if default
1428 * route equals to the top of default router list
1429 */
1430 bzero(&any, sizeof(any));
1431 defrouter_delreq(&any, 0);
1432 defrouter_select();
1062 /* xxx sumikawa: flush prefix list */
1063 break;
1064 case SIOCSPFXFLUSH_IN6:
1065 {
1066 /* flush all the prefix advertised by routers */
1067 struct nd_prefix *pr, *next;
1068
1069 s = splnet();
1433 /* xxx sumikawa: flush prefix list */
1434 break;
1435 case SIOCSPFXFLUSH_IN6:
1436 {
1437 /* flush all the prefix advertised by routers */
1438 struct nd_prefix *pr, *next;
1439
1440 s = splnet();
1070 for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
1071 next = LIST_NEXT(pr, ndpr_entry);
1441 for (pr = nd_prefix.lh_first; pr; pr = next) {
1442 next = pr->ndpr_next;
1072 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
1073 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
1074 prelist_remove(pr);
1075 }
1076 splx(s);
1077 break;
1078 }
1079 case SIOCSRTRFLUSH_IN6:
1080 {
1081 /* flush all the default routers */
1082 struct nd_defrouter *dr, *next;
1083
1084 s = splnet();
1443 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
1444 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
1445 prelist_remove(pr);
1446 }
1447 splx(s);
1448 break;
1449 }
1450 case SIOCSRTRFLUSH_IN6:
1451 {
1452 /* flush all the default routers */
1453 struct nd_defrouter *dr, *next;
1454
1455 s = splnet();
1085 if ((dr = LIST_FIRST(&nd_defrouter)) != NULL) {
1456 if ((dr = TAILQ_FIRST(&nd_defrouter)) != NULL) {
1086 /*
1087 * The first entry of the list may be stored in
1088 * the routing table, so we'll delete it later.
1089 */
1457 /*
1458 * The first entry of the list may be stored in
1459 * the routing table, so we'll delete it later.
1460 */
1090 for (dr = LIST_NEXT(dr, dr_entry); dr; dr = next) {
1091 next = LIST_NEXT(dr, dr_entry);
1461 for (dr = TAILQ_NEXT(dr, dr_entry); dr; dr = next) {
1462 next = TAILQ_NEXT(dr, dr_entry);
1092 defrtrlist_del(dr);
1093 }
1463 defrtrlist_del(dr);
1464 }
1094 defrtrlist_del(LIST_FIRST(&nd_defrouter));
1465 defrtrlist_del(TAILQ_FIRST(&nd_defrouter));
1095 }
1096 splx(s);
1097 break;
1098 }
1099 case SIOCGNBRINFO_IN6:
1100 {
1101 struct llinfo_nd6 *ln;
1102 struct in6_addr nb_addr = nbi->addr; /* make local for safety */

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

1111
1112 if (*idp == 0)
1113 *idp = htons(ifp->if_index);
1114 }
1115
1116 s = splnet();
1117 if ((rt = nd6_lookup(&nb_addr, 0, ifp)) == NULL) {
1118 error = EINVAL;
1466 }
1467 splx(s);
1468 break;
1469 }
1470 case SIOCGNBRINFO_IN6:
1471 {
1472 struct llinfo_nd6 *ln;
1473 struct in6_addr nb_addr = nbi->addr; /* make local for safety */

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

1482
1483 if (*idp == 0)
1484 *idp = htons(ifp->if_index);
1485 }
1486
1487 s = splnet();
1488 if ((rt = nd6_lookup(&nb_addr, 0, ifp)) == NULL) {
1489 error = EINVAL;
1490 splx(s);
1119 break;
1120 }
1121 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1122 nbi->state = ln->ln_state;
1123 nbi->asked = ln->ln_asked;
1124 nbi->isrouter = ln->ln_router;
1125 nbi->expire = ln->ln_expire;
1126 splx(s);
1127
1128 break;
1129 }
1491 break;
1492 }
1493 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1494 nbi->state = ln->ln_state;
1495 nbi->asked = ln->ln_asked;
1496 nbi->isrouter = ln->ln_router;
1497 nbi->expire = ln->ln_expire;
1498 splx(s);
1499
1500 break;
1501 }
1502 case SIOCGDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */
1503 ndif->ifindex = nd6_defifindex;
1504 break;
1505 case SIOCSDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */
1506 return(nd6_setdefaultiface(ndif->ifindex));
1507 break;
1130 }
1131 return(error);
1132}
1133
1134/*
1135 * Create neighbor cache entry and cache link-layer address,
1136 * on reception of inbound ND6 packets. (RS/RA/NS/redirect)
1137 */

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

1169 * XXX If the link does not have link-layer adderss, what should
1170 * we do? (ifp->if_addrlen == 0)
1171 * Spec says nothing in sections for RA, RS and NA. There's small
1172 * description on it in NS section (RFC 2461 7.2.3).
1173 */
1174
1175 rt = nd6_lookup(from, 0, ifp);
1176 if (!rt) {
1508 }
1509 return(error);
1510}
1511
1512/*
1513 * Create neighbor cache entry and cache link-layer address,
1514 * on reception of inbound ND6 packets. (RS/RA/NS/redirect)
1515 */

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

1547 * XXX If the link does not have link-layer adderss, what should
1548 * we do? (ifp->if_addrlen == 0)
1549 * Spec says nothing in sections for RA, RS and NA. There's small
1550 * description on it in NS section (RFC 2461 7.2.3).
1551 */
1552
1553 rt = nd6_lookup(from, 0, ifp);
1554 if (!rt) {
1555#if 0
1556 /* nothing must be done if there's no lladdr */
1557 if (!lladdr || !lladdrlen)
1558 return NULL;
1559#endif
1560
1177 rt = nd6_lookup(from, 1, ifp);
1178 is_newentry = 1;
1179 } else
1180 is_newentry = 0;
1181
1182 if (!rt)
1183 return NULL;
1184 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {

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

1243 /*
1244 * Update the state of the neighbor cache.
1245 */
1246 ln->ln_state = newstate;
1247
1248 if (ln->ln_state == ND6_LLINFO_STALE) {
1249 rt->rt_flags &= ~RTF_REJECT;
1250 if (ln->ln_hold) {
1561 rt = nd6_lookup(from, 1, ifp);
1562 is_newentry = 1;
1563 } else
1564 is_newentry = 0;
1565
1566 if (!rt)
1567 return NULL;
1568 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {

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

1627 /*
1628 * Update the state of the neighbor cache.
1629 */
1630 ln->ln_state = newstate;
1631
1632 if (ln->ln_state == ND6_LLINFO_STALE) {
1633 rt->rt_flags &= ~RTF_REJECT;
1634 if (ln->ln_hold) {
1251 nd6_output(ifp, ln->ln_hold,
1635#ifdef OLDIP6OUTPUT
1636 (*ifp->if_output)(ifp, ln->ln_hold,
1637 rt_key(rt), rt);
1638#else
1639 /*
1640 * we assume ifp is not a p2p here, so just
1641 * set the 2nd argument as the 1st one.
1642 */
1643 nd6_output(ifp, ifp, ln->ln_hold,
1252 (struct sockaddr_in6 *)rt_key(rt),
1253 rt);
1644 (struct sockaddr_in6 *)rt_key(rt),
1645 rt);
1646#endif
1254 ln->ln_hold = 0;
1255 }
1256 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
1257 /* probe right away */
1258 ln->ln_expire = time_second;
1259 }
1260 }
1261

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

1296 if (is_newentry) /*(6-7)*/
1297 ln->ln_router = 0;
1298 break;
1299 case ND_REDIRECT:
1300 /*
1301 * If the icmp is a redirect to a better router, always set the
1302 * is_router flag. Otherwise, if the entry is newly created,
1303 * clear the flag. [RFC 2461, sec 8.3]
1647 ln->ln_hold = 0;
1648 }
1649 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
1650 /* probe right away */
1651 ln->ln_expire = time_second;
1652 }
1653 }
1654

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

1689 if (is_newentry) /*(6-7)*/
1690 ln->ln_router = 0;
1691 break;
1692 case ND_REDIRECT:
1693 /*
1694 * If the icmp is a redirect to a better router, always set the
1695 * is_router flag. Otherwise, if the entry is newly created,
1696 * clear the flag. [RFC 2461, sec 8.3]
1304 *
1305 */
1306 if (code == ND_REDIRECT_ROUTER)
1307 ln->ln_router = 1;
1308 else if (is_newentry) /*(6-7)*/
1309 ln->ln_router = 0;
1310 break;
1311 case ND_ROUTER_SOLICIT:
1312 /*

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

1333 void *ignored_arg;
1334{
1335 int s = splnet();
1336 register int i;
1337 register struct nd_ifinfo *nd6if;
1338
1339 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
1340 for (i = 1; i < if_index + 1; i++) {
1697 */
1698 if (code == ND_REDIRECT_ROUTER)
1699 ln->ln_router = 1;
1700 else if (is_newentry) /*(6-7)*/
1701 ln->ln_router = 0;
1702 break;
1703 case ND_ROUTER_SOLICIT:
1704 /*

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

1725 void *ignored_arg;
1726{
1727 int s = splnet();
1728 register int i;
1729 register struct nd_ifinfo *nd6if;
1730
1731 timeout(nd6_slowtimo, (caddr_t)0, ND6_SLOWTIMER_INTERVAL * hz);
1732 for (i = 1; i < if_index + 1; i++) {
1733 if (!nd_ifinfo || i >= nd_ifinfo_indexlim)
1734 continue;
1341 nd6if = &nd_ifinfo[i];
1342 if (nd6if->basereachable && /* already initialized */
1343 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) {
1344 /*
1345 * Since reachable time rarely changes by router
1346 * advertisements, we SHOULD insure that a new random
1347 * value gets recomputed at least once every few hours.
1348 * (RFC 2461, 6.3.4)
1349 */
1350 nd6if->recalctm = nd6_recalc_reachtm_interval;
1351 nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable);
1352 }
1353 }
1354 splx(s);
1355}
1356
1357#define senderr(e) { error = (e); goto bad;}
1358int
1735 nd6if = &nd_ifinfo[i];
1736 if (nd6if->basereachable && /* already initialized */
1737 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) {
1738 /*
1739 * Since reachable time rarely changes by router
1740 * advertisements, we SHOULD insure that a new random
1741 * value gets recomputed at least once every few hours.
1742 * (RFC 2461, 6.3.4)
1743 */
1744 nd6if->recalctm = nd6_recalc_reachtm_interval;
1745 nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable);
1746 }
1747 }
1748 splx(s);
1749}
1750
1751#define senderr(e) { error = (e); goto bad;}
1752int
1359nd6_output(ifp, m0, dst, rt0)
1753nd6_output(ifp, origifp, m0, dst, rt0)
1360 register struct ifnet *ifp;
1754 register struct ifnet *ifp;
1755 struct ifnet *origifp;
1361 struct mbuf *m0;
1362 struct sockaddr_in6 *dst;
1363 struct rtentry *rt0;
1364{
1365 register struct mbuf *m = m0;
1366 register struct rtentry *rt = rt0;
1756 struct mbuf *m0;
1757 struct sockaddr_in6 *dst;
1758 struct rtentry *rt0;
1759{
1760 register struct mbuf *m = m0;
1761 register struct rtentry *rt = rt0;
1762 struct sockaddr_in6 *gw6 = NULL;
1367 struct llinfo_nd6 *ln = NULL;
1368 int error = 0;
1369
1370 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
1371 goto sendpkt;
1372
1373 /*
1374 * XXX: we currently do not make neighbor cache on any interface
1763 struct llinfo_nd6 *ln = NULL;
1764 int error = 0;
1765
1766 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
1767 goto sendpkt;
1768
1769 /*
1770 * XXX: we currently do not make neighbor cache on any interface
1375 * other than ARCnet, Ethernet and FDDI.
1771 * other than ARCnet, Ethernet, FDDI and GIF.
1772 *
1773 * draft-ietf-ngtrans-mech-06.txt says:
1774 * - unidirectional tunnels needs no ND
1376 */
1377 switch (ifp->if_type) {
1378 case IFT_ARCNET:
1379 case IFT_ETHER:
1380 case IFT_FDDI:
1775 */
1776 switch (ifp->if_type) {
1777 case IFT_ARCNET:
1778 case IFT_ETHER:
1779 case IFT_FDDI:
1780 case IFT_GIF: /* XXX need more cases? */
1381 break;
1382 default:
1383 goto sendpkt;
1384 }
1385
1386 /*
1387 * next hop determination. This routine is derived from ether_outpout.
1388 */
1389 if (rt) {
1390 if ((rt->rt_flags & RTF_UP) == 0) {
1391 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) !=
1392 NULL)
1393 {
1394 rt->rt_refcnt--;
1781 break;
1782 default:
1783 goto sendpkt;
1784 }
1785
1786 /*
1787 * next hop determination. This routine is derived from ether_outpout.
1788 */
1789 if (rt) {
1790 if ((rt->rt_flags & RTF_UP) == 0) {
1791 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) !=
1792 NULL)
1793 {
1794 rt->rt_refcnt--;
1395 if (rt->rt_ifp != ifp)
1396 return nd6_output(ifp, m0, dst, rt); /* XXX: loop care? */
1795 if (rt->rt_ifp != ifp) {
1796 /* XXX: loop care? */
1797 return nd6_output(ifp, origifp, m0,
1798 dst, rt);
1799 }
1397 } else
1398 senderr(EHOSTUNREACH);
1399 }
1800 } else
1801 senderr(EHOSTUNREACH);
1802 }
1803
1400 if (rt->rt_flags & RTF_GATEWAY) {
1804 if (rt->rt_flags & RTF_GATEWAY) {
1805 gw6 = (struct sockaddr_in6 *)rt->rt_gateway;
1806
1807 /*
1808 * We skip link-layer address resolution and NUD
1809 * if the gateway is not a neighbor from ND point
1810 * of view, regardless the value of the value of
1811 * nd_ifinfo.flags.
1812 * The second condition is a bit tricky: we skip
1813 * if the gateway is our own address, which is
1814 * sometimes used to install a route to a p2p link.
1815 */
1816 if (!nd6_is_addr_neighbor(gw6, ifp) ||
1817 in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) {
1818 if (rt->rt_flags & RTF_REJECT)
1819 senderr(EHOSTDOWN);
1820
1821 /*
1822 * We allow this kind of tricky route only
1823 * when the outgoing interface is p2p.
1824 * XXX: we may need a more generic rule here.
1825 */
1826 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
1827 senderr(EHOSTUNREACH);
1828
1829 goto sendpkt;
1830 }
1831
1401 if (rt->rt_gwroute == 0)
1402 goto lookup;
1403 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
1404 rtfree(rt); rt = rt0;
1405 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL);
1406 if ((rt = rt->rt_gwroute) == 0)
1407 senderr(EHOSTUNREACH);
1408 }

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

1417 * At this point, the destination of the packet must be a unicast
1418 * or an anycast address(i.e. not a multicast).
1419 */
1420
1421 /* Look up the neighbor cache for the nexthop */
1422 if (rt && (rt->rt_flags & RTF_LLINFO) != 0)
1423 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1424 else {
1832 if (rt->rt_gwroute == 0)
1833 goto lookup;
1834 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
1835 rtfree(rt); rt = rt0;
1836 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL);
1837 if ((rt = rt->rt_gwroute) == 0)
1838 senderr(EHOSTUNREACH);
1839 }

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

1848 * At this point, the destination of the packet must be a unicast
1849 * or an anycast address(i.e. not a multicast).
1850 */
1851
1852 /* Look up the neighbor cache for the nexthop */
1853 if (rt && (rt->rt_flags & RTF_LLINFO) != 0)
1854 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1855 else {
1425 if ((rt = nd6_lookup(&dst->sin6_addr, 1, ifp)) != NULL)
1856 /*
1857 * Since nd6_is_addr_neighbor() internally calls nd6_lookup(),
1858 * the condition below is not very efficient. But we believe
1859 * it is tolerable, because this should be a rare case.
1860 */
1861 if (nd6_is_addr_neighbor(dst, ifp) &&
1862 (rt = nd6_lookup(&dst->sin6_addr, 1, ifp)) != NULL)
1426 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1427 }
1428 if (!ln || !rt) {
1863 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1864 }
1865 if (!ln || !rt) {
1429 log(LOG_DEBUG, "nd6_output: can't allocate llinfo for %s "
1430 "(ln=%p, rt=%p)\n",
1431 ip6_sprintf(&dst->sin6_addr), ln, rt);
1432 senderr(EIO); /* XXX: good error? */
1866 if ((ifp->if_flags & IFF_POINTOPOINT) == 0 &&
1867 !(nd_ifinfo[ifp->if_index].flags & ND6_IFF_PERFORMNUD)) {
1868 log(LOG_DEBUG,
1869 "nd6_output: can't allocate llinfo for %s "
1870 "(ln=%p, rt=%p)\n",
1871 ip6_sprintf(&dst->sin6_addr), ln, rt);
1872 senderr(EIO); /* XXX: good error? */
1873 }
1874
1875 goto sendpkt; /* send anyway */
1433 }
1434
1876 }
1877
1878 /* We don't have to do link-layer address resolution on a p2p link. */
1879 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 &&
1880 ln->ln_state < ND6_LLINFO_REACHABLE)
1881 ln->ln_state = ND6_LLINFO_STALE;
1435
1436 /*
1437 * The first time we send a packet to a neighbor whose entry is
1438 * STALE, we have to change the state to DELAY and a sets a timer to
1439 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
1440 * neighbor unreachability detection on expiration.
1441 * (RFC 2461 7.3.3)
1442 */

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

1476 ln->ln_expire = time_second +
1477 nd_ifinfo[ifp->if_index].retrans / 1000;
1478 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
1479 }
1480 }
1481 return(0);
1482
1483 sendpkt:
1882
1883 /*
1884 * The first time we send a packet to a neighbor whose entry is
1885 * STALE, we have to change the state to DELAY and a sets a timer to
1886 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
1887 * neighbor unreachability detection on expiration.
1888 * (RFC 2461 7.3.3)
1889 */

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

1923 ln->ln_expire = time_second +
1924 nd_ifinfo[ifp->if_index].retrans / 1000;
1925 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
1926 }
1927 }
1928 return(0);
1929
1930 sendpkt:
1931
1932#ifdef FAKE_LOOPBACK_IF
1933 if (ifp->if_flags & IFF_LOOPBACK) {
1934 return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
1935 rt));
1936 }
1937#endif
1484 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt));
1938 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt));
1485
1939
1486 bad:
1487 if (m)
1488 m_freem(m);
1489 return (error);
1490}
1491#undef senderr
1492
1493int

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

1517 }
1518
1519 if (rt == NULL ||
1520 rt->rt_gateway->sa_family != AF_LINK) {
1521 printf("nd6_storelladdr: something odd happens\n");
1522 return(0);
1523 }
1524 sdl = SDL(rt->rt_gateway);
1940 bad:
1941 if (m)
1942 m_freem(m);
1943 return (error);
1944}
1945#undef senderr
1946
1947int

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

1971 }
1972
1973 if (rt == NULL ||
1974 rt->rt_gateway->sa_family != AF_LINK) {
1975 printf("nd6_storelladdr: something odd happens\n");
1976 return(0);
1977 }
1978 sdl = SDL(rt->rt_gateway);
1525 if (sdl->sdl_alen != 0)
1526 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
1979 if (sdl->sdl_alen == 0) {
1980 /* this should be impossible, but we bark here for debugging */
1981 printf("nd6_storelladdr: sdl_alen == 0\n");
1982 return(0);
1983 }
1527
1984
1985 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
1528 return(1);
1529}
1986 return(1);
1987}