]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/in6_prefix.c
2 * Copyright (c) 2008 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 /* $KAME: in6_prefix.c,v 1.27 2000/03/29 23:13:13 itojun Exp $ */
32 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the project nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * Copyright (c) 1982, 1986, 1991, 1993
62 * The Regents of the University of California. All rights reserved.
64 * Redistribution and use in source and binary forms, with or without
65 * modification, are permitted provided that the following conditions
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright
70 * notice, this list of conditions and the following disclaimer in the
71 * documentation and/or other materials provided with the distribution.
72 * 3. All advertising materials mentioning features or use of this software
73 * must display the following acknowledgement:
74 * This product includes software developed by the University of
75 * California, Berkeley and its contributors.
76 * 4. Neither the name of the University nor the names of its contributors
77 * may be used to endorse or promote products derived from this software
78 * without specific prior written permission.
80 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
81 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
86 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
87 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
88 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
89 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * @(#)in.c 8.2 (Berkeley) 11/15/93
95 #include <sys/param.h>
96 #include <sys/malloc.h>
97 #include <sys/kernel.h>
98 #include <sys/socket.h>
99 #include <sys/socketvar.h>
100 #include <sys/sockio.h>
101 #include <sys/systm.h>
102 #include <sys/syslog.h>
103 #include <sys/proc.h>
107 #include <netinet/in.h>
108 #include <netinet/in_var.h>
109 #include <netinet/ip6.h>
110 #include <netinet6/in6_prefix.h>
111 #include <netinet6/ip6_var.h>
114 #define M_IP6RR M_IP6MISC
115 #define M_RR_ADDR M_IP6MISC
117 static MALLOC_DEFINE(M_IP6RR
, "ip6rr", "IPv6 Router Renumbering Prefix");
118 static MALLOC_DEFINE(M_RR_ADDR
, "rp_addr", "IPv6 Router Renumbering Ifid");
121 struct rr_prhead rr_prefix
;
123 #include <net/net_osdep.h>
125 static void add_each_addr(struct socket
*so
, struct rr_prefix
*rpp
,
126 struct rp_addr
*rap
);
127 static int create_ra_entry(struct rp_addr
**rapp
);
128 static int add_each_prefix(struct socket
*so
, struct rr_prefix
*rpp
);
129 static void free_rp_entries(struct rr_prefix
*rpp
);
130 static int link_stray_ia6s(struct rr_prefix
*rpp
);
131 static void rp_remove(struct rr_prefix
*rpp
);
132 extern lck_mtx_t
*prefix6_mutex
;
135 * Copy bits from src to tgt, from off bit for len bits.
136 * Caller must specify collect tgtsize and srcsize.
139 bit_copy(char *tgt
, u_int tgtsize
, char *src
, u_int srcsize
,
140 u_int off
, u_int len
)
144 /* arg values check */
145 if (srcsize
< off
|| srcsize
< (off
+ len
) ||
146 tgtsize
< off
|| tgtsize
< (off
+ len
)) {
148 "in6_prefix.c: bit_copy: invalid args: srcsize %d,\n"
149 "tgtsize %d, off %d, len %d\n", srcsize
, tgtsize
, off
,
154 /* search start point */
155 for (sp
= src
, tp
= tgt
; off
>= 8; sp
++, tp
++)
157 /* copy starting bits */
162 startbits
= min((8 - off
), len
);
164 for (setbit
= (0x80 >> off
); startbits
;
165 setbit
>>= 1, startbits
--, len
--)
166 *tp
|= (setbit
& *sp
);
170 /* copy midium bits */
171 for (; len
>= 8; sp
++, tp
++) {
175 /* copy ending bits */
179 for (setbit
= 0x80; len
; setbit
>>= 1, len
--)
180 *tp
|= (setbit
& *sp
);
184 static struct ifprefix
*
185 in6_prefixwithifp(struct ifnet
*ifp
, int plen
, struct in6_addr
*dst
)
187 struct ifprefix
*ifpr
;
189 /* search matched prefix */
190 ifnet_lock_shared(ifp
);
191 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
192 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
194 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
195 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
197 if (plen
<= in6_matchlen(dst
, IFPR_IN6(ifpr
)))
200 ifnet_lock_done(ifp
);
206 * Search prefix which matches arg prefix as specified in
207 * draft-ietf-ipngwg-router-renum-08.txt
209 static struct rr_prefix
*
210 search_matched_prefix(struct ifnet
*ifp
, struct in6_prefixreq
*ipr
)
212 struct ifprefix
*ifpr
;
214 struct rr_prefix
*rpp
;
216 /* search matched prefix */
217 ifpr
= in6_prefixwithifp(ifp
, ipr
->ipr_plen
,
218 &ipr
->ipr_prefix
.sin6_addr
);
220 return ifpr2rp(ifpr
);
223 * search matched addr, and then search prefix
224 * which matches the addr
227 ifnet_lock_shared(ifp
);
228 TAILQ_FOREACH(ifa
, &ifp
->if_addrlist
, ifa_list
)
230 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
233 in6_matchlen(&ipr
->ipr_prefix
.sin6_addr
, IFA_IN6(ifa
)))
237 ifnet_lock_done(ifp
);
241 rpp
= ifpr2rp(((struct in6_ifaddr
*)ifa
)->ia6_ifpr
);
243 ifnet_lock_done(ifp
);
247 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
248 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
250 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
251 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
253 if (ifpr
->ifpr_plen
<= in6_matchlen(IFA_IN6(ifa
),
257 ifnet_lock_done(ifp
);
259 log(LOG_ERR
, "in6_prefix.c: search_matched_prefix: addr %s"
260 "has no pointer to prefix %s\n", ip6_sprintf(IFA_IN6(ifa
)),
261 ip6_sprintf(IFPR_IN6(ifpr
)));
262 return ifpr2rp(ifpr
);
266 * Search prefix which matches arg prefix as specified in
267 * draft-ietf-ipngwg-router-renum-08.txt, and mark it if exists.
268 * Return 1 if anything matched, and 0 if nothing matched.
271 mark_matched_prefixes(u_int32_t cmd
, struct ifnet
*ifp
, struct in6_rrenumreq
*irr
)
273 struct ifprefix
*ifpr
;
275 int matchlen
, matched
= 0;
277 /* search matched prefixes */
278 ifnet_lock_exclusive(ifp
); /* Should if_prefixhead be protected by IPv6?? */
279 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
280 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
282 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
283 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
285 matchlen
= in6_matchlen(&irr
->irr_matchprefix
.sin6_addr
,
287 if (irr
->irr_m_minlen
> ifpr
->ifpr_plen
||
288 irr
->irr_m_maxlen
< ifpr
->ifpr_plen
||
289 irr
->irr_m_len
> matchlen
)
292 ifpr2rp(ifpr
)->rp_statef_addmark
= 1;
293 if (cmd
== SIOCCIFPREFIX_IN6
)
294 ifpr2rp(ifpr
)->rp_statef_delmark
= 1;
298 * search matched addr, and then search prefixes
299 * which matche the addr
301 TAILQ_FOREACH(ifa
, &ifp
->if_addrlist
, ifa_list
)
303 struct rr_prefix
*rpp
;
305 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
307 matchlen
= in6_matchlen(&irr
->irr_matchprefix
.sin6_addr
,
309 if (irr
->irr_m_minlen
> matchlen
||
310 irr
->irr_m_maxlen
< matchlen
|| irr
->irr_m_len
> matchlen
)
312 rpp
= ifpr2rp(((struct in6_ifaddr
*)ifa
)->ia6_ifpr
);
315 rpp
->rp_statef_addmark
= 1;
316 if (cmd
== SIOCCIFPREFIX_IN6
)
317 rpp
->rp_statef_delmark
= 1;
319 log(LOG_WARNING
, "in6_prefix.c: mark_matched_prefixes:"
320 "no back pointer to ifprefix for %s. "
321 "ND autoconfigured addr?\n",
322 ip6_sprintf(IFA_IN6(ifa
)));
324 ifnet_lock_done(ifp
);
329 * Mark global prefixes as to be deleted.
332 delmark_global_prefixes(struct ifnet
*ifp
, __unused
struct in6_rrenumreq
*irr
)
334 struct ifprefix
*ifpr
;
336 /* search matched prefixes */
337 ifnet_lock_exclusive(ifp
);
338 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
339 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
341 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
342 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
344 /* mark delete global prefix */
345 if (in6_addrscope(RP_IN6(ifpr2rp(ifpr
))) ==
346 IPV6_ADDR_SCOPE_GLOBAL
)
347 ifpr2rp(ifpr
)->rp_statef_delmark
= 1;
349 ifnet_lock_done(ifp
);
352 /* Unmark prefixes */
354 unmark_prefixes(struct ifnet
*ifp
)
356 struct ifprefix
*ifpr
;
358 /* unmark all prefix */
359 ifnet_lock_exclusive(ifp
);
360 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
361 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
363 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
364 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
367 ifpr2rp(ifpr
)->rp_statef_addmark
= 0;
368 ifpr2rp(ifpr
)->rp_statef_delmark
= 0;
370 ifnet_lock_done(ifp
);
375 init_prefix_ltimes(struct rr_prefix
*rpp
)
377 struct timeval timenow
;
379 getmicrotime(&timenow
);
381 if (rpp
->rp_pltime
== RR_INFINITE_LIFETIME
||
382 rpp
->rp_rrf_decrprefd
== 0)
383 rpp
->rp_preferred
= 0;
385 rpp
->rp_preferred
= timenow
.tv_sec
+ rpp
->rp_pltime
;
386 if (rpp
->rp_vltime
== RR_INFINITE_LIFETIME
||
387 rpp
->rp_rrf_decrvalid
== 0)
390 rpp
->rp_expire
= timenow
.tv_sec
+ rpp
->rp_vltime
;
394 rr_are_ifid_equal(struct in6_addr
*ii1
, struct in6_addr
*ii2
, int ii_len
)
396 int ii_bytelen
, ii_bitlen
;
397 int p_bytelen
, p_bitlen
;
401 ii_len
> 124) { /* as RFC2373, prefix is at least 4 bit */
402 log(LOG_ERR
, "rr_are_ifid_equal: invalid ifid length(%d)\n",
407 ii_bytelen
= ii_len
/ 8;
408 ii_bitlen
= ii_len
% 8;
410 p_bytelen
= sizeof(struct in6_addr
) - ii_bytelen
- 1;
411 p_bitlen
= 8 - ii_bitlen
;
413 if (bcmp(ii1
->s6_addr
+ p_bytelen
+ 1, ii2
->s6_addr
+ p_bytelen
+ 1,
416 if (((ii1
->s6_addr
[p_bytelen
] << p_bitlen
) & 0xff) !=
417 ((ii2
->s6_addr
[p_bytelen
] << p_bitlen
) & 0xff))
423 static struct rp_addr
*
424 search_ifidwithprefix(struct rr_prefix
*rpp
, struct in6_addr
*ifid
)
428 lck_mtx_lock(prefix6_mutex
);
429 LIST_FOREACH(rap
, &rpp
->rp_addrhead
, ra_entry
)
431 if (rr_are_ifid_equal(ifid
, &rap
->ra_ifid
,
432 (sizeof(struct in6_addr
) << 3) -
436 lck_mtx_unlock(prefix6_mutex
);
441 assign_ra_entry(struct rr_prefix
*rpp
, int iilen
, struct in6_ifaddr
*ia
)
446 if ((error
= create_ra_entry(&rap
)) != 0)
449 /* copy interface id part */
450 bit_copy((caddr_t
)&rap
->ra_ifid
, sizeof(rap
->ra_ifid
) << 3,
451 (caddr_t
)IA6_IN6(ia
),
452 sizeof(*IA6_IN6(ia
)) << 3, rpp
->rp_plen
, iilen
);
453 /* link to ia, and put into list */
455 ifaref(&rap
->ra_addr
->ia_ifa
);
456 #if 0 /* Can't do this now, because rpp may be on th stack. should fix it? */
457 ia
->ia6_ifpr
= rp2ifpr(rpp
);
459 lck_mtx_lock(prefix6_mutex
);
460 LIST_INSERT_HEAD(&rpp
->rp_addrhead
, rap
, ra_entry
);
461 lck_mtx_unlock(prefix6_mutex
);
467 * add a link-local address to an interface. we will add new interface address
468 * (prefix database + new interface id).
471 in6_prefix_add_llifid(__unused
int iilen
, struct in6_ifaddr
*ia
)
473 struct rr_prefix
*rpp
;
478 if ((error
= create_ra_entry(&rap
)) != 0)
480 /* copy interface id part */
481 bit_copy((caddr_t
)&rap
->ra_ifid
, sizeof(rap
->ra_ifid
) << 3,
482 (caddr_t
)IA6_IN6(ia
), sizeof(*IA6_IN6(ia
)) << 3,
483 64, (sizeof(rap
->ra_ifid
) << 3) - 64);
484 /* XXX: init dummy so */
485 bzero(&so
, sizeof(so
));
486 /* insert into list */
487 lck_mtx_lock(prefix6_mutex
);
488 LIST_FOREACH(rpp
, &rr_prefix
, rp_entry
)
491 * do not attempt to add an address, if ifp does not match
493 if (rpp
->rp_ifp
!= ia
->ia_ifp
)
496 LIST_INSERT_HEAD(&rpp
->rp_addrhead
, rap
, ra_entry
);
497 add_each_addr(&so
, rpp
, rap
);
499 lck_mtx_unlock(prefix6_mutex
);
504 * add an address to an interface. if the interface id portion is new,
505 * we will add new interface address (prefix database + new interface id).
508 in6_prefix_add_ifid(int iilen
, struct in6_ifaddr
*ia
)
510 int plen
= (sizeof(*IA6_IN6(ia
)) << 3) - iilen
;
511 struct ifprefix
*ifpr
;
515 if (IN6_IS_ADDR_LINKLOCAL(IA6_IN6(ia
)))
516 return(in6_prefix_add_llifid(iilen
, ia
));
517 ifpr
= in6_prefixwithifp(ia
->ia_ifp
, plen
, IA6_IN6(ia
));
521 int pplen
= (plen
== 128) ? 64 : plen
; /* XXX hardcoded 64 is bad */
523 /* allocate a prefix for ia, with default properties */
526 bzero(&rp
, sizeof(rp
));
527 rp
.rp_type
= IN6_PREFIX_RR
;
528 rp
.rp_ifp
= ia
->ia_ifp
;
530 rp
.rp_prefix
.sin6_len
= sizeof(rp
.rp_prefix
);
531 rp
.rp_prefix
.sin6_family
= AF_INET6
;
532 bit_copy((char *)RP_IN6(&rp
), sizeof(*RP_IN6(&rp
)) << 3,
533 (char *)&ia
->ia_addr
.sin6_addr
,
534 sizeof(ia
->ia_addr
.sin6_addr
) << 3,
536 rp
.rp_vltime
= rp
.rp_pltime
= RR_INFINITE_LIFETIME
;
537 rp
.rp_raf_onlink
= 1;
539 /* Is some FlagMasks for rrf necessary? */
540 rp
.rp_rrf_decrvalid
= rp
.rp_rrf_decrprefd
= 0;
541 rp
.rp_origin
= PR_ORIG_RR
; /* can be renumbered */
543 /* create ra_entry */
544 error
= link_stray_ia6s(&rp
);
546 free_rp_entries(&rp
);
550 /* XXX: init dummy so */
551 bzero(&so
, sizeof(so
));
553 error
= add_each_prefix(&so
, &rp
);
555 /* free each rp_addr entry */
556 free_rp_entries(&rp
);
562 ifpr
= in6_prefixwithifp(ia
->ia_ifp
, pplen
, IA6_IN6(ia
));
566 rap
= search_ifidwithprefix(ifpr2rp(ifpr
), IA6_IN6(ia
));
568 if (rap
->ra_addr
== NULL
) {
570 ifaref(&rap
->ra_addr
->ia_ifa
);
571 } else if (rap
->ra_addr
!= ia
) {
572 /* There may be some inconsistencies between addrs. */
573 log(LOG_ERR
, "ip6_prefix.c: addr %s/%d matched prefix"
574 " already has another ia %p(%s) on its ifid list\n",
575 ip6_sprintf(IA6_IN6(ia
)), plen
,
577 ip6_sprintf(IA6_IN6(rap
->ra_addr
)));
578 return EADDRINUSE
/* XXX */;
583 error
= assign_ra_entry(ifpr2rp(ifpr
), iilen
, ia
);
590 in6_prefix_remove_ifid(__unused
int iilen
, struct in6_ifaddr
*ia
)
594 if (ia
->ia6_ifpr
== NULL
)
596 rap
= search_ifidwithprefix(ifpr2rp(ia
->ia6_ifpr
), IA6_IN6(ia
));
598 lck_mtx_lock(prefix6_mutex
);
599 LIST_REMOVE(rap
, ra_entry
);
600 lck_mtx_unlock(prefix6_mutex
);
602 ifafree(&rap
->ra_addr
->ia_ifa
);
603 FREE(rap
, M_RR_ADDR
);
606 if (LIST_EMPTY(&ifpr2rp(ia
->ia6_ifpr
)->rp_addrhead
))
607 rp_remove(ifpr2rp(ia
->ia6_ifpr
));
614 struct ifprefix
*ifpr
, *nextifpr
;
616 /* delete prefixes before ifnet goes away */
617 ifnet_lock_exclusive(ifp
);
618 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
;
621 nextifpr
= TAILQ_NEXT(ifpr
, ifpr_list
);
622 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
623 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
625 (void)delete_each_prefix(ifpr2rp(ifpr
), PR_ORIG_KERNEL
);
627 ifnet_lock_done(ifp
);
631 add_each_addr(struct socket
*so
, struct rr_prefix
*rpp
, struct rp_addr
*rap
)
633 struct in6_ifaddr
*ia6
;
634 struct in6_aliasreq ifra
;
635 struct proc
*p
= current_proc();
636 int error
, p64
= proc_is64bit(p
);
639 bzero(&ifra
, sizeof(ifra
));
640 strncpy(ifra
.ifra_name
, if_name(rpp
->rp_ifp
), sizeof(ifra
.ifra_name
));
641 ifra
.ifra_addr
.sin6_family
= ifra
.ifra_prefixmask
.sin6_family
=
643 ifra
.ifra_addr
.sin6_len
= ifra
.ifra_prefixmask
.sin6_len
=
644 sizeof(ifra
.ifra_addr
);
645 /* copy prefix part */
646 bit_copy((char *)&ifra
.ifra_addr
.sin6_addr
,
647 sizeof(ifra
.ifra_addr
.sin6_addr
) << 3,
648 (char *)RP_IN6(rpp
), sizeof(*RP_IN6(rpp
)) << 3,
650 /* copy interface id part */
651 bit_copy((char *)&ifra
.ifra_addr
.sin6_addr
,
652 sizeof(ifra
.ifra_addr
.sin6_addr
) << 3,
653 (char *)&rap
->ra_ifid
, sizeof(rap
->ra_ifid
) << 3,
654 rpp
->rp_plen
, (sizeof(rap
->ra_ifid
) << 3) - rpp
->rp_plen
);
655 in6_prefixlen2mask(&ifra
.ifra_prefixmask
.sin6_addr
, rpp
->rp_plen
);
656 /* don't care ifra_flags for now */
659 * XXX: if we did this with finite lifetime values, the lifetimes would
660 * decrese in time and never incremented.
661 * we should need more clarifications on the prefix mechanism...
663 ifra
.ifra_lifetime
.ia6t_vltime
= rpp
->rp_vltime
;
664 ifra
.ifra_lifetime
.ia6t_pltime
= rpp
->rp_pltime
;
666 ia6
= in6ifa_ifpwithaddr(rpp
->rp_ifp
, &ifra
.ifra_addr
.sin6_addr
);
668 if (ia6
->ia6_ifpr
== NULL
) {
669 /* link this addr and the prefix each other */
671 ifafree(&rap
->ra_addr
->ia_ifa
);
672 /* Reference held in in6ifa_ifpwithaddr() */
674 ia6
->ia6_ifpr
= rp2ifpr(rpp
);
677 if (ia6
->ia6_ifpr
== rp2ifpr(rpp
)) {
679 ifafree(&rap
->ra_addr
->ia_ifa
);
680 /* Reference held in in6ifa_ifpwithaddr() */
685 * The addr is already assigned to other
687 * There may be some inconsistencies between
689 * e.g. overraped prefixes with common starting
690 * part and different plefixlen.
691 * Or, completely duplicated prefixes?
695 "in6_prefix.c: add_each_addr: addition of an addr %s/%d "
696 "failed because there is already another addr %s/%d\n",
697 ip6_sprintf(&ifra
.ifra_addr
.sin6_addr
), rpp
->rp_plen
,
698 ip6_sprintf(IA6_IN6(ia6
)),
699 in6_mask2len(&ia6
->ia_prefixmask
.sin6_addr
, NULL
));
700 ifafree(&ia6
->ia_ifa
);
703 /* propagate ANYCAST flag if it is set for ancestor addr */
704 if (rap
->ra_flags
.anycast
!= 0)
705 ifra
.ifra_flags
|= IN6_IFF_ANYCAST
;
708 #if defined(__LP64__)
709 struct in6_aliasreq_32 ifra_32
;
711 * Use 32-bit ioctl and structure for 32-bit process.
713 in6_aliasreq_64_to_32((struct in6_aliasreq_64
*)&ifra
,
715 error
= in6_control(so
, SIOCAIFADDR_IN6_32
, (caddr_t
)&ifra_32
,
718 error
= in6_control(so
, SIOCAIFADDR_IN6
, (caddr_t
)&ifra
,
720 #endif /* __LP64__ */
722 #if defined(__LP64__)
723 error
= in6_control(so
, SIOCAIFADDR_IN6
, (caddr_t
)&ifra
,
726 struct in6_aliasreq_64 ifra_64
;
728 * Use 32-bit ioctl and structure for 32-bit process.
730 in6_aliasreq_32_to_64((struct in6_aliasreq_32
*)&ifra
,
732 error
= in6_control(so
, SIOCAIFADDR_IN6_64
, (caddr_t
)&ifra_64
,
734 #endif /* __LP64__ */
738 log(LOG_ERR
, "in6_prefix.c: add_each_addr: addition of an addr"
739 "%s/%d failed because in6_control failed for error %d\n",
740 ip6_sprintf(&ifra
.ifra_addr
.sin6_addr
), rpp
->rp_plen
,
746 * link beween this addr and the prefix will be done
747 * in in6_prefix_add_ifid
752 rrpr_update(struct socket
*so
, struct rr_prefix
*new)
754 struct rr_prefix
*rpp
;
755 struct ifprefix
*ifpr
;
758 /* search existing prefix */
759 ifnet_lock_exclusive(new->rp_ifp
);
760 for (ifpr
= TAILQ_FIRST(&new->rp_ifp
->if_prefixhead
); ifpr
;
761 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
763 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
764 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
766 if (ifpr
->ifpr_plen
== new->rp_plen
&&
767 in6_are_prefix_equal(IFPR_IN6(ifpr
), RP_IN6(new),
774 * We got a prefix which we have seen in the past.
777 * If the origin of the already-installed prefix is more
778 * preferable than the new one, ignore installation request.
780 if (rpp
->rp_origin
> new->rp_origin
) {
781 ifnet_lock_done(new->rp_ifp
);
785 /* update prefix information */
786 rpp
->rp_flags
.prf_ra
= new->rp_flags
.prf_ra
;
787 if (rpp
->rp_origin
>= PR_ORIG_RR
)
788 rpp
->rp_flags
.prf_rr
= new->rp_flags
.prf_rr
;
789 rpp
->rp_vltime
= new->rp_vltime
;
790 rpp
->rp_pltime
= new->rp_pltime
;
791 rpp
->rp_expire
= new->rp_expire
;
792 rpp
->rp_preferred
= new->rp_preferred
;
793 rpp
->rp_statef_delmark
= 0; /* cancel deletion */
795 * Interface id related update.
796 * add rp_addr entries in new into rpp, if they have not
797 * been already included in rpp.
799 lck_mtx_lock(prefix6_mutex
);
800 while (!LIST_EMPTY(&new->rp_addrhead
))
802 rap
= LIST_FIRST(&new->rp_addrhead
);
803 LIST_REMOVE(rap
, ra_entry
);
804 if (search_ifidwithprefix(rpp
, &rap
->ra_ifid
)
807 ifafree(&rap
->ra_addr
->ia_ifa
);
808 FREE(rap
, M_RR_ADDR
);
811 LIST_INSERT_HEAD(&rpp
->rp_addrhead
, rap
, ra_entry
);
813 lck_mtx_unlock(prefix6_mutex
);
816 * We got a fresh prefix.
818 /* create new prefix */
819 rpp
= (struct rr_prefix
*)_MALLOC(sizeof(*rpp
), M_IP6RR
,
822 log(LOG_ERR
, "in6_prefix.c: rrpr_update:%d"
823 ": ENOBUFS for rr_prefix\n", __LINE__
);
824 ifnet_lock_done(new->rp_ifp
);
828 lck_mtx_lock(prefix6_mutex
);
830 LIST_INIT(&rpp
->rp_addrhead
);
831 /* move rp_addr entries of new to rpp */
832 while (!LIST_EMPTY(&new->rp_addrhead
))
834 rap
= LIST_FIRST(&new->rp_addrhead
);
835 LIST_REMOVE(rap
, ra_entry
);
836 LIST_INSERT_HEAD(&rpp
->rp_addrhead
, rap
, ra_entry
);
838 lck_mtx_unlock(prefix6_mutex
);
840 /* let rp_ifpr.ifpr_prefix point rr_prefix. */
841 rpp
->rp_ifpr
.ifpr_prefix
= (struct sockaddr
*)&rpp
->rp_prefix
;
842 /* link rr_prefix entry to if_prefixlist */
844 struct ifnet
*ifp
= rpp
->rp_ifp
;
846 if ((ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
))
848 for ( ; TAILQ_NEXT(ifpr
, ifpr_list
);
849 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
))
851 TAILQ_NEXT(ifpr
, ifpr_list
) = rp2ifpr(rpp
);
853 TAILQ_FIRST(&ifp
->if_prefixhead
) =
855 rp2ifpr(rpp
)->ifpr_type
= IN6_PREFIX_RR
;
857 /* link rr_prefix entry to rr_prefix list */
858 lck_mtx_lock(prefix6_mutex
);
859 LIST_INSERT_HEAD(&rr_prefix
, rpp
, rp_entry
);
860 lck_mtx_unlock(prefix6_mutex
);
862 ifnet_lock_done(new->rp_ifp
);
864 if (!new->rp_raf_auto
)
868 * Add an address for each interface id, if it is not yet
869 * If it existed but not pointing to the prefix yet,
870 * init the prefix pointer.
872 lck_mtx_lock(prefix6_mutex
);
873 LIST_FOREACH(rap
, &rpp
->rp_addrhead
, ra_entry
)
875 if (rap
->ra_addr
!= NULL
) {
876 if (rap
->ra_addr
->ia6_ifpr
== NULL
)
877 rap
->ra_addr
->ia6_ifpr
= rp2ifpr(rpp
);
880 add_each_addr(so
, rpp
, rap
);
882 lck_mtx_unlock(prefix6_mutex
);
887 add_each_prefix(struct socket
*so
, struct rr_prefix
*rpp
)
889 init_prefix_ltimes(rpp
);
890 return(rrpr_update(so
, rpp
));
894 rp_remove(struct rr_prefix
*rpp
)
897 /* unlink rp_entry from if_prefixlist */
898 lck_mtx_lock(prefix6_mutex
);
900 struct ifnet
*ifp
= rpp
->rp_ifp
;
901 struct ifprefix
*ifpr
;
903 ifnet_lock_exclusive(ifp
);
904 if ((ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
)) == rp2ifpr(rpp
))
905 TAILQ_FIRST(&ifp
->if_prefixhead
) =
906 TAILQ_NEXT(ifpr
, ifpr_list
);
908 while (TAILQ_NEXT(ifpr
, ifpr_list
) != NULL
&&
909 (TAILQ_NEXT(ifpr
, ifpr_list
) != rp2ifpr(rpp
)))
910 ifpr
= TAILQ_NEXT(ifpr
, ifpr_list
);
911 if (TAILQ_NEXT(ifpr
, ifpr_list
))
912 TAILQ_NEXT(ifpr
, ifpr_list
) =
913 TAILQ_NEXT(rp2ifpr(rpp
), ifpr_list
);
915 printf("Couldn't unlink rr_prefix from ifp\n");
917 ifnet_lock_done(ifp
);
919 /* unlink rp_entry from rr_prefix list */
920 LIST_REMOVE(rpp
, rp_entry
);
921 lck_mtx_unlock(prefix6_mutex
);
926 create_ra_entry(struct rp_addr
**rapp
)
928 *rapp
= (struct rp_addr
*)_MALLOC(sizeof(struct rp_addr
), M_RR_ADDR
,
931 log(LOG_ERR
, "in6_prefix.c:%d: ENOBUFS"
932 "for rp_addr\n", __LINE__
);
935 bzero(*rapp
, sizeof(*(*rapp
)));
942 init_newprefix(struct in6_rrenumreq
*irr
, struct ifprefix
*ifpr
,
943 struct rr_prefix
*rpp
)
945 struct rp_addr
*orap
;
948 bzero(rpp
, sizeof(*rpp
));
949 rpp
->rp_type
= IN6_PREFIX_RR
;
950 rpp
->rp_ifp
= ifpr
->ifpr_ifp
;
951 rpp
->rp_plen
= ifpr
->ifpr_plen
;
952 rpp
->rp_prefix
.sin6_len
= sizeof(rpp
->rp_prefix
);
953 rpp
->rp_prefix
.sin6_family
= AF_INET6
;
954 bit_copy((char *)RP_IN6(rpp
), sizeof(*RP_IN6(rpp
)) << 3,
955 (char *)&irr
->irr_useprefix
.sin6_addr
,
956 sizeof(irr
->irr_useprefix
.sin6_addr
) << 3,
957 0, irr
->irr_u_uselen
);
958 /* copy keeplen part if necessary as necessary len */
959 if (irr
->irr_u_uselen
< ifpr
->ifpr_plen
)
960 bit_copy((char *)RP_IN6(rpp
), sizeof(*RP_IN6(rpp
)) << 3,
961 (char *)IFPR_IN6(ifpr
), sizeof(*IFPR_IN6(ifpr
)) << 3,
963 min(ifpr
->ifpr_plen
- irr
->irr_u_uselen
,
964 irr
->irr_u_keeplen
));
965 lck_mtx_lock(prefix6_mutex
);
966 LIST_FOREACH(orap
, &(ifpr2rp(ifpr
)->rp_addrhead
), ra_entry
)
971 if ((error
= create_ra_entry(&rap
)) != 0)
973 rap
->ra_ifid
= orap
->ra_ifid
;
974 rap
->ra_flags
.anycast
= (orap
->ra_addr
!= NULL
&&
975 (orap
->ra_addr
->ia6_flags
&
976 IN6_IFF_ANYCAST
) != 0) ? 1 : 0;
977 LIST_INSERT_HEAD(&rpp
->rp_addrhead
, rap
, ra_entry
);
979 rpp
->rp_vltime
= irr
->irr_vltime
;
980 rpp
->rp_pltime
= irr
->irr_pltime
;
981 rpp
->rp_raf_onlink
= irr
->irr_raf_mask_onlink
? irr
->irr_raf_onlink
:
982 ifpr2rp(ifpr
)->rp_raf_onlink
;
983 rpp
->rp_raf_auto
= irr
->irr_raf_mask_auto
? irr
->irr_raf_auto
:
984 ifpr2rp(ifpr
)->rp_raf_auto
;
985 /* Is some FlagMasks for rrf necessary? */
986 rpp
->rp_rrf
= irr
->irr_rrf
;
987 rpp
->rp_origin
= irr
->irr_origin
;
988 lck_mtx_unlock(prefix6_mutex
);
995 free_rp_entries(struct rr_prefix
*rpp
)
998 * This func is only called with rpp on stack(not on list).
999 * So no splnet() here
1001 lck_mtx_lock(prefix6_mutex
);
1002 while (!LIST_EMPTY(&rpp
->rp_addrhead
))
1004 struct rp_addr
*rap
;
1006 rap
= LIST_FIRST(&rpp
->rp_addrhead
);
1007 LIST_REMOVE(rap
, ra_entry
);
1009 ifafree(&rap
->ra_addr
->ia_ifa
);
1010 FREE(rap
, M_RR_ADDR
);
1012 lck_mtx_unlock(prefix6_mutex
);
1017 add_useprefixes(struct socket
*so
, struct ifnet
*ifp
,
1018 struct in6_rrenumreq
*irr
)
1020 struct ifprefix
*ifpr
, *nextifpr
;
1021 struct rr_prefix rp
;
1024 /* add prefixes to each of marked prefix */
1025 ifnet_lock_exclusive(ifp
);
1026 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
; ifpr
= nextifpr
)
1028 nextifpr
= TAILQ_NEXT(ifpr
, ifpr_list
);
1029 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
1030 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
1032 if (ifpr2rp(ifpr
)->rp_statef_addmark
) {
1033 if ((error
= init_newprefix(irr
, ifpr
, &rp
)) != 0)
1035 error
= add_each_prefix(so
, &rp
);
1038 ifnet_lock_done(ifp
);
1039 /* free each rp_addr entry */
1040 free_rp_entries(&rp
);
1047 unprefer_prefix(struct rr_prefix
*rpp
)
1049 struct rp_addr
*rap
;
1050 struct timeval timenow
;
1052 getmicrotime(&timenow
);
1054 lck_mtx_lock(prefix6_mutex
);
1055 for (rap
= rpp
->rp_addrhead
.lh_first
; rap
!= NULL
;
1056 rap
= rap
->ra_entry
.le_next
) {
1057 if (rap
->ra_addr
== NULL
)
1059 rap
->ra_addr
->ia6_lifetime
.ia6t_preferred
= timenow
.tv_sec
;
1060 rap
->ra_addr
->ia6_lifetime
.ia6t_pltime
= 0;
1062 lck_mtx_unlock(prefix6_mutex
);
1067 delete_each_prefix(struct rr_prefix
*rpp
, u_char origin
)
1071 if (rpp
->rp_origin
> origin
)
1074 lck_mtx_lock(prefix6_mutex
);
1075 while (rpp
->rp_addrhead
.lh_first
!= NULL
) {
1076 struct rp_addr
*rap
;
1078 rap
= LIST_FIRST(&rpp
->rp_addrhead
);
1082 LIST_REMOVE(rap
, ra_entry
);
1083 if (rap
->ra_addr
== NULL
) {
1084 FREE(rap
, M_RR_ADDR
);
1087 rap
->ra_addr
->ia6_ifpr
= NULL
;
1089 in6_purgeaddr(&rap
->ra_addr
->ia_ifa
, 0);
1090 ifafree(&rap
->ra_addr
->ia_ifa
);
1091 FREE(rap
, M_RR_ADDR
);
1094 lck_mtx_unlock(prefix6_mutex
);
1101 delete_prefixes(struct ifnet
*ifp
, u_char origin
)
1103 struct ifprefix
*ifpr
, *nextifpr
;
1105 /* delete prefixes marked as tobe deleted */
1106 ifnet_lock_exclusive(ifp
);
1107 for (ifpr
= TAILQ_FIRST(&ifp
->if_prefixhead
); ifpr
; ifpr
= nextifpr
)
1109 nextifpr
= TAILQ_NEXT(ifpr
, ifpr_list
);
1110 if (ifpr
->ifpr_prefix
->sa_family
!= AF_INET6
||
1111 ifpr
->ifpr_type
!= IN6_PREFIX_RR
)
1113 if (ifpr2rp(ifpr
)->rp_statef_delmark
)
1114 (void)delete_each_prefix(ifpr2rp(ifpr
), origin
);
1116 ifnet_lock_done(ifp
);
1121 link_stray_ia6s(struct rr_prefix
*rpp
)
1125 for (ifa
= rpp
->rp_ifp
->if_addrlist
.tqh_first
; ifa
;
1126 ifa
= ifa
->ifa_list
.tqe_next
)
1128 struct rp_addr
*rap
;
1129 struct rr_prefix
*orpp
;
1132 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
1134 if (rpp
->rp_plen
> in6_matchlen(RP_IN6(rpp
), IFA_IN6(ifa
)))
1137 orpp
= ifpr2rp(((struct in6_ifaddr
*)ifa
)->ia6_ifpr
);
1139 if (!in6_are_prefix_equal(RP_IN6(orpp
), RP_IN6(rpp
),
1141 log(LOG_ERR
, "in6_prefix.c: link_stray_ia6s:"
1142 "addr %s/%d already linked to a prefix"
1143 "and it matches also %s/%d\n",
1144 ip6_sprintf(IFA_IN6(ifa
)), orpp
->rp_plen
,
1145 ip6_sprintf(RP_IN6(rpp
)),
1149 if ((error
= assign_ra_entry(rpp
,
1150 (sizeof(rap
->ra_ifid
) << 3) -
1152 (struct in6_ifaddr
*)ifa
)) != 0)
1159 /* XXX assumes that permission is already checked by the caller */
1161 in6_prefix_ioctl(struct socket
*so
, u_long cmd
, caddr_t data
,
1164 struct rr_prefix
*rpp
, rp_tmp
;
1165 struct rp_addr
*rap
;
1166 struct in6_prefixreq
*ipr
= (struct in6_prefixreq
*)data
;
1167 struct in6_rrenumreq
*irr
= (struct in6_rrenumreq
*)data
;
1172 * Failsafe for erroneous address config program.
1173 * Let's hope rrenumd don't make a mistakes.
1175 if (ipr
->ipr_origin
<= PR_ORIG_RA
)
1176 ipr
->ipr_origin
= PR_ORIG_STATIC
;
1179 case SIOCSGIFPREFIX_IN6
:
1180 delmark_global_prefixes(ifp
, irr
);
1182 case SIOCAIFPREFIX_IN6
:
1183 case SIOCCIFPREFIX_IN6
:
1184 /* check if preferred lifetime > valid lifetime */
1185 if (irr
->irr_pltime
> irr
->irr_vltime
) {
1187 "in6_prefix_ioctl: preferred lifetime"
1188 "(%ld) is greater than valid lifetime(%ld)\n",
1189 (u_int32_t
)irr
->irr_pltime
, (u_int32_t
)irr
->irr_vltime
);
1193 if (mark_matched_prefixes(cmd
, ifp
, irr
)) {
1194 if (irr
->irr_u_uselen
!= 0)
1195 if ((error
= add_useprefixes(so
, ifp
, irr
))
1198 if (cmd
!= SIOCAIFPREFIX_IN6
)
1199 delete_prefixes(ifp
, irr
->irr_origin
);
1201 return (EADDRNOTAVAIL
);
1203 unmark_prefixes(ifp
);
1205 case SIOCGIFPREFIX_IN6
:
1206 rpp
= search_matched_prefix(ifp
, ipr
);
1207 if (rpp
== NULL
|| ifp
!= rpp
->rp_ifp
)
1208 return (EADDRNOTAVAIL
);
1210 ipr
->ipr_origin
= rpp
->rp_origin
;
1211 ipr
->ipr_plen
= rpp
->rp_plen
;
1212 ipr
->ipr_vltime
= rpp
->rp_vltime
;
1213 ipr
->ipr_pltime
= rpp
->rp_pltime
;
1214 ipr
->ipr_flags
= rpp
->rp_flags
;
1215 ipr
->ipr_prefix
= rpp
->rp_prefix
;
1218 case SIOCSIFPREFIX_IN6
:
1219 /* check if preferred lifetime > valid lifetime */
1220 if (ipr
->ipr_pltime
> ipr
->ipr_vltime
) {
1222 "in6_prefix_ioctl: preferred lifetime"
1223 "(%ld) is greater than valid lifetime(%ld)\n",
1224 (u_int32_t
)ipr
->ipr_pltime
, (u_int32_t
)ipr
->ipr_vltime
);
1230 bzero((caddr_t
)&rp_tmp
, sizeof(rp_tmp
));
1231 rp_tmp
.rp_ifp
= ifp
;
1232 rp_tmp
.rp_plen
= ipr
->ipr_plen
;
1233 rp_tmp
.rp_prefix
= ipr
->ipr_prefix
;
1234 rp_tmp
.rp_vltime
= ipr
->ipr_vltime
;
1235 rp_tmp
.rp_pltime
= ipr
->ipr_pltime
;
1236 rp_tmp
.rp_flags
= ipr
->ipr_flags
;
1237 rp_tmp
.rp_origin
= ipr
->ipr_origin
;
1239 /* create rp_addr entries, usually at least for lladdr */
1240 if ((error
= link_stray_ia6s(&rp_tmp
)) != 0) {
1241 free_rp_entries(&rp_tmp
);
1244 ifnet_lock_exclusive(ifp
);
1245 for (ifa
= ifp
->if_addrlist
.tqh_first
;
1247 ifa
= ifa
->ifa_list
.tqe_next
)
1249 if (ifa
->ifa_addr
== NULL
)
1250 continue; /* just for safety */
1251 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
1253 if (IN6_IS_ADDR_LINKLOCAL(IFA_IN6(ifa
)) == 0)
1256 if ((error
= create_ra_entry(&rap
)) != 0) {
1257 free_rp_entries(&rp_tmp
);
1260 /* copy interface id part */
1261 bit_copy((caddr_t
)&rap
->ra_ifid
,
1262 sizeof(rap
->ra_ifid
) << 3,
1263 (caddr_t
)IFA_IN6(ifa
),
1264 sizeof(*IFA_IN6(ifa
)) << 3,
1266 (sizeof(rap
->ra_ifid
) << 3) - rp_tmp
.rp_plen
);
1267 /* insert into list */
1268 lck_mtx_lock(prefix6_mutex
);
1269 LIST_INSERT_HEAD(&rp_tmp
.rp_addrhead
, rap
, ra_entry
);
1270 lck_mtx_unlock(prefix6_mutex
);
1272 ifnet_lock_done(ifp
);
1274 error
= add_each_prefix(so
, &rp_tmp
);
1276 /* free each rp_addr entry */
1277 free_rp_entries(&rp_tmp
);
1280 case SIOCDIFPREFIX_IN6
:
1281 rpp
= search_matched_prefix(ifp
, ipr
);
1282 if (rpp
== NULL
|| ifp
!= rpp
->rp_ifp
)
1283 return (EADDRNOTAVAIL
);
1285 ifnet_lock_exclusive(ifp
);
1286 error
= delete_each_prefix(rpp
, ipr
->ipr_origin
);
1287 ifnet_lock_done(ifp
);
1296 in6_rr_timer(__unused
void *ignored_arg
)
1298 struct rr_prefix
*rpp
;
1299 struct timeval timenow
;
1301 getmicrotime(&timenow
);
1304 lck_mtx_lock(prefix6_mutex
);
1305 rpp
= LIST_FIRST(&rr_prefix
);
1307 if (rpp
->rp_expire
&& rpp
->rp_expire
< timenow
.tv_sec
) {
1308 struct rr_prefix
*next_rpp
;
1310 next_rpp
= LIST_NEXT(rpp
, rp_entry
);
1311 delete_each_prefix(rpp
, PR_ORIG_KERNEL
);
1315 if (rpp
->rp_preferred
&& rpp
->rp_preferred
< timenow
.tv_sec
)
1316 unprefer_prefix(rpp
);
1317 rpp
= LIST_NEXT(rpp
, rp_entry
);
1319 lck_mtx_unlock(prefix6_mutex
);
1320 timeout(in6_rr_timer
, (caddr_t
)0, ip6_rr_prune
* hz
);