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