1 /* $FreeBSD: src/sys/netinet6/nd6.c,v 1.20 2002/08/02 20:49:14 rwatson Exp $ */
2 /* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun Exp $ */
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
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
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
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/malloc.h>
45 #include <sys/socket.h>
46 #include <sys/sockio.h>
48 #include <sys/kernel.h>
49 #include <sys/sysctl.h>
50 #include <sys/errno.h>
51 #include <sys/syslog.h>
52 #include <sys/protosw.h>
53 #include <kern/queue.h>
54 #include <kern/lock.h>
56 #define DONT_WARN_OBSOLETE
58 #include <net/if_dl.h>
59 #include <net/if_types.h>
60 #include <net/if_atm.h>
61 #include <net/route.h>
64 #include <netinet/in.h>
65 #include <netinet/if_ether.h>
66 #include <netinet/if_fddi.h>
67 #include <netinet6/in6_var.h>
68 #include <netinet/ip6.h>
69 #include <netinet6/ip6_var.h>
70 #include <netinet6/nd6.h>
71 #include <netinet6/in6_prefix.h>
72 #include <netinet/icmp6.h>
76 #include <net/net_osdep.h>
78 #define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */
79 #define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */
81 #define SIN6(s) ((struct sockaddr_in6 *)s)
82 #define SDL(s) ((struct sockaddr_dl *)s)
85 int nd6_prune
= 1; /* walk list every 1 seconds */
86 int nd6_delay
= 5; /* delay first probe time 5 second */
87 int nd6_umaxtries
= 3; /* maximum unicast query */
88 int nd6_mmaxtries
= 3; /* maximum multicast query */
89 int nd6_useloopback
= 1; /* use loopback interface for local traffic */
90 int nd6_gctimer
= (60 * 60 * 24); /* 1 day: garbage collection timer */
92 /* preventing too many loops in ND option parsing */
93 int nd6_maxndopt
= 10; /* max # of ND options allowed */
95 int nd6_maxnudhint
= 0; /* max # of subsequent upper layer hints */
104 static int nd6_inuse
, nd6_allocated
;
106 struct llinfo_nd6 llinfo_nd6
= {&llinfo_nd6
, &llinfo_nd6
, NULL
, NULL
, 0, 0, 0, 0, 0 };
107 size_t nd_ifinfo_indexlim
= 32; /* increased for 5589193 */
108 struct nd_ifinfo
*nd_ifinfo
= NULL
;
109 struct nd_drhead nd_defrouter
;
110 struct nd_prhead nd_prefix
= { 0 };
112 int nd6_recalc_reachtm_interval
= ND6_RECALC_REACHTM_INTERVAL
;
113 static struct sockaddr_in6 all1_sa
;
115 static int regen_tmpaddr(struct in6_ifaddr
*);
116 extern lck_mtx_t
*rt_mtx
;
117 extern lck_mtx_t
*ip6_mutex
;
118 extern lck_mtx_t
*nd6_mutex
;
120 static void nd6_slowtimo(void *ignored_arg
);
125 static int nd6_init_done
= 0;
129 log(LOG_NOTICE
, "nd6_init called more than once(ignored)\n");
133 all1_sa
.sin6_family
= AF_INET6
;
134 all1_sa
.sin6_len
= sizeof(struct sockaddr_in6
);
135 for (i
= 0; i
< sizeof(all1_sa
.sin6_addr
); i
++)
136 all1_sa
.sin6_addr
.s6_addr
[i
] = 0xff;
138 /* initialization of the default router list */
139 TAILQ_INIT(&nd_defrouter
);
144 timeout(nd6_slowtimo
, (caddr_t
)0, ND6_SLOWTIMER_INTERVAL
* hz
);
153 * We have some arrays that should be indexed by if_index.
154 * since if_index will grow dynamically, they should grow too.
156 if (nd_ifinfo
== NULL
|| if_index
>= nd_ifinfo_indexlim
) {
160 while (if_index
>= nd_ifinfo_indexlim
)
161 nd_ifinfo_indexlim
<<= 1;
164 n
= nd_ifinfo_indexlim
* sizeof(struct nd_ifinfo
);
165 q
= (caddr_t
)_MALLOC(n
, M_IP6NDP
, M_WAITOK
);
168 bcopy((caddr_t
)nd_ifinfo
, q
, n
/2);
170 * SU fix purposely leaks the old nd_ifinfo array
171 * if we grow the arraw to more than 32 interfaces
172 * Fix for future release is to use proper locking.
174 FREE((caddr_t)nd_ifinfo, M_IP6NDP);
177 nd_ifinfo
= (struct nd_ifinfo
*)q
;
180 #define ND nd_ifinfo[ifp->if_index]
183 * Don't initialize if called twice.
184 * XXX: to detect this, we should choose a member that is never set
185 * before initialization of the ND structure itself. We formaly used
186 * the linkmtu member, which was not suitable because it could be
187 * initialized via "ifconfig mtu".
189 if (ND
.basereachable
)
192 ND
.linkmtu
= ifindex2ifnet
[ifp
->if_index
]->if_mtu
;
193 ND
.chlim
= IPV6_DEFHLIM
;
194 ND
.basereachable
= REACHABLE_TIME
;
195 ND
.reachable
= ND_COMPUTE_RTIME(ND
.basereachable
);
196 ND
.retrans
= RETRANS_TIMER
;
198 ND
.flags
= ND6_IFF_PERFORMNUD
;
204 * Reset ND level link MTU. This function is called when the physical MTU
205 * changes, which means we might have to adjust the ND level MTU.
208 nd6_setmtu(struct ifnet
*ifp
)
210 struct nd_ifinfo
*ndi
;
214 * Make sure IPv6 is enabled for the interface first,
215 * because this can be called directly from SIOCSIFMTU for IPv4
218 if (ifp
->if_index
>= nd_ifinfo_indexlim
) {
219 return; /* we're out of bound for nd_ifinfo */
222 ndi
= &nd_ifinfo
[ifp
->if_index
];
223 oldmaxmtu
= ndi
->maxmtu
;
226 * The ND level maxmtu is somewhat redundant to the interface MTU
227 * and is an implementation artifact of KAME. Instead of hard-
228 * limiting the maxmtu based on the interface type here, we simply
229 * take the if_mtu value since SIOCSIFMTU would have taken care of
230 * the sanity checks related to the maximum MTU allowed for the
231 * interface (a value that is known only by the interface layer),
232 * by sending the request down via ifnet_ioctl(). The use of the
233 * ND level maxmtu and linkmtu (the latter obtained via RA) are done
234 * via IN6_LINKMTU() which does further checking against if_mtu.
236 ndi
->maxmtu
= ifp
->if_mtu
;
239 * Decreasing the interface MTU under IPV6 minimum MTU may cause
240 * undesirable situation. We thus notify the operator of the change
241 * explicitly. The check for oldmaxmtu is necessary to restrict the
242 * log to the case of changing the MTU, not initializing it.
244 if (oldmaxmtu
>= IPV6_MMTU
&& ndi
->maxmtu
< IPV6_MMTU
) {
245 log(LOG_NOTICE
, "nd6_setmtu: "
246 "new link MTU on %s%d (%lu) is too small for IPv6\n",
247 ifp
->if_name
, ifp
->if_unit
, (unsigned long)ndi
->maxmtu
);
250 /* also adjust in6_maxmtu if necessary. */
251 if (ndi
->maxmtu
> in6_maxmtu
)
259 union nd_opts
*ndopts
)
261 bzero(ndopts
, sizeof(*ndopts
));
262 ndopts
->nd_opts_search
= (struct nd_opt_hdr
*)opt
;
264 = (struct nd_opt_hdr
*)(((u_char
*)opt
) + icmp6len
);
267 ndopts
->nd_opts_done
= 1;
268 ndopts
->nd_opts_search
= NULL
;
273 * Take one ND option.
277 union nd_opts
*ndopts
)
279 struct nd_opt_hdr
*nd_opt
;
283 panic("ndopts == NULL in nd6_option\n");
284 if (!ndopts
->nd_opts_last
)
285 panic("uninitialized ndopts in nd6_option\n");
286 if (!ndopts
->nd_opts_search
)
288 if (ndopts
->nd_opts_done
)
291 nd_opt
= ndopts
->nd_opts_search
;
293 /* make sure nd_opt_len is inside the buffer */
294 if ((caddr_t
)&nd_opt
->nd_opt_len
>= (caddr_t
)ndopts
->nd_opts_last
) {
295 bzero(ndopts
, sizeof(*ndopts
));
299 olen
= nd_opt
->nd_opt_len
<< 3;
302 * Message validation requires that all included
303 * options have a length that is greater than zero.
305 bzero(ndopts
, sizeof(*ndopts
));
309 ndopts
->nd_opts_search
= (struct nd_opt_hdr
*)((caddr_t
)nd_opt
+ olen
);
310 if (ndopts
->nd_opts_search
> ndopts
->nd_opts_last
) {
311 /* option overruns the end of buffer, invalid */
312 bzero(ndopts
, sizeof(*ndopts
));
314 } else if (ndopts
->nd_opts_search
== ndopts
->nd_opts_last
) {
315 /* reached the end of options chain */
316 ndopts
->nd_opts_done
= 1;
317 ndopts
->nd_opts_search
= NULL
;
323 * Parse multiple ND options.
324 * This function is much easier to use, for ND routines that do not need
325 * multiple options of the same type.
329 union nd_opts
*ndopts
)
331 struct nd_opt_hdr
*nd_opt
;
335 panic("ndopts == NULL in nd6_options\n");
336 if (!ndopts
->nd_opts_last
)
337 panic("uninitialized ndopts in nd6_options\n");
338 if (!ndopts
->nd_opts_search
)
342 nd_opt
= nd6_option(ndopts
);
343 if (!nd_opt
&& !ndopts
->nd_opts_last
) {
345 * Message validation requires that all included
346 * options have a length that is greater than zero.
348 icmp6stat
.icp6s_nd_badopt
++;
349 bzero(ndopts
, sizeof(*ndopts
));
356 switch (nd_opt
->nd_opt_type
) {
357 case ND_OPT_SOURCE_LINKADDR
:
358 case ND_OPT_TARGET_LINKADDR
:
360 case ND_OPT_REDIRECTED_HEADER
:
361 if (ndopts
->nd_opt_array
[nd_opt
->nd_opt_type
]) {
363 "duplicated ND6 option found (type=%d)\n",
364 nd_opt
->nd_opt_type
));
367 ndopts
->nd_opt_array
[nd_opt
->nd_opt_type
]
371 case ND_OPT_PREFIX_INFORMATION
:
372 if (ndopts
->nd_opt_array
[nd_opt
->nd_opt_type
] == 0) {
373 ndopts
->nd_opt_array
[nd_opt
->nd_opt_type
]
376 ndopts
->nd_opts_pi_end
=
377 (struct nd_opt_prefix_info
*)nd_opt
;
381 * Unknown options must be silently ignored,
382 * to accomodate future extension to the protocol.
385 "nd6_options: unsupported option %d - "
386 "option ignored\n", nd_opt
->nd_opt_type
));
391 if (i
> nd6_maxndopt
) {
392 icmp6stat
.icp6s_nd_toomanyopt
++;
393 nd6log((LOG_INFO
, "too many loop in nd opt\n"));
397 if (ndopts
->nd_opts_done
)
405 * ND6 timer routine to expire default route list and prefix list
409 __unused
void *ignored_arg
)
411 struct llinfo_nd6
*ln
;
412 struct nd_defrouter
*dr
;
413 struct nd_prefix
*pr
;
414 struct ifnet
*ifp
= NULL
;
415 struct in6_ifaddr
*ia6
, *nia6
;
416 struct in6_addrlifetime
*lt6
;
417 struct timeval timenow
;
419 getmicrotime(&timenow
);
423 ln
= llinfo_nd6
.ln_next
;
424 while (ln
&& ln
!= &llinfo_nd6
) {
426 struct sockaddr_in6
*dst
;
427 struct llinfo_nd6
*next
= ln
->ln_next
;
428 /* XXX: used for the DELAY case only: */
429 struct nd_ifinfo
*ndi
= NULL
;
431 if ((rt
= ln
->ln_rt
) == NULL
) {
435 if ((ifp
= rt
->rt_ifp
) == NULL
) {
439 ndi
= &nd_ifinfo
[ifp
->if_index
];
440 dst
= (struct sockaddr_in6
*)rt_key(rt
);
442 if (ln
->ln_expire
> timenow
.tv_sec
) {
449 printf("rt=0 in nd6_timer(ln=%p)\n", ln
);
453 if (rt
->rt_llinfo
&& (struct llinfo_nd6
*)rt
->rt_llinfo
!= ln
) {
454 printf("rt_llinfo(%p) is not equal to ln(%p)\n",
460 printf("dst=0 in nd6_timer(ln=%p)\n", ln
);
465 switch (ln
->ln_state
) {
466 case ND6_LLINFO_INCOMPLETE
:
467 if (ln
->ln_asked
< nd6_mmaxtries
) {
469 ln
->ln_expire
= timenow
.tv_sec
+
470 nd_ifinfo
[ifp
->if_index
].retrans
/ 1000;
471 nd6_ns_output(ifp
, NULL
, &dst
->sin6_addr
,
474 struct mbuf
*m
= ln
->ln_hold
;
479 * Fake rcvif to make ICMP error
480 * more helpful in diagnosing
482 * XXX: should we consider
485 m
->m_pkthdr
.rcvif
= rt
->rt_ifp
;
487 icmp6_error(m
, ICMP6_DST_UNREACH
,
488 ICMP6_DST_UNREACH_ADDR
, 0);
494 case ND6_LLINFO_REACHABLE
:
496 ln
->ln_state
= ND6_LLINFO_STALE
;
497 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
501 case ND6_LLINFO_STALE
:
502 /* Garbage Collection(RFC 2461 5.3) */
507 case ND6_LLINFO_DELAY
:
508 if (ndi
&& (ndi
->flags
& ND6_IFF_PERFORMNUD
) != 0) {
511 ln
->ln_state
= ND6_LLINFO_PROBE
;
512 ln
->ln_expire
= timenow
.tv_sec
+
514 nd6_ns_output(ifp
, &dst
->sin6_addr
,
518 ln
->ln_state
= ND6_LLINFO_STALE
; /* XXX */
519 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
522 case ND6_LLINFO_PROBE
:
523 if (ln
->ln_asked
< nd6_umaxtries
) {
525 ln
->ln_expire
= timenow
.tv_sec
+
526 nd_ifinfo
[ifp
->if_index
].retrans
/ 1000;
527 nd6_ns_output(ifp
, &dst
->sin6_addr
,
528 &dst
->sin6_addr
, ln
, 0, 0);
537 /* expire default router list */
538 lck_mtx_lock(nd6_mutex
);
539 dr
= TAILQ_FIRST(&nd_defrouter
);
541 if (dr
->expire
&& dr
->expire
< timenow
.tv_sec
) {
542 struct nd_defrouter
*t
;
543 t
= TAILQ_NEXT(dr
, dr_entry
);
544 defrtrlist_del(dr
, 1);
547 dr
= TAILQ_NEXT(dr
, dr_entry
);
552 * expire interface addresses.
553 * in the past the loop was inside prefix expiry processing.
554 * However, from a stricter speci-confrmance standpoint, we should
555 * rather separate address lifetimes and prefix lifetimes.
558 for (ia6
= in6_ifaddrs
; ia6
; ia6
= nia6
) {
560 /* check address lifetime */
561 lt6
= &ia6
->ia6_lifetime
;
562 if (IFA6_IS_INVALID(ia6
)) {
566 * If the expiring address is temporary, try
567 * regenerating a new one. This would be useful when
568 * we suspended a laptop PC, then turned it on after a
569 * period that could invalidate all temporary
570 * addresses. Although we may have to restart the
571 * loop (see below), it must be after purging the
572 * address. Otherwise, we'd see an infinite loop of
575 if (ip6_use_tempaddr
&&
576 (ia6
->ia6_flags
& IN6_IFF_TEMPORARY
) != 0) {
577 /* NOTE: We have to drop the lock here because
578 * regen_tmpaddr() eventually calls in6_update_ifa(),
579 * which must take the lock and would otherwise cause a
580 * hang. This is safe because the goto addrloop
581 * leads to a reevaluation of the in6_ifaddrs list
583 lck_mtx_unlock(nd6_mutex
);
584 if (regen_tmpaddr(ia6
) == 0)
586 lck_mtx_lock(nd6_mutex
);
589 in6_purgeaddr(&ia6
->ia_ifa
, 1);
592 goto addrloop
; /* XXX: see below */
594 if (IFA6_IS_DEPRECATED(ia6
)) {
595 int oldflags
= ia6
->ia6_flags
;
597 ia6
->ia6_flags
|= IN6_IFF_DEPRECATED
;
600 * If a temporary address has just become deprecated,
601 * regenerate a new one if possible.
603 if (ip6_use_tempaddr
&&
604 (ia6
->ia6_flags
& IN6_IFF_TEMPORARY
) != 0 &&
605 (oldflags
& IN6_IFF_DEPRECATED
) == 0) {
608 lck_mtx_unlock(nd6_mutex
);
609 if (regen_tmpaddr(ia6
) == 0) {
611 * A new temporary address is
613 * XXX: this means the address chain
614 * has changed while we are still in
615 * the loop. Although the change
616 * would not cause disaster (because
617 * it's not a deletion, but an
618 * addition,) we'd rather restart the
619 * loop just for safety. Or does this
620 * significantly reduce performance??
622 lck_mtx_lock(nd6_mutex
);
625 lck_mtx_lock(nd6_mutex
);
629 * A new RA might have made a deprecated address
632 ia6
->ia6_flags
&= ~IN6_IFF_DEPRECATED
;
636 /* expire prefix list */
637 pr
= nd_prefix
.lh_first
;
640 * check prefix lifetime.
641 * since pltime is just for autoconf, pltime processing for
642 * prefix is not necessary.
644 if (pr
->ndpr_expire
&& pr
->ndpr_expire
< timenow
.tv_sec
) {
649 * address expiration and prefix expiration are
650 * separate. NEVER perform in6_purgeaddr here.
653 prelist_remove(pr
, 1);
658 lck_mtx_unlock(nd6_mutex
);
659 timeout(nd6_timer
, (caddr_t
)0, nd6_prune
* hz
);
664 struct in6_ifaddr
*ia6
) /* deprecated/invalidated temporary address */
668 struct in6_ifaddr
*public_ifa6
= NULL
;
669 struct timeval timenow
;
671 getmicrotime(&timenow
);
673 ifp
= ia6
->ia_ifa
.ifa_ifp
;
674 ifnet_lock_exclusive(ifp
);
675 for (ifa
= ifp
->if_addrlist
.tqh_first
; ifa
;
676 ifa
= ifa
->ifa_list
.tqe_next
)
678 struct in6_ifaddr
*it6
;
680 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
683 it6
= (struct in6_ifaddr
*)ifa
;
685 /* ignore no autoconf addresses. */
686 if ((it6
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
689 /* ignore autoconf addresses with different prefixes. */
690 if (it6
->ia6_ndpr
== NULL
|| it6
->ia6_ndpr
!= ia6
->ia6_ndpr
)
694 * Now we are looking at an autoconf address with the same
695 * prefix as ours. If the address is temporary and is still
696 * preferred, do not create another one. It would be rare, but
697 * could happen, for example, when we resume a laptop PC after
700 if ((it6
->ia6_flags
& IN6_IFF_TEMPORARY
) != 0 &&
701 !IFA6_IS_DEPRECATED(it6
)) {
707 * This is a public autoconf address that has the same prefix
708 * as ours. If it is preferred, keep it. We can't break the
709 * loop here, because there may be a still-preferred temporary
710 * address with the prefix.
712 if (!IFA6_IS_DEPRECATED(it6
))
715 ifnet_lock_done(ifp
);
717 if (public_ifa6
!= NULL
) {
720 if ((e
= in6_tmpifadd(public_ifa6
, 0)) != 0) {
721 log(LOG_NOTICE
, "regen_tmpaddr: failed to create a new"
722 " tmp addr,errno=%d\n", e
);
732 * Nuke neighbor cache/prefix/default router management table, right before
739 struct llinfo_nd6
*ln
, *nln
;
740 struct nd_defrouter
*dr
, *ndr
, drany
;
741 struct nd_prefix
*pr
, *npr
;
743 /* Nuke default router list entries toward ifp */
744 lck_mtx_lock(nd6_mutex
);
745 if ((dr
= TAILQ_FIRST(&nd_defrouter
)) != NULL
) {
747 * The first entry of the list may be stored in
748 * the routing table, so we'll delete it later.
750 for (dr
= TAILQ_NEXT(dr
, dr_entry
); dr
; dr
= ndr
) {
751 ndr
= TAILQ_NEXT(dr
, dr_entry
);
753 defrtrlist_del(dr
, 1);
755 dr
= TAILQ_FIRST(&nd_defrouter
);
757 defrtrlist_del(dr
, 1);
760 /* Nuke prefix list entries toward ifp */
761 for (pr
= nd_prefix
.lh_first
; pr
; pr
= npr
) {
763 if (pr
->ndpr_ifp
== ifp
) {
765 * Previously, pr->ndpr_addr is removed as well,
766 * but I strongly believe we don't have to do it.
767 * nd6_purge() is only called from in6_ifdetach(),
768 * which removes all the associated interface addresses
770 * (jinmei@kame.net 20010129)
772 prelist_remove(pr
, 1);
776 /* cancel default outgoing interface setting */
777 if (nd6_defifindex
== ifp
->if_index
)
778 nd6_setdefaultiface(0);
780 if (!ip6_forwarding
&& (ip6_accept_rtadv
|| (ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
781 /* refresh default router list */
782 bzero(&drany
, sizeof(drany
));
783 defrouter_delreq(&drany
, 0);
786 lck_mtx_unlock(nd6_mutex
);
789 * Nuke neighbor cache entries for the ifp.
790 * Note that rt->rt_ifp may not be the same as ifp,
791 * due to KAME goto ours hack. See RTM_RESOLVE case in
792 * nd6_rtrequest(), and ip6_input().
794 ln
= llinfo_nd6
.ln_next
;
795 while (ln
&& ln
!= &llinfo_nd6
) {
797 struct sockaddr_dl
*sdl
;
801 if (rt
&& rt
->rt_gateway
&&
802 rt
->rt_gateway
->sa_family
== AF_LINK
) {
803 sdl
= (struct sockaddr_dl
*)rt
->rt_gateway
;
804 if (sdl
->sdl_index
== ifp
->if_index
)
813 struct in6_addr
*addr6
,
819 struct sockaddr_in6 sin6
;
821 bzero(&sin6
, sizeof(sin6
));
822 sin6
.sin6_len
= sizeof(struct sockaddr_in6
);
823 sin6
.sin6_family
= AF_INET6
;
824 sin6
.sin6_addr
= *addr6
;
826 sin6
.sin6_scope_id
= in6_addr2scopeid(ifp
, addr6
);
829 lck_mtx_lock(rt_mtx
);
830 rt
= rtalloc1_locked((struct sockaddr
*)&sin6
, create
, 0UL);
831 if (rt
&& (rt
->rt_flags
& RTF_LLINFO
) == 0) {
833 * This is the case for the default route.
834 * If we want to create a neighbor cache for the address, we
835 * should free the route for the destination and allocate an
848 * If no route is available and create is set,
849 * we allocate a host route for the destination
850 * and treat it like an interface route.
851 * This hack is necessary for a neighbor which can't
852 * be covered by our own prefix.
855 ifaof_ifpforaddr((struct sockaddr
*)&sin6
, ifp
);
858 lck_mtx_unlock(rt_mtx
);
863 * Create a new route. RTF_LLINFO is necessary
864 * to create a Neighbor Cache entry for the
865 * destination in nd6_rtrequest which will be
866 * called in rtrequest via ifa->ifa_rtrequest.
868 if ((e
= rtrequest_locked(RTM_ADD
, (struct sockaddr
*)&sin6
,
870 (struct sockaddr
*)&all1_sa
,
872 RTF_HOST
| RTF_LLINFO
) &
877 "nd6_lookup: failed to add route for a "
878 "neighbor(%s), errno=%d\n",
879 ip6_sprintf(addr6
), e
);
884 lck_mtx_unlock(rt_mtx
);
888 struct llinfo_nd6
*ln
=
889 (struct llinfo_nd6
*)rt
->rt_llinfo
;
890 ln
->ln_state
= ND6_LLINFO_NOSTATE
;
894 lck_mtx_unlock(rt_mtx
);
900 * Validation for the entry.
901 * Note that the check for rt_llinfo is necessary because a cloned
902 * route from a parent route that has the L flag (e.g. the default
903 * route to a p2p interface) may have the flag, too, while the
904 * destination is not actually a neighbor.
905 * XXX: we can't use rt->rt_ifp to check for the interface, since
906 * it might be the loopback interface if the entry is for our
907 * own address on a non-loopback interface. Instead, we should
908 * use rt->rt_ifa->ifa_ifp, which would specify the REAL
911 if ((ifp
&& ifp
->if_type
!=IFT_PPP
) && ((rt
->rt_flags
& RTF_GATEWAY
) || (rt
->rt_flags
& RTF_LLINFO
) == 0 ||
912 rt
->rt_gateway
->sa_family
!= AF_LINK
|| rt
->rt_llinfo
== NULL
||
913 (ifp
&& rt
->rt_ifa
->ifa_ifp
!= ifp
))) {
915 lck_mtx_unlock(rt_mtx
);
917 log(LOG_DEBUG
, "nd6_lookup: failed to lookup %s (if = %s)\n",
918 ip6_sprintf(addr6
), ifp
? if_name(ifp
) : "unspec");
919 /* xxx more logs... kazu */
924 lck_mtx_unlock(rt_mtx
);
929 * Detect if a given IPv6 address identifies a neighbor on a given link.
930 * XXX: should take care of the destination of a p2p link?
933 nd6_is_addr_neighbor(
934 struct sockaddr_in6
*addr
,
941 #define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
942 #define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
945 * A link-local address is always a neighbor.
946 * XXX: we should use the sin6_scope_id field rather than the embedded
949 if (IN6_IS_ADDR_LINKLOCAL(&addr
->sin6_addr
) &&
950 ntohs(*(u_int16_t
*)&addr
->sin6_addr
.s6_addr
[2]) == ifp
->if_index
)
954 * If the address matches one of our addresses,
955 * it should be a neighbor.
957 ifnet_lock_shared(ifp
);
958 for (ifa
= ifp
->if_addrlist
.tqh_first
;
960 ifa
= ifa
->ifa_list
.tqe_next
)
962 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
965 for (i
= 0; i
< 4; i
++) {
966 if ((IFADDR6(ifa
).s6_addr32
[i
] ^
967 addr
->sin6_addr
.s6_addr32
[i
]) &
968 IFMASK6(ifa
).s6_addr32
[i
])
971 ifnet_lock_done(ifp
);
974 ifnet_lock_done(ifp
);
977 * Even if the address matches none of our addresses, it might be
978 * in the neighbor cache.
980 if (nd6_lookup(&addr
->sin6_addr
, 0, ifp
, rt_locked
) != NULL
)
989 * Free an nd6 llinfo entry.
995 struct llinfo_nd6
*ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
, *next
;
996 struct in6_addr in6
= ((struct sockaddr_in6
*)rt_key(rt
))->sin6_addr
;
997 struct nd_defrouter
*dr
;
1000 * we used to have pfctlinput(PRC_HOSTDEAD) here.
1001 * even though it is not harmful, it was not really necessary.
1004 if (!ip6_forwarding
&& (ip6_accept_rtadv
|| (rt
->rt_ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
1005 lck_mtx_lock(nd6_mutex
);
1006 dr
= defrouter_lookup(&((struct sockaddr_in6
*)rt_key(rt
))->sin6_addr
,
1009 if ((ln
&& ln
->ln_router
) || dr
) {
1011 * rt6_flush must be called whether or not the neighbor
1012 * is in the Default Router List.
1013 * See a corresponding comment in nd6_na_input().
1015 rt6_flush(&in6
, rt
->rt_ifp
);
1020 * Unreachablity of a router might affect the default
1021 * router selection and on-link detection of advertised
1026 * Temporarily fake the state to choose a new default
1027 * router and to perform on-link determination of
1028 * prefixes correctly.
1029 * Below the state will be set correctly,
1030 * or the entry itself will be deleted.
1032 ln
->ln_state
= ND6_LLINFO_INCOMPLETE
;
1035 * Since defrouter_select() does not affect the
1036 * on-link determination and MIP6 needs the check
1037 * before the default router selection, we perform
1040 pfxlist_onlink_check(1);
1042 if (dr
== TAILQ_FIRST(&nd_defrouter
)) {
1044 * It is used as the current default router,
1045 * so we have to move it to the end of the
1046 * list and choose a new one.
1047 * XXX: it is not very efficient if this is
1050 TAILQ_REMOVE(&nd_defrouter
, dr
, dr_entry
);
1051 TAILQ_INSERT_TAIL(&nd_defrouter
, dr
, dr_entry
);
1056 lck_mtx_unlock(nd6_mutex
);
1060 * Before deleting the entry, remember the next entry as the
1061 * return value. We need this because pfxlist_onlink_check() above
1062 * might have freed other entries (particularly the old next entry) as
1063 * a side effect (XXX).
1071 * Detach the route from the routing tree and the list of neighbor
1072 * caches, and disable the route entry not to be used in already
1075 rtrequest(RTM_DELETE
, rt_key(rt
), (struct sockaddr
*)0,
1076 rt_mask(rt
), 0, (struct rtentry
**)0);
1082 * Upper-layer reachability hint for Neighbor Unreachability Detection.
1084 * XXX cost-effective metods?
1089 struct in6_addr
*dst6
,
1092 struct llinfo_nd6
*ln
;
1093 struct timeval timenow
;
1095 getmicrotime(&timenow
);
1098 * If the caller specified "rt", use that. Otherwise, resolve the
1099 * routing table by supplied "dst6".
1104 if (!(rt
= nd6_lookup(dst6
, 0, NULL
, 0)))
1108 if ((rt
->rt_flags
& RTF_GATEWAY
) != 0 ||
1109 (rt
->rt_flags
& RTF_LLINFO
) == 0 ||
1110 !rt
->rt_llinfo
|| !rt
->rt_gateway
||
1111 rt
->rt_gateway
->sa_family
!= AF_LINK
) {
1112 /* This is not a host route. */
1116 ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
1117 if (ln
->ln_state
< ND6_LLINFO_REACHABLE
)
1121 * if we get upper-layer reachability confirmation many times,
1122 * it is possible we have false information.
1126 if (ln
->ln_byhint
> nd6_maxnudhint
)
1130 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
1132 ln
->ln_expire
= timenow
.tv_sec
+
1133 nd_ifinfo
[rt
->rt_ifp
->if_index
].reachable
;
1140 __unused
struct sockaddr
*sa
)
1142 struct sockaddr
*gate
= rt
->rt_gateway
;
1143 struct llinfo_nd6
*ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
1144 static struct sockaddr_dl null_sdl
= {sizeof(null_sdl
), AF_LINK
, 0, 0, 0, 0, 0,
1145 {0,0,0,0,0,0,0,0,0,0,0,0,} };
1146 struct ifnet
*ifp
= rt
->rt_ifp
;
1148 struct timeval timenow
;
1151 if ((rt
->rt_flags
& RTF_GATEWAY
))
1154 if (nd6_need_cache(ifp
) == 0 && (rt
->rt_flags
& RTF_HOST
) == 0) {
1156 * This is probably an interface direct route for a link
1157 * which does not need neighbor caches (e.g. fe80::%lo0/64).
1158 * We do not need special treatment below for such a route.
1159 * Moreover, the RTF_LLINFO flag which would be set below
1160 * would annoy the ndp(8) command.
1165 if (req
== RTM_RESOLVE
&&
1166 (nd6_need_cache(ifp
) == 0 || /* stf case */
1167 !nd6_is_addr_neighbor((struct sockaddr_in6
*)rt_key(rt
), ifp
, 1))) {
1169 * FreeBSD and BSD/OS often make a cloned host route based
1170 * on a less-specific route (e.g. the default route).
1171 * If the less specific route does not have a "gateway"
1172 * (this is the case when the route just goes to a p2p or an
1173 * stf interface), we'll mistakenly make a neighbor cache for
1174 * the host route, and will see strange neighbor solicitation
1175 * for the corresponding destination. In order to avoid the
1176 * confusion, we check if the destination of the route is
1177 * a neighbor in terms of neighbor discovery, and stop the
1178 * process if not. Additionally, we remove the LLINFO flag
1179 * so that ndp(8) will not try to get the neighbor information
1180 * of the destination.
1182 rt
->rt_flags
&= ~RTF_LLINFO
;
1186 getmicrotime(&timenow
);
1190 * There is no backward compatibility :)
1192 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1193 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1194 * rt->rt_flags |= RTF_CLONING;
1196 if (rt
->rt_flags
& (RTF_CLONING
| RTF_LLINFO
)) {
1198 * Case 1: This route should come from
1199 * a route to interface. RTF_LLINFO flag is set
1200 * for a host route whose destination should be
1201 * treated as on-link.
1203 rt_setgate(rt
, rt_key(rt
),
1204 (struct sockaddr
*)&null_sdl
);
1205 gate
= rt
->rt_gateway
;
1206 SDL(gate
)->sdl_type
= ifp
->if_type
;
1207 SDL(gate
)->sdl_index
= ifp
->if_index
;
1209 ln
->ln_expire
= timenow
.tv_sec
;
1211 if (ln
&& ln
->ln_expire
== 0) {
1212 /* kludge for desktops */
1214 printf("nd6_rtequest: time.tv_sec is zero; "
1220 if ((rt
->rt_flags
& RTF_CLONING
))
1224 * In IPv4 code, we try to annonuce new RTF_ANNOUNCE entry here.
1225 * We don't do that here since llinfo is not ready yet.
1227 * There are also couple of other things to be discussed:
1228 * - unsolicited NA code needs improvement beforehand
1229 * - RFC2461 says we MAY send multicast unsolicited NA
1230 * (7.2.6 paragraph 4), however, it also says that we
1231 * SHOULD provide a mechanism to prevent multicast NA storm.
1232 * we don't have anything like it right now.
1233 * note that the mechanism needs a mutual agreement
1234 * between proxies, which means that we need to implement
1235 * a new protocol, or a new kludge.
1236 * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA.
1237 * we need to check ip6forwarding before sending it.
1238 * (or should we allow proxy ND configuration only for
1239 * routers? there's no mention about proxy ND from hosts)
1242 /* XXX it does not work */
1243 if (rt
->rt_flags
& RTF_ANNOUNCE
)
1245 &SIN6(rt_key(rt
))->sin6_addr
,
1246 &SIN6(rt_key(rt
))->sin6_addr
,
1247 ip6_forwarding
? ND_NA_FLAG_ROUTER
: 0,
1252 if ((ifp
->if_flags
& (IFF_POINTOPOINT
| IFF_LOOPBACK
)) == 0) {
1254 * Address resolution isn't necessary for a point to
1255 * point link, so we can skip this test for a p2p link.
1257 if (gate
->sa_family
!= AF_LINK
||
1258 gate
->sa_len
< sizeof(null_sdl
)) {
1260 "nd6_rtrequest: bad gateway value: %s\n",
1264 SDL(gate
)->sdl_type
= ifp
->if_type
;
1265 SDL(gate
)->sdl_index
= ifp
->if_index
;
1268 break; /* This happens on a route change */
1270 * Case 2: This route may come from cloning, or a manual route
1271 * add with a LL address.
1273 R_Malloc(ln
, struct llinfo_nd6
*, sizeof(*ln
));
1274 rt
->rt_llinfo
= (caddr_t
)ln
;
1276 log(LOG_DEBUG
, "nd6_rtrequest: malloc failed\n");
1281 Bzero(ln
, sizeof(*ln
));
1283 /* this is required for "ndp" command. - shin */
1284 if (req
== RTM_ADD
) {
1286 * gate should have some valid AF_LINK entry,
1287 * and ln->ln_expire should have some lifetime
1288 * which is specified by ndp command.
1290 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
1294 * When req == RTM_RESOLVE, rt is created and
1295 * initialized in rtrequest(), so rt_expire is 0.
1297 ln
->ln_state
= ND6_LLINFO_NOSTATE
;
1298 ln
->ln_expire
= timenow
.tv_sec
;
1300 rt
->rt_flags
|= RTF_LLINFO
;
1301 ln
->ln_next
= llinfo_nd6
.ln_next
;
1302 llinfo_nd6
.ln_next
= ln
;
1303 ln
->ln_prev
= &llinfo_nd6
;
1304 ln
->ln_next
->ln_prev
= ln
;
1307 * check if rt_key(rt) is one of my address assigned
1310 ifa
= (struct ifaddr
*)in6ifa_ifpwithaddr(rt
->rt_ifp
,
1311 &SIN6(rt_key(rt
))->sin6_addr
);
1313 caddr_t macp
= nd6_ifptomac(ifp
);
1315 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
1318 Bcopy(macp
, LLADDR(SDL(gate
)), ifp
->if_addrlen
);
1319 SDL(gate
)->sdl_alen
= ifp
->if_addrlen
;
1321 if (nd6_useloopback
) {
1322 rt
->rt_ifp
= lo_ifp
; /* XXX */
1324 * Make sure rt_ifa be equal to the ifaddr
1325 * corresponding to the address.
1326 * We need this because when we refer
1327 * rt_ifa->ia6_flags in ip6_input, we assume
1328 * that the rt_ifa points to the address instead
1329 * of the loopback address.
1331 if (ifa
!= rt
->rt_ifa
) {
1335 } else if (rt
->rt_flags
& RTF_ANNOUNCE
) {
1337 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
1340 /* join solicited node multicast for proxy ND */
1341 if (ifp
->if_flags
& IFF_MULTICAST
) {
1342 struct in6_addr llsol
;
1345 llsol
= SIN6(rt_key(rt
))->sin6_addr
;
1346 llsol
.s6_addr16
[0] = htons(0xff02);
1347 llsol
.s6_addr16
[1] = htons(ifp
->if_index
);
1348 llsol
.s6_addr32
[1] = 0;
1349 llsol
.s6_addr32
[2] = htonl(1);
1350 llsol
.s6_addr8
[12] = 0xff;
1352 if (!in6_addmulti(&llsol
, ifp
, &error
, 0)) {
1353 nd6log((LOG_ERR
, "%s: failed to join "
1354 "%s (errno=%d)\n", if_name(ifp
),
1355 ip6_sprintf(&llsol
), error
));
1364 /* leave from solicited node multicast for proxy ND */
1365 if ((rt
->rt_flags
& RTF_ANNOUNCE
) != 0 &&
1366 (ifp
->if_flags
& IFF_MULTICAST
) != 0) {
1367 struct in6_addr llsol
;
1368 struct in6_multi
*in6m
;
1370 llsol
= SIN6(rt_key(rt
))->sin6_addr
;
1371 llsol
.s6_addr16
[0] = htons(0xff02);
1372 llsol
.s6_addr16
[1] = htons(ifp
->if_index
);
1373 llsol
.s6_addr32
[1] = 0;
1374 llsol
.s6_addr32
[2] = htonl(1);
1375 llsol
.s6_addr8
[12] = 0xff;
1377 ifnet_lock_shared(ifp
);
1378 IN6_LOOKUP_MULTI(llsol
, ifp
, in6m
);
1379 ifnet_lock_done(ifp
);
1381 in6_delmulti(in6m
, 0);
1384 ln
->ln_next
->ln_prev
= ln
->ln_prev
;
1385 ln
->ln_prev
->ln_next
= ln
->ln_next
;
1388 rt
->rt_flags
&= ~RTF_LLINFO
;
1390 m_freem(ln
->ln_hold
);
1392 R_Free((caddr_t
)ln
);
1402 struct in6_drlist
*drl
= (struct in6_drlist
*)data
;
1403 struct in6_prlist
*prl
= (struct in6_prlist
*)data
;
1404 struct in6_ndireq
*ndi
= (struct in6_ndireq
*)data
;
1405 struct in6_nbrinfo
*nbi
= (struct in6_nbrinfo
*)data
;
1406 struct in6_ndifreq
*ndif
= (struct in6_ndifreq
*)data
;
1407 struct nd_defrouter
*dr
, any
;
1408 struct nd_prefix
*pr
;
1410 int i
= 0, error
= 0;
1413 case SIOCGDRLST_IN6
:
1415 * obsolete API, use sysctl under net.inet6.icmp6
1417 lck_mtx_lock(nd6_mutex
);
1418 bzero(drl
, sizeof(*drl
));
1419 dr
= TAILQ_FIRST(&nd_defrouter
);
1420 while (dr
&& i
< DRLSTSIZ
) {
1421 drl
->defrouter
[i
].rtaddr
= dr
->rtaddr
;
1422 if (IN6_IS_ADDR_LINKLOCAL(&drl
->defrouter
[i
].rtaddr
)) {
1423 /* XXX: need to this hack for KAME stack */
1424 drl
->defrouter
[i
].rtaddr
.s6_addr16
[1] = 0;
1427 "default router list contains a "
1428 "non-linklocal address(%s)\n",
1429 ip6_sprintf(&drl
->defrouter
[i
].rtaddr
));
1431 drl
->defrouter
[i
].flags
= dr
->flags
;
1432 drl
->defrouter
[i
].rtlifetime
= dr
->rtlifetime
;
1433 drl
->defrouter
[i
].expire
= dr
->expire
;
1434 drl
->defrouter
[i
].if_index
= dr
->ifp
->if_index
;
1436 dr
= TAILQ_NEXT(dr
, dr_entry
);
1438 lck_mtx_unlock(nd6_mutex
);
1440 case SIOCGPRLST_IN6
:
1442 * obsolete API, use sysctl under net.inet6.icmp6
1445 * XXX meaning of fields, especialy "raflags", is very
1446 * differnet between RA prefix list and RR/static prefix list.
1447 * how about separating ioctls into two?
1449 bzero(prl
, sizeof(*prl
));
1450 lck_mtx_lock(nd6_mutex
);
1451 pr
= nd_prefix
.lh_first
;
1452 while (pr
&& i
< PRLSTSIZ
) {
1453 struct nd_pfxrouter
*pfr
;
1456 (void)in6_embedscope(&prl
->prefix
[i
].prefix
,
1457 &pr
->ndpr_prefix
, NULL
, NULL
);
1458 prl
->prefix
[i
].raflags
= pr
->ndpr_raf
;
1459 prl
->prefix
[i
].prefixlen
= pr
->ndpr_plen
;
1460 prl
->prefix
[i
].vltime
= pr
->ndpr_vltime
;
1461 prl
->prefix
[i
].pltime
= pr
->ndpr_pltime
;
1462 prl
->prefix
[i
].if_index
= pr
->ndpr_ifp
->if_index
;
1463 prl
->prefix
[i
].expire
= pr
->ndpr_expire
;
1465 pfr
= pr
->ndpr_advrtrs
.lh_first
;
1469 #define RTRADDR prl->prefix[i].advrtr[j]
1470 RTRADDR
= pfr
->router
->rtaddr
;
1471 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR
)) {
1472 /* XXX: hack for KAME */
1473 RTRADDR
.s6_addr16
[1] = 0;
1476 "a router(%s) advertises "
1478 "non-link local address\n",
1479 ip6_sprintf(&RTRADDR
));
1483 pfr
= pfr
->pfr_next
;
1485 prl
->prefix
[i
].advrtrs
= j
;
1486 prl
->prefix
[i
].origin
= PR_ORIG_RA
;
1492 struct rr_prefix
*rpp
;
1494 for (rpp
= LIST_FIRST(&rr_prefix
); rpp
;
1495 rpp
= LIST_NEXT(rpp
, rp_entry
)) {
1498 (void)in6_embedscope(&prl
->prefix
[i
].prefix
,
1499 &pr
->ndpr_prefix
, NULL
, NULL
);
1500 prl
->prefix
[i
].raflags
= rpp
->rp_raf
;
1501 prl
->prefix
[i
].prefixlen
= rpp
->rp_plen
;
1502 prl
->prefix
[i
].vltime
= rpp
->rp_vltime
;
1503 prl
->prefix
[i
].pltime
= rpp
->rp_pltime
;
1504 prl
->prefix
[i
].if_index
= rpp
->rp_ifp
->if_index
;
1505 prl
->prefix
[i
].expire
= rpp
->rp_expire
;
1506 prl
->prefix
[i
].advrtrs
= 0;
1507 prl
->prefix
[i
].origin
= rpp
->rp_origin
;
1511 lck_mtx_unlock(nd6_mutex
);
1513 case OSIOCGIFINFO_IN6
:
1514 if (!nd_ifinfo
|| i
>= nd_ifinfo_indexlim
) {
1518 ndi
->ndi
.linkmtu
= IN6_LINKMTU(ifp
);
1519 ndi
->ndi
.maxmtu
= nd_ifinfo
[ifp
->if_index
].maxmtu
;
1520 ndi
->ndi
.basereachable
=
1521 nd_ifinfo
[ifp
->if_index
].basereachable
;
1522 ndi
->ndi
.reachable
= nd_ifinfo
[ifp
->if_index
].reachable
;
1523 ndi
->ndi
.retrans
= nd_ifinfo
[ifp
->if_index
].retrans
;
1524 ndi
->ndi
.flags
= nd_ifinfo
[ifp
->if_index
].flags
;
1525 ndi
->ndi
.recalctm
= nd_ifinfo
[ifp
->if_index
].recalctm
;
1526 ndi
->ndi
.chlim
= nd_ifinfo
[ifp
->if_index
].chlim
;
1527 ndi
->ndi
.receivedra
= nd_ifinfo
[ifp
->if_index
].receivedra
;
1529 case SIOCGIFINFO_IN6
:
1530 if (!nd_ifinfo
|| i
>= nd_ifinfo_indexlim
) {
1534 ndi
->ndi
= nd_ifinfo
[ifp
->if_index
];
1536 case SIOCSIFINFO_FLAGS
:
1537 /* XXX: almost all other fields of ndi->ndi is unused */
1538 if (!nd_ifinfo
|| i
>= nd_ifinfo_indexlim
) {
1542 nd_ifinfo
[ifp
->if_index
].flags
= ndi
->ndi
.flags
;
1544 case SIOCSNDFLUSH_IN6
: /* XXX: the ioctl name is confusing... */
1545 /* flush default router list */
1547 * xxx sumikawa: should not delete route if default
1548 * route equals to the top of default router list
1550 bzero(&any
, sizeof(any
));
1551 lck_mtx_lock(nd6_mutex
);
1552 defrouter_delreq(&any
, 1);
1554 lck_mtx_unlock(nd6_mutex
);
1555 /* xxx sumikawa: flush prefix list */
1557 case SIOCSPFXFLUSH_IN6
:
1559 /* flush all the prefix advertised by routers */
1560 struct nd_prefix
*next
;
1561 lck_mtx_lock(nd6_mutex
);
1563 for (pr
= nd_prefix
.lh_first
; pr
; pr
= next
) {
1564 struct in6_ifaddr
*ia
, *ia_next
;
1566 next
= pr
->ndpr_next
;
1568 if (IN6_IS_ADDR_LINKLOCAL(&pr
->ndpr_prefix
.sin6_addr
))
1571 /* do we really have to remove addresses as well? */
1572 for (ia
= in6_ifaddrs
; ia
; ia
= ia_next
) {
1573 /* ia might be removed. keep the next ptr. */
1574 ia_next
= ia
->ia_next
;
1576 if ((ia
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
1579 if (ia
->ia6_ndpr
== pr
)
1580 in6_purgeaddr(&ia
->ia_ifa
, 1);
1582 prelist_remove(pr
, 1);
1584 lck_mtx_unlock(nd6_mutex
);
1587 case SIOCSRTRFLUSH_IN6
:
1589 /* flush all the default routers */
1590 struct nd_defrouter
*next
;
1592 lck_mtx_lock(nd6_mutex
);
1593 if ((dr
= TAILQ_FIRST(&nd_defrouter
)) != NULL
) {
1595 * The first entry of the list may be stored in
1596 * the routing table, so we'll delete it later.
1598 for (dr
= TAILQ_NEXT(dr
, dr_entry
); dr
; dr
= next
) {
1599 next
= TAILQ_NEXT(dr
, dr_entry
);
1600 defrtrlist_del(dr
, 1);
1602 defrtrlist_del(TAILQ_FIRST(&nd_defrouter
), 1);
1604 lck_mtx_unlock(nd6_mutex
);
1607 case SIOCGNBRINFO_IN6
:
1609 struct llinfo_nd6
*ln
;
1610 struct in6_addr nb_addr
= nbi
->addr
; /* make local for safety */
1613 * XXX: KAME specific hack for scoped addresses
1614 * XXXX: for other scopes than link-local?
1616 if (IN6_IS_ADDR_LINKLOCAL(&nbi
->addr
) ||
1617 IN6_IS_ADDR_MC_LINKLOCAL(&nbi
->addr
)) {
1618 u_int16_t
*idp
= (u_int16_t
*)&nb_addr
.s6_addr
[2];
1621 *idp
= htons(ifp
->if_index
);
1624 if ((rt
= nd6_lookup(&nb_addr
, 0, ifp
, 0)) == NULL
) {
1628 ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
1629 nbi
->state
= ln
->ln_state
;
1630 nbi
->asked
= ln
->ln_asked
;
1631 nbi
->isrouter
= ln
->ln_router
;
1632 nbi
->expire
= ln
->ln_expire
;
1636 case SIOCGDEFIFACE_IN6
: /* XXX: should be implemented as a sysctl? */
1637 ndif
->ifindex
= nd6_defifindex
;
1639 case SIOCSDEFIFACE_IN6
: /* XXX: should be implemented as a sysctl? */
1640 return(nd6_setdefaultiface(ndif
->ifindex
));
1647 * Create neighbor cache entry and cache link-layer address,
1648 * on reception of inbound ND6 packets. (RS/RA/NS/redirect)
1653 struct in6_addr
*from
,
1655 __unused
int lladdrlen
,
1656 int type
, /* ICMP6 type */
1657 int code
) /* type dependent information */
1659 struct rtentry
*rt
= NULL
;
1660 struct llinfo_nd6
*ln
= NULL
;
1662 struct sockaddr_dl
*sdl
= NULL
;
1667 struct timeval timenow
;
1670 panic("ifp == NULL in nd6_cache_lladdr");
1672 panic("from == NULL in nd6_cache_lladdr");
1674 /* nothing must be updated for unspecified address */
1675 if (IN6_IS_ADDR_UNSPECIFIED(from
))
1679 * Validation about ifp->if_addrlen and lladdrlen must be done in
1682 * XXX If the link does not have link-layer adderss, what should
1683 * we do? (ifp->if_addrlen == 0)
1684 * Spec says nothing in sections for RA, RS and NA. There's small
1685 * description on it in NS section (RFC 2461 7.2.3).
1687 getmicrotime(&timenow
);
1689 lck_mtx_lock(rt_mtx
);
1690 rt
= nd6_lookup(from
, 0, ifp
, 1);
1693 /* nothing must be done if there's no lladdr */
1694 if (!lladdr
|| !lladdrlen
)
1698 rt
= nd6_lookup(from
, 1, ifp
, 1);
1701 /* do nothing if static ndp is set */
1702 if (rt
->rt_flags
& RTF_STATIC
) {
1703 lck_mtx_unlock(rt_mtx
);
1709 lck_mtx_unlock(rt_mtx
);
1713 if ((rt
->rt_flags
& (RTF_GATEWAY
| RTF_LLINFO
)) != RTF_LLINFO
) {
1718 ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
1721 if (!rt
->rt_gateway
)
1723 if (rt
->rt_gateway
->sa_family
!= AF_LINK
)
1725 sdl
= SDL(rt
->rt_gateway
);
1727 olladdr
= (sdl
->sdl_alen
) ? 1 : 0;
1728 if (olladdr
&& lladdr
) {
1729 if (bcmp(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
))
1737 * newentry olladdr lladdr llchange (*=record)
1740 * 0 n y -- (3) * STALE
1742 * 0 y y y (5) * STALE
1743 * 1 -- n -- (6) NOSTATE(= PASSIVE)
1744 * 1 -- y -- (7) * STALE
1747 if (lladdr
) { /* (3-5) and (7) */
1749 * Record source link-layer address
1750 * XXX is it dependent to ifp->if_type?
1752 sdl
->sdl_alen
= ifp
->if_addrlen
;
1753 bcopy(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
);
1757 if ((!olladdr
&& lladdr
) /* (3) */
1758 || (olladdr
&& lladdr
&& llchange
)) { /* (5) */
1760 newstate
= ND6_LLINFO_STALE
;
1761 } else /* (1-2,4) */
1765 if (!lladdr
) /* (6) */
1766 newstate
= ND6_LLINFO_NOSTATE
;
1768 newstate
= ND6_LLINFO_STALE
;
1773 * Update the state of the neighbor cache.
1775 ln
->ln_state
= newstate
;
1777 if (ln
->ln_state
== ND6_LLINFO_STALE
) {
1779 * XXX: since nd6_output() below will cause
1780 * state tansition to DELAY and reset the timer,
1781 * we must set the timer now, although it is actually
1784 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
1788 * we assume ifp is not a p2p here, so just
1789 * set the 2nd argument as the 1st one.
1791 nd6_output(ifp
, ifp
, ln
->ln_hold
,
1792 (struct sockaddr_in6
*)rt_key(rt
),
1796 } else if (ln
->ln_state
== ND6_LLINFO_INCOMPLETE
) {
1797 /* probe right away */
1798 ln
->ln_expire
= timenow
.tv_sec
;
1803 * ICMP6 type dependent behavior.
1805 * NS: clear IsRouter if new entry
1806 * RS: clear IsRouter
1807 * RA: set IsRouter if there's lladdr
1808 * redir: clear IsRouter if new entry
1811 * The spec says that we must set IsRouter in the following cases:
1812 * - If lladdr exist, set IsRouter. This means (1-5).
1813 * - If it is old entry (!newentry), set IsRouter. This means (7).
1814 * So, based on the spec, in (1-5) and (7) cases we must set IsRouter.
1815 * A quetion arises for (1) case. (1) case has no lladdr in the
1816 * neighbor cache, this is similar to (6).
1817 * This case is rare but we figured that we MUST NOT set IsRouter.
1819 * newentry olladdr lladdr llchange NS RS RA redir
1821 * 0 n n -- (1) c ? s
1822 * 0 y n -- (2) c s s
1823 * 0 n y -- (3) c s s
1826 * 1 -- n -- (6) c c c s
1827 * 1 -- y -- (7) c c s c s
1831 switch (type
& 0xff) {
1832 case ND_NEIGHBOR_SOLICIT
:
1834 * New entry must have is_router flag cleared.
1836 if (is_newentry
) /* (6-7) */
1841 * If the icmp is a redirect to a better router, always set the
1842 * is_router flag. Otherwise, if the entry is newly created,
1843 * clear the flag. [RFC 2461, sec 8.3]
1845 if (code
== ND_REDIRECT_ROUTER
)
1847 else if (is_newentry
) /* (6-7) */
1850 case ND_ROUTER_SOLICIT
:
1852 * is_router flag must always be cleared.
1856 case ND_ROUTER_ADVERT
:
1858 * Mark an entry with lladdr as a router.
1860 if ((!is_newentry
&& (olladdr
|| lladdr
)) /* (2-5) */
1861 || (is_newentry
&& lladdr
)) { /* (7) */
1868 * When the link-layer address of a router changes, select the
1869 * best router again. In particular, when the neighbor entry is newly
1870 * created, it might affect the selection policy.
1871 * Question: can we restrict the first condition to the "is_newentry"
1873 * XXX: when we hear an RA from a new router with the link-layer
1874 * address option, defrouter_select() is called twice, since
1875 * defrtrlist_update called the function as well. However, I believe
1876 * we can compromise the overhead, since it only happens the first
1878 * XXX: although defrouter_select() should not have a bad effect
1879 * for those are not autoconfigured hosts, we explicitly avoid such
1882 if (do_update
&& ln
->ln_router
&& !ip6_forwarding
&& (ip6_accept_rtadv
|| (ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
1883 lck_mtx_lock(nd6_mutex
);
1885 lck_mtx_unlock(nd6_mutex
);
1893 __unused
void *ignored_arg
)
1896 struct nd_ifinfo
*nd6if
;
1898 lck_mtx_lock(nd6_mutex
);
1899 for (i
= 1; i
< if_index
+ 1; i
++) {
1900 if (!nd_ifinfo
|| i
>= nd_ifinfo_indexlim
)
1902 nd6if
= &nd_ifinfo
[i
];
1903 if (nd6if
->basereachable
&& /* already initialized */
1904 (nd6if
->recalctm
-= ND6_SLOWTIMER_INTERVAL
) <= 0) {
1906 * Since reachable time rarely changes by router
1907 * advertisements, we SHOULD insure that a new random
1908 * value gets recomputed at least once every few hours.
1911 nd6if
->recalctm
= nd6_recalc_reachtm_interval
;
1912 nd6if
->reachable
= ND_COMPUTE_RTIME(nd6if
->basereachable
);
1915 lck_mtx_unlock(nd6_mutex
);
1916 timeout(nd6_slowtimo
, (caddr_t
)0, ND6_SLOWTIMER_INTERVAL
* hz
);
1920 #define senderr(e) { error = (e); goto bad;}
1924 struct ifnet
*origifp
,
1926 struct sockaddr_in6
*dst
,
1927 struct rtentry
*rt0
,
1930 struct mbuf
*m
= m0
;
1931 struct rtentry
*rt
= rt0
;
1932 struct sockaddr_in6
*gw6
= NULL
;
1933 struct llinfo_nd6
*ln
= NULL
;
1935 struct timeval timenow
;
1937 if (IN6_IS_ADDR_MULTICAST(&dst
->sin6_addr
))
1940 if (nd6_need_cache(ifp
) == 0)
1944 * next hop determination. This routine is derived from ether_outpout.
1946 lck_mtx_lock(rt_mtx
);
1948 if ((rt
->rt_flags
& RTF_UP
) == 0) {
1949 if ((rt0
= rt
= rtalloc1_locked((struct sockaddr
*)dst
, 1, 0UL)) !=
1953 if (rt
->rt_ifp
!= ifp
) {
1954 /* XXX: loop care? */
1955 lck_mtx_unlock(rt_mtx
);
1956 return nd6_output(ifp
, origifp
, m0
,
1960 lck_mtx_unlock(rt_mtx
);
1961 senderr(EHOSTUNREACH
);
1965 if (rt
->rt_flags
& RTF_GATEWAY
) {
1966 gw6
= (struct sockaddr_in6
*)rt
->rt_gateway
;
1969 * We skip link-layer address resolution and NUD
1970 * if the gateway is not a neighbor from ND point
1971 * of view, regardless of the value of nd_ifinfo.flags.
1972 * The second condition is a bit tricky; we skip
1973 * if the gateway is our own address, which is
1974 * sometimes used to install a route to a p2p link.
1976 if (!nd6_is_addr_neighbor(gw6
, ifp
, 1) ||
1977 in6ifa_ifpwithaddr(ifp
, &gw6
->sin6_addr
)) {
1979 * We allow this kind of tricky route only
1980 * when the outgoing interface is p2p.
1981 * XXX: we may need a more generic rule here.
1983 lck_mtx_unlock(rt_mtx
);
1984 if ((ifp
->if_flags
& IFF_POINTOPOINT
) == 0)
1985 senderr(EHOSTUNREACH
);
1990 if (rt
->rt_gwroute
== 0)
1992 if (((rt
= rt
->rt_gwroute
)->rt_flags
& RTF_UP
) == 0) {
1993 rtfree_locked(rt
); rt
= rt0
;
1994 lookup
: rt
->rt_gwroute
= rtalloc1_locked(rt
->rt_gateway
, 1, 0UL);
1995 if ((rt
= rt
->rt_gwroute
) == 0) {
1996 lck_mtx_unlock(rt_mtx
);
1997 senderr(EHOSTUNREACH
);
2004 * Address resolution or Neighbor Unreachability Detection
2006 * At this point, the destination of the packet must be a unicast
2007 * or an anycast address(i.e. not a multicast).
2010 /* Look up the neighbor cache for the nexthop */
2011 if (rt
&& (rt
->rt_flags
& RTF_LLINFO
) != 0)
2012 ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
2015 * Since nd6_is_addr_neighbor() internally calls nd6_lookup(),
2016 * the condition below is not very efficient. But we believe
2017 * it is tolerable, because this should be a rare case.
2019 if (nd6_is_addr_neighbor(dst
, ifp
, 1) &&
2020 (rt
= nd6_lookup(&dst
->sin6_addr
, 1, ifp
, 1)) != NULL
)
2021 ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
;
2023 lck_mtx_unlock(rt_mtx
);
2025 if ((ifp
->if_flags
& IFF_POINTOPOINT
) == 0 &&
2026 !(nd_ifinfo
[ifp
->if_index
].flags
& ND6_IFF_PERFORMNUD
)) {
2028 "nd6_output: can't allocate llinfo for %s "
2030 ip6_sprintf(&dst
->sin6_addr
), ln
, rt
);
2031 senderr(EIO
); /* XXX: good error? */
2034 goto sendpkt
; /* send anyway */
2037 getmicrotime(&timenow
);
2039 /* We don't have to do link-layer address resolution on a p2p link. */
2040 if ((ifp
->if_flags
& IFF_POINTOPOINT
) != 0 &&
2041 ln
->ln_state
< ND6_LLINFO_REACHABLE
) {
2042 ln
->ln_state
= ND6_LLINFO_STALE
;
2043 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
2047 * The first time we send a packet to a neighbor whose entry is
2048 * STALE, we have to change the state to DELAY and a sets a timer to
2049 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
2050 * neighbor unreachability detection on expiration.
2053 if (ln
->ln_state
== ND6_LLINFO_STALE
) {
2055 ln
->ln_state
= ND6_LLINFO_DELAY
;
2056 ln
->ln_expire
= timenow
.tv_sec
+ nd6_delay
;
2060 * If the neighbor cache entry has a state other than INCOMPLETE
2061 * (i.e. its link-layer address is already resolved), just
2064 if (ln
->ln_state
> ND6_LLINFO_INCOMPLETE
)
2068 * There is a neighbor cache entry, but no ethernet address
2069 * response yet. Replace the held mbuf (if any) with this
2072 * This code conforms to the rate-limiting rule described in Section
2073 * 7.2.2 of RFC 2461, because the timer is set correctly after sending
2076 if (ln
->ln_state
== ND6_LLINFO_NOSTATE
)
2077 ln
->ln_state
= ND6_LLINFO_INCOMPLETE
;
2079 m_freem(ln
->ln_hold
);
2081 if (ln
->ln_expire
) {
2082 if (ln
->ln_asked
< nd6_mmaxtries
&&
2083 ln
->ln_expire
< timenow
.tv_sec
) {
2085 ln
->ln_expire
= timenow
.tv_sec
+
2086 nd_ifinfo
[ifp
->if_index
].retrans
/ 1000;
2087 nd6_ns_output(ifp
, NULL
, &dst
->sin6_addr
, ln
, 0, locked
);
2095 /* Make sure the HW checksum flags are cleaned before sending the packet */
2097 m
->m_pkthdr
.csum_data
= 0;
2098 m
->m_pkthdr
.csum_flags
= 0;
2100 if ((ifp
->if_flags
& IFF_LOOPBACK
) != 0) {
2101 m
->m_pkthdr
.rcvif
= origifp
; /* forwarding rules require the original scope_id */
2103 lck_mtx_unlock(ip6_mutex
);
2104 error
= dlil_output(origifp
, PF_INET6
, m
, (caddr_t
)rt
, (struct sockaddr
*)dst
, 0);
2106 lck_mtx_lock(ip6_mutex
);
2109 /* Do not allow loopback address to wind up on a wire */
2110 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
2112 if ((IN6_IS_ADDR_LOOPBACK(&ip6
->ip6_src
) ||
2113 IN6_IS_ADDR_LOOPBACK(&ip6
->ip6_dst
))) {
2114 ip6stat
.ip6s_badscope
++;
2116 * Do not simply drop the packet just like a firewall -- we want the
2117 * the application to feel the pain.
2118 * Return ENETUNREACH like ip6_output does in some similar cases.
2119 * This can startle the otherwise clueless process that specifies
2120 * loopback as the source address.
2122 error
= ENETUNREACH
;
2127 m
->m_pkthdr
.rcvif
= 0;
2129 lck_mtx_unlock(ip6_mutex
);
2130 error
= dlil_output(ifp
, PF_INET6
, m
, (caddr_t
)rt
, (struct sockaddr
*)dst
, 0);
2132 lck_mtx_lock(ip6_mutex
);
2135 if ((ifp
->if_flags
& IFF_LOOPBACK
) != 0) {
2136 return((*ifp
->if_output
)(origifp
, m
, (struct sockaddr
*)dst
,
2139 return((*ifp
->if_output
)(ifp
, m
, (struct sockaddr
*)dst
, rt
));
2154 * XXX: we currently do not make neighbor cache on any interface
2155 * other than ARCnet, Ethernet, FDDI and GIF.
2158 * - unidirectional tunnels needs no ND
2160 switch (ifp
->if_type
) {
2166 case IFT_IEEE8023ADLAG
:
2170 case IFT_GIF
: /* XXX need more cases? */
2182 struct sockaddr
*dst
,
2186 struct sockaddr_dl
*sdl
;
2188 if (m
->m_flags
& M_MCAST
) {
2189 switch (ifp
->if_type
) {
2193 case IFT_IEEE8023ADLAG
:
2197 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst
)->sin6_addr
,
2201 for (i
= 0; i
< ifp
->if_addrlen
; i
++)
2208 return(0); /* caller will free mbuf */
2213 /* this could happen, if we could not allocate memory */
2214 return(0); /* caller will free mbuf */
2216 if (rt
->rt_gateway
->sa_family
!= AF_LINK
) {
2217 printf("nd6_storelladdr: something odd happens\n");
2218 return(0); /* caller will free mbuf */
2220 sdl
= SDL(rt
->rt_gateway
);
2221 if (sdl
->sdl_alen
== 0) {
2222 /* this should be impossible, but we bark here for debugging */
2223 printf("nd6_storelladdr: sdl_alen == 0\n");
2224 return(0); /* caller will free mbuf */
2227 bcopy(LLADDR(sdl
), desten
, sdl
->sdl_alen
);
2231 extern errno_t
arp_route_to_gateway_route(const struct sockaddr
*net_dest
,
2232 route_t hint
, route_t
*out_route
);
2237 const struct sockaddr_in6
*ip6_dest
,
2238 struct sockaddr_dl
*ll_dest
,
2243 route_t route
= hint
;
2245 struct sockaddr_dl
*sdl
= NULL
;
2248 if (ip6_dest
->sin6_family
!= AF_INET6
)
2249 return EAFNOSUPPORT
;
2251 if ((ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) != (IFF_UP
|IFF_RUNNING
))
2255 result
= arp_route_to_gateway_route((const struct sockaddr
*)ip6_dest
, hint
, &route
);
2260 if ((packet
->m_flags
& M_MCAST
) != 0) {
2261 return dlil_resolve_multi(ifp
, (const struct sockaddr
*)ip6_dest
,
2262 (struct sockaddr
*)ll_dest
, ll_dest_len
);
2265 if (route
== NULL
) {
2266 /* this could happen, if we could not allocate memory */
2270 lck_mtx_lock(rt_mtx
);
2272 if (route
->rt_gateway
->sa_family
!= AF_LINK
) {
2273 printf("nd6_lookup_ipv6: gateway address not AF_LINK\n");
2274 result
= EADDRNOTAVAIL
;
2278 sdl
= SDL(route
->rt_gateway
);
2279 if (sdl
->sdl_alen
== 0) {
2280 /* this should be impossible, but we bark here for debugging */
2281 printf("nd6_storelladdr: sdl_alen == 0\n");
2282 result
= EHOSTUNREACH
;
2285 copy_len
= sdl
->sdl_len
<= ll_dest_len
? sdl
->sdl_len
: ll_dest_len
;
2286 bcopy(sdl
, ll_dest
, copy_len
);
2289 lck_mtx_unlock(rt_mtx
);
2293 SYSCTL_DECL(_net_inet6_icmp6
);
2296 nd6_sysctl_drlist SYSCTL_HANDLER_ARGS
2298 #pragma unused(oidp, arg1, arg2)
2301 struct in6_defrouter
*d
, *de
;
2302 struct nd_defrouter
*dr
;
2308 lck_mtx_lock(nd6_mutex
);
2309 for (dr
= TAILQ_FIRST(&nd_defrouter
);
2311 dr
= TAILQ_NEXT(dr
, dr_entry
)) {
2312 d
= (struct in6_defrouter
*)buf
;
2313 de
= (struct in6_defrouter
*)(buf
+ sizeof(buf
));
2316 bzero(d
, sizeof(*d
));
2317 d
->rtaddr
.sin6_family
= AF_INET6
;
2318 d
->rtaddr
.sin6_len
= sizeof(d
->rtaddr
);
2319 if (in6_recoverscope(&d
->rtaddr
, &dr
->rtaddr
,
2323 "default router list (%s)\n",
2324 ip6_sprintf(&dr
->rtaddr
));
2325 d
->flags
= dr
->flags
;
2326 d
->rtlifetime
= dr
->rtlifetime
;
2327 d
->expire
= dr
->expire
;
2328 d
->if_index
= dr
->ifp
->if_index
;
2330 panic("buffer too short");
2332 error
= SYSCTL_OUT(req
, buf
, sizeof(*d
));
2336 lck_mtx_unlock(nd6_mutex
);
2341 nd6_sysctl_prlist SYSCTL_HANDLER_ARGS
2343 #pragma unused(oidp, arg1, arg2)
2346 struct in6_prefix
*p
, *pe
;
2347 struct nd_prefix
*pr
;
2353 lck_mtx_lock(nd6_mutex
);
2355 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
2356 u_short advrtrs
= 0;
2358 struct sockaddr_in6
*sin6
, *s6
;
2359 struct nd_pfxrouter
*pfr
;
2361 p
= (struct in6_prefix
*)buf
;
2362 pe
= (struct in6_prefix
*)(buf
+ sizeof(buf
));
2365 bzero(p
, sizeof(*p
));
2366 sin6
= (struct sockaddr_in6
*)(p
+ 1);
2368 p
->prefix
= pr
->ndpr_prefix
;
2369 if (in6_recoverscope(&p
->prefix
,
2370 &p
->prefix
.sin6_addr
, pr
->ndpr_ifp
) != 0)
2372 "scope error in prefix list (%s)\n",
2373 ip6_sprintf(&p
->prefix
.sin6_addr
));
2374 p
->raflags
= pr
->ndpr_raf
;
2375 p
->prefixlen
= pr
->ndpr_plen
;
2376 p
->vltime
= pr
->ndpr_vltime
;
2377 p
->pltime
= pr
->ndpr_pltime
;
2378 p
->if_index
= pr
->ndpr_ifp
->if_index
;
2379 p
->expire
= pr
->ndpr_expire
;
2380 p
->refcnt
= pr
->ndpr_refcnt
;
2381 p
->flags
= pr
->ndpr_stateflags
;
2382 p
->origin
= PR_ORIG_RA
;
2384 for (pfr
= pr
->ndpr_advrtrs
.lh_first
;
2386 pfr
= pfr
->pfr_next
) {
2387 if ((void *)&sin6
[advrtrs
+ 1] >
2392 s6
= &sin6
[advrtrs
];
2393 bzero(s6
, sizeof(*s6
));
2394 s6
->sin6_family
= AF_INET6
;
2395 s6
->sin6_len
= sizeof(*sin6
);
2396 if (in6_recoverscope(s6
,
2397 &pfr
->router
->rtaddr
,
2398 pfr
->router
->ifp
) != 0)
2401 "prefix list (%s)\n",
2402 ip6_sprintf(&pfr
->router
->rtaddr
));
2405 p
->advrtrs
= advrtrs
;
2407 panic("buffer too short");
2409 advance
= sizeof(*p
) + sizeof(*sin6
) * advrtrs
;
2410 error
= SYSCTL_OUT(req
, buf
, advance
);
2414 lck_mtx_unlock(nd6_mutex
);
2417 SYSCTL_PROC(_net_inet6_icmp6
, ICMPV6CTL_ND6_DRLIST
, nd6_drlist
,
2418 CTLFLAG_RD
, 0, 0, nd6_sysctl_drlist
, "S,in6_defrouter","");
2419 SYSCTL_PROC(_net_inet6_icmp6
, ICMPV6CTL_ND6_PRLIST
, nd6_prlist
,
2420 CTLFLAG_RD
, 0, 0, nd6_sysctl_prlist
, "S,in6_defrouter","");