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