xref: /freebsd/sys/netinet6/in6.h (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the project nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	$KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $
32  */
33 
34 /*-
35  * Copyright (c) 1982, 1986, 1990, 1993
36  *	The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  */
62 
63 #ifndef __KAME_NETINET_IN_H_INCLUDED_
64 #error "do not include netinet6/in6.h directly, include netinet/in.h.  see RFC2553"
65 #endif
66 
67 #ifndef _NETINET6_IN6_H_
68 #define _NETINET6_IN6_H_
69 
70 /*
71  * Identification of the network protocol stack
72  * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
73  * has the table of implementation/integration differences.
74  */
75 #define __KAME__
76 #define __KAME_VERSION		"FreeBSD"
77 
78 /*
79  * IPv6 port allocation rules should mirror the IPv4 rules and are controlled
80  * by the net.inet.ip.portrange sysctl tree. The following defines exist
81  * for compatibility with userland applications that need them.
82  */
83 #if __BSD_VISIBLE
84 #define	IPV6PORT_RESERVED	1024
85 #define	IPV6PORT_ANONMIN	49152
86 #define	IPV6PORT_ANONMAX	65535
87 #define	IPV6PORT_RESERVEDMIN	600
88 #define	IPV6PORT_RESERVEDMAX	(IPV6PORT_RESERVED-1)
89 #endif
90 
91 /*
92  * IPv6 address
93  */
94 struct in6_addr {
95 	union {
96 		uint8_t		__u6_addr8[16];
97 		uint16_t	__u6_addr16[8];
98 		uint32_t	__u6_addr32[4];
99 	} __u6_addr;			/* 128-bit IP6 address */
100 };
101 
102 #define s6_addr   __u6_addr.__u6_addr8
103 #if __BSD_VISIBLE
104 /*
105  * s6_addr is the only in6_addr element specified in RFCs 2553 and 3493,
106  * also in POSIX 1003.1-2017.  The following three definitions were not
107  * exposed to user programs in FreeBSD before 14.1, or in other BSDs,
108  * and are thus less portable than s6_addr.
109  */
110 #define s6_addr8  __u6_addr.__u6_addr8
111 #define s6_addr16 __u6_addr.__u6_addr16
112 #define s6_addr32 __u6_addr.__u6_addr32
113 #endif
114 
115 #define INET6_ADDRSTRLEN	46
116 
117 /*
118  * XXX missing POSIX.1-2001 macro IPPROTO_IPV6.
119  */
120 
121 /*
122  * Socket address for IPv6
123  */
124 #if __BSD_VISIBLE
125 #define SIN6_LEN
126 #endif
127 
128 struct sockaddr_in6 {
129 	uint8_t		sin6_len;	/* length of this struct */
130 	sa_family_t	sin6_family;	/* AF_INET6 */
131 	in_port_t	sin6_port;	/* Transport layer port # */
132 	uint32_t	sin6_flowinfo;	/* IP6 flow information */
133 	struct in6_addr	sin6_addr;	/* IP6 address */
134 	uint32_t	sin6_scope_id;	/* scope zone index */
135 };
136 
137 /*
138  * Local definition for masks
139  */
140 #ifdef _KERNEL	/* XXX nonstandard */
141 #define IN6MASK0	{{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
142 #define IN6MASK32	{{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
143 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
144 #define IN6MASK64	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
145 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
146 #define IN6MASK96	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
147 			    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
148 #define IN6MASK128	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
149 			    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
150 #endif
151 
152 #ifdef _KERNEL
153 extern const struct sockaddr_in6 sa6_any;
154 
155 extern const struct in6_addr in6mask0;
156 extern const struct in6_addr in6mask32;
157 extern const struct in6_addr in6mask64;
158 extern const struct in6_addr in6mask96;
159 extern const struct in6_addr in6mask128;
160 #endif /* _KERNEL */
161 
162 /*
163  * Macros started with IPV6_ADDR is KAME local
164  */
165 #ifdef _KERNEL	/* XXX nonstandard */
166 #if _BYTE_ORDER == _BIG_ENDIAN
167 #define IPV6_ADDR_INT32_ONE	1
168 #define IPV6_ADDR_INT32_TWO	2
169 #define IPV6_ADDR_INT32_MNL	0xff010000
170 #define IPV6_ADDR_INT32_MLL	0xff020000
171 #define IPV6_ADDR_INT32_SMP	0x0000ffff
172 #define IPV6_ADDR_INT16_ULL	0xfe80
173 #define IPV6_ADDR_INT16_USL	0xfec0
174 #define IPV6_ADDR_INT16_MLL	0xff02
175 #elif _BYTE_ORDER == _LITTLE_ENDIAN
176 #define IPV6_ADDR_INT32_ONE	0x01000000
177 #define IPV6_ADDR_INT32_TWO	0x02000000
178 #define IPV6_ADDR_INT32_MNL	0x000001ff
179 #define IPV6_ADDR_INT32_MLL	0x000002ff
180 #define IPV6_ADDR_INT32_SMP	0xffff0000
181 #define IPV6_ADDR_INT16_ULL	0x80fe
182 #define IPV6_ADDR_INT16_USL	0xc0fe
183 #define IPV6_ADDR_INT16_MLL	0x02ff
184 #endif
185 #endif
186 
187 /*
188  * Definition of some useful macros to handle IP6 addresses
189  */
190 #if __BSD_VISIBLE
191 #define IN6ADDR_ANY_INIT \
192 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
193 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
194 #define IN6ADDR_LOOPBACK_INIT \
195 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
196 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
197 #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
198 	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
199 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
200 #define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
201 	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
202 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
203 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
204 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
205 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
206 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
207 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
208 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
209 #define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
210 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
211 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
212 #endif
213 
214 extern const struct in6_addr in6addr_any;
215 extern const struct in6_addr in6addr_loopback;
216 #if __BSD_VISIBLE
217 extern const struct in6_addr in6addr_nodelocal_allnodes;
218 extern const struct in6_addr in6addr_linklocal_allnodes;
219 extern const struct in6_addr in6addr_linklocal_allrouters;
220 extern const struct in6_addr in6addr_linklocal_allv2routers;
221 #endif
222 
223 /*
224  * Equality
225  */
226 #if __BSD_VISIBLE
227 #define IN6_ARE_ADDR_EQUAL(a, b)			\
228     (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
229 #endif
230 
231 /*
232  * Unspecified
233  */
234 #define IN6_IS_ADDR_UNSPECIFIED(a)	\
235 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
236 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
237 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
238 	 (a)->__u6_addr.__u6_addr32[3] == 0)
239 
240 /*
241  * Loopback
242  */
243 #define IN6_IS_ADDR_LOOPBACK(a)		\
244 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
245 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
246 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
247 	 (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
248 
249 /*
250  * IPv4 compatible
251  */
252 #define IN6_IS_ADDR_V4COMPAT(a)		\
253 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
254 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
255 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
256 	 (a)->__u6_addr.__u6_addr32[3] != 0 &&	\
257 	 (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
258 
259 /*
260  * Mapped
261  */
262 #define IN6_IS_ADDR_V4MAPPED(a)		      \
263 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
264 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
265 	 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
266 
267 /*
268  * KAME Scope Values
269  */
270 
271 #ifdef _KERNEL	/* XXX nonstandard */
272 #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
273 #define IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
274 #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
275 #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
276 #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
277 #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
278 #else
279 #define __IPV6_ADDR_SCOPE_NODELOCAL	0x01
280 #define __IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
281 #define __IPV6_ADDR_SCOPE_LINKLOCAL	0x02
282 #define __IPV6_ADDR_SCOPE_SITELOCAL	0x05
283 #define __IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
284 #define __IPV6_ADDR_SCOPE_GLOBAL	0x0e
285 #endif
286 
287 /*
288  * Unicast Scope
289  * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
290  */
291 #define IN6_IS_ADDR_LINKLOCAL(a)	\
292 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
293 #define IN6_IS_ADDR_SITELOCAL(a)	\
294 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
295 
296 /*
297  * Multicast
298  */
299 #define IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
300 
301 #ifdef _KERNEL	/* XXX nonstandard */
302 #define IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
303 #else
304 #define __IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
305 #endif
306 
307 /*
308  * Multicast Scope
309  */
310 #ifdef _KERNEL	/* refers nonstandard items */
311 #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
312 	(IN6_IS_ADDR_MULTICAST(a) &&	\
313 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
314 #define IN6_IS_ADDR_MC_INTFACELOCAL(a)	\
315 	(IN6_IS_ADDR_MULTICAST(a) &&	\
316 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
317 #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
318 	(IN6_IS_ADDR_MULTICAST(a) &&	\
319 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
320 #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
321 	(IN6_IS_ADDR_MULTICAST(a) &&	\
322 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
323 #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
324 	(IN6_IS_ADDR_MULTICAST(a) &&	\
325 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
326 #define IN6_IS_ADDR_MC_GLOBAL(a)	\
327 	(IN6_IS_ADDR_MULTICAST(a) &&	\
328 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
329 #else
330 #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
331 	(IN6_IS_ADDR_MULTICAST(a) &&	\
332 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
333 #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
334 	(IN6_IS_ADDR_MULTICAST(a) &&	\
335 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
336 #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
337 	(IN6_IS_ADDR_MULTICAST(a) &&	\
338 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
339 #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
340 	(IN6_IS_ADDR_MULTICAST(a) &&	\
341 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
342 #define IN6_IS_ADDR_MC_GLOBAL(a)	\
343 	(IN6_IS_ADDR_MULTICAST(a) &&	\
344 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
345 #endif
346 
347 #ifdef _KERNEL	/* nonstandard */
348 /*
349  * KAME Scope
350  */
351 #define IN6_IS_SCOPE_LINKLOCAL(a)	\
352 	((IN6_IS_ADDR_LINKLOCAL(a)) ||	\
353 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
354 #define	IN6_IS_SCOPE_EMBED(a)			\
355 	((IN6_IS_ADDR_LINKLOCAL(a)) ||		\
356 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)) ||	\
357 	 (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
358 
359 #define IFA6_IS_DEPRECATED(a) \
360 	((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
361 	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
362 	 (a)->ia6_lifetime.ia6t_pltime)
363 #define IFA6_IS_INVALID(a) \
364 	((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
365 	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
366 	 (a)->ia6_lifetime.ia6t_vltime)
367 #endif /* _KERNEL */
368 
369 /*
370  * IP6 route structure
371  */
372 #if __BSD_VISIBLE
373 struct nhop_object;
374 struct route_in6 {
375 	struct nhop_object *ro_nh;
376 	struct	llentry *ro_lle;
377 	/*
378 	 * ro_prepend and ro_plen are only used for bpf to pass in a
379 	 * preformed header.  They are not cacheable.
380 	 */
381 	char		*ro_prepend;
382 	uint16_t	ro_plen;
383 	uint16_t	ro_flags;
384 	uint16_t	ro_mtu;	/* saved ro_rt mtu */
385 	uint16_t	spare;
386 	struct	sockaddr_in6 ro_dst;
387 };
388 #endif
389 
390 #ifdef _KERNEL
391 #define MTAG_ABI_IPV6		1444287380	/* IPv6 ABI */
392 #define IPV6_TAG_DIRECT		0		/* direct-dispatch IPv6 */
393 #endif /* _KERNEL */
394 
395 /*
396  * Options for use with [gs]etsockopt at the IPV6 level.
397  * First word of comment is data type; bool is stored in int.
398  */
399 /* no hdrincl */
400 #if 0 /* the followings are relic in IPv4 and hence are disabled */
401 #define IPV6_OPTIONS		1  /* buf/ip6_opts; set/get IP6 options */
402 #define IPV6_RECVOPTS		5  /* bool; receive all IP6 opts w/dgram */
403 #define IPV6_RECVRETOPTS	6  /* bool; receive IP6 opts for response */
404 #define IPV6_RECVDSTADDR	7  /* bool; receive IP6 dst addr w/dgram */
405 #define IPV6_RETOPTS		8  /* ip6_opts; set/get IP6 options */
406 #endif
407 #define IPV6_SOCKOPT_RESERVED1	3  /* reserved for future use */
408 #define IPV6_UNICAST_HOPS	4  /* int; IP6 hops */
409 #define IPV6_MULTICAST_IF	9  /* u_int; set/get IP6 multicast i/f  */
410 #define IPV6_MULTICAST_HOPS	10 /* int; set/get IP6 multicast hops */
411 #define IPV6_MULTICAST_LOOP	11 /* u_int; set/get IP6 multicast loopback */
412 #define IPV6_JOIN_GROUP		12 /* ipv6_mreq; join a group membership */
413 #define IPV6_LEAVE_GROUP	13 /* ipv6_mreq; leave a group membership */
414 #define IPV6_PORTRANGE		14 /* int; range to choose for unspec port */
415 #define ICMP6_FILTER		18 /* icmp6_filter; icmp6 filter */
416 /* RFC2292 options */
417 #ifdef _KERNEL
418 #define IPV6_2292PKTINFO	19 /* bool; send/recv if, src/dst addr */
419 #define IPV6_2292HOPLIMIT	20 /* bool; hop limit */
420 #define IPV6_2292NEXTHOP	21 /* bool; next hop addr */
421 #define IPV6_2292HOPOPTS	22 /* bool; hop-by-hop option */
422 #define IPV6_2292DSTOPTS	23 /* bool; destinaion option */
423 #define IPV6_2292RTHDR		24 /* bool; routing header */
424 #define IPV6_2292PKTOPTIONS	25 /* buf/cmsghdr; set/get IPv6 options */
425 #endif
426 
427 #define IPV6_CHECKSUM		26 /* int; checksum offset for raw socket */
428 #define IPV6_V6ONLY		27 /* bool; make AF_INET6 sockets v6 only */
429 #ifndef _KERNEL
430 #define IPV6_BINDV6ONLY		IPV6_V6ONLY
431 #endif
432 
433 #define IPV6_IPSEC_POLICY	28 /* struct; get/set security policy */
434 				   /* 29; unused; was IPV6_FAITH */
435 #if 1 /* IPV6FIREWALL */
436 #define IPV6_FW_ADD		30 /* add a firewall rule to chain */
437 #define IPV6_FW_DEL		31 /* delete a firewall rule from chain */
438 #define IPV6_FW_FLUSH		32 /* flush firewall rule chain */
439 #define IPV6_FW_ZERO		33 /* clear single/all firewall counter(s) */
440 #define IPV6_FW_GET		34 /* get entire firewall rule chain */
441 #endif
442 
443 /* new socket options introduced in RFC3542 */
444 #define IPV6_RTHDRDSTOPTS	35 /* ip6_dest; send dst option before rthdr */
445 
446 #define IPV6_RECVPKTINFO	36 /* bool; recv if, dst addr */
447 #define IPV6_RECVHOPLIMIT	37 /* bool; recv hop limit */
448 #define IPV6_RECVRTHDR		38 /* bool; recv routing header */
449 #define IPV6_RECVHOPOPTS	39 /* bool; recv hop-by-hop option */
450 #define IPV6_RECVDSTOPTS	40 /* bool; recv dst option after rthdr */
451 #ifdef _KERNEL
452 #define IPV6_RECVRTHDRDSTOPTS	41 /* bool; recv dst option before rthdr */
453 #endif
454 
455 #define IPV6_USE_MIN_MTU	42 /* bool; send packets at the minimum MTU */
456 #define IPV6_RECVPATHMTU	43 /* bool; notify an according MTU */
457 
458 #define IPV6_PATHMTU		44 /* mtuinfo; get the current path MTU (sopt),
459 				      4 bytes int; MTU notification (cmsg) */
460 #if 0 /*obsoleted during 2292bis -> 3542*/
461 #define IPV6_REACHCONF		45 /* no data; ND reachability confirm
462 				      (cmsg only/not in of RFC3542) */
463 #endif
464 
465 /* more new socket options introduced in RFC3542 */
466 #define IPV6_PKTINFO		46 /* in6_pktinfo; send if, src addr */
467 #define IPV6_HOPLIMIT		47 /* int; send hop limit */
468 #define IPV6_NEXTHOP		48 /* sockaddr; next hop addr */
469 #define IPV6_HOPOPTS		49 /* ip6_hbh; send hop-by-hop option */
470 #define IPV6_DSTOPTS		50 /* ip6_dest; send dst option befor rthdr */
471 #define IPV6_RTHDR		51 /* ip6_rthdr; send routing header */
472 #if 0
473 #define IPV6_PKTOPTIONS		52 /* buf/cmsghdr; set/get IPv6 options */
474 				   /* obsoleted by RFC3542 */
475 #endif
476 
477 #define IPV6_RECVTCLASS		57 /* bool; recv traffic class values */
478 
479 #define IPV6_AUTOFLOWLABEL	59 /* bool; attach flowlabel automagically */
480 
481 #define IPV6_TCLASS		61 /* int; send traffic class value */
482 #define IPV6_DONTFRAG		62 /* bool; disable IPv6 fragmentation */
483 
484 #define IPV6_PREFER_TEMPADDR	63 /* int; prefer temporary addresses as
485 				    * the source address.
486 				    */
487 
488 #define	IPV6_BINDANY		64 /* bool: allow bind to any address */
489 				   /* unused; was IPV6_BIND_MULTI */
490 				   /* unused; was IPV6_RSS_LISTEN_BUCKET */
491 #define	IPV6_FLOWID		67 /* int; flowid of given socket */
492 #define	IPV6_FLOWTYPE		68 /* int; flowtype of given socket */
493 #define	IPV6_RSSBUCKETID	69 /* int; RSS bucket ID of given socket */
494 #define	IPV6_RECVFLOWID		70 /* bool; receive IP6 flowid/flowtype w/ datagram */
495 #define	IPV6_RECVRSSBUCKETID	71 /* bool; receive IP6 RSS bucket id w/ datagram */
496 
497 #define	IPV6_ORIGDSTADDR	72 /* bool: allow getting dstaddr /port info */
498 #define	IPV6_RECVORIGDSTADDR	IPV6_ORIGDSTADDR
499 
500 /*
501  * The following option is private; do not use it from user applications.
502  * It is deliberately defined to the same value as IP_MSFILTER.
503  */
504 #define	IPV6_MSFILTER		74 /* struct __msfilterreq;
505 				    * set/get multicast source filter list.
506 				    */
507 
508 /* The following option deals with the 802.1Q Ethernet Priority Code Point */
509 #define	IPV6_VLAN_PCP		75  /* int; set/get PCP used for packet, */
510 				    /*      -1 use interface default */
511 
512 /* to define items, should talk with KAME guys first, for *BSD compatibility */
513 
514 #define IPV6_RTHDR_LOOSE     0 /* this hop need not be a neighbor. XXX old spec */
515 #define IPV6_RTHDR_STRICT    1 /* this hop must be a neighbor. XXX old spec */
516 #define IPV6_RTHDR_TYPE_0    0 /* IPv6 routing header type 0 */
517 
518 /*
519  * Defaults and limits for options
520  */
521 #define IPV6_DEFAULT_MULTICAST_HOPS 1	/* normally limit m'casts to 1 hop */
522 #define IPV6_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member */
523 
524 /*
525  * Limit for IPv6 multicast memberships
526  */
527 #define	IPV6_MAX_MEMBERSHIPS	4095
528 
529 /*
530  * Default resource limits for IPv6 multicast source filtering.
531  * These may be modified by sysctl.
532  */
533 #define	IPV6_MAX_GROUP_SRC_FILTER	512	/* sources per group */
534 #define	IPV6_MAX_SOCK_SRC_FILTER	128	/* sources per socket/group */
535 
536 /*
537  * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
538  */
539 struct ipv6_mreq {
540 	struct in6_addr	ipv6mr_multiaddr;
541 	unsigned int	ipv6mr_interface;
542 };
543 
544 /*
545  * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
546  */
547 struct in6_pktinfo {
548 	struct in6_addr	ipi6_addr;	/* src/dst IPv6 address */
549 	unsigned int	ipi6_ifindex;	/* send/recv interface index */
550 };
551 
552 /*
553  * Control structure for IPV6_RECVPATHMTU socket option.
554  */
555 struct ip6_mtuinfo {
556 	struct sockaddr_in6 ip6m_addr;	/* or sockaddr_storage? */
557 	uint32_t ip6m_mtu;
558 };
559 
560 /*
561  * Argument for IPV6_PORTRANGE:
562  * - which range to search when port is unspecified at bind() or connect()
563  */
564 #define	IPV6_PORTRANGE_DEFAULT	0	/* default range */
565 #define	IPV6_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
566 #define	IPV6_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
567 
568 #if __BSD_VISIBLE
569 /*
570  * Definitions for inet6 sysctl operations.
571  *
572  * Third level is protocol number.
573  * Fourth level is desired variable within that protocol.
574  */
575 #define IPV6PROTO_MAXID	(IPPROTO_PIM + 1)	/* don't list to IPV6PROTO_MAX */
576 
577 /*
578  * Names for IP sysctl objects
579  */
580 #define IPV6CTL_FORWARDING	1	/* act as router */
581 #define IPV6CTL_SENDREDIRECTS	2	/* may send redirects when forwarding*/
582 #define IPV6CTL_DEFHLIM		3	/* default Hop-Limit */
583 #ifdef notyet
584 #define IPV6CTL_DEFMTU		4	/* default MTU */
585 #endif
586 #define IPV6CTL_FORWSRCRT	5	/* forward source-routed dgrams */
587 #define IPV6CTL_STATS		6	/* stats */
588 #define IPV6CTL_MRTSTATS	7	/* multicast forwarding stats */
589 #define IPV6CTL_MRTPROTO	8	/* multicast routing protocol */
590 #define IPV6CTL_MAXFRAGPACKETS	9	/* max packets reassembly queue */
591 #define IPV6CTL_SOURCECHECK	10	/* verify source route and intf */
592 #define IPV6CTL_SOURCECHECK_LOGINT 11	/* minimume logging interval */
593 #define IPV6CTL_ACCEPT_RTADV	12
594 					/* 13; unused; was: IPV6CTL_KEEPFAITH */
595 #define IPV6CTL_LOG_INTERVAL	14
596 #define IPV6CTL_HDRNESTLIMIT	15
597 #define IPV6CTL_DAD_COUNT	16
598 #define IPV6CTL_AUTO_FLOWLABEL	17
599 #define IPV6CTL_DEFMCASTHLIM	18
600 #define IPV6CTL_GIF_HLIM	19	/* default HLIM for gif encap packet */
601 #define IPV6CTL_KAME_VERSION	20
602 #define IPV6CTL_USE_DEPRECATED	21	/* use deprecated addr (RFC2462 5.5.4) */
603 #define IPV6CTL_RR_PRUNE	22	/* walk timer for router renumbering */
604 #if 0	/* obsolete */
605 #define IPV6CTL_MAPPED_ADDR	23
606 #endif
607 #define IPV6CTL_V6ONLY		24
608 /*	IPV6CTL_RTEXPIRE	25	deprecated */
609 /*	IPV6CTL_RTMINEXPIRE	26	deprecated */
610 /*	IPV6CTL_RTMAXCACHE	27	deprecated */
611 
612 #define IPV6CTL_USETEMPADDR	32	/* use temporary addresses (RFC3041) */
613 #define IPV6CTL_TEMPPLTIME	33	/* preferred lifetime for tmpaddrs */
614 #define IPV6CTL_TEMPVLTIME	34	/* valid lifetime for tmpaddrs */
615 #define IPV6CTL_AUTO_LINKLOCAL	35	/* automatic link-local addr assign */
616 #define IPV6CTL_RIP6STATS	36	/* raw_ip6 stats */
617 #define IPV6CTL_PREFER_TEMPADDR	37	/* prefer temporary addr as src */
618 #define IPV6CTL_ADDRCTLPOLICY	38	/* get/set address selection policy */
619 #define IPV6CTL_USE_DEFAULTZONE	39	/* use default scope zone */
620 
621 #define IPV6CTL_MAXFRAGS	41	/* max fragments */
622 #if 0
623 #define IPV6CTL_IFQ		42	/* ip6intrq node */
624 #define IPV6CTL_ISATAPRTR	43	/* isatap router */
625 #endif
626 #define IPV6CTL_MCAST_PMTU	44	/* enable pMTU discovery for multicast? */
627 
628 /* New entries should be added here from current IPV6CTL_MAXID value. */
629 /* to define items, should talk with KAME guys first, for *BSD compatibility */
630 #define IPV6CTL_STEALTH		45
631 
632 #define	ICMPV6CTL_ND6_ONLINKNSRFC4861	47
633 #define	IPV6CTL_NO_RADR		48	/* No defroute from RA */
634 #define	IPV6CTL_NORBIT_RAIF	49	/* Disable R-bit in NA on RA
635 					 * receiving IF. */
636 #define	IPV6CTL_RFC6204W3	50	/* Accept defroute even when forwarding
637 					   enabled */
638 #define	IPV6CTL_INTRQMAXLEN	51	/* max length of IPv6 netisr queue */
639 #define	IPV6CTL_INTRDQMAXLEN	52	/* max length of direct IPv6 netisr
640 					 * queue */
641 #define	IPV6CTL_MAXFRAGSPERPACKET	53 /* Max fragments per packet */
642 #define	IPV6CTL_MAXFRAGBUCKETSIZE	54 /* Max reassembly queues per bucket */
643 #define	IPV6CTL_MAXID		55
644 #endif /* __BSD_VISIBLE */
645 
646 /*
647  * Since both netinet/ and netinet6/ call into netipsec/ and netpfil/,
648  * the protocol specific mbuf flags are shared between them.
649  */
650 #define	M_FASTFWD_OURS		M_PROTO1	/* changed dst to local */
651 #define	M_IP6_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
652 #define	M_IP_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
653 #define	M_SKIP_FIREWALL		M_PROTO3	/* skip firewall processing */
654 #define	M_AUTHIPHDR		M_PROTO4
655 #define	M_DECRYPTED		M_PROTO5
656 #define	M_LOOP			M_PROTO6
657 #define	M_AUTHIPDGM		M_PROTO7
658 #define	M_RTALERT_MLD		M_PROTO8
659 #define	M_FRAGMENTED		M_PROTO9	/* contained fragment header */
660 
661 #ifdef _KERNEL
662 struct cmsghdr;
663 struct ip6_hdr;
664 
665 int	in6_cksum(struct mbuf *, uint8_t, uint32_t, uint32_t);
666 int	in6_cksum_partial(struct mbuf *, uint8_t, uint32_t, uint32_t, uint32_t);
667 int	in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
668 
669 int	in6_localaddr(struct in6_addr *);
670 int	in6_localip(struct in6_addr *);
671 bool	in6_localip_fib(struct in6_addr *, uint16_t);
672 int	in6_ifhasaddr(struct ifnet *, struct in6_addr *);
673 int	in6_addrscope(const struct in6_addr *);
674 char	*ip6_sprintf(char *, const struct in6_addr *);
675 struct	in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
676 extern void in6_if_up(struct ifnet *);
677 struct sockaddr;
678 
679 void	in6_sin6_2_sin(struct sockaddr_in *sin,
680 			    struct sockaddr_in6 *sin6);
681 void	in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
682 				 struct sockaddr_in6 *sin6);
683 void	in6_sin6_2_sin_in_sock(struct sockaddr *nam);
684 extern void addrsel_policy_init(void);
685 
686 #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
687 #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
688 #define	ifatoia6(ifa)	((struct in6_ifaddr *)(ifa))
689 
690 #endif /* _KERNEL */
691 
692 #ifndef _SIZE_T_DECLARED
693 typedef	__size_t	size_t;
694 #define	_SIZE_T_DECLARED
695 #endif
696 
697 #ifndef _SOCKLEN_T_DECLARED
698 typedef	__socklen_t	socklen_t;
699 #define	_SOCKLEN_T_DECLARED
700 #endif
701 
702 #if __BSD_VISIBLE
703 
704 __BEGIN_DECLS
705 struct cmsghdr;
706 
707 extern int inet6_option_space(int);
708 extern int inet6_option_init(void *, struct cmsghdr **, int);
709 extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
710 	int, int);
711 extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
712 extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
713 extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
714 
715 extern size_t inet6_rthdr_space(int, int);
716 extern struct cmsghdr *inet6_rthdr_init(void *, int);
717 extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
718 	unsigned int);
719 extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
720 #if 0 /* not implemented yet */
721 extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
722 #endif
723 extern int inet6_rthdr_segments(const struct cmsghdr *);
724 extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
725 extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
726 
727 extern int inet6_opt_init(void *, socklen_t);
728 extern int inet6_opt_append(void *, socklen_t, int, uint8_t, socklen_t,
729 	uint8_t, void **);
730 extern int inet6_opt_finish(void *, socklen_t, int);
731 extern int inet6_opt_set_val(void *, int, void *, socklen_t);
732 
733 extern int inet6_opt_next(void *, socklen_t, int, uint8_t *, socklen_t *,
734 	void **);
735 extern int inet6_opt_find(void *, socklen_t, int, uint8_t, socklen_t *,
736 	void **);
737 extern int inet6_opt_get_val(void *, int, void *, socklen_t);
738 extern socklen_t inet6_rth_space(int, int);
739 extern void *inet6_rth_init(void *, socklen_t, int, int);
740 extern int inet6_rth_add(void *, const struct in6_addr *);
741 extern int inet6_rth_reverse(const void *, void *);
742 extern int inet6_rth_segments(const void *);
743 extern struct in6_addr *inet6_rth_getaddr(const void *, int);
744 __END_DECLS
745 
746 #endif /* __BSD_VISIBLE */
747 
748 #endif /* !_NETINET6_IN6_H_ */
749