2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 /* $FreeBSD: src/sys/netinet6/nd6_rtr.c,v 1.11 2002/04/19 04:46:23 suz Exp $ */
30 /* $KAME: nd6_rtr.c,v 1.111 2001/04/27 01:37:15 jinmei Exp $ */
33 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the project nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/malloc.h>
66 #include <sys/socket.h>
67 #include <sys/sockio.h>
69 #include <sys/kernel.h>
70 #include <sys/errno.h>
71 #include <sys/syslog.h>
72 #include <sys/queue.h>
73 #include <kern/lock.h>
76 #include <net/if_types.h>
77 #include <net/if_dl.h>
78 #include <net/route.h>
79 #include <net/radix.h>
81 #include <netinet/in.h>
82 #include <netinet6/in6_var.h>
83 #include <netinet6/in6_ifattach.h>
84 #include <netinet/ip6.h>
85 #include <netinet6/ip6_var.h>
86 #include <netinet6/nd6.h>
87 #include <netinet/icmp6.h>
88 #include <netinet6/scope6_var.h>
90 #include <net/net_osdep.h>
92 #define SDL(s) ((struct sockaddr_dl *)s)
94 static struct nd_defrouter
*defrtrlist_update(struct nd_defrouter
*);
95 static struct in6_ifaddr
*in6_ifadd(struct nd_prefix
*,
97 static struct nd_pfxrouter
*pfxrtr_lookup(struct nd_prefix
*,
98 struct nd_defrouter
*);
99 static void pfxrtr_add(struct nd_prefix
*, struct nd_defrouter
*);
100 static void pfxrtr_del(struct nd_pfxrouter
*);
101 static struct nd_pfxrouter
*find_pfxlist_reachable_router(struct nd_prefix
*);
102 static void defrouter_addifreq(struct ifnet
*);
103 static void nd6_rtmsg(int, struct rtentry
*);
105 static void in6_init_address_ltimes(struct nd_prefix
*ndpr
,
106 struct in6_addrlifetime
*lt6
);
108 static int rt6_deleteroute(struct radix_node
*, void *);
110 extern int nd6_recalc_reachtm_interval
;
112 static struct ifnet
*nd6_defifp
;
115 int ip6_use_tempaddr
= 0;
117 int ip6_desync_factor
;
118 u_int32_t ip6_temp_preferred_lifetime
= DEF_TEMP_PREFERRED_LIFETIME
;
119 u_int32_t ip6_temp_valid_lifetime
= DEF_TEMP_VALID_LIFETIME
;
121 * shorter lifetimes for debugging purposes.
122 int ip6_temp_preferred_lifetime = 800;
123 static int ip6_temp_valid_lifetime = 1800;
125 int ip6_temp_regen_advance
= TEMPADDR_REGEN_ADVANCE
;
127 extern lck_mtx_t
*rt_mtx
;
128 extern lck_mtx_t
*nd6_mutex
;
131 * Receive Router Solicitation Message - just for routers.
132 * Router solicitation/advertisement is mostly managed by userland program
133 * (rtadvd) so here we have no function like nd6_ra_output().
143 struct ifnet
*ifp
= m
->m_pkthdr
.rcvif
;
144 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
145 struct nd_router_solicit
*nd_rs
;
146 struct in6_addr saddr6
= ip6
->ip6_src
;
148 struct in6_addr daddr6
= ip6
->ip6_dst
;
153 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)NULL
;
154 struct llinfo_nd6
*ln
= (struct llinfo_nd6
*)NULL
;
155 struct rtentry
*rt
= NULL
;
158 union nd_opts ndopts
;
160 /* If I'm not a router, ignore it. */
161 if (ip6_accept_rtadv
!= 0 || (ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
) || ip6_forwarding
!= 1)
165 if (ip6
->ip6_hlim
!= 255) {
167 "nd6_rs_input: invalid hlim (%d) from %s to %s on %s\n",
168 ip6
->ip6_hlim
, ip6_sprintf(&ip6
->ip6_src
),
169 ip6_sprintf(&ip6
->ip6_dst
), if_name(ifp
)));
174 * Don't update the neighbor cache, if src = ::.
175 * This indicates that the src has no IP address assigned yet.
177 if (IN6_IS_ADDR_UNSPECIFIED(&saddr6
))
180 #ifndef PULLDOWN_TEST
181 IP6_EXTHDR_CHECK(m
, off
, icmp6len
, return);
182 nd_rs
= (struct nd_router_solicit
*)((caddr_t
)ip6
+ off
);
184 IP6_EXTHDR_GET(nd_rs
, struct nd_router_solicit
*, m
, off
, icmp6len
);
186 icmp6stat
.icp6s_tooshort
++;
191 icmp6len
-= sizeof(*nd_rs
);
192 nd6_option_init(nd_rs
+ 1, icmp6len
, &ndopts
);
193 if (nd6_options(&ndopts
) < 0) {
195 "nd6_rs_input: invalid ND option, ignored\n"));
196 /* nd6_options have incremented stats */
200 if (ndopts
.nd_opts_src_lladdr
) {
201 lladdr
= (char *)(ndopts
.nd_opts_src_lladdr
+ 1);
202 lladdrlen
= ndopts
.nd_opts_src_lladdr
->nd_opt_len
<< 3;
205 if (lladdr
&& ((ifp
->if_addrlen
+ 2 + 7) & ~7) != lladdrlen
) {
207 "nd6_rs_input: lladdrlen mismatch for %s "
208 "(if %d, RS packet %d)\n",
209 ip6_sprintf(&saddr6
), ifp
->if_addrlen
, lladdrlen
- 2));
213 nd6_cache_lladdr(ifp
, &saddr6
, lladdr
, lladdrlen
, ND_ROUTER_SOLICIT
, 0);
220 icmp6stat
.icp6s_badrs
++;
225 * Receive Router Advertisement Message.
228 * TODO: on-link bit on prefix information
229 * TODO: ND_RA_FLAG_{OTHER,MANAGED} processing
237 struct ifnet
*ifp
= m
->m_pkthdr
.rcvif
;
238 struct nd_ifinfo
*ndi
= &nd_ifinfo
[ifp
->if_index
];
239 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
240 struct nd_router_advert
*nd_ra
;
241 struct in6_addr saddr6
= ip6
->ip6_src
;
243 struct in6_addr daddr6
= ip6
->ip6_dst
;
244 int flags
; /* = nd_ra->nd_ra_flags_reserved; */
245 int is_managed
= ((flags
& ND_RA_FLAG_MANAGED
) != 0);
246 int is_other
= ((flags
& ND_RA_FLAG_OTHER
) != 0);
248 union nd_opts ndopts
;
249 struct nd_defrouter
*dr
;
250 struct timeval timenow
;
252 getmicrotime(&timenow
);
254 if (ip6_accept_rtadv
== 0 && ((ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
) == 0))
257 if (ip6
->ip6_hlim
!= 255) {
259 "nd6_ra_input: invalid hlim (%d) from %s to %s on %s\n",
260 ip6
->ip6_hlim
, ip6_sprintf(&ip6
->ip6_src
),
261 ip6_sprintf(&ip6
->ip6_dst
), if_name(ifp
)));
265 if (!IN6_IS_ADDR_LINKLOCAL(&saddr6
)) {
267 "nd6_ra_input: src %s is not link-local\n",
268 ip6_sprintf(&saddr6
)));
272 #ifndef PULLDOWN_TEST
273 IP6_EXTHDR_CHECK(m
, off
, icmp6len
, return);
274 nd_ra
= (struct nd_router_advert
*)((caddr_t
)ip6
+ off
);
276 IP6_EXTHDR_GET(nd_ra
, struct nd_router_advert
*, m
, off
, icmp6len
);
278 icmp6stat
.icp6s_tooshort
++;
283 icmp6len
-= sizeof(*nd_ra
);
284 nd6_option_init(nd_ra
+ 1, icmp6len
, &ndopts
);
285 if (nd6_options(&ndopts
) < 0) {
287 "nd6_ra_input: invalid ND option, ignored\n"));
288 /* nd6_options have incremented stats */
293 struct nd_defrouter dr0
;
294 u_int32_t advreachable
= nd_ra
->nd_ra_reachable
;
297 dr0
.flags
= nd_ra
->nd_ra_flags_reserved
;
298 dr0
.rtlifetime
= ntohs(nd_ra
->nd_ra_router_lifetime
);
299 dr0
.expire
= timenow
.tv_sec
+ dr0
.rtlifetime
;
301 dr0
.advint
= 0; /* Mobile IPv6 */
302 dr0
.advint_expire
= 0; /* Mobile IPv6 */
303 dr0
.advints_lost
= 0; /* Mobile IPv6 */
304 /* unspecified or not? (RFC 2461 6.3.4) */
306 advreachable
= ntohl(advreachable
);
307 if (advreachable
<= MAX_REACHABLE_TIME
&&
308 ndi
->basereachable
!= advreachable
) {
309 ndi
->basereachable
= advreachable
;
310 ndi
->reachable
= ND_COMPUTE_RTIME(ndi
->basereachable
);
311 ndi
->recalctm
= nd6_recalc_reachtm_interval
; /* reset */
314 if (nd_ra
->nd_ra_retransmit
)
315 ndi
->retrans
= ntohl(nd_ra
->nd_ra_retransmit
);
316 if (nd_ra
->nd_ra_curhoplimit
)
317 ndi
->chlim
= nd_ra
->nd_ra_curhoplimit
;
318 dr
= defrtrlist_update(&dr0
);
324 if (ndopts
.nd_opts_pi
) {
325 struct nd_opt_hdr
*pt
;
326 struct nd_opt_prefix_info
*pi
= NULL
;
329 for (pt
= (struct nd_opt_hdr
*)ndopts
.nd_opts_pi
;
330 pt
<= (struct nd_opt_hdr
*)ndopts
.nd_opts_pi_end
;
331 pt
= (struct nd_opt_hdr
*)((caddr_t
)pt
+
332 (pt
->nd_opt_len
<< 3))) {
333 if (pt
->nd_opt_type
!= ND_OPT_PREFIX_INFORMATION
)
335 pi
= (struct nd_opt_prefix_info
*)pt
;
337 if (pi
->nd_opt_pi_len
!= 4) {
339 "nd6_ra_input: invalid option "
340 "len %d for prefix information option, "
341 "ignored\n", pi
->nd_opt_pi_len
));
345 if (128 < pi
->nd_opt_pi_prefix_len
) {
347 "nd6_ra_input: invalid prefix "
348 "len %d for prefix information option, "
349 "ignored\n", pi
->nd_opt_pi_prefix_len
));
353 if (IN6_IS_ADDR_MULTICAST(&pi
->nd_opt_pi_prefix
)
354 || IN6_IS_ADDR_LINKLOCAL(&pi
->nd_opt_pi_prefix
)) {
356 "nd6_ra_input: invalid prefix "
358 ip6_sprintf(&pi
->nd_opt_pi_prefix
)));
362 /* aggregatable unicast address, rfc2374 */
363 if ((pi
->nd_opt_pi_prefix
.s6_addr8
[0] & 0xe0) == 0x20
364 && pi
->nd_opt_pi_prefix_len
!= 64) {
366 "nd6_ra_input: invalid prefixlen "
367 "%d for rfc2374 prefix %s, ignored\n",
368 pi
->nd_opt_pi_prefix_len
,
369 ip6_sprintf(&pi
->nd_opt_pi_prefix
)));
373 bzero(&pr
, sizeof(pr
));
374 pr
.ndpr_prefix
.sin6_family
= AF_INET6
;
375 pr
.ndpr_prefix
.sin6_len
= sizeof(pr
.ndpr_prefix
);
376 pr
.ndpr_prefix
.sin6_addr
= pi
->nd_opt_pi_prefix
;
377 pr
.ndpr_ifp
= m
->m_pkthdr
.rcvif
;
379 pr
.ndpr_raf_onlink
= (pi
->nd_opt_pi_flags_reserved
&
380 ND_OPT_PI_FLAG_ONLINK
) ? 1 : 0;
381 pr
.ndpr_raf_auto
= (pi
->nd_opt_pi_flags_reserved
&
382 ND_OPT_PI_FLAG_AUTO
) ? 1 : 0;
383 pr
.ndpr_plen
= pi
->nd_opt_pi_prefix_len
;
384 pr
.ndpr_vltime
= ntohl(pi
->nd_opt_pi_valid_time
);
386 ntohl(pi
->nd_opt_pi_preferred_time
);
388 if (in6_init_prefix_ltimes(&pr
))
389 continue; /* prefix lifetime init failed */
391 (void)prelist_update(&pr
, dr
, m
);
398 if (ndopts
.nd_opts_mtu
&& ndopts
.nd_opts_mtu
->nd_opt_mtu_len
== 1) {
399 u_int32_t mtu
= ntohl(ndopts
.nd_opts_mtu
->nd_opt_mtu_mtu
);
402 if (mtu
< IPV6_MMTU
) {
403 nd6log((LOG_INFO
, "nd6_ra_input: bogus mtu option "
404 "mtu=%d sent from %s, ignoring\n",
405 mtu
, ip6_sprintf(&ip6
->ip6_src
)));
411 if (mtu
<= ndi
->maxmtu
) {
412 int change
= (ndi
->linkmtu
!= mtu
);
415 if (change
) /* in6_maxmtu may change */
418 nd6log((LOG_INFO
, "nd6_ra_input: bogus mtu "
419 "mtu=%d sent from %s; "
420 "exceeds maxmtu %d, ignoring\n",
421 mtu
, ip6_sprintf(&ip6
->ip6_src
),
425 nd6log((LOG_INFO
, "nd6_ra_input: mtu option "
426 "mtu=%d sent from %s; maxmtu unknown, "
428 mtu
, ip6_sprintf(&ip6
->ip6_src
)));
435 * Source link layer address
441 if (ndopts
.nd_opts_src_lladdr
) {
442 lladdr
= (char *)(ndopts
.nd_opts_src_lladdr
+ 1);
443 lladdrlen
= ndopts
.nd_opts_src_lladdr
->nd_opt_len
<< 3;
446 if (lladdr
&& ((ifp
->if_addrlen
+ 2 + 7) & ~7) != lladdrlen
) {
448 "nd6_ra_input: lladdrlen mismatch for %s "
449 "(if %d, RA packet %d)\n",
450 ip6_sprintf(&saddr6
), ifp
->if_addrlen
, lladdrlen
- 2));
454 nd6_cache_lladdr(ifp
, &saddr6
, lladdr
, lladdrlen
, ND_ROUTER_ADVERT
, 0);
457 * Installing a link-layer address might change the state of the
458 * router's neighbor cache, which might also affect our on-link
459 * detection of adveritsed prefixes.
461 pfxlist_onlink_check(0);
469 icmp6stat
.icp6s_badra
++;
474 * default router list proccessing sub routines
477 /* tell the change to user processes watching the routing socket. */
483 struct rt_addrinfo info
;
485 lck_mtx_assert(rt_mtx
, LCK_MTX_ASSERT_OWNED
);
487 bzero((caddr_t
)&info
, sizeof(info
));
488 info
.rti_info
[RTAX_DST
] = rt_key(rt
);
489 info
.rti_info
[RTAX_GATEWAY
] = rt
->rt_gateway
;
490 info
.rti_info
[RTAX_NETMASK
] = rt_mask(rt
);
491 info
.rti_info
[RTAX_IFP
] =
492 TAILQ_FIRST(&rt
->rt_ifp
->if_addrlist
)->ifa_addr
;
493 info
.rti_info
[RTAX_IFA
] = rt
->rt_ifa
->ifa_addr
;
495 rt_missmsg(cmd
, &info
, rt
->rt_flags
, 0);
500 struct nd_defrouter
*new)
502 struct sockaddr_in6 def
, mask
, gate
;
503 struct rtentry
*newrt
= NULL
;
505 Bzero(&def
, sizeof(def
));
506 Bzero(&mask
, sizeof(mask
));
507 Bzero(&gate
, sizeof(gate
));
509 def
.sin6_len
= mask
.sin6_len
= gate
.sin6_len
510 = sizeof(struct sockaddr_in6
);
511 def
.sin6_family
= mask
.sin6_family
= gate
.sin6_family
= AF_INET6
;
512 gate
.sin6_addr
= new->rtaddr
;
514 lck_mtx_lock(rt_mtx
);
515 (void)rtrequest_locked(RTM_ADD
, (struct sockaddr
*)&def
,
516 (struct sockaddr
*)&gate
, (struct sockaddr
*)&mask
,
517 RTF_GATEWAY
, &newrt
);
519 nd6_rtmsg(RTM_ADD
, newrt
); /* tell user process */
522 lck_mtx_unlock(rt_mtx
);
526 /* Add a route to a given interface as default */
531 struct sockaddr_in6 def
, mask
;
532 struct ifaddr
*ifa
= NULL
;
533 struct rtentry
*newrt
= NULL
;
537 bzero(&def
, sizeof(def
));
538 bzero(&mask
, sizeof(mask
));
540 def
.sin6_len
= mask
.sin6_len
= sizeof(struct sockaddr_in6
);
541 def
.sin6_family
= mask
.sin6_family
= AF_INET6
;
544 * Search for an ifaddr beloging to the specified interface.
545 * XXX: An IPv6 address are required to be assigned on the interface.
547 if ((ifa
= ifaof_ifpforaddr((struct sockaddr
*)&def
, ifp
)) == NULL
) {
548 nd6log((LOG_ERR
, /* better error? */
549 "defrouter_addifreq: failed to find an ifaddr "
550 "to install a route to interface %s\n",
555 lck_mtx_lock(rt_mtx
);
556 flags
= ifa
->ifa_flags
;
557 error
= rtrequest_locked(RTM_ADD
, (struct sockaddr
*)&def
, ifa
->ifa_addr
,
558 (struct sockaddr
*)&mask
, flags
, &newrt
);
561 "defrouter_addifreq: failed to install a route to "
562 "interface %s (errno = %d)\n",
563 if_name(ifp
), error
));
565 if (newrt
) /* maybe unnecessary, but do it for safety */
569 nd6_rtmsg(RTM_ADD
, newrt
);
572 in6_post_msg(ifp
, KEV_INET6_DEFROUTER
, (struct in6_ifaddr
*)ifa
);
574 lck_mtx_unlock(rt_mtx
);
578 struct nd_defrouter
*
580 struct in6_addr
*addr
,
583 struct nd_defrouter
*dr
;
586 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
588 for (dr
= TAILQ_FIRST(&nd_defrouter
); dr
;
589 dr
= TAILQ_NEXT(dr
, dr_entry
)) {
590 if (dr
->ifp
== ifp
&& IN6_ARE_ADDR_EQUAL(addr
, &dr
->rtaddr
))
594 return(NULL
); /* search failed */
599 struct nd_defrouter
*dr
,
602 struct sockaddr_in6 def
, mask
, gate
;
603 struct rtentry
*oldrt
= NULL
;
605 Bzero(&def
, sizeof(def
));
606 Bzero(&mask
, sizeof(mask
));
607 Bzero(&gate
, sizeof(gate
));
609 def
.sin6_len
= mask
.sin6_len
= gate
.sin6_len
610 = sizeof(struct sockaddr_in6
);
611 def
.sin6_family
= mask
.sin6_family
= gate
.sin6_family
= AF_INET6
;
612 gate
.sin6_addr
= dr
->rtaddr
;
614 lck_mtx_lock(rt_mtx
);
615 rtrequest_locked(RTM_DELETE
, (struct sockaddr
*)&def
,
616 (struct sockaddr
*)&gate
,
617 (struct sockaddr
*)&mask
,
618 RTF_GATEWAY
, &oldrt
);
620 nd6_rtmsg(RTM_DELETE
, oldrt
);
621 rtfree_locked(oldrt
);
624 if (dofree
) /* XXX: necessary? */
626 lck_mtx_unlock(rt_mtx
);
631 struct nd_defrouter
*dr
, int nd6locked
)
633 struct nd_defrouter
*deldr
= NULL
;
634 struct nd_prefix
*pr
;
637 * Flush all the routing table entries that use the router
640 if (!ip6_forwarding
&& (ip6_accept_rtadv
|| (dr
->ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
641 /* above is a good condition? */
642 rt6_flush(&dr
->rtaddr
, dr
->ifp
);
646 lck_mtx_lock(nd6_mutex
);
647 if (dr
== TAILQ_FIRST(&nd_defrouter
))
648 deldr
= dr
; /* The router is primary. */
650 TAILQ_REMOVE(&nd_defrouter
, dr
, dr_entry
);
653 * Also delete all the pointers to the router in each prefix lists.
655 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
656 struct nd_pfxrouter
*pfxrtr
;
657 if ((pfxrtr
= pfxrtr_lookup(pr
, dr
)) != NULL
)
660 pfxlist_onlink_check(1);
663 * If the router is the primary one, choose a new one.
664 * Note that defrouter_select() will remove the current gateway
665 * from the routing table.
671 lck_mtx_unlock(nd6_mutex
);
677 * Default Router Selection according to Section 6.3.6 of RFC 2461:
678 * 1) Routers that are reachable or probably reachable should be
680 * 2) When no routers on the list are known to be reachable or
681 * probably reachable, routers SHOULD be selected in a round-robin
683 * 3) If the Default Router List is empty, assume that all
684 * destinations are on-link.
689 struct nd_defrouter
*dr
, anydr
;
690 struct rtentry
*rt
= NULL
;
691 struct llinfo_nd6
*ln
= NULL
;
694 * Search for a (probably) reachable router from the list.
696 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
698 for (dr
= TAILQ_FIRST(&nd_defrouter
); dr
;
699 dr
= TAILQ_NEXT(dr
, dr_entry
)) {
700 if ((rt
= nd6_lookup(&dr
->rtaddr
, 0, dr
->ifp
, 0)) &&
701 (ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
) &&
702 ND6_IS_LLINFO_PROBREACH(ln
)) {
703 /* Got it, and move it to the head */
704 TAILQ_REMOVE(&nd_defrouter
, dr
, dr_entry
);
705 TAILQ_INSERT_HEAD(&nd_defrouter
, dr
, dr_entry
);
710 if ((dr
= TAILQ_FIRST(&nd_defrouter
))) {
712 * De-install the previous default gateway and install
714 * Note that if there is no reachable router in the list,
715 * the head entry will be used anyway.
716 * XXX: do we have to check the current routing table entry?
718 bzero(&anydr
, sizeof(anydr
));
719 defrouter_delreq(&anydr
, 0);
720 defrouter_addreq(dr
);
724 * The Default Router List is empty, so install the default
725 * route to an inteface.
726 * XXX: The specification does not say this mechanism should
727 * be restricted to hosts, but this would be not useful
728 * (even harmful) for routers.
730 if (!ip6_forwarding
) {
732 * De-install the current default route
735 bzero(&anydr
, sizeof(anydr
));
736 defrouter_delreq(&anydr
, 0);
739 * Install a route to the default interface
741 * XXX: we enable this for host only, because
742 * this may override a default route installed
743 * a user process (e.g. routing daemon) in a
746 defrouter_addifreq(nd6_defifp
);
748 nd6log((LOG_INFO
, "defrouter_select: "
749 "there's no default router and no default"
758 static struct nd_defrouter
*
760 struct nd_defrouter
*new)
762 struct nd_defrouter
*dr
, *n
;
764 lck_mtx_lock(nd6_mutex
);
765 if ((dr
= defrouter_lookup(&new->rtaddr
, new->ifp
)) != NULL
) {
767 if (new->rtlifetime
== 0) {
768 defrtrlist_del(dr
, 1);
772 dr
->flags
= new->flags
; /* xxx flag check */
773 dr
->rtlifetime
= new->rtlifetime
;
774 dr
->expire
= new->expire
;
776 lck_mtx_unlock(nd6_mutex
);
780 /* entry does not exist */
781 if (new->rtlifetime
== 0) {
782 lck_mtx_unlock(nd6_mutex
);
786 n
= (struct nd_defrouter
*)_MALLOC(sizeof(*n
), M_IP6NDP
, M_NOWAIT
);
788 lck_mtx_unlock(nd6_mutex
);
791 bzero(n
, sizeof(*n
));
795 * Insert the new router at the end of the Default Router List.
796 * If there is no other router, install it anyway. Otherwise,
797 * just continue to use the current default router.
799 TAILQ_INSERT_TAIL(&nd_defrouter
, n
, dr_entry
);
800 if (TAILQ_FIRST(&nd_defrouter
) == n
)
803 lck_mtx_unlock(nd6_mutex
);
807 static struct nd_pfxrouter
*
809 struct nd_prefix
*pr
,
810 struct nd_defrouter
*dr
)
812 struct nd_pfxrouter
*search
;
814 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
815 for (search
= pr
->ndpr_advrtrs
.lh_first
; search
; search
= search
->pfr_next
) {
816 if (search
->router
== dr
)
825 struct nd_prefix
*pr
,
826 struct nd_defrouter
*dr
)
828 struct nd_pfxrouter
*new;
830 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
832 new = (struct nd_pfxrouter
*)_MALLOC(sizeof(*new), M_IP6NDP
, M_NOWAIT
);
835 bzero(new, sizeof(*new));
838 LIST_INSERT_HEAD(&pr
->ndpr_advrtrs
, new, pfr_entry
);
840 pfxlist_onlink_check(1);
845 struct nd_pfxrouter
*pfr
)
847 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
848 LIST_REMOVE(pfr
, pfr_entry
);
854 struct nd_prefix
*pr
)
856 struct nd_prefix
*search
;
858 lck_mtx_lock(nd6_mutex
);
859 for (search
= nd_prefix
.lh_first
; search
; search
= search
->ndpr_next
) {
860 if (pr
->ndpr_ifp
== search
->ndpr_ifp
&&
861 pr
->ndpr_plen
== search
->ndpr_plen
&&
862 in6_are_prefix_equal(&pr
->ndpr_prefix
.sin6_addr
,
863 &search
->ndpr_prefix
.sin6_addr
,
870 ndpr_hold(search
, TRUE
);
871 lck_mtx_unlock(nd6_mutex
);
877 ndpr_hold(struct nd_prefix
*pr
, boolean_t locked
)
880 lck_mtx_lock(nd6_mutex
);
882 if (pr
->ndpr_usecnt
< 0)
883 panic("%s: bad usecnt %d for pr %p\n", __func__
,
884 pr
->ndpr_usecnt
, pr
);
889 lck_mtx_unlock(nd6_mutex
);
893 ndpr_rele(struct nd_prefix
*pr
, boolean_t locked
)
896 lck_mtx_lock(nd6_mutex
);
898 if (pr
->ndpr_usecnt
<= 0)
899 panic("%s: bad usecnt %d for pr %p\n", __func__
,
900 pr
->ndpr_usecnt
, pr
);
905 lck_mtx_unlock(nd6_mutex
);
910 struct nd_prefix
*pr
,
911 struct nd_defrouter
*dr
,
912 struct nd_prefix
**newp
)
914 struct nd_prefix
*new = NULL
;
917 new = (struct nd_prefix
*)_MALLOC(sizeof(*new), M_IP6NDP
, M_NOWAIT
);
920 bzero(new, sizeof(*new));
926 LIST_INIT(&new->ndpr_advrtrs
);
927 in6_prefixlen2mask(&new->ndpr_mask
, new->ndpr_plen
);
928 /* make prefix in the canonical form */
929 for (i
= 0; i
< 4; i
++)
930 new->ndpr_prefix
.sin6_addr
.s6_addr32
[i
] &=
931 new->ndpr_mask
.s6_addr32
[i
];
933 /* link ndpr_entry to nd_prefix list */
934 lck_mtx_lock(nd6_mutex
);
935 LIST_INSERT_HEAD(&nd_prefix
, new, ndpr_entry
);
937 new->ndpr_usecnt
= 0;
938 ndpr_hold(new, TRUE
);
940 /* ND_OPT_PI_FLAG_ONLINK processing */
941 if (new->ndpr_raf_onlink
) {
944 if ((e
= nd6_prefix_onlink(new, 0, 1)) != 0) {
945 nd6log((LOG_ERR
, "nd6_prelist_add: failed to make "
946 "the prefix %s/%d on-link on %s (errno=%d)\n",
947 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
948 pr
->ndpr_plen
, if_name(pr
->ndpr_ifp
), e
));
949 /* proceed anyway. XXX: is it correct? */
956 lck_mtx_unlock(nd6_mutex
);
963 struct nd_prefix
*pr
, int nd6locked
)
965 struct nd_pfxrouter
*pfr
, *next
;
968 /* make sure to invalidate the prefix until it is really freed. */
973 * Though these flags are now meaningless, we'd rather keep the value
974 * not to confuse users when executing "ndp -p".
976 pr
->ndpr_raf_onlink
= 0;
977 pr
->ndpr_raf_auto
= 0;
979 if ((pr
->ndpr_stateflags
& NDPRF_ONLINK
) != 0 &&
980 (e
= nd6_prefix_offlink(pr
)) != 0) {
981 nd6log((LOG_ERR
, "prelist_remove: failed to make %s/%d offlink "
983 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
984 pr
->ndpr_plen
, if_name(pr
->ndpr_ifp
), e
));
985 /* what should we do? */
989 lck_mtx_lock(nd6_mutex
);
991 if (pr
->ndpr_usecnt
> 0 || pr
->ndpr_refcnt
> 0)
992 goto done
; /* notice here? */
994 /* unlink ndpr_entry from nd_prefix list */
995 LIST_REMOVE(pr
, ndpr_entry
);
997 /* free list of routers that adversed the prefix */
998 for (pfr
= pr
->ndpr_advrtrs
.lh_first
; pfr
; pfr
= next
) {
999 next
= pfr
->pfr_next
;
1001 FREE(pfr
, M_IP6NDP
);
1006 pfxlist_onlink_check(1);
1009 lck_mtx_unlock(nd6_mutex
);
1014 struct nd_prefix
*new,
1015 struct nd_defrouter
*dr
, /* may be NULL */
1018 struct in6_ifaddr
*ia6
= NULL
, *ia6_match
= NULL
;
1020 struct ifnet
*ifp
= new->ndpr_ifp
;
1021 struct nd_prefix
*pr
;
1025 struct in6_addrlifetime lt6_tmp
;
1026 struct timeval timenow
;
1031 * Authenticity for NA consists authentication for
1032 * both IP header and IP datagrams, doesn't it ?
1034 #if defined(M_AUTHIPHDR) && defined(M_AUTHIPDGM)
1035 auth
= (m
->m_flags
& M_AUTHIPHDR
1036 && m
->m_flags
& M_AUTHIPDGM
) ? 1 : 0;
1041 if ((pr
= nd6_prefix_lookup(new)) != NULL
) {
1043 * nd6_prefix_lookup() ensures that pr and new have the same
1044 * prefix on a same interface.
1048 * Update prefix information. Note that the on-link (L) bit
1049 * and the autonomous (A) bit should NOT be changed from 1
1052 if (new->ndpr_raf_onlink
== 1)
1053 pr
->ndpr_raf_onlink
= 1;
1054 if (new->ndpr_raf_auto
== 1)
1055 pr
->ndpr_raf_auto
= 1;
1056 if (new->ndpr_raf_onlink
) {
1057 pr
->ndpr_vltime
= new->ndpr_vltime
;
1058 pr
->ndpr_pltime
= new->ndpr_pltime
;
1059 pr
->ndpr_preferred
= new->ndpr_preferred
;
1060 pr
->ndpr_expire
= new->ndpr_expire
;
1063 if (new->ndpr_raf_onlink
&&
1064 (pr
->ndpr_stateflags
& NDPRF_ONLINK
) == 0) {
1067 if ((e
= nd6_prefix_onlink(pr
, 0, 0)) != 0) {
1069 "prelist_update: failed to make "
1070 "the prefix %s/%d on-link on %s "
1072 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
1073 pr
->ndpr_plen
, if_name(pr
->ndpr_ifp
), e
));
1074 /* proceed anyway. XXX: is it correct? */
1078 lck_mtx_lock(nd6_mutex
);
1079 if (dr
&& pfxrtr_lookup(pr
, dr
) == NULL
)
1081 lck_mtx_unlock(nd6_mutex
);
1083 struct nd_prefix
*newpr
= NULL
;
1087 if (new->ndpr_vltime
== 0)
1089 if (new->ndpr_raf_onlink
== 0 && new->ndpr_raf_auto
== 0)
1092 bzero(&new->ndpr_addr
, sizeof(struct in6_addr
));
1094 error
= nd6_prelist_add(new, dr
, &newpr
);
1095 if (error
!= 0 || newpr
== NULL
) {
1096 nd6log((LOG_NOTICE
, "prelist_update: "
1097 "nd6_prelist_add failed for %s/%d on %s "
1098 "errno=%d, returnpr=%p\n",
1099 ip6_sprintf(&new->ndpr_prefix
.sin6_addr
),
1100 new->ndpr_plen
, if_name(new->ndpr_ifp
),
1102 goto end
; /* we should just give up in this case. */
1106 * XXX: from the ND point of view, we can ignore a prefix
1107 * with the on-link bit being zero. However, we need a
1108 * prefix structure for references from autoconfigured
1109 * addresses. Thus, we explicitly make suret that the prefix
1110 * itself expires now.
1112 if (newpr
->ndpr_raf_onlink
== 0) {
1113 newpr
->ndpr_vltime
= 0;
1114 newpr
->ndpr_pltime
= 0;
1115 in6_init_prefix_ltimes(newpr
);
1122 * Address autoconfiguration based on Section 5.5.3 of RFC 2462.
1123 * Note that pr must be non NULL at this point.
1126 /* 5.5.3 (a). Ignore the prefix without the A bit set. */
1127 if (!new->ndpr_raf_auto
)
1131 * 5.5.3 (b). the link-local prefix should have been ignored in
1136 * 5.5.3 (c). Consistency check on lifetimes: pltime <= vltime.
1137 * This should have been done in nd6_ra_input.
1141 * 5.5.3 (d). If the prefix advertised does not match the prefix of an
1142 * address already in the list, and the Valid Lifetime is not 0,
1143 * form an address. Note that even a manually configured address
1144 * should reject autoconfiguration of a new address.
1146 getmicrotime(&timenow
);
1148 ifnet_lock_exclusive(ifp
);
1149 TAILQ_FOREACH(ifa
, &ifp
->if_addrlist
, ifa_list
)
1151 struct in6_ifaddr
*ifa6
;
1153 u_int32_t storedlifetime
;
1155 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
1158 ifa6
= (struct in6_ifaddr
*)ifa
;
1161 * Spec is not clear here, but I believe we should concentrate
1162 * on unicast (i.e. not anycast) addresses.
1163 * XXX: other ia6_flags? detached or duplicated?
1165 if ((ifa6
->ia6_flags
& IN6_IFF_ANYCAST
) != 0)
1168 ifa_plen
= in6_mask2len(&ifa6
->ia_prefixmask
.sin6_addr
, NULL
);
1169 if (ifa_plen
!= new->ndpr_plen
||
1170 !in6_are_prefix_equal(&ifa6
->ia_addr
.sin6_addr
,
1171 &new->ndpr_prefix
.sin6_addr
,
1175 if (ia6_match
== NULL
) /* remember the first one */
1178 if ((ifa6
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
1182 * An already autoconfigured address matched. Now that we
1183 * are sure there is at least one matched address, we can
1184 * proceed to 5.5.3. (e): update the lifetimes according to the
1185 * "two hours" rule and the privacy extension.
1187 #define TWOHOUR (120*60)
1188 lt6_tmp
= ifa6
->ia6_lifetime
;
1190 storedlifetime
= IFA6_IS_INVALID(ifa6
) ? 0 :
1191 (lt6_tmp
.ia6t_expire
- timenow
.tv_sec
);
1193 if (TWOHOUR
< new->ndpr_vltime
||
1194 storedlifetime
< new->ndpr_vltime
) {
1195 lt6_tmp
.ia6t_vltime
= new->ndpr_vltime
;
1196 } else if (storedlifetime
<= TWOHOUR
1199 * This condition is logically redundant, so we just
1201 * See IPng 6712, 6717, and 6721.
1203 && new->ndpr_vltime
<= storedlifetime
1207 lt6_tmp
.ia6t_vltime
= new->ndpr_vltime
;
1211 * new->ndpr_vltime <= TWOHOUR &&
1212 * TWOHOUR < storedlifetime
1214 lt6_tmp
.ia6t_vltime
= TWOHOUR
;
1217 /* The 2 hour rule is not imposed for preferred lifetime. */
1218 lt6_tmp
.ia6t_pltime
= new->ndpr_pltime
;
1220 in6_init_address_ltimes(pr
, <6_tmp
);
1223 * When adjusting the lifetimes of an existing temporary
1224 * address, only lower the lifetimes.
1225 * RFC 3041 3.3. (1).
1226 * XXX: how should we modify ia6t_[pv]ltime?
1228 if ((ifa6
->ia6_flags
& IN6_IFF_TEMPORARY
) != 0) {
1229 if (lt6_tmp
.ia6t_expire
== 0 || /* no expire */
1230 lt6_tmp
.ia6t_expire
>
1231 ifa6
->ia6_lifetime
.ia6t_expire
) {
1232 lt6_tmp
.ia6t_expire
=
1233 ifa6
->ia6_lifetime
.ia6t_expire
;
1235 if (lt6_tmp
.ia6t_preferred
== 0 || /* no expire */
1236 lt6_tmp
.ia6t_preferred
>
1237 ifa6
->ia6_lifetime
.ia6t_preferred
) {
1238 lt6_tmp
.ia6t_preferred
=
1239 ifa6
->ia6_lifetime
.ia6t_preferred
;
1243 ifa6
->ia6_lifetime
= lt6_tmp
;
1245 ifnet_lock_done(ifp
);
1246 if (ia6_match
== NULL
&& new->ndpr_vltime
) {
1248 * No address matched and the valid lifetime is non-zero.
1249 * Create a new address.
1251 if ((ia6
= in6_ifadd(new, NULL
)) != NULL
) {
1253 * note that we should use pr (not new) for reference.
1255 lck_mtx_lock(nd6_mutex
);
1257 lck_mtx_unlock(nd6_mutex
);
1261 /* XXXYYY Don't do this, according to Jinmei. */
1262 pr
->ndpr_addr
= new->ndpr_addr
;
1267 * When a new public address is created as described
1268 * in RFC2462, also create a new temporary address.
1271 * When an interface connects to a new link, a new
1272 * randomized interface identifier should be generated
1273 * immediately together with a new set of temporary
1274 * addresses. Thus, we specifiy 1 as the 2nd arg of
1277 if (ip6_use_tempaddr
) {
1279 if ((e
= in6_tmpifadd(ia6
, 1)) != 0) {
1280 nd6log((LOG_NOTICE
, "prelist_update: "
1281 "failed to create a temporary "
1282 "address, errno=%d\n",
1288 * A newly added address might affect the status
1289 * of other addresses, so we check and update it.
1290 * XXX: what if address duplication happens?
1292 pfxlist_onlink_check(0);
1294 /* just set an error. do not bark here. */
1295 error
= EADDRNOTAVAIL
; /* XXX: might be unused. */
1303 ndpr_rele(pr
, FALSE
);
1309 * A supplement function used in the on-link detection below;
1310 * detect if a given prefix has a (probably) reachable advertising router.
1311 * XXX: lengthy function name...
1313 static struct nd_pfxrouter
*
1314 find_pfxlist_reachable_router(
1315 struct nd_prefix
*pr
)
1317 struct nd_pfxrouter
*pfxrtr
;
1319 struct llinfo_nd6
*ln
;
1321 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
1323 for (pfxrtr
= LIST_FIRST(&pr
->ndpr_advrtrs
); pfxrtr
;
1324 pfxrtr
= LIST_NEXT(pfxrtr
, pfr_entry
)) {
1325 if ((rt
= nd6_lookup(&pfxrtr
->router
->rtaddr
, 0,
1326 pfxrtr
->router
->ifp
, 0)) &&
1327 (ln
= (struct llinfo_nd6
*)rt
->rt_llinfo
) &&
1328 ND6_IS_LLINFO_PROBREACH(ln
))
1337 * Check if each prefix in the prefix list has at least one available router
1338 * that advertised the prefix (a router is "available" if its neighbor cache
1339 * entry is reachable or probably reachable).
1340 * If the check fails, the prefix may be off-link, because, for example,
1341 * we have moved from the network but the lifetime of the prefix has not
1342 * expired yet. So we should not use the prefix if there is another prefix
1343 * that has an available router.
1344 * But, if there is no prefix that has an available router, we still regards
1345 * all the prefixes as on-link. This is because we can't tell if all the
1346 * routers are simply dead or if we really moved from the network and there
1347 * is no router around us.
1350 pfxlist_onlink_check(int nd6locked
)
1352 struct nd_prefix
*pr
;
1353 struct in6_ifaddr
*ifa
;
1356 * Check if there is a prefix that has a reachable advertising
1360 lck_mtx_lock(nd6_mutex
);
1361 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
1362 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
1363 if (pr
->ndpr_raf_onlink
&& find_pfxlist_reachable_router(pr
))
1369 * There is at least one prefix that has a reachable router.
1370 * Detach prefixes which have no reachable advertising
1371 * router, and attach other prefixes.
1373 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
1374 /* XXX: a link-local prefix should never be detached */
1375 if (IN6_IS_ADDR_LINKLOCAL(&pr
->ndpr_prefix
.sin6_addr
))
1379 * we aren't interested in prefixes without the L bit
1382 if (pr
->ndpr_raf_onlink
== 0)
1385 if ((pr
->ndpr_stateflags
& NDPRF_DETACHED
) == 0 &&
1386 find_pfxlist_reachable_router(pr
) == NULL
)
1387 pr
->ndpr_stateflags
|= NDPRF_DETACHED
;
1388 if ((pr
->ndpr_stateflags
& NDPRF_DETACHED
) != 0 &&
1389 find_pfxlist_reachable_router(pr
) != 0)
1390 pr
->ndpr_stateflags
&= ~NDPRF_DETACHED
;
1393 /* there is no prefix that has a reachable router */
1394 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
1395 if (IN6_IS_ADDR_LINKLOCAL(&pr
->ndpr_prefix
.sin6_addr
))
1398 if (pr
->ndpr_raf_onlink
== 0)
1401 if ((pr
->ndpr_stateflags
& NDPRF_DETACHED
) != 0)
1402 pr
->ndpr_stateflags
&= ~NDPRF_DETACHED
;
1407 * Remove each interface route associated with a (just) detached
1408 * prefix, and reinstall the interface route for a (just) attached
1409 * prefix. Note that all attempt of reinstallation does not
1410 * necessarily success, when a same prefix is shared among multiple
1411 * interfaces. Such cases will be handled in nd6_prefix_onlink,
1412 * so we don't have to care about them.
1414 for (pr
= nd_prefix
.lh_first
; pr
; pr
= pr
->ndpr_next
) {
1417 if (IN6_IS_ADDR_LINKLOCAL(&pr
->ndpr_prefix
.sin6_addr
))
1420 if (pr
->ndpr_raf_onlink
== 0)
1423 if ((pr
->ndpr_stateflags
& NDPRF_DETACHED
) != 0 &&
1424 (pr
->ndpr_stateflags
& NDPRF_ONLINK
) != 0) {
1425 if ((e
= nd6_prefix_offlink(pr
)) != 0) {
1427 "pfxlist_onlink_check: failed to "
1428 "make %s/%d offlink, errno=%d\n",
1429 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
1433 if ((pr
->ndpr_stateflags
& NDPRF_DETACHED
) == 0 &&
1434 (pr
->ndpr_stateflags
& NDPRF_ONLINK
) == 0 &&
1435 pr
->ndpr_raf_onlink
) {
1436 if ((e
= nd6_prefix_onlink(pr
, 0, 1)) != 0) {
1438 "pfxlist_onlink_check: failed to "
1439 "make %s/%d offlink, errno=%d\n",
1440 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
1447 * Changes on the prefix status might affect address status as well.
1448 * Make sure that all addresses derived from an attached prefix are
1449 * attached, and that all addresses derived from a detached prefix are
1450 * detached. Note, however, that a manually configured address should
1451 * always be attached.
1452 * The precise detection logic is same as the one for prefixes.
1454 for (ifa
= in6_ifaddrs
; ifa
; ifa
= ifa
->ia_next
) {
1455 if ((ifa
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
1458 if (ifa
->ia6_ndpr
== NULL
) {
1460 * This can happen when we first configure the address
1461 * (i.e. the address exists, but the prefix does not).
1462 * XXX: complicated relationships...
1467 if (find_pfxlist_reachable_router(ifa
->ia6_ndpr
))
1471 for (ifa
= in6_ifaddrs
; ifa
; ifa
= ifa
->ia_next
) {
1472 if ((ifa
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
1475 if (ifa
->ia6_ndpr
== NULL
) /* XXX: see above. */
1478 if (find_pfxlist_reachable_router(ifa
->ia6_ndpr
))
1479 ifa
->ia6_flags
&= ~IN6_IFF_DETACHED
;
1481 ifa
->ia6_flags
|= IN6_IFF_DETACHED
;
1485 for (ifa
= in6_ifaddrs
; ifa
; ifa
= ifa
->ia_next
) {
1486 if ((ifa
->ia6_flags
& IN6_IFF_AUTOCONF
) == 0)
1489 ifa
->ia6_flags
&= ~IN6_IFF_DETACHED
;
1493 lck_mtx_unlock(nd6_mutex
);
1498 struct nd_prefix
*pr
, int rtlocked
, int nd6locked
)
1501 struct ifnet
*ifp
= pr
->ndpr_ifp
;
1502 struct sockaddr_in6 mask6
;
1503 struct nd_prefix
*opr
;
1506 struct rtentry
*rt
= NULL
;
1509 if ((pr
->ndpr_stateflags
& NDPRF_ONLINK
) != 0) {
1511 "nd6_prefix_onlink: %s/%d is already on-link\n",
1512 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
), pr
->ndpr_plen
);
1517 * Add the interface route associated with the prefix. Before
1518 * installing the route, check if there's the same prefix on another
1519 * interface, and the prefix has already installed the interface route.
1520 * Although such a configuration is expected to be rare, we explicitly
1524 lck_mtx_lock(nd6_mutex
);
1526 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
1527 for (opr
= nd_prefix
.lh_first
; opr
; opr
= opr
->ndpr_next
) {
1531 if ((opr
->ndpr_stateflags
& NDPRF_ONLINK
) == 0)
1534 if (opr
->ndpr_plen
== pr
->ndpr_plen
&&
1535 in6_are_prefix_equal(&pr
->ndpr_prefix
.sin6_addr
,
1536 &opr
->ndpr_prefix
.sin6_addr
,
1539 lck_mtx_unlock(nd6_mutex
);
1545 lck_mtx_unlock(nd6_mutex
);
1547 * We prefer link-local addresses as the associated interface address.
1549 /* search for a link-local addr */
1550 ifa
= (struct ifaddr
*)in6ifa_ifpforlinklocal(ifp
,
1554 /* XXX: freebsd does not have ifa_ifwithaf */
1555 ifnet_lock_exclusive(ifp
);
1556 TAILQ_FOREACH(ifa
, &ifp
->if_addrlist
, ifa_list
)
1558 if (ifa
->ifa_addr
->sa_family
== AF_INET6
)
1561 ifnet_lock_done(ifp
);
1562 /* should we care about ia6_flags? */
1566 * This can still happen, when, for example, we receive an RA
1567 * containing a prefix with the L bit set and the A bit clear,
1568 * after removing all IPv6 addresses on the receiving
1569 * interface. This should, of course, be rare though.
1572 "nd6_prefix_onlink: failed to find any ifaddr"
1573 " to add route for a prefix(%s/%d) on %s\n",
1574 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
1575 pr
->ndpr_plen
, if_name(ifp
)));
1580 * in6_ifinit() sets nd6_rtrequest to ifa_rtrequest for all ifaddrs.
1581 * ifa->ifa_rtrequest = nd6_rtrequest;
1583 bzero(&mask6
, sizeof(mask6
));
1584 mask6
.sin6_len
= sizeof(mask6
);
1585 mask6
.sin6_addr
= pr
->ndpr_mask
;
1588 lck_mtx_lock(rt_mtx
);
1590 rtflags
= ifa
->ifa_flags
| RTF_CLONING
| RTF_UP
;
1591 if (nd6_need_cache(ifp
)) {
1592 /* explicitly set in case ifa_flags does not set the flag. */
1593 rtflags
|= RTF_CLONING
;
1596 * explicitly clear the cloning bit in case ifa_flags sets it.
1598 rtflags
&= ~RTF_CLONING
;
1600 error
= rtrequest_locked(RTM_ADD
, (struct sockaddr
*)&pr
->ndpr_prefix
,
1601 ifa
->ifa_addr
, (struct sockaddr
*)&mask6
,
1604 if (rt
!= NULL
) /* this should be non NULL, though */
1605 nd6_rtmsg(RTM_ADD
, rt
);
1606 pr
->ndpr_stateflags
|= NDPRF_ONLINK
;
1609 nd6log((LOG_ERR
, "nd6_prefix_onlink: failed to add route for a"
1610 " prefix (%s/%d) on %s, gw=%s, mask=%s, flags=%lx "
1612 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
),
1613 pr
->ndpr_plen
, if_name(ifp
),
1614 ip6_sprintf(&((struct sockaddr_in6
*)ifa
->ifa_addr
)->sin6_addr
),
1615 ip6_sprintf(&mask6
.sin6_addr
), rtflags
, error
));
1622 lck_mtx_unlock(rt_mtx
);
1628 struct nd_prefix
*pr
)
1631 struct ifnet
*ifp
= pr
->ndpr_ifp
;
1632 struct nd_prefix
*opr
;
1633 struct sockaddr_in6 sa6
, mask6
;
1634 struct rtentry
*rt
= NULL
;
1637 if ((pr
->ndpr_stateflags
& NDPRF_ONLINK
) == 0) {
1639 "nd6_prefix_offlink: %s/%d is already off-link\n",
1640 ip6_sprintf(&pr
->ndpr_prefix
.sin6_addr
), pr
->ndpr_plen
));
1644 bzero(&sa6
, sizeof(sa6
));
1645 sa6
.sin6_family
= AF_INET6
;
1646 sa6
.sin6_len
= sizeof(sa6
);
1647 bcopy(&pr
->ndpr_prefix
.sin6_addr
, &sa6
.sin6_addr
,
1648 sizeof(struct in6_addr
));
1649 bzero(&mask6
, sizeof(mask6
));
1650 mask6
.sin6_family
= AF_INET6
;
1651 mask6
.sin6_len
= sizeof(sa6
);
1652 bcopy(&pr
->ndpr_mask
, &mask6
.sin6_addr
, sizeof(struct in6_addr
));
1653 lck_mtx_lock(rt_mtx
);
1654 error
= rtrequest_locked(RTM_DELETE
, (struct sockaddr
*)&sa6
, NULL
,
1655 (struct sockaddr
*)&mask6
, 0, &rt
);
1657 pr
->ndpr_stateflags
&= ~NDPRF_ONLINK
;
1659 /* report the route deletion to the routing socket. */
1661 nd6_rtmsg(RTM_DELETE
, rt
);
1664 * There might be the same prefix on another interface,
1665 * the prefix which could not be on-link just because we have
1666 * the interface route (see comments in nd6_prefix_onlink).
1667 * If there's one, try to make the prefix on-link on the
1670 lck_mtx_assert(nd6_mutex
, LCK_MTX_ASSERT_OWNED
);
1671 for (opr
= nd_prefix
.lh_first
; opr
; opr
= opr
->ndpr_next
) {
1675 if ((opr
->ndpr_stateflags
& NDPRF_ONLINK
) != 0)
1679 * KAME specific: detached prefixes should not be
1682 if ((opr
->ndpr_stateflags
& NDPRF_DETACHED
) != 0)
1685 if (opr
->ndpr_plen
== pr
->ndpr_plen
&&
1686 in6_are_prefix_equal(&pr
->ndpr_prefix
.sin6_addr
,
1687 &opr
->ndpr_prefix
.sin6_addr
,
1691 if ((e
= nd6_prefix_onlink(opr
, 1, 1)) != 0) {
1693 "nd6_prefix_offlink: failed to "
1694 "recover a prefix %s/%d from %s "
1695 "to %s (errno = %d)\n",
1696 ip6_sprintf(&opr
->ndpr_prefix
.sin6_addr
),
1697 opr
->ndpr_plen
, if_name(ifp
),
1698 if_name(opr
->ndpr_ifp
), e
));
1704 /* XXX: can we still set the NDPRF_ONLINK flag? */
1706 "nd6_prefix_offlink: failed to delete route: "
1707 "%s/%d on %s (errno = %d)\n",
1708 ip6_sprintf(&sa6
.sin6_addr
), pr
->ndpr_plen
, if_name(ifp
),
1715 lck_mtx_unlock(rt_mtx
);
1720 static struct in6_ifaddr
*
1722 struct nd_prefix
*pr
,
1723 struct in6_addr
*ifid
) /* Mobile IPv6 addition */
1725 struct ifnet
*ifp
= pr
->ndpr_ifp
;
1727 struct in6_aliasreq ifra
;
1728 struct in6_ifaddr
*ia
, *ib
;
1730 struct in6_addr mask
;
1731 int prefixlen
= pr
->ndpr_plen
;
1733 in6_len2mask(&mask
, prefixlen
);
1736 * find a link-local address (will be interface ID).
1737 * Is it really mandatory? Theoretically, a global or a site-local
1738 * address can be configured without a link-local address, if we
1739 * have a unique interface identifier...
1741 * it is not mandatory to have a link-local address, we can generate
1742 * interface identifier on the fly. we do this because:
1743 * (1) it should be the easiest way to find interface identifier.
1744 * (2) RFC2462 5.4 suggesting the use of the same interface identifier
1745 * for multiple addresses on a single interface, and possible shortcut
1746 * of DAD. we omitted DAD for this reason in the past.
1747 * (3) a user can prevent autoconfiguration of global address
1748 * by removing link-local address by hand (this is partly because we
1749 * don't have other way to control the use of IPv6 on a interface.
1750 * this has been our design choice - cf. NRL's "ifconfig auto").
1751 * (4) it is easier to manage when an interface has addresses
1752 * with the same interface identifier, than to have multiple addresses
1753 * with different interface identifiers.
1755 * Mobile IPv6 addition: allow for caller to specify a wished interface
1756 * ID. This is to not break connections when moving addresses between
1759 ifa
= (struct ifaddr
*)in6ifa_ifpforlinklocal(ifp
, 0);/* 0 is OK? */
1761 ib
= (struct in6_ifaddr
*)ifa
;
1765 #if 0 /* don't care link local addr state, and always do DAD */
1766 /* if link-local address is not eligible, do not autoconfigure. */
1767 if (((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_NOTREADY
) {
1768 printf("in6_ifadd: link-local address not ready\n");
1773 /* prefixlen + ifidlen must be equal to 128 */
1774 plen0
= in6_mask2len(&ib
->ia_prefixmask
.sin6_addr
, NULL
);
1775 if (prefixlen
!= plen0
) {
1776 nd6log((LOG_INFO
, "in6_ifadd: wrong prefixlen for %s "
1777 "(prefix=%d ifid=%d)\n",
1778 if_name(ifp
), prefixlen
, 128 - plen0
));
1784 bzero(&ifra
, sizeof(ifra
));
1786 * in6_update_ifa() does not use ifra_name, but we accurately set it
1789 strncpy(ifra
.ifra_name
, if_name(ifp
), sizeof(ifra
.ifra_name
));
1790 ifra
.ifra_addr
.sin6_family
= AF_INET6
;
1791 ifra
.ifra_addr
.sin6_len
= sizeof(struct sockaddr_in6
);
1793 bcopy(&pr
->ndpr_prefix
.sin6_addr
, &ifra
.ifra_addr
.sin6_addr
,
1794 sizeof(ifra
.ifra_addr
.sin6_addr
));
1795 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[0] &= mask
.s6_addr32
[0];
1796 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[1] &= mask
.s6_addr32
[1];
1797 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[2] &= mask
.s6_addr32
[2];
1798 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[3] &= mask
.s6_addr32
[3];
1801 if (ifid
== NULL
|| IN6_IS_ADDR_UNSPECIFIED(ifid
))
1802 ifid
= &ib
->ia_addr
.sin6_addr
;
1803 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[0]
1804 |= (ifid
->s6_addr32
[0] & ~mask
.s6_addr32
[0]);
1805 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[1]
1806 |= (ifid
->s6_addr32
[1] & ~mask
.s6_addr32
[1]);
1807 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[2]
1808 |= (ifid
->s6_addr32
[2] & ~mask
.s6_addr32
[2]);
1809 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[3]
1810 |= (ifid
->s6_addr32
[3] & ~mask
.s6_addr32
[3]);
1812 /* new prefix mask. */
1813 ifra
.ifra_prefixmask
.sin6_len
= sizeof(struct sockaddr_in6
);
1814 ifra
.ifra_prefixmask
.sin6_family
= AF_INET6
;
1815 bcopy(&mask
, &ifra
.ifra_prefixmask
.sin6_addr
,
1816 sizeof(ifra
.ifra_prefixmask
.sin6_addr
));
1820 * XXX: in6_init_address_ltimes would override these values later.
1821 * We should reconsider this logic.
1823 ifra
.ifra_lifetime
.ia6t_vltime
= pr
->ndpr_vltime
;
1824 ifra
.ifra_lifetime
.ia6t_pltime
= pr
->ndpr_pltime
;
1826 /* XXX: scope zone ID? */
1828 ifra
.ifra_flags
|= IN6_IFF_AUTOCONF
; /* obey autoconf */
1830 * temporarily set the nopfx flag to avoid conflict.
1831 * XXX: we should reconsider the entire mechanism about prefix
1834 ifra
.ifra_flags
|= IN6_IFF_NOPFX
;
1837 * keep the new address, regardless of the result of in6_update_ifa.
1838 * XXX: this address is now meaningless.
1839 * We should reconsider its role.
1841 pr
->ndpr_addr
= ifra
.ifra_addr
.sin6_addr
;
1843 /* allocate ifaddr structure, link into chain, etc. */
1844 if ((error
= in6_update_ifa(ifp
, &ifra
, NULL
)) != 0) {
1846 "in6_ifadd: failed to make ifaddr %s on %s (errno=%d)\n",
1847 ip6_sprintf(&ifra
.ifra_addr
.sin6_addr
), if_name(ifp
),
1849 return(NULL
); /* ifaddr must not have been allocated. */
1852 ia
= in6ifa_ifpwithaddr(ifp
, &ifra
.ifra_addr
.sin6_addr
);
1854 in6_post_msg(ifp
, KEV_INET6_NEW_RTADV_ADDR
, ia
);
1856 return(ia
); /* this must NOT be NULL. */
1861 const struct in6_ifaddr
*ia0
, /* corresponding public address */
1864 struct ifnet
*ifp
= ia0
->ia_ifa
.ifa_ifp
;
1865 struct in6_ifaddr
*newia
;
1866 struct in6_aliasreq ifra
;
1868 int trylimit
= 3; /* XXX: adhoc value */
1869 u_int32_t randid
[2];
1870 time_t vltime0
, pltime0
;
1871 struct timeval timenow
;
1873 getmicrotime(&timenow
);
1875 bzero(&ifra
, sizeof(ifra
));
1876 strncpy(ifra
.ifra_name
, if_name(ifp
), sizeof(ifra
.ifra_name
));
1877 ifra
.ifra_addr
= ia0
->ia_addr
;
1878 /* copy prefix mask */
1879 ifra
.ifra_prefixmask
= ia0
->ia_prefixmask
;
1880 /* clear the old IFID */
1881 for (i
= 0; i
< 4; i
++) {
1882 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[i
]
1883 &= ifra
.ifra_prefixmask
.sin6_addr
.s6_addr32
[i
];
1887 in6_get_tmpifid(ifp
, (u_int8_t
*)randid
,
1888 (const u_int8_t
*)&ia0
->ia_addr
.sin6_addr
.s6_addr
[8],
1890 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[2]
1891 |= (randid
[0] & ~(ifra
.ifra_prefixmask
.sin6_addr
.s6_addr32
[2]));
1892 ifra
.ifra_addr
.sin6_addr
.s6_addr32
[3]
1893 |= (randid
[1] & ~(ifra
.ifra_prefixmask
.sin6_addr
.s6_addr32
[3]));
1896 * If by chance the new temporary address is the same as an address
1897 * already assigned to the interface, generate a new randomized
1898 * interface identifier and repeat this step.
1901 if (in6ifa_ifpwithaddr(ifp
, &ifra
.ifra_addr
.sin6_addr
) != NULL
) {
1902 if (trylimit
-- == 0) {
1903 nd6log((LOG_NOTICE
, "in6_tmpifadd: failed to find "
1904 "a unique random IFID\n"));
1912 * The Valid Lifetime is the lower of the Valid Lifetime of the
1913 * public address or TEMP_VALID_LIFETIME.
1914 * The Preferred Lifetime is the lower of the Preferred Lifetime
1915 * of the public address or TEMP_PREFERRED_LIFETIME -
1918 if (ia0
->ia6_lifetime
.ia6t_expire
!= 0) {
1919 vltime0
= IFA6_IS_INVALID(ia0
) ? 0 :
1920 (ia0
->ia6_lifetime
.ia6t_expire
- timenow
.tv_sec
);
1921 if (vltime0
> ip6_temp_valid_lifetime
)
1922 vltime0
= ip6_temp_valid_lifetime
;
1924 vltime0
= ip6_temp_valid_lifetime
;
1925 if (ia0
->ia6_lifetime
.ia6t_preferred
!= 0) {
1926 pltime0
= IFA6_IS_DEPRECATED(ia0
) ? 0 :
1927 (ia0
->ia6_lifetime
.ia6t_preferred
- timenow
.tv_sec
);
1928 if (pltime0
> ip6_temp_preferred_lifetime
- ip6_desync_factor
){
1929 pltime0
= ip6_temp_preferred_lifetime
-
1933 pltime0
= ip6_temp_preferred_lifetime
- ip6_desync_factor
;
1934 ifra
.ifra_lifetime
.ia6t_vltime
= vltime0
;
1935 ifra
.ifra_lifetime
.ia6t_pltime
= pltime0
;
1938 * A temporary address is created only if this calculated Preferred
1939 * Lifetime is greater than REGEN_ADVANCE time units.
1941 if (ifra
.ifra_lifetime
.ia6t_pltime
<= ip6_temp_regen_advance
)
1944 /* XXX: scope zone ID? */
1946 ifra
.ifra_flags
|= (IN6_IFF_AUTOCONF
|IN6_IFF_TEMPORARY
);
1948 /* allocate ifaddr structure, link into chain, etc. */
1949 if ((error
= in6_update_ifa(ifp
, &ifra
, NULL
)) != 0)
1952 newia
= in6ifa_ifpwithaddr(ifp
, &ifra
.ifra_addr
.sin6_addr
);
1953 if (newia
== NULL
) { /* XXX: can it happen? */
1955 "in6_tmpifadd: ifa update succeeded, but we got "
1957 return(EINVAL
); /* XXX */
1959 lck_mtx_lock(nd6_mutex
);
1960 newia
->ia6_ndpr
= ia0
->ia6_ndpr
;
1961 newia
->ia6_ndpr
->ndpr_refcnt
++;
1964 * A newly added address might affect the status of other addresses.
1965 * XXX: when the temporary address is generated with a new public
1966 * address, the onlink check is redundant. However, it would be safe
1967 * to do the check explicitly everywhere a new address is generated,
1968 * and, in fact, we surely need the check when we create a new
1969 * temporary address due to deprecation of an old temporary address.
1971 pfxlist_onlink_check(1);
1972 lck_mtx_unlock(nd6_mutex
);
1978 in6_init_prefix_ltimes(struct nd_prefix
*ndpr
)
1980 struct timeval timenow
;
1982 getmicrotime(&timenow
);
1983 /* check if preferred lifetime > valid lifetime. RFC2462 5.5.3 (c) */
1984 if (ndpr
->ndpr_pltime
> ndpr
->ndpr_vltime
) {
1985 nd6log((LOG_INFO
, "in6_init_prefix_ltimes: preferred lifetime"
1986 "(%d) is greater than valid lifetime(%d)\n",
1987 (u_int
)ndpr
->ndpr_pltime
, (u_int
)ndpr
->ndpr_vltime
));
1990 if (ndpr
->ndpr_pltime
== ND6_INFINITE_LIFETIME
)
1991 ndpr
->ndpr_preferred
= 0;
1993 ndpr
->ndpr_preferred
= timenow
.tv_sec
+ ndpr
->ndpr_pltime
;
1994 if (ndpr
->ndpr_vltime
== ND6_INFINITE_LIFETIME
)
1995 ndpr
->ndpr_expire
= 0;
1997 ndpr
->ndpr_expire
= timenow
.tv_sec
+ ndpr
->ndpr_vltime
;
2003 in6_init_address_ltimes(__unused
struct nd_prefix
*new, struct in6_addrlifetime
*lt6
)
2005 struct timeval timenow
;
2007 getmicrotime(&timenow
);
2008 /* Valid lifetime must not be updated unless explicitly specified. */
2009 /* init ia6t_expire */
2010 if (lt6
->ia6t_vltime
== ND6_INFINITE_LIFETIME
)
2011 lt6
->ia6t_expire
= 0;
2013 lt6
->ia6t_expire
= timenow
.tv_sec
;
2014 lt6
->ia6t_expire
+= lt6
->ia6t_vltime
;
2017 /* init ia6t_preferred */
2018 if (lt6
->ia6t_pltime
== ND6_INFINITE_LIFETIME
)
2019 lt6
->ia6t_preferred
= 0;
2021 lt6
->ia6t_preferred
= timenow
.tv_sec
;
2022 lt6
->ia6t_preferred
+= lt6
->ia6t_pltime
;
2027 * Delete all the routing table entries that use the specified gateway.
2028 * XXX: this function causes search through all entries of routing table, so
2029 * it shouldn't be called when acting as a router.
2033 struct in6_addr
*gateway
,
2036 struct radix_node_head
*rnh
= rt_tables
[AF_INET6
];
2038 /* We'll care only link-local addresses */
2039 if (!IN6_IS_ADDR_LINKLOCAL(gateway
)) {
2042 lck_mtx_lock(rt_mtx
);
2043 /* XXX: hack for KAME's link-local address kludge */
2044 gateway
->s6_addr16
[1] = htons(ifp
->if_index
);
2046 rnh
->rnh_walktree(rnh
, rt6_deleteroute
, (void *)gateway
);
2047 lck_mtx_unlock(rt_mtx
);
2052 struct radix_node
*rn
,
2055 #define SIN6(s) ((struct sockaddr_in6 *)s)
2056 struct rtentry
*rt
= (struct rtentry
*)rn
;
2057 struct in6_addr
*gate
= (struct in6_addr
*)arg
;
2059 lck_mtx_assert(rt_mtx
, LCK_MTX_ASSERT_OWNED
);
2061 if (rt
->rt_gateway
== NULL
|| rt
->rt_gateway
->sa_family
!= AF_INET6
)
2064 if (!IN6_ARE_ADDR_EQUAL(gate
, &SIN6(rt
->rt_gateway
)->sin6_addr
))
2068 * Do not delete a static route.
2069 * XXX: this seems to be a bit ad-hoc. Should we consider the
2070 * 'cloned' bit instead?
2072 if ((rt
->rt_flags
& RTF_STATIC
) != 0)
2076 * We delete only host route. This means, in particular, we don't
2077 * delete default route.
2079 if ((rt
->rt_flags
& RTF_HOST
) == 0)
2082 return(rtrequest_locked(RTM_DELETE
, rt_key(rt
),
2083 rt
->rt_gateway
, rt_mask(rt
), rt
->rt_flags
, 0));
2088 nd6_setdefaultiface(
2093 if (ifindex
< 0 || if_index
< ifindex
)
2096 lck_mtx_lock(nd6_mutex
);
2097 if (nd6_defifindex
!= ifindex
) {
2098 nd6_defifindex
= ifindex
;
2099 if (nd6_defifindex
> 0)
2100 nd6_defifp
= ifindex2ifnet
[nd6_defifindex
];
2105 * If the Default Router List is empty, install a route
2106 * to the specified interface as default or remove the default
2107 * route when the default interface becomes canceled.
2108 * The check for the queue is actually redundant, but
2109 * we do this here to avoid re-install the default route
2110 * if the list is NOT empty.
2112 if (TAILQ_FIRST(&nd_defrouter
) == NULL
)
2116 * Our current implementation assumes one-to-one maping between
2117 * interfaces and links, so it would be natural to use the
2118 * default interface as the default link.
2120 scope6_setdefault(nd6_defifp
);
2123 lck_mtx_unlock(nd6_mutex
);