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