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