]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/in6_var.h
xnu-3789.1.32.tar.gz
[apple/xnu.git] / bsd / netinet6 / in6_var.h
1 /*
2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*
30 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. Neither the name of the project nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 */
57
58 /*
59 * Copyright (c) 1985, 1986, 1993
60 * The Regents of the University of California. All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
64 * are met:
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the distribution.
70 * 3. All advertising materials mentioning features or use of this software
71 * must display the following acknowledgement:
72 * This product includes software developed by the University of
73 * California, Berkeley and its contributors.
74 * 4. Neither the name of the University nor the names of its contributors
75 * may be used to endorse or promote products derived from this software
76 * without specific prior written permission.
77 *
78 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
79 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
81 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * SUCH DAMAGE.
89 *
90 * @(#)in_var.h 8.1 (Berkeley) 6/10/93
91 */
92
93 #ifndef _NETINET6_IN6_VAR_H_
94 #define _NETINET6_IN6_VAR_H_
95 #include <sys/appleapiopts.h>
96 #include <net/net_kev.h>
97
98 #ifdef BSD_KERNEL_PRIVATE
99 #include <sys/tree.h>
100 #include <sys/mcache.h>
101 #endif /* BSD_KERNEL_PRIVATE */
102 #include <netinet6/scope6_var.h>
103 #include <sys/kern_event.h>
104 #include <net/ethernet.h>
105
106 /*
107 * pltime/vltime are just for future reference (required to implements 2
108 * hour rule for hosts). they should never be modified by nd6_timeout or
109 * anywhere else.
110 * userland -> kernel: accept pltime/vltime
111 * kernel -> userland: throw up everything
112 * in kernel: modify preferred/expire only
113 */
114 struct in6_addrlifetime {
115 time_t ia6t_expire; /* valid lifetime expiration time */
116 time_t ia6t_preferred; /* preferred lifetime expiration time */
117 u_int32_t ia6t_vltime; /* valid lifetime */
118 u_int32_t ia6t_pltime; /* prefix lifetime */
119 };
120
121 #ifdef BSD_KERNEL_PRIVATE
122 struct in6_addrlifetime_32 {
123 u_int32_t ia6t_expire;
124 u_int32_t ia6t_preferred;
125 u_int32_t ia6t_vltime;
126 u_int32_t ia6t_pltime;
127 };
128
129 struct in6_addrlifetime_64 {
130 u_int64_t ia6t_expire;
131 u_int64_t ia6t_preferred;
132 u_int32_t ia6t_vltime;
133 u_int32_t ia6t_pltime;
134 };
135
136 /*
137 * Internal representation of ia6_lifetime (expiration in uptime unit)
138 */
139 struct in6_addrlifetime_i {
140 u_int64_t ia6ti_expire; /* valid lifetime expiration time */
141 u_int64_t ia6ti_preferred; /* preferred lifetime expiration time */
142 u_int32_t ia6ti_vltime; /* valid lifetime */
143 u_int32_t ia6ti_pltime; /* prefix lifetime */
144 u_int64_t ia6ti_base_calendartime; /* calendar time at creation */
145 u_int64_t ia6ti_base_uptime; /* uptime at creation */
146 };
147
148 /*
149 * Interface address, IPv6 version. One of these structures
150 * is allocated for each interface with an IPv6 address.
151 * The ifaddr structure contains the protocol-independent part
152 * of the structure and is assumed to be first.
153 */
154
155 struct in6_ifaddr {
156 struct ifaddr ia_ifa; /* protocol-independent info */
157 #define ia_ifp ia_ifa.ifa_ifp
158 #define ia_flags ia_ifa.ifa_flags
159 struct sockaddr_in6 ia_addr; /* interface address */
160 struct sockaddr_in6 ia_net; /* network number of interface */
161 struct sockaddr_in6 ia_dstaddr; /* space for destination addr */
162 struct sockaddr_in6 ia_prefixmask; /* prefix mask */
163 u_int32_t ia_plen; /* prefix length */
164 struct in6_ifaddr *ia_next; /* next in6 list of IP6 addresses */
165 int ia6_flags;
166
167 struct in6_addrlifetime_i ia6_lifetime;
168 /*
169 * the creation time of this address, which is
170 * currently used for temporary addresses only.
171 */
172 u_int64_t ia6_createtime;
173 u_int64_t ia6_updatetime;
174
175 /* back pointer to the ND prefix */
176 struct nd_prefix *ia6_ndpr;
177
178 /* multicast addresses joined from the kernel */
179 LIST_HEAD(, in6_multi_mship) ia6_memberships;
180 };
181
182 #define ifatoia6(ifa) ((struct in6_ifaddr *)(void *)(ifa))
183 #endif /* BSD_KERNEL_PRIVATE */
184
185 /* control structure to manage address selection policy */
186 struct in6_addrpolicy {
187 struct sockaddr_in6 addr; /* prefix address */
188 struct sockaddr_in6 addrmask; /* prefix mask */
189 int preced; /* precedence */
190 int label; /* matching label */
191 u_quad_t use; /* statistics */
192 };
193
194 /*
195 * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12).
196 */
197 struct in6_ifstat {
198 u_quad_t ifs6_in_receive; /* # of total input datagram */
199 u_quad_t ifs6_in_hdrerr; /* # of datagrams with invalid hdr */
200 u_quad_t ifs6_in_toobig; /* # of datagrams exceeded MTU */
201 u_quad_t ifs6_in_noroute; /* # of datagrams with no route */
202 u_quad_t ifs6_in_addrerr; /* # of datagrams with invalid dst */
203 u_quad_t ifs6_in_protounknown; /* # of datagrams with unknown proto */
204 /* NOTE: increment on final dst if */
205 u_quad_t ifs6_in_truncated; /* # of truncated datagrams */
206 u_quad_t ifs6_in_discard; /* # of discarded datagrams */
207 /* NOTE: fragment timeout is not here */
208 u_quad_t ifs6_in_deliver; /* # of datagrams delivered to ULP */
209 /* NOTE: increment on final dst if */
210 u_quad_t ifs6_out_forward; /* # of datagrams forwarded */
211 /* NOTE: increment on outgoing if */
212 u_quad_t ifs6_out_request; /* # of outgoing datagrams from ULP */
213 /* NOTE: does not include forwrads */
214 u_quad_t ifs6_out_discard; /* # of discarded datagrams */
215 u_quad_t ifs6_out_fragok; /* # of datagrams fragmented */
216 u_quad_t ifs6_out_fragfail; /* # of datagrams failed on fragment */
217 u_quad_t ifs6_out_fragcreat; /* # of fragment datagrams */
218 /* NOTE: this is # after fragment */
219 u_quad_t ifs6_reass_reqd; /* # of incoming fragmented packets */
220 /* NOTE: increment on final dst if */
221 u_quad_t ifs6_reass_ok; /* # of reassembled packets */
222 /* NOTE: this is # after reass */
223 /* NOTE: increment on final dst if */
224 u_quad_t ifs6_atmfrag_rcvd; /* # of atomic fragments received */
225 u_quad_t ifs6_reass_fail; /* # of reass failures */
226 /* NOTE: may not be packet count */
227 /* NOTE: increment on final dst if */
228 u_quad_t ifs6_in_mcast; /* # of inbound multicast datagrams */
229 u_quad_t ifs6_out_mcast; /* # of outbound multicast datagrams */
230 };
231
232 /*
233 * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry.
234 * XXX: I'm not sure if this file is the right place for this structure...
235 */
236 struct icmp6_ifstat {
237 /*
238 * Input statistics
239 */
240 /* ipv6IfIcmpInMsgs, total # of input messages */
241 u_quad_t ifs6_in_msg;
242 /* ipv6IfIcmpInErrors, # of input error messages */
243 u_quad_t ifs6_in_error;
244 /* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */
245 u_quad_t ifs6_in_dstunreach;
246 /* ipv6IfIcmpInAdminProhibs, # of input admin. prohibited errs */
247 u_quad_t ifs6_in_adminprohib;
248 /* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */
249 u_quad_t ifs6_in_timeexceed;
250 /* ipv6IfIcmpInParmProblems, # of input parameter problem errors */
251 u_quad_t ifs6_in_paramprob;
252 /* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */
253 u_quad_t ifs6_in_pkttoobig;
254 /* ipv6IfIcmpInEchos, # of input echo requests */
255 u_quad_t ifs6_in_echo;
256 /* ipv6IfIcmpInEchoReplies, # of input echo replies */
257 u_quad_t ifs6_in_echoreply;
258 /* ipv6IfIcmpInRouterSolicits, # of input router solicitations */
259 u_quad_t ifs6_in_routersolicit;
260 /* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */
261 u_quad_t ifs6_in_routeradvert;
262 /* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */
263 u_quad_t ifs6_in_neighborsolicit;
264 /* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advs. */
265 u_quad_t ifs6_in_neighboradvert;
266 /* ipv6IfIcmpInRedirects, # of input redirects */
267 u_quad_t ifs6_in_redirect;
268 /* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */
269 u_quad_t ifs6_in_mldquery;
270 /* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */
271 u_quad_t ifs6_in_mldreport;
272 /* ipv6IfIcmpInGroupMembReductions, # of input MLD done */
273 u_quad_t ifs6_in_mlddone;
274
275 /*
276 * Output statistics. We should solve unresolved routing problem...
277 */
278 /* ipv6IfIcmpOutMsgs, total # of output messages */
279 u_quad_t ifs6_out_msg;
280 /* ipv6IfIcmpOutErrors, # of output error messages */
281 u_quad_t ifs6_out_error;
282 /* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */
283 u_quad_t ifs6_out_dstunreach;
284 /* ipv6IfIcmpOutAdminProhibs, # of output admin. prohibited errs */
285 u_quad_t ifs6_out_adminprohib;
286 /* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */
287 u_quad_t ifs6_out_timeexceed;
288 /* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */
289 u_quad_t ifs6_out_paramprob;
290 /* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */
291 u_quad_t ifs6_out_pkttoobig;
292 /* ipv6IfIcmpOutEchos, # of output echo requests */
293 u_quad_t ifs6_out_echo;
294 /* ipv6IfIcmpOutEchoReplies, # of output echo replies */
295 u_quad_t ifs6_out_echoreply;
296 /* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */
297 u_quad_t ifs6_out_routersolicit;
298 /* ipv6IfIcmpOutRouterAdvertisements, # of output router advs. */
299 u_quad_t ifs6_out_routeradvert;
300 /* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */
301 u_quad_t ifs6_out_neighborsolicit;
302 /* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advs. */
303 u_quad_t ifs6_out_neighboradvert;
304 /* ipv6IfIcmpOutRedirects, # of output redirects */
305 u_quad_t ifs6_out_redirect;
306 /* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */
307 u_quad_t ifs6_out_mldquery;
308 /* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */
309 u_quad_t ifs6_out_mldreport;
310 /* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */
311 u_quad_t ifs6_out_mlddone;
312 };
313
314 struct in6_ifreq {
315 char ifr_name[IFNAMSIZ];
316 union {
317 struct sockaddr_in6 ifru_addr;
318 struct sockaddr_in6 ifru_dstaddr;
319 int ifru_flags;
320 int ifru_flags6;
321 int ifru_metric;
322 int ifru_intval;
323 caddr_t ifru_data;
324 struct in6_addrlifetime ifru_lifetime;
325 struct in6_ifstat ifru_stat;
326 struct icmp6_ifstat ifru_icmp6stat;
327 u_int32_t ifru_scope_id[SCOPE6_ID_MAX];
328 } ifr_ifru;
329 };
330
331 struct in6_aliasreq {
332 char ifra_name[IFNAMSIZ];
333 struct sockaddr_in6 ifra_addr;
334 struct sockaddr_in6 ifra_dstaddr;
335 struct sockaddr_in6 ifra_prefixmask;
336 int ifra_flags;
337 struct in6_addrlifetime ifra_lifetime;
338 };
339
340 #ifdef PRIVATE
341 #define IN6_CGA_MODIFIER_LENGTH 16
342
343 struct in6_cga_modifier {
344 u_int8_t octets[IN6_CGA_MODIFIER_LENGTH];
345 };
346
347 struct in6_cga_prepare {
348 struct in6_cga_modifier cga_modifier;
349 u_int8_t cga_security_level;
350 u_int8_t reserved_A[15];
351 };
352
353 #define IN6_CGA_KEY_MAXSIZE 2048 /* octets */
354
355 struct in6_cga_nodecfg {
356 struct iovec cga_privkey;
357 struct iovec cga_pubkey;
358 struct in6_cga_prepare cga_prepare;
359 };
360
361 /*
362 * XXX in6_llstartreq will be removed once
363 * configd adopts the more generically named
364 * in6_cgareq structure.
365 */
366 struct in6_llstartreq {
367 char llsr_name[IFNAMSIZ];
368 int llsr_flags;
369 struct in6_cga_prepare llsr_cgaprep;
370 struct in6_addrlifetime llsr_lifetime;
371 };
372
373 struct in6_cgareq {
374 char cgar_name[IFNAMSIZ];
375 int cgar_flags;
376 struct in6_cga_prepare cgar_cgaprep;
377 struct in6_addrlifetime cgar_lifetime;
378 };
379
380 #ifdef BSD_KERNEL_PRIVATE
381 /*
382 * XXX Corresponding versions of in6_llstartreq
383 * will be removed after the new in6_cgareq is
384 * adopted by configd
385 */
386 struct in6_llstartreq_32 {
387 char llsr_name[IFNAMSIZ];
388 int llsr_flags;
389 struct in6_cga_prepare llsr_cgaprep;
390 struct in6_addrlifetime_32 llsr_lifetime;
391 };
392
393 struct in6_llstartreq_64 {
394 char llsr_name[IFNAMSIZ];
395 int llsr_flags;
396 struct in6_cga_prepare llsr_cgaprep;
397 struct in6_addrlifetime_64 llsr_lifetime;
398 };
399
400 struct in6_cgareq_32 {
401 char cgar_name[IFNAMSIZ];
402 int cgar_flags;
403 struct in6_cga_prepare cgar_cgaprep;
404 struct in6_addrlifetime_32 cgar_lifetime;
405 };
406
407 struct in6_cgareq_64 {
408 char cgar_name[IFNAMSIZ];
409 int cgar_flags;
410 struct in6_cga_prepare cgar_cgaprep;
411 struct in6_addrlifetime_64 cgar_lifetime;
412 };
413
414 #endif /* !BSD_KERNEL_PRIVATE */
415 #endif /* PRIVATE */
416
417 #ifdef BSD_KERNEL_PRIVATE
418 struct in6_aliasreq_32 {
419 char ifra_name[IFNAMSIZ];
420 struct sockaddr_in6 ifra_addr;
421 struct sockaddr_in6 ifra_dstaddr;
422 struct sockaddr_in6 ifra_prefixmask;
423 int ifra_flags;
424 struct in6_addrlifetime_32 ifra_lifetime;
425 };
426
427 struct in6_aliasreq_64 {
428 char ifra_name[IFNAMSIZ];
429 struct sockaddr_in6 ifra_addr;
430 struct sockaddr_in6 ifra_dstaddr;
431 struct sockaddr_in6 ifra_prefixmask;
432 int ifra_flags;
433 struct in6_addrlifetime_64 ifra_lifetime;
434 };
435 #endif /* BSD_KERNEL_PRIVATE */
436
437 /* prefix type macro */
438 #define IN6_PREFIX_ND 1
439 #define IN6_PREFIX_RR 2
440
441 /*
442 * prefix related flags passed between kernel(NDP related part) and
443 * user land command(ifconfig) and daemon(rtadvd).
444 */
445 struct in6_prflags {
446 struct prf_ra {
447 u_char onlink : 1;
448 u_char autonomous : 1;
449 u_char reserved : 6;
450 } prf_ra;
451 u_char prf_reserved1;
452 u_short prf_reserved2;
453 /* want to put this on 4byte offset */
454 struct prf_rr {
455 u_char decrvalid : 1;
456 u_char decrprefd : 1;
457 u_char reserved : 6;
458 } prf_rr;
459 u_char prf_reserved3;
460 u_short prf_reserved4;
461 };
462
463 struct in6_prefixreq {
464 char ipr_name[IFNAMSIZ];
465 u_char ipr_origin;
466 u_char ipr_plen;
467 u_int32_t ipr_vltime;
468 u_int32_t ipr_pltime;
469 struct in6_prflags ipr_flags;
470 struct sockaddr_in6 ipr_prefix;
471 };
472
473 #define PR_ORIG_RA 0
474 #define PR_ORIG_RR 1
475 #define PR_ORIG_STATIC 2
476 #define PR_ORIG_KERNEL 3
477
478 #define ipr_raf_onlink ipr_flags.prf_ra.onlink
479 #define ipr_raf_auto ipr_flags.prf_ra.autonomous
480
481 #define ipr_statef_onlink ipr_flags.prf_state.onlink
482
483 #define ipr_rrf_decrvalid ipr_flags.prf_rr.decrvalid
484 #define ipr_rrf_decrprefd ipr_flags.prf_rr.decrprefd
485
486 struct in6_rrenumreq {
487 char irr_name[IFNAMSIZ];
488 u_char irr_origin;
489 u_char irr_m_len; /* match len for matchprefix */
490 u_char irr_m_minlen; /* minlen for matching prefix */
491 u_char irr_m_maxlen; /* maxlen for matching prefix */
492 u_char irr_u_uselen; /* uselen for adding prefix */
493 u_char irr_u_keeplen; /* keeplen from matching prefix */
494 struct irr_raflagmask {
495 u_char onlink : 1;
496 u_char autonomous : 1;
497 u_char reserved : 6;
498 } irr_raflagmask;
499 u_int32_t irr_vltime;
500 u_int32_t irr_pltime;
501 struct in6_prflags irr_flags;
502 struct sockaddr_in6 irr_matchprefix;
503 struct sockaddr_in6 irr_useprefix;
504 };
505
506 #define irr_raf_mask_onlink irr_raflagmask.onlink
507 #define irr_raf_mask_auto irr_raflagmask.autonomous
508 #define irr_raf_mask_reserved irr_raflagmask.reserved
509
510 #define irr_raf_onlink irr_flags.prf_ra.onlink
511 #define irr_raf_auto irr_flags.prf_ra.autonomous
512
513 #define irr_statef_onlink irr_flags.prf_state.onlink
514
515 #define irr_rrf irr_flags.prf_rr
516 #define irr_rrf_decrvalid irr_flags.prf_rr.decrvalid
517 #define irr_rrf_decrprefd irr_flags.prf_rr.decrprefd
518
519 /*
520 * Event data, inet6 style.
521 */
522 struct kev_in6_addrlifetime {
523 u_int32_t ia6t_expire;
524 u_int32_t ia6t_preferred;
525 u_int32_t ia6t_vltime;
526 u_int32_t ia6t_pltime;
527 };
528
529 struct kev_in6_data {
530 struct net_event_data link_data;
531 struct sockaddr_in6 ia_addr; /* interface address */
532 struct sockaddr_in6 ia_net; /* network number of interface */
533 struct sockaddr_in6 ia_dstaddr; /* space for destination addr */
534 struct sockaddr_in6 ia_prefixmask; /* prefix mask */
535 u_int32_t ia_plen; /* prefix length */
536 u_int32_t ia6_flags; /* address flags from in6_ifaddr */
537 struct kev_in6_addrlifetime ia_lifetime; /* address life info */
538 uint8_t ia_mac[ETHER_ADDR_LEN];
539 };
540
541 #ifdef BSD_KERNEL_PRIVATE
542 /* Utility function used inside netinet6 kernel code for generating events */
543 void in6_post_msg(struct ifnet *, u_int32_t, struct in6_ifaddr *, uint8_t *mac);
544
545 #define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
546 (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
547 (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
548 (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
549 (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0)
550
551 /*
552 * Given a pointer to an in6_ifaddr (ifaddr),
553 * return a pointer to the addr as a sockaddr_in6
554 */
555 #define IA6_IN6(ia) (&((ia)->ia_addr.sin6_addr))
556 #define IA6_DSTIN6(ia) (&((ia)->ia_dstaddr.sin6_addr))
557 #define IA6_MASKIN6(ia) (&((ia)->ia_prefixmask.sin6_addr))
558 #define IA6_SIN6(ia) (&((ia)->ia_addr))
559 #define IA6_DSTSIN6(ia) (&((ia)->ia_dstaddr))
560 #define IFA_IN6(x) \
561 (&((struct sockaddr_in6 *)(void *)((x)->ifa_addr))->sin6_addr)
562 #define IFA_DSTIN6(x) \
563 (&((struct sockaddr_in6 *)(void *)((x)->ifa_dstaddr))->sin6_addr)
564 #define IFPR_IN6(x) \
565 (&((struct sockaddr_in6 *)(void *)((x)->ifpr_prefix))->sin6_addr)
566 #endif /* BSD_KERNEL_PRIVATE */
567
568 #define SIOCSIFADDR_IN6 _IOW('i', 12, struct in6_ifreq)
569 #define SIOCGIFADDR_IN6 _IOWR('i', 33, struct in6_ifreq)
570
571 /*
572 * SIOCSxxx ioctls should be unused (see comments in in6.c), but
573 * we do not shift numbers for binary compatibility.
574 */
575 #define SIOCSIFDSTADDR_IN6 _IOW('i', 14, struct in6_ifreq)
576 #define SIOCSIFNETMASK_IN6 _IOW('i', 22, struct in6_ifreq)
577
578 #define SIOCGIFDSTADDR_IN6 _IOWR('i', 34, struct in6_ifreq)
579 #define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq)
580
581 #define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq)
582 #define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq)
583 #ifdef BSD_KERNEL_PRIVATE
584 #define SIOCAIFADDR_IN6_32 _IOW('i', 26, struct in6_aliasreq_32)
585 #define SIOCAIFADDR_IN6_64 _IOW('i', 26, struct in6_aliasreq_64)
586 #endif /* BSD_KERNEL_PRIVATE */
587
588 #define SIOCSIFPHYADDR_IN6 _IOW('i', 62, struct in6_aliasreq)
589 #ifdef BSD_KERNEL_PRIVATE
590 #define SIOCSIFPHYADDR_IN6_32 _IOW('i', 62, struct in6_aliasreq_32)
591 #define SIOCSIFPHYADDR_IN6_64 _IOW('i', 62, struct in6_aliasreq_64)
592 #endif /* BSD_KERNEL_PRIVATE */
593 #define SIOCGIFPSRCADDR_IN6 _IOWR('i', 63, struct in6_ifreq)
594 #define SIOCGIFPDSTADDR_IN6 _IOWR('i', 64, struct in6_ifreq)
595 #define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq)
596
597 #define SIOCGDRLST_IN6 _IOWR('i', 74, struct in6_drlist)
598 #ifdef BSD_KERNEL_PRIVATE
599 #define SIOCGDRLST_IN6_32 _IOWR('i', 74, struct in6_drlist_32)
600 #define SIOCGDRLST_IN6_64 _IOWR('i', 74, struct in6_drlist_64)
601 #endif /* BSD_KERNEL_PRIVATE */
602
603 #define SIOCGPRLST_IN6 _IOWR('i', 75, struct in6_prlist)
604 #ifdef BSD_KERNEL_PRIVATE
605 #define SIOCGPRLST_IN6_32 _IOWR('i', 75, struct in6_prlist_32)
606 #define SIOCGPRLST_IN6_64 _IOWR('i', 75, struct in6_prlist_64)
607 #endif /* BSD_KERNEL_PRIVATE */
608
609 #define OSIOCGIFINFO_IN6 _IOWR('i', 108, struct in6_ondireq)
610 #define SIOCGIFINFO_IN6 _IOWR('i', 76, struct in6_ondireq)
611 #define SIOCSNDFLUSH_IN6 _IOWR('i', 77, struct in6_ifreq)
612
613 #define SIOCGNBRINFO_IN6 _IOWR('i', 78, struct in6_nbrinfo)
614 #ifdef BSD_KERNEL_PRIVATE
615 #define SIOCGNBRINFO_IN6_32 _IOWR('i', 78, struct in6_nbrinfo_32)
616 #define SIOCGNBRINFO_IN6_64 _IOWR('i', 78, struct in6_nbrinfo_64)
617 #endif /* BSD_KERNEL_PRIVATE */
618
619 #define SIOCSPFXFLUSH_IN6 _IOWR('i', 79, struct in6_ifreq)
620 #define SIOCSRTRFLUSH_IN6 _IOWR('i', 80, struct in6_ifreq)
621
622 #define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq)
623 #define SIOCSIFALIFETIME_IN6 _IOWR('i', 82, struct in6_ifreq)
624 #define SIOCGIFSTAT_IN6 _IOWR('i', 83, struct in6_ifreq)
625 #define SIOCGIFSTAT_ICMP6 _IOWR('i', 84, struct in6_ifreq)
626
627 #define SIOCSDEFIFACE_IN6 _IOWR('i', 85, struct in6_ndifreq)
628 #define SIOCGDEFIFACE_IN6 _IOWR('i', 86, struct in6_ndifreq)
629 #ifdef BSD_KERNEL_PRIVATE
630 #define SIOCSDEFIFACE_IN6_32 _IOWR('i', 85, struct in6_ndifreq_32)
631 #define SIOCSDEFIFACE_IN6_64 _IOWR('i', 85, struct in6_ndifreq_64)
632 #define SIOCGDEFIFACE_IN6_32 _IOWR('i', 86, struct in6_ndifreq_32)
633 #define SIOCGDEFIFACE_IN6_64 _IOWR('i', 86, struct in6_ndifreq_64)
634 #endif /* BSD_KERNEL_PRIVATE */
635
636 #define SIOCSIFINFO_FLAGS _IOWR('i', 87, struct in6_ndireq) /* XXX */
637
638 /* N.B.: These 3 ioctls are deprecated and won't work */
639 #define SIOCSSCOPE6 _IOW('i', 88, struct in6_ifreq)
640 #define SIOCGSCOPE6 _IOWR('i', 89, struct in6_ifreq)
641 #define SIOCGSCOPE6DEF _IOWR('i', 90, struct in6_ifreq)
642
643 #define SIOCSIFPREFIX_IN6 _IOW('i', 100, struct in6_prefixreq) /* set */
644 #define SIOCGIFPREFIX_IN6 _IOWR('i', 101, struct in6_prefixreq) /* get */
645 #define SIOCDIFPREFIX_IN6 _IOW('i', 102, struct in6_prefixreq) /* del */
646 #define SIOCAIFPREFIX_IN6 _IOW('i', 103, struct in6_rrenumreq) /* add */
647
648 /* change */
649 #define SIOCCIFPREFIX_IN6 _IOW('i', 104, struct in6_rrenumreq)
650
651 /* set global */
652 #define SIOCSGIFPREFIX_IN6 _IOW('i', 105, struct in6_rrenumreq)
653
654 /*
655 * multicast routing, get s/g pkt cnt, pkt cnt per interface.
656 */
657 #define SIOCGETSGCNT_IN6 _IOWR('u', 28, struct sioc_sg_req6)
658 #define SIOCGETMIFCNT_IN6 _IOWR('u', 107, struct sioc_mif_req6)
659 #ifdef BSD_KERNEL_PRIVATE
660 #define SIOCGETMIFCNT_IN6_32 _IOWR('u', 107, struct sioc_mif_req6_32)
661 #define SIOCGETMIFCNT_IN6_64 _IOWR('u', 107, struct sioc_mif_req6_64)
662 #endif /* BSD_KERNEL_PRIVATE */
663
664 #define SIOCAADDRCTL_POLICY _IOW('u', 108, struct in6_addrpolicy)
665 #define SIOCDADDRCTL_POLICY _IOW('u', 109, struct in6_addrpolicy)
666
667 #ifdef PRIVATE
668 /*
669 * temporary control calls to attach/detach IPv6 to/from an interface.
670 */
671 #define SIOCPROTOATTACH_IN6 _IOWR('i', 110, struct in6_aliasreq)
672 #ifdef BSD_KERNEL_PRIVATE
673 #define SIOCPROTOATTACH_IN6_32 _IOWR('i', 110, struct in6_aliasreq_32)
674 #define SIOCPROTOATTACH_IN6_64 _IOWR('i', 110, struct in6_aliasreq_64)
675 #endif /* BSD_KERNEL_PRIVATE */
676 #define SIOCPROTODETACH_IN6 _IOWR('i', 111, struct in6_ifreq)
677
678 /*
679 * start/stop aquiring linklocal on interface
680 */
681 #define SIOCLL_START _IOWR('i', 130, struct in6_aliasreq)
682 #ifdef BSD_KERNEL_PRIVATE
683 #define SIOCLL_START_32 _IOWR('i', 130, struct in6_aliasreq_32)
684 #define SIOCLL_START_64 _IOWR('i', 130, struct in6_aliasreq_64)
685 #endif /* BSD_KERNEL_PRIVATE */
686 #define SIOCLL_STOP _IOWR('i', 131, struct in6_ifreq)
687
688 /*
689 * accept rtadvd (and stop accepting) on this interface.
690 */
691 #define SIOCAUTOCONF_START _IOWR('i', 132, struct in6_ifreq)
692 #define SIOCAUTOCONF_STOP _IOWR('i', 133, struct in6_ifreq)
693
694 /*
695 * add/remove default IPv6 router.
696 */
697 #define SIOCDRADD_IN6 _IOWR('u', 134, struct in6_defrouter)
698 #ifdef BSD_KERNEL_PRIVATE
699 #define SIOCDRADD_IN6_32 _IOWR('u', 134, struct in6_defrouter_32)
700 #define SIOCDRADD_IN6_64 _IOWR('u', 134, struct in6_defrouter_64)
701 #endif /* BSD_KERNEL_PRIVATE */
702 #define SIOCDRDEL_IN6 _IOWR('u', 135, struct in6_defrouter)
703 #ifdef BSD_KERNEL_PRIVATE
704 #define SIOCDRDEL_IN6_32 _IOWR('u', 135, struct in6_defrouter_32)
705 #define SIOCDRDEL_IN6_64 _IOWR('u', 135, struct in6_defrouter_64)
706 #endif /* BSD_KERNEL_PRIVATE */
707
708 /*
709 * enable/disable IPv6 router mode on interface.
710 */
711 #define SIOCSETROUTERMODE_IN6 _IOWR('i', 136, struct in6_ifreq)
712
713 /*
714 * start secure link-local interface addresses
715 */
716 #define SIOCLL_CGASTART _IOW('i', 160, struct in6_cgareq)
717 #ifdef BSD_KERNEL_PRIVATE
718 #define SIOCLL_CGASTART_32 _IOW('i', 160, struct in6_cgareq_32)
719 #define SIOCLL_CGASTART_64 _IOW('i', 160, struct in6_cgareq_64)
720 #endif
721 #define SIOCGIFCGAPREP_IN6 _IOWR('i', 187, struct in6_cgareq)
722 #define SIOCSIFCGAPREP_IN6 _IOWR('i', 188, struct in6_cgareq)
723
724 #endif /* PRIVATE */
725
726 #ifdef BSD_KERNEL_PRIVATE
727 /*
728 * XXX: Do not extend IN6_IFF values beyond 16-bit. We currently copy the
729 * values from ia6_flags as is into m_pkthdr.{src,dst}_iff which are
730 * defined as 16-bit variables. We can relax this once we define a
731 * unified set of interface flags for {ia,ia6}_flags and perform
732 * translation between those and the publicly-defined ones below.
733 */
734 #endif /* BSD_KERNEL_PRIVATE */
735 #define IN6_IFF_ANYCAST 0x0001 /* anycast address */
736 #define IN6_IFF_TENTATIVE 0x0002 /* tentative address */
737 #define IN6_IFF_DUPLICATED 0x0004 /* DAD detected duplicate */
738 #define IN6_IFF_DETACHED 0x0008 /* may be detached from the link */
739 #define IN6_IFF_DEPRECATED 0x0010 /* deprecated address */
740
741 /* don't perform DAD on this address (used only at first SIOC* call) */
742 #define IN6_IFF_NODAD 0x0020
743
744 #define IN6_IFF_AUTOCONF 0x0040 /* autoconfigurable address. */
745 #define IN6_IFF_TEMPORARY 0x0080 /* temporary (anonymous) address. */
746 #define IN6_IFF_DYNAMIC 0x0100 /* assigned by DHCPv6 service */
747 #define IN6_IFF_OPTIMISTIC 0x0200 /* optimistic DAD, i.e. RFC 4429 */
748 #define IN6_IFF_SECURED 0x0400 /* cryptographically generated */
749 #ifdef PRIVATE
750 #define IN6_IFF_SWIFTDAD 0x0800 /* DAD with no delay */
751 #endif
752 #define IN6_IFF_NOPFX 0x8000 /* Depreciated. Don't use. */
753
754 /* Duplicate Address Detection [DAD] in progress. */
755 #define IN6_IFF_DADPROGRESS (IN6_IFF_TENTATIVE|IN6_IFF_OPTIMISTIC)
756
757 /* do not input/output */
758 #define IN6_IFF_NOTREADY (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)
759
760 /* SLAAC/DHCPv6 address */
761 #define IN6_IFF_NOTMANUAL (IN6_IFF_AUTOCONF|IN6_IFF_DYNAMIC)
762
763 #ifdef KERNEL
764 #define IN6_ARE_SCOPE_CMP(a, b) ((a) - (b))
765 #define IN6_ARE_SCOPE_EQUAL(a, b) ((a) == (b))
766 #endif /* KERNEL */
767
768 #ifdef BSD_KERNEL_PRIVATE
769 extern struct in6_ifaddr *in6_ifaddrs;
770
771 extern struct icmp6stat icmp6stat;
772 extern lck_rw_t in6_ifaddr_rwlock;
773 extern lck_mtx_t proxy6_lock;
774 extern u_char inet6ctlerrmap[];
775 extern u_int32_t in6_maxmtu;
776
777 /* N.B.: if_inet6data is never freed once set, so we don't need to lock */
778 #define in6_ifstat_inc_common(_ifp, _tag, _atomic) do { \
779 if (_ifp != NULL && IN6_IFEXTRA(_ifp) != NULL) { \
780 if (_atomic) \
781 atomic_add_64( \
782 &IN6_IFEXTRA(_ifp)->in6_ifstat._tag, 1); \
783 else \
784 IN6_IFEXTRA(_ifp)->in6_ifstat._tag++; \
785 } \
786 } while (0)
787
788 /* atomic version */
789 #define in6_ifstat_inc(_ifp, _tag) \
790 in6_ifstat_inc_common(_ifp, _tag, TRUE)
791
792 /* non-atomic version (for fast paths) */
793 #define in6_ifstat_inc_na(_ifp, _tag) \
794 in6_ifstat_inc_common(_ifp, _tag, FALSE)
795
796 /*
797 * Macro for finding the internet address structure (in6_ifaddr) corresponding
798 * to a given interface (ifnet structure).
799 */
800
801 #define IFP_TO_IA6(ifp, ia) \
802 /* struct ifnet *ifp; */ \
803 /* struct in6_ifaddr *ia; */ \
804 do { \
805 struct ifaddr *_ifa; \
806 ifnet_lock_assert(ifp, LCK_RW_ASSERT_HELD); \
807 for (_ifa = (ifp)->if_addrlist.tqh_first; _ifa != NULL; \
808 _ifa = _ifa->ifa_list.tqe_next) { \
809 IFA_LOCK(_ifa); \
810 if (_ifa->ifa_addr->sa_family == AF_INET6) { \
811 IFA_ADDREF_LOCKED(_ifa); \
812 IFA_UNLOCK(_ifa); \
813 break; \
814 } \
815 IFA_UNLOCK(_ifa); \
816 } \
817 (ia) = (struct in6_ifaddr *)_ifa; \
818 } while (0)
819
820 /*
821 * IPv6 multicast MLD-layer source entry.
822 */
823 struct ip6_msource {
824 RB_ENTRY(ip6_msource) im6s_link; /* RB tree links */
825 struct in6_addr im6s_addr;
826 struct im6s_st {
827 uint16_t ex; /* # of exclusive members */
828 uint16_t in; /* # of inclusive members */
829 } im6s_st[2]; /* state at t0, t1 */
830 uint8_t im6s_stp; /* pending query */
831 };
832
833 RB_HEAD(ip6_msource_tree, ip6_msource);
834
835 RB_PROTOTYPE_SC_PREV(__private_extern__, ip6_msource_tree, ip6_msource,
836 im6s_link, ip6_msource_cmp);
837
838 /*
839 * IPv6 multicast PCB-layer source entry.
840 *
841 * NOTE: overlapping use of struct ip6_msource fields at start.
842 */
843 struct in6_msource {
844 RB_ENTRY(ip6_msource) im6s_link; /* Common field */
845 struct in6_addr im6s_addr; /* Common field */
846 uint8_t im6sl_st[2]; /* state before/at commit */
847 };
848
849 /*
850 * IPv6 multicast PCB-layer group filter descriptor.
851 */
852 struct in6_mfilter {
853 struct ip6_msource_tree im6f_sources; /* source list for (S,G) */
854 u_long im6f_nsrc; /* # of source entries */
855 uint8_t im6f_st[2]; /* state before/at commit */
856 };
857
858 /*
859 * Legacy KAME IPv6 multicast membership descriptor.
860 */
861 struct in6_multi_mship {
862 struct in6_multi *i6mm_maddr; /* Multicast address pointer */
863 LIST_ENTRY(in6_multi_mship) i6mm_chain; /* multicast options chain */
864 };
865
866 #ifdef BSD_KERNEL_PRIVATE
867 #include <netinet6/nd6_var.h>
868 /*
869 * * Per-interface IPv6 structures.
870 * */
871 struct in6_ifextra {
872 struct scope6_id scope6_id;
873 struct in6_ifstat in6_ifstat;
874 struct icmp6_ifstat icmp6_ifstat;
875 struct nd_ifinfo nd_ifinfo;
876 uint32_t netsig_len;
877 u_int8_t netsig[IFNET_SIGNATURELEN];
878 };
879 #define IN6_IFEXTRA(_ifp) ((struct in6_ifextra *)(_ifp->if_inet6data))
880 #endif /* BSD_KERNEL_PRIVATE */
881
882 struct mld_ifinfo;
883
884 /*
885 * IPv6 group descriptor.
886 *
887 * For every entry on an ifnet's if_multiaddrs list which represents
888 * an IP multicast group, there is one of these structures.
889 *
890 * If any source filters are present, then a node will exist in the RB-tree
891 * to permit fast lookup by source whenever an operation takes place.
892 * This permits pre-order traversal when we issue reports.
893 * Source filter trees are kept separately from the socket layer to
894 * greatly simplify locking.
895 *
896 * When MLDv2 is active, in6m_timer is the response to group query timer.
897 * The state-change timer in6m_sctimer is separate; whenever state changes
898 * for the group the state change record is generated and transmitted,
899 * and kept if retransmissions are necessary.
900 *
901 * The request count here is a count of requests for this address, not a
902 * count of pointers to this structure.
903 *
904 * FUTURE: in6m_entry is now only used when groups are being purged
905 * on a detaching ifnet. It could be demoted to a SLIST_ENTRY.
906 */
907 struct in6_multi {
908 decl_lck_mtx_data(, in6m_lock);
909 u_int32_t in6m_refcount; /* reference count */
910 u_int32_t in6m_reqcnt; /* request count for this address */
911 u_int32_t in6m_debug; /* see ifa_debug flags */
912 LIST_ENTRY(in6_multi) in6m_entry; /* list glue */
913 struct in6_addr in6m_addr; /* IP6 multicast address */
914 struct ifnet *in6m_ifp; /* back pointer to ifnet */
915 struct ifmultiaddr *in6m_ifma; /* back pointer to ifmultiaddr */
916 u_int in6m_state; /* state of the membership */
917 u_int in6m_timer; /* MLD6 listener report timer */
918
919 /* New fields for MLDv2 follow. */
920 struct mld_ifinfo *in6m_mli; /* MLD info */
921 SLIST_ENTRY(in6_multi) in6m_dtle; /* detached waiting for rele */
922 SLIST_ENTRY(in6_multi) in6m_nrele; /* to-be-released by MLD */
923 u_int32_t in6m_nrelecnt; /* deferred release count */
924 struct ip6_msource_tree in6m_srcs; /* tree of sources */
925 u_long in6m_nsrc; /* # of tree entries */
926
927 struct ifqueue in6m_scq; /* pending state-change packets */
928 struct timeval in6m_lastgsrtv; /* last G-S-R query */
929 uint16_t in6m_sctimer; /* state-change timer */
930 uint16_t in6m_scrv; /* state-change rexmit count */
931
932 /*
933 * SSM state counters which track state at T0 (the time the last
934 * state-change report's RV timer went to zero) and T1
935 * (time of pending report, i.e. now).
936 * Used for computing MLDv2 state-change reports. Several refcounts
937 * are maintained here to optimize for common use-cases.
938 */
939 struct in6m_st {
940 uint16_t iss_fmode; /* MLD filter mode */
941 uint16_t iss_asm; /* # of ASM listeners */
942 uint16_t iss_ex; /* # of exclusive members */
943 uint16_t iss_in; /* # of inclusive members */
944 uint16_t iss_rec; /* # of recorded sources */
945 } in6m_st[2]; /* state at t0, t1 */
946
947 void (*in6m_trace) /* callback fn for tracing refs */
948 (struct in6_multi *, int);
949 };
950
951 #define IN6M_LOCK_ASSERT_HELD(_in6m) \
952 lck_mtx_assert(&(_in6m)->in6m_lock, LCK_MTX_ASSERT_OWNED)
953
954 #define IN6M_LOCK_ASSERT_NOTHELD(_in6m) \
955 lck_mtx_assert(&(_in6m)->in6m_lock, LCK_MTX_ASSERT_NOTOWNED)
956
957 #define IN6M_LOCK(_in6m) \
958 lck_mtx_lock(&(_in6m)->in6m_lock)
959
960 #define IN6M_LOCK_SPIN(_in6m) \
961 lck_mtx_lock_spin(&(_in6m)->in6m_lock)
962
963 #define IN6M_CONVERT_LOCK(_in6m) do { \
964 IN6M_LOCK_ASSERT_HELD(_in6m); \
965 lck_mtx_convert_spin(&(_in6m)->in6m_lock); \
966 } while (0)
967
968 #define IN6M_UNLOCK(_in6m) \
969 lck_mtx_unlock(&(_in6m)->in6m_lock)
970
971 #define IN6M_ADDREF(_in6m) \
972 in6m_addref(_in6m, 0)
973
974 #define IN6M_ADDREF_LOCKED(_in6m) \
975 in6m_addref(_in6m, 1)
976
977 #define IN6M_REMREF(_in6m) \
978 in6m_remref(_in6m, 0)
979
980 #define IN6M_REMREF_LOCKED(_in6m) \
981 in6m_remref(_in6m, 1)
982
983 /* flags to in6_update_ifa */
984 #define IN6_IFAUPDATE_NOWAIT 0x1 /* don't block allocating memory */
985 #define IN6_IFAUPDATE_1STADDR 0x2 /* first address on interface */
986 #define IN6_IFAUPDATE_NEWADDR 0x4 /* new address on interface */
987 #define IN6_IFAUPDATE_DADDELAY 0x8 /* must delay initial DAD probe */
988
989 struct ip6_moptions;
990 struct sockopt;
991 struct inpcb;
992
993 extern LIST_HEAD(in6_multihead, in6_multi) in6_multihead;
994
995 /*
996 * Structure used by macros below to remember position when stepping through
997 * all of the in6_multi records.
998 */
999 struct in6_multistep {
1000 struct in6_ifaddr *i_ia;
1001 struct in6_multi *i_in6m;
1002 };
1003
1004 /*
1005 * Macros for looking up the in6_multi record for a given IP6 multicast
1006 * address on a given interface. If no matching record is found, "in6m"
1007 * returns NULL.
1008 *
1009 * We do this differently compared other BSD implementations; instead of
1010 * walking the if_multiaddrs list at the interface and returning the
1011 * ifma_protospec value of a matching entry, we search the global list
1012 * of in6_multi records and find it that way. Otherwise either the two
1013 * structures (in6_multi, ifmultiaddr) need to be ref counted both ways,
1014 * which will make things too complicated, or they need to reside in the
1015 * same protected domain, which they aren't.
1016 *
1017 * Must be called with in6_multihead_lock held.
1018 */
1019 #define IN6_LOOKUP_MULTI(addr, ifp, in6m) \
1020 /* struct in6_addr *addr; */ \
1021 /* struct ifnet *ifp; */ \
1022 /* struct in6_multi *in6m; */ \
1023 do { \
1024 struct in6_multistep _step; \
1025 IN6_FIRST_MULTI(_step, in6m); \
1026 while ((in6m) != NULL) { \
1027 IN6M_LOCK_SPIN(in6m); \
1028 if ((in6m)->in6m_ifp == (ifp) && \
1029 IN6_ARE_ADDR_EQUAL(&(in6m)->in6m_addr, (addr))) { \
1030 IN6M_ADDREF_LOCKED(in6m); \
1031 IN6M_UNLOCK(in6m); \
1032 break; \
1033 } \
1034 IN6M_UNLOCK(in6m); \
1035 IN6_NEXT_MULTI(_step, in6m); \
1036 } \
1037 } while (0)
1038
1039 /*
1040 * Macro to step through all of the in6_multi records, one at a time.
1041 * The current position is remembered in "step", which the caller must
1042 * provide. IN6_FIRST_MULTI(), below, must be called to initialize "step"
1043 * and get the first record. Both macros return a NULL "in6m" when there
1044 * are no remaining records.
1045 *
1046 * Must be called with in6_multihead_lock held.
1047 */
1048 #define IN6_NEXT_MULTI(step, in6m) \
1049 /* struct in6_multistep step; */ \
1050 /* struct in6_multi *in6m; */ \
1051 do { \
1052 in6_multihead_lock_assert(LCK_RW_ASSERT_HELD); \
1053 if (((in6m) = (step).i_in6m) != NULL) \
1054 (step).i_in6m = (step).i_in6m->in6m_entry.le_next; \
1055 } while (0)
1056
1057 #define IN6_FIRST_MULTI(step, in6m) \
1058 /* struct in6_multistep step; */ \
1059 /* struct in6_multi *in6m */ \
1060 do { \
1061 in6_multihead_lock_assert(LCK_RW_ASSERT_HELD); \
1062 (step).i_in6m = in6_multihead.lh_first; \
1063 IN6_NEXT_MULTI((step), (in6m)); \
1064 } while (0)
1065
1066 extern lck_mtx_t *inet6_domain_mutex;
1067 extern struct domain *inet6domain;
1068
1069 struct ip6_pktopts;
1070
1071 /* Multicast private KPIs. */
1072 extern int im6o_mc_filter(const struct ip6_moptions *, const struct ifnet *,
1073 const struct sockaddr *, const struct sockaddr *);
1074 extern int in6_mc_join(struct ifnet *, const struct in6_addr *,
1075 struct in6_mfilter *, struct in6_multi **, int);
1076 extern int in6_mc_leave(struct in6_multi *, struct in6_mfilter *);
1077 extern void in6m_clear_recorded(struct in6_multi *);
1078 extern void in6m_commit(struct in6_multi *);
1079 extern void in6m_purge(struct in6_multi *);
1080 extern void in6m_print(const struct in6_multi *);
1081 extern int in6m_record_source(struct in6_multi *, const struct in6_addr *);
1082 extern int ip6_getmoptions(struct inpcb *, struct sockopt *);
1083 extern int ip6_setmoptions(struct inpcb *, struct sockopt *);
1084 /* Legacy KAME multicast private KPIs. */
1085 extern struct in6_multi_mship *in6_joingroup(struct ifnet *,
1086 struct in6_addr *, int *, int);
1087 extern int in6_leavegroup(struct in6_multi_mship *);
1088 extern void in6_multi_init(void);
1089 extern void in6m_addref(struct in6_multi *, int);
1090 extern void in6m_remref(struct in6_multi *, int);
1091 extern int in6_multi_detach(struct in6_multi *);
1092 extern int in6_ifindex2scopeid(int);
1093 extern int in6_mask2len(struct in6_addr *, u_char *);
1094 extern void in6_len2mask(struct in6_addr *, int);
1095 extern int in6_control(struct socket *, u_long, caddr_t, struct ifnet *,
1096 struct proc *);
1097 extern int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, int,
1098 struct in6_ifaddr **);
1099 extern void in6_purgeaddr(struct ifaddr *);
1100 extern int in6if_do_dad(struct ifnet *);
1101 extern void in6_purgeif(struct ifnet *);
1102 extern void in6_savemkludge(struct in6_ifaddr *);
1103 extern void in6_setmaxmtu(void);
1104 extern void in6_restoremkludge(struct in6_ifaddr *, struct ifnet *);
1105 extern void in6_purgemkludge(struct ifnet *);
1106 extern struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int);
1107 extern struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *);
1108 extern struct in6_ifaddr *in6ifa_prproxyaddr(struct in6_addr *);
1109 extern void in6ifa_getlifetime(struct in6_ifaddr *,
1110 struct in6_addrlifetime *, int);
1111 extern void in6ifa_setlifetime(struct in6_ifaddr *, struct in6_addrlifetime *);
1112 extern char *ip6_sprintf(const struct in6_addr *);
1113 extern int in6_addr2scopeid(struct ifnet *, struct in6_addr *);
1114 extern int in6_matchlen(struct in6_addr *, struct in6_addr *);
1115 extern int in6_are_prefix_equal(struct in6_addr *p1, struct in6_addr *p2,
1116 int len);
1117 extern void in6_prefixlen2mask(struct in6_addr *maskp, int len);
1118 extern int in6_prefix_add_ifid(int iilen, struct in6_ifaddr *ia);
1119 extern void in6_prefix_remove_ifid(int iilen, struct in6_ifaddr *ia);
1120 extern void in6_purgeprefix(struct ifnet *);
1121 extern void in6_purgeaddrs(struct ifnet *);
1122 extern uint8_t im6s_get_mode(const struct in6_multi *,
1123 const struct ip6_msource *, uint8_t);
1124 extern void im6f_leave(struct in6_mfilter *);
1125 extern void im6f_purge(struct in6_mfilter *);
1126 extern int in6_embedscope(struct in6_addr *, const struct sockaddr_in6 *,
1127 struct inpcb *, struct ifnet **, struct ip6_pktopts *);
1128 extern int in6_recoverscope(struct sockaddr_in6 *, const struct in6_addr *,
1129 struct ifnet *);
1130 extern void in6_aliasreq_64_to_32(struct in6_aliasreq_64 *,
1131 struct in6_aliasreq_32 *);
1132 extern void in6_aliasreq_32_to_64(struct in6_aliasreq_32 *,
1133 struct in6_aliasreq_64 *);
1134 extern void in6_ifaddr_init(void);
1135 extern int in6_inithead(void **, int);
1136 extern void in6_rtqdrain(void);
1137 extern struct radix_node *in6_validate(struct radix_node *);
1138 extern int in6_if2idlen(struct ifnet *);
1139 extern int in6_src_ioctl(u_long, caddr_t);
1140 extern void in6_multihead_lock_exclusive(void);
1141 extern void in6_multihead_lock_shared(void);
1142 extern void in6_multihead_lock_assert(int);
1143 extern void in6_multihead_lock_done(void);
1144
1145 extern void in6_cga_init(void);
1146 extern void in6_cga_node_lock(void);
1147 extern void in6_cga_node_unlock(void);
1148 extern void in6_cga_query(struct in6_cga_nodecfg *);
1149 extern int in6_cga_start(const struct in6_cga_nodecfg *);
1150 extern int in6_cga_stop(void);
1151 extern ssize_t in6_cga_parameters_prepare(void *, size_t,
1152 const struct in6_addr *, u_int8_t, const struct in6_cga_modifier *);
1153 extern int in6_cga_generate(struct in6_cga_prepare *, u_int8_t,
1154 struct in6_addr *);
1155
1156 #endif /* BSD_KERNEL_PRIVATE */
1157 #endif /* _NETINET6_IN6_VAR_H_ */