xref: /freebsd/sys/netinet6/in6.h (revision 51369649b03ece2aed3eb61b0c8214b9aa5b2fa2)
1caf43b02SWarner Losh /*-
2*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*51369649SPedro F. Giffuni  *
476429de4SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
576429de4SYoshinobu Inoue  * All rights reserved.
676429de4SYoshinobu Inoue  *
776429de4SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
876429de4SYoshinobu Inoue  * modification, are permitted provided that the following conditions
976429de4SYoshinobu Inoue  * are met:
1076429de4SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
1176429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1276429de4SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1376429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1476429de4SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1576429de4SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
1676429de4SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
1776429de4SYoshinobu Inoue  *    without specific prior written permission.
1876429de4SYoshinobu Inoue  *
1976429de4SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2076429de4SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2176429de4SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2276429de4SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2376429de4SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2476429de4SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2576429de4SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2676429de4SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2776429de4SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2876429de4SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2976429de4SYoshinobu Inoue  * SUCH DAMAGE.
30b48287a3SDavid E. O'Brien  *
31b48287a3SDavid E. O'Brien  *	$KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $
3276429de4SYoshinobu Inoue  */
3376429de4SYoshinobu Inoue 
34caf43b02SWarner Losh /*-
3576429de4SYoshinobu Inoue  * Copyright (c) 1982, 1986, 1990, 1993
3676429de4SYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
3776429de4SYoshinobu Inoue  *
3876429de4SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
3976429de4SYoshinobu Inoue  * modification, are permitted provided that the following conditions
4076429de4SYoshinobu Inoue  * are met:
4176429de4SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
4276429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
4376429de4SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
4476429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
4576429de4SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
46fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
4776429de4SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
4876429de4SYoshinobu Inoue  *    without specific prior written permission.
4976429de4SYoshinobu Inoue  *
5076429de4SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5176429de4SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5276429de4SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5376429de4SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5476429de4SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5576429de4SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5676429de4SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5776429de4SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5876429de4SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5976429de4SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6076429de4SYoshinobu Inoue  * SUCH DAMAGE.
6176429de4SYoshinobu Inoue  *
6276429de4SYoshinobu Inoue  *	@(#)in.h	8.3 (Berkeley) 1/3/94
63b48287a3SDavid E. O'Brien  * $FreeBSD$
6476429de4SYoshinobu Inoue  */
6576429de4SYoshinobu Inoue 
66686cdd19SJun-ichiro itojun Hagino #ifndef __KAME_NETINET_IN_H_INCLUDED_
6733841545SHajimu UMEMOTO #error "do not include netinet6/in6.h directly, include netinet/in.h.  see RFC2553"
68686cdd19SJun-ichiro itojun Hagino #endif
69686cdd19SJun-ichiro itojun Hagino 
7076429de4SYoshinobu Inoue #ifndef _NETINET6_IN6_H_
7176429de4SYoshinobu Inoue #define _NETINET6_IN6_H_
7276429de4SYoshinobu Inoue 
7376429de4SYoshinobu Inoue /*
7476429de4SYoshinobu Inoue  * Identification of the network protocol stack
7533841545SHajimu UMEMOTO  * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
7633841545SHajimu UMEMOTO  * has the table of implementation/integration differences.
7776429de4SYoshinobu Inoue  */
7876429de4SYoshinobu Inoue #define __KAME__
79e381ac4dSSUZUKI Shinsuke #define __KAME_VERSION		"FreeBSD"
8076429de4SYoshinobu Inoue 
8176429de4SYoshinobu Inoue /*
82fe124573SDavid Malone  * IPv6 port allocation rules should mirror the IPv4 rules and are controlled
836bccea7cSRebecca Cran  * by the net.inet.ip.portrange sysctl tree. The following defines exist
84fe124573SDavid Malone  * for compatibility with userland applications that need them.
8576429de4SYoshinobu Inoue  */
869e2e036fSMike Barcroft #if __BSD_VISIBLE
8776429de4SYoshinobu Inoue #define	IPV6PORT_RESERVED	1024
8876429de4SYoshinobu Inoue #define	IPV6PORT_ANONMIN	49152
8976429de4SYoshinobu Inoue #define	IPV6PORT_ANONMAX	65535
9076429de4SYoshinobu Inoue #define	IPV6PORT_RESERVEDMIN	600
9176429de4SYoshinobu Inoue #define	IPV6PORT_RESERVEDMAX	(IPV6PORT_RESERVED-1)
929e2e036fSMike Barcroft #endif
9376429de4SYoshinobu Inoue 
9476429de4SYoshinobu Inoue /*
9576429de4SYoshinobu Inoue  * IPv6 address
9676429de4SYoshinobu Inoue  */
9776429de4SYoshinobu Inoue struct in6_addr {
9876429de4SYoshinobu Inoue 	union {
999e2e036fSMike Barcroft 		uint8_t		__u6_addr8[16];
1009e2e036fSMike Barcroft 		uint16_t	__u6_addr16[8];
1019e2e036fSMike Barcroft 		uint32_t	__u6_addr32[4];
10276429de4SYoshinobu Inoue 	} __u6_addr;			/* 128-bit IP6 address */
10376429de4SYoshinobu Inoue };
10476429de4SYoshinobu Inoue 
10576429de4SYoshinobu Inoue #define s6_addr   __u6_addr.__u6_addr8
10676429de4SYoshinobu Inoue #ifdef _KERNEL	/* XXX nonstandard */
10776429de4SYoshinobu Inoue #define s6_addr8  __u6_addr.__u6_addr8
10876429de4SYoshinobu Inoue #define s6_addr16 __u6_addr.__u6_addr16
10976429de4SYoshinobu Inoue #define s6_addr32 __u6_addr.__u6_addr32
11076429de4SYoshinobu Inoue #endif
11176429de4SYoshinobu Inoue 
11276429de4SYoshinobu Inoue #define INET6_ADDRSTRLEN	46
11376429de4SYoshinobu Inoue 
11476429de4SYoshinobu Inoue /*
1159e2e036fSMike Barcroft  * XXX missing POSIX.1-2001 macro IPPROTO_IPV6.
1169e2e036fSMike Barcroft  */
1179e2e036fSMike Barcroft 
1189e2e036fSMike Barcroft /*
11976429de4SYoshinobu Inoue  * Socket address for IPv6
12076429de4SYoshinobu Inoue  */
1219e2e036fSMike Barcroft #if __BSD_VISIBLE
12276429de4SYoshinobu Inoue #define SIN6_LEN
12376429de4SYoshinobu Inoue #endif
1249e2e036fSMike Barcroft 
12576429de4SYoshinobu Inoue struct sockaddr_in6 {
126a5b71fafSHajimu UMEMOTO 	uint8_t		sin6_len;	/* length of this struct */
1279e2e036fSMike Barcroft 	sa_family_t	sin6_family;	/* AF_INET6 */
1289e2e036fSMike Barcroft 	in_port_t	sin6_port;	/* Transport layer port # */
1299e2e036fSMike Barcroft 	uint32_t	sin6_flowinfo;	/* IP6 flow information */
13076429de4SYoshinobu Inoue 	struct in6_addr	sin6_addr;	/* IP6 address */
1319e2e036fSMike Barcroft 	uint32_t	sin6_scope_id;	/* scope zone index */
13276429de4SYoshinobu Inoue };
13376429de4SYoshinobu Inoue 
13476429de4SYoshinobu Inoue /*
13576429de4SYoshinobu Inoue  * Local definition for masks
13676429de4SYoshinobu Inoue  */
13776429de4SYoshinobu Inoue #ifdef _KERNEL	/* XXX nonstandard */
13876429de4SYoshinobu Inoue #define IN6MASK0	{{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
13976429de4SYoshinobu Inoue #define IN6MASK32	{{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
14076429de4SYoshinobu Inoue 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
14176429de4SYoshinobu Inoue #define IN6MASK64	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
14276429de4SYoshinobu Inoue 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
14376429de4SYoshinobu Inoue #define IN6MASK96	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
14476429de4SYoshinobu Inoue 			    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
14576429de4SYoshinobu Inoue #define IN6MASK128	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
14676429de4SYoshinobu Inoue 			    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
14776429de4SYoshinobu Inoue #endif
14876429de4SYoshinobu Inoue 
14976429de4SYoshinobu Inoue #ifdef _KERNEL
15033841545SHajimu UMEMOTO extern const struct sockaddr_in6 sa6_any;
15133841545SHajimu UMEMOTO 
15276429de4SYoshinobu Inoue extern const struct in6_addr in6mask0;
15376429de4SYoshinobu Inoue extern const struct in6_addr in6mask32;
15476429de4SYoshinobu Inoue extern const struct in6_addr in6mask64;
15576429de4SYoshinobu Inoue extern const struct in6_addr in6mask96;
15676429de4SYoshinobu Inoue extern const struct in6_addr in6mask128;
15776429de4SYoshinobu Inoue #endif /* _KERNEL */
15876429de4SYoshinobu Inoue 
15976429de4SYoshinobu Inoue /*
16076429de4SYoshinobu Inoue  * Macros started with IPV6_ADDR is KAME local
16176429de4SYoshinobu Inoue  */
16276429de4SYoshinobu Inoue #ifdef _KERNEL	/* XXX nonstandard */
1639e2e036fSMike Barcroft #if _BYTE_ORDER == _BIG_ENDIAN
16476429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_ONE	1
16576429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_TWO	2
16676429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_MNL	0xff010000
16776429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_MLL	0xff020000
16876429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_SMP	0x0000ffff
16976429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_ULL	0xfe80
17076429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_USL	0xfec0
17176429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_MLL	0xff02
1729e2e036fSMike Barcroft #elif _BYTE_ORDER == _LITTLE_ENDIAN
17376429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_ONE	0x01000000
17476429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_TWO	0x02000000
17576429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_MNL	0x000001ff
17676429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_MLL	0x000002ff
17776429de4SYoshinobu Inoue #define IPV6_ADDR_INT32_SMP	0xffff0000
17876429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_ULL	0x80fe
17976429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_USL	0xc0fe
18076429de4SYoshinobu Inoue #define IPV6_ADDR_INT16_MLL	0x02ff
18176429de4SYoshinobu Inoue #endif
18276429de4SYoshinobu Inoue #endif
18376429de4SYoshinobu Inoue 
18476429de4SYoshinobu Inoue /*
18576429de4SYoshinobu Inoue  * Definition of some useful macros to handle IP6 addresses
18676429de4SYoshinobu Inoue  */
1879e2e036fSMike Barcroft #if __BSD_VISIBLE
18876429de4SYoshinobu Inoue #define IN6ADDR_ANY_INIT \
18976429de4SYoshinobu Inoue 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
19076429de4SYoshinobu Inoue 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
19176429de4SYoshinobu Inoue #define IN6ADDR_LOOPBACK_INIT \
19276429de4SYoshinobu Inoue 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
19376429de4SYoshinobu Inoue 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
19476429de4SYoshinobu Inoue #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
19576429de4SYoshinobu Inoue 	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
19676429de4SYoshinobu Inoue 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
1979a4f9608SHajimu UMEMOTO #define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
1989a4f9608SHajimu UMEMOTO 	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
1999a4f9608SHajimu UMEMOTO 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
20076429de4SYoshinobu Inoue #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
20176429de4SYoshinobu Inoue 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
20276429de4SYoshinobu Inoue 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
20376429de4SYoshinobu Inoue #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
20476429de4SYoshinobu Inoue 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
20576429de4SYoshinobu Inoue 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
206ba970783SBruce M Simpson #define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
207ba970783SBruce M Simpson 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
208ba970783SBruce M Simpson 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
2099e2e036fSMike Barcroft #endif
21076429de4SYoshinobu Inoue 
21176429de4SYoshinobu Inoue extern const struct in6_addr in6addr_any;
21276429de4SYoshinobu Inoue extern const struct in6_addr in6addr_loopback;
2139e2e036fSMike Barcroft #if __BSD_VISIBLE
21476429de4SYoshinobu Inoue extern const struct in6_addr in6addr_nodelocal_allnodes;
21576429de4SYoshinobu Inoue extern const struct in6_addr in6addr_linklocal_allnodes;
21676429de4SYoshinobu Inoue extern const struct in6_addr in6addr_linklocal_allrouters;
217ba970783SBruce M Simpson extern const struct in6_addr in6addr_linklocal_allv2routers;
2189e2e036fSMike Barcroft #endif
21976429de4SYoshinobu Inoue 
22076429de4SYoshinobu Inoue /*
22176429de4SYoshinobu Inoue  * Equality
222a082a654SJun-ichiro itojun Hagino  * NOTE: Some of kernel programming environment (for example, openbsd/sparc)
223a082a654SJun-ichiro itojun Hagino  * does not supply memcmp().  For userland memcmp() is preferred as it is
224a082a654SJun-ichiro itojun Hagino  * in ANSI standard.
22576429de4SYoshinobu Inoue  */
226a082a654SJun-ichiro itojun Hagino #ifdef _KERNEL
227a082a654SJun-ichiro itojun Hagino #define IN6_ARE_ADDR_EQUAL(a, b)			\
228686cdd19SJun-ichiro itojun Hagino     (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
229a082a654SJun-ichiro itojun Hagino #else
2309e2e036fSMike Barcroft #if __BSD_VISIBLE
23176429de4SYoshinobu Inoue #define IN6_ARE_ADDR_EQUAL(a, b)			\
232686cdd19SJun-ichiro itojun Hagino     (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
233a082a654SJun-ichiro itojun Hagino #endif
2349e2e036fSMike Barcroft #endif
23576429de4SYoshinobu Inoue 
23676429de4SYoshinobu Inoue /*
23776429de4SYoshinobu Inoue  * Unspecified
23876429de4SYoshinobu Inoue  */
23976429de4SYoshinobu Inoue #define IN6_IS_ADDR_UNSPECIFIED(a)	\
2409c2ae3b1SGleb Smirnoff 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
2419c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
2429c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
2439c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[3] == 0)
24476429de4SYoshinobu Inoue 
24576429de4SYoshinobu Inoue /*
24676429de4SYoshinobu Inoue  * Loopback
24776429de4SYoshinobu Inoue  */
24876429de4SYoshinobu Inoue #define IN6_IS_ADDR_LOOPBACK(a)		\
2499c2ae3b1SGleb Smirnoff 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
2509c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
2519c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
2529c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
25376429de4SYoshinobu Inoue 
25476429de4SYoshinobu Inoue /*
25576429de4SYoshinobu Inoue  * IPv4 compatible
25676429de4SYoshinobu Inoue  */
25776429de4SYoshinobu Inoue #define IN6_IS_ADDR_V4COMPAT(a)		\
2589c2ae3b1SGleb Smirnoff 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
2599c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
2609c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
2619c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[3] != 0 &&	\
2629c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
26376429de4SYoshinobu Inoue 
26476429de4SYoshinobu Inoue /*
26576429de4SYoshinobu Inoue  * Mapped
26676429de4SYoshinobu Inoue  */
26776429de4SYoshinobu Inoue #define IN6_IS_ADDR_V4MAPPED(a)		      \
2689c2ae3b1SGleb Smirnoff 	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
2699c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
2709c2ae3b1SGleb Smirnoff 	 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
27176429de4SYoshinobu Inoue 
27276429de4SYoshinobu Inoue /*
27376429de4SYoshinobu Inoue  * KAME Scope Values
27476429de4SYoshinobu Inoue  */
27576429de4SYoshinobu Inoue 
27676429de4SYoshinobu Inoue #ifdef _KERNEL	/* XXX nonstandard */
27776429de4SYoshinobu Inoue #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
2789a4f9608SHajimu UMEMOTO #define IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
27976429de4SYoshinobu Inoue #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
28076429de4SYoshinobu Inoue #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
28176429de4SYoshinobu Inoue #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
28276429de4SYoshinobu Inoue #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
28376429de4SYoshinobu Inoue #else
28476429de4SYoshinobu Inoue #define __IPV6_ADDR_SCOPE_NODELOCAL	0x01
2859a4f9608SHajimu UMEMOTO #define __IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
28676429de4SYoshinobu Inoue #define __IPV6_ADDR_SCOPE_LINKLOCAL	0x02
28776429de4SYoshinobu Inoue #define __IPV6_ADDR_SCOPE_SITELOCAL	0x05
28876429de4SYoshinobu Inoue #define __IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
28976429de4SYoshinobu Inoue #define __IPV6_ADDR_SCOPE_GLOBAL	0x0e
29076429de4SYoshinobu Inoue #endif
29176429de4SYoshinobu Inoue 
29276429de4SYoshinobu Inoue /*
29376429de4SYoshinobu Inoue  * Unicast Scope
29476429de4SYoshinobu Inoue  * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
29576429de4SYoshinobu Inoue  */
29676429de4SYoshinobu Inoue #define IN6_IS_ADDR_LINKLOCAL(a)	\
29776429de4SYoshinobu Inoue 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
29876429de4SYoshinobu Inoue #define IN6_IS_ADDR_SITELOCAL(a)	\
29976429de4SYoshinobu Inoue 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
30076429de4SYoshinobu Inoue 
30176429de4SYoshinobu Inoue /*
30276429de4SYoshinobu Inoue  * Multicast
30376429de4SYoshinobu Inoue  */
30476429de4SYoshinobu Inoue #define IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
30576429de4SYoshinobu Inoue 
30676429de4SYoshinobu Inoue #ifdef _KERNEL	/* XXX nonstandard */
30776429de4SYoshinobu Inoue #define IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
30876429de4SYoshinobu Inoue #else
30976429de4SYoshinobu Inoue #define __IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
31076429de4SYoshinobu Inoue #endif
31176429de4SYoshinobu Inoue 
31276429de4SYoshinobu Inoue /*
31376429de4SYoshinobu Inoue  * Multicast Scope
31476429de4SYoshinobu Inoue  */
31576429de4SYoshinobu Inoue #ifdef _KERNEL	/* refers nonstandard items */
31676429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
31776429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
31876429de4SYoshinobu Inoue 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
3199a4f9608SHajimu UMEMOTO #define IN6_IS_ADDR_MC_INTFACELOCAL(a)	\
3209a4f9608SHajimu UMEMOTO 	(IN6_IS_ADDR_MULTICAST(a) &&	\
3219a4f9608SHajimu UMEMOTO 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
32276429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
32376429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
32476429de4SYoshinobu Inoue 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
32576429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
32676429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
32776429de4SYoshinobu Inoue 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
32876429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
32976429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
33076429de4SYoshinobu Inoue 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
33176429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_GLOBAL(a)	\
33276429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
33376429de4SYoshinobu Inoue 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
33476429de4SYoshinobu Inoue #else
33576429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
33676429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
33776429de4SYoshinobu Inoue 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
33876429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
33976429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
34076429de4SYoshinobu Inoue 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
34176429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
34276429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
34376429de4SYoshinobu Inoue 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
34476429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
34576429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
34676429de4SYoshinobu Inoue 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
34776429de4SYoshinobu Inoue #define IN6_IS_ADDR_MC_GLOBAL(a)	\
34876429de4SYoshinobu Inoue 	(IN6_IS_ADDR_MULTICAST(a) &&	\
34976429de4SYoshinobu Inoue 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
35076429de4SYoshinobu Inoue #endif
35176429de4SYoshinobu Inoue 
35233841545SHajimu UMEMOTO #ifdef _KERNEL	/* nonstandard */
35333841545SHajimu UMEMOTO /*
35476429de4SYoshinobu Inoue  * KAME Scope
35576429de4SYoshinobu Inoue  */
35676429de4SYoshinobu Inoue #define IN6_IS_SCOPE_LINKLOCAL(a)	\
35776429de4SYoshinobu Inoue 	((IN6_IS_ADDR_LINKLOCAL(a)) ||	\
35876429de4SYoshinobu Inoue 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
35960ee3847SMax Laier #define	IN6_IS_SCOPE_EMBED(a)			\
36060ee3847SMax Laier 	((IN6_IS_ADDR_LINKLOCAL(a)) ||		\
36160ee3847SMax Laier 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)) ||	\
36260ee3847SMax Laier 	 (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
36360ee3847SMax Laier 
36433841545SHajimu UMEMOTO #define IFA6_IS_DEPRECATED(a) \
365743eee66SSUZUKI Shinsuke 	((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
3667d26db17SHiroki Sato 	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
367743eee66SSUZUKI Shinsuke 	 (a)->ia6_lifetime.ia6t_pltime)
36833841545SHajimu UMEMOTO #define IFA6_IS_INVALID(a) \
369743eee66SSUZUKI Shinsuke 	((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
3707d26db17SHiroki Sato 	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
371743eee66SSUZUKI Shinsuke 	 (a)->ia6_lifetime.ia6t_vltime)
37233841545SHajimu UMEMOTO #endif /* _KERNEL */
37376429de4SYoshinobu Inoue 
37476429de4SYoshinobu Inoue /*
37576429de4SYoshinobu Inoue  * IP6 route structure
37676429de4SYoshinobu Inoue  */
3779e2e036fSMike Barcroft #if __BSD_VISIBLE
37876429de4SYoshinobu Inoue struct route_in6 {
37976429de4SYoshinobu Inoue 	struct	rtentry *ro_rt;
3806d768226SGeorge V. Neville-Neil 	struct	llentry *ro_lle;
3816d768226SGeorge V. Neville-Neil 	/*
3826d768226SGeorge V. Neville-Neil 	 * ro_prepend and ro_plen are only used for bpf to pass in a
3836d768226SGeorge V. Neville-Neil 	 * preformed header.  They are not cacheable.
3846d768226SGeorge V. Neville-Neil 	 */
3854fb3a820SAlexander V. Chernikov 	char		*ro_prepend;
3864fb3a820SAlexander V. Chernikov 	uint16_t	ro_plen;
3874fb3a820SAlexander V. Chernikov 	uint16_t	ro_flags;
3880d4df029SAlexander V. Chernikov 	uint16_t	ro_mtu;	/* saved ro_rt mtu */
3890d4df029SAlexander V. Chernikov 	uint16_t	spare;
39076429de4SYoshinobu Inoue 	struct	sockaddr_in6 ro_dst;
39176429de4SYoshinobu Inoue };
39276429de4SYoshinobu Inoue #endif
39376429de4SYoshinobu Inoue 
394aaa46574SAdrian Chadd #ifdef _KERNEL
395aaa46574SAdrian Chadd #define MTAG_ABI_IPV6		1444287380	/* IPv6 ABI */
396aaa46574SAdrian Chadd #define IPV6_TAG_DIRECT		0		/* direct-dispatch IPv6 */
397aaa46574SAdrian Chadd #endif /* _KERNEL */
398aaa46574SAdrian Chadd 
39976429de4SYoshinobu Inoue /*
40076429de4SYoshinobu Inoue  * Options for use with [gs]etsockopt at the IPV6 level.
40176429de4SYoshinobu Inoue  * First word of comment is data type; bool is stored in int.
40276429de4SYoshinobu Inoue  */
40376429de4SYoshinobu Inoue /* no hdrincl */
404686cdd19SJun-ichiro itojun Hagino #if 0 /* the followings are relic in IPv4 and hence are disabled */
405686cdd19SJun-ichiro itojun Hagino #define IPV6_OPTIONS		1  /* buf/ip6_opts; set/get IP6 options */
40676429de4SYoshinobu Inoue #define IPV6_RECVOPTS		5  /* bool; receive all IP6 opts w/dgram */
40776429de4SYoshinobu Inoue #define IPV6_RECVRETOPTS	6  /* bool; receive IP6 opts for response */
40876429de4SYoshinobu Inoue #define IPV6_RECVDSTADDR	7  /* bool; receive IP6 dst addr w/dgram */
40976429de4SYoshinobu Inoue #define IPV6_RETOPTS		8  /* ip6_opts; set/get IP6 options */
410686cdd19SJun-ichiro itojun Hagino #endif
411686cdd19SJun-ichiro itojun Hagino #define IPV6_SOCKOPT_RESERVED1	3  /* reserved for future use */
412f95d4633SHajimu UMEMOTO #define IPV6_UNICAST_HOPS	4  /* int; IP6 hops */
413f95d4633SHajimu UMEMOTO #define IPV6_MULTICAST_IF	9  /* u_int; set/get IP6 multicast i/f  */
414f95d4633SHajimu UMEMOTO #define IPV6_MULTICAST_HOPS	10 /* int; set/get IP6 multicast hops */
415f95d4633SHajimu UMEMOTO #define IPV6_MULTICAST_LOOP	11 /* u_int; set/get IP6 multicast loopback */
416cae54c66SBernd Walter #define IPV6_JOIN_GROUP		12 /* ipv6_mreq; join a group membership */
417cae54c66SBernd Walter #define IPV6_LEAVE_GROUP	13 /* ipv6_mreq; leave a group membership */
41876429de4SYoshinobu Inoue #define IPV6_PORTRANGE		14 /* int; range to choose for unspec port */
41976429de4SYoshinobu Inoue #define ICMP6_FILTER		18 /* icmp6_filter; icmp6 filter */
42033841545SHajimu UMEMOTO /* RFC2292 options */
421f95d4633SHajimu UMEMOTO #ifdef _KERNEL
422f95d4633SHajimu UMEMOTO #define IPV6_2292PKTINFO	19 /* bool; send/recv if, src/dst addr */
423f95d4633SHajimu UMEMOTO #define IPV6_2292HOPLIMIT	20 /* bool; hop limit */
424f95d4633SHajimu UMEMOTO #define IPV6_2292NEXTHOP	21 /* bool; next hop addr */
425f95d4633SHajimu UMEMOTO #define IPV6_2292HOPOPTS	22 /* bool; hop-by-hop option */
426f95d4633SHajimu UMEMOTO #define IPV6_2292DSTOPTS	23 /* bool; destinaion option */
427f95d4633SHajimu UMEMOTO #define IPV6_2292RTHDR		24 /* bool; routing header */
428f95d4633SHajimu UMEMOTO #define IPV6_2292PKTOPTIONS	25 /* buf/cmsghdr; set/get IPv6 options */
429f95d4633SHajimu UMEMOTO #endif
43076429de4SYoshinobu Inoue 
43133841545SHajimu UMEMOTO #define IPV6_CHECKSUM		26 /* int; checksum offset for raw socket */
432f95d4633SHajimu UMEMOTO #define IPV6_V6ONLY		27 /* bool; make AF_INET6 sockets v6 only */
43333841545SHajimu UMEMOTO #ifndef _KERNEL
43433841545SHajimu UMEMOTO #define IPV6_BINDV6ONLY		IPV6_V6ONLY
43533841545SHajimu UMEMOTO #endif
43633841545SHajimu UMEMOTO 
43776429de4SYoshinobu Inoue #define IPV6_IPSEC_POLICY	28 /* struct; get/set security policy */
438603eaf79SAlexander V. Chernikov 				   /* 29; unused; was IPV6_FAITH */
43933841545SHajimu UMEMOTO #if 1 /* IPV6FIREWALL */
44076429de4SYoshinobu Inoue #define IPV6_FW_ADD		30 /* add a firewall rule to chain */
44176429de4SYoshinobu Inoue #define IPV6_FW_DEL		31 /* delete a firewall rule from chain */
44276429de4SYoshinobu Inoue #define IPV6_FW_FLUSH		32 /* flush firewall rule chain */
44376429de4SYoshinobu Inoue #define IPV6_FW_ZERO		33 /* clear single/all firewall counter(s) */
44476429de4SYoshinobu Inoue #define IPV6_FW_GET		34 /* get entire firewall rule chain */
44533841545SHajimu UMEMOTO #endif
44633841545SHajimu UMEMOTO 
44718b35df8SHajimu UMEMOTO /* new socket options introduced in RFC3542 */
448f95d4633SHajimu UMEMOTO #define IPV6_RTHDRDSTOPTS	35 /* ip6_dest; send dst option before rthdr */
449f95d4633SHajimu UMEMOTO 
450f95d4633SHajimu UMEMOTO #define IPV6_RECVPKTINFO	36 /* bool; recv if, dst addr */
451f95d4633SHajimu UMEMOTO #define IPV6_RECVHOPLIMIT	37 /* bool; recv hop limit */
452f95d4633SHajimu UMEMOTO #define IPV6_RECVRTHDR		38 /* bool; recv routing header */
453f95d4633SHajimu UMEMOTO #define IPV6_RECVHOPOPTS	39 /* bool; recv hop-by-hop option */
454f95d4633SHajimu UMEMOTO #define IPV6_RECVDSTOPTS	40 /* bool; recv dst option after rthdr */
455f95d4633SHajimu UMEMOTO #ifdef _KERNEL
456f95d4633SHajimu UMEMOTO #define IPV6_RECVRTHDRDSTOPTS	41 /* bool; recv dst option before rthdr */
457f95d4633SHajimu UMEMOTO #endif
458f95d4633SHajimu UMEMOTO 
459f95d4633SHajimu UMEMOTO #define IPV6_USE_MIN_MTU	42 /* bool; send packets at the minimum MTU */
460f95d4633SHajimu UMEMOTO #define IPV6_RECVPATHMTU	43 /* bool; notify an according MTU */
461f95d4633SHajimu UMEMOTO 
462f95d4633SHajimu UMEMOTO #define IPV6_PATHMTU		44 /* mtuinfo; get the current path MTU (sopt),
463f95d4633SHajimu UMEMOTO 				      4 bytes int; MTU notification (cmsg) */
464f95d4633SHajimu UMEMOTO #if 0 /*obsoleted during 2292bis -> 3542*/
465f95d4633SHajimu UMEMOTO #define IPV6_REACHCONF		45 /* no data; ND reachability confirm
466f95d4633SHajimu UMEMOTO 				      (cmsg only/not in of RFC3542) */
467f95d4633SHajimu UMEMOTO #endif
468f95d4633SHajimu UMEMOTO 
46918b35df8SHajimu UMEMOTO /* more new socket options introduced in RFC3542 */
470f95d4633SHajimu UMEMOTO #define IPV6_PKTINFO		46 /* in6_pktinfo; send if, src addr */
471f95d4633SHajimu UMEMOTO #define IPV6_HOPLIMIT		47 /* int; send hop limit */
472f95d4633SHajimu UMEMOTO #define IPV6_NEXTHOP		48 /* sockaddr; next hop addr */
473f95d4633SHajimu UMEMOTO #define IPV6_HOPOPTS		49 /* ip6_hbh; send hop-by-hop option */
474f95d4633SHajimu UMEMOTO #define IPV6_DSTOPTS		50 /* ip6_dest; send dst option befor rthdr */
475f95d4633SHajimu UMEMOTO #define IPV6_RTHDR		51 /* ip6_rthdr; send routing header */
476f95d4633SHajimu UMEMOTO #if 0
477f95d4633SHajimu UMEMOTO #define IPV6_PKTOPTIONS		52 /* buf/cmsghdr; set/get IPv6 options */
47818b35df8SHajimu UMEMOTO 				   /* obsoleted by RFC3542 */
479f95d4633SHajimu UMEMOTO #endif
480f95d4633SHajimu UMEMOTO 
481f95d4633SHajimu UMEMOTO #define IPV6_RECVTCLASS		57 /* bool; recv traffic class values */
482f95d4633SHajimu UMEMOTO 
483f95d4633SHajimu UMEMOTO #define IPV6_AUTOFLOWLABEL	59 /* bool; attach flowlabel automagically */
484f95d4633SHajimu UMEMOTO 
485f95d4633SHajimu UMEMOTO #define IPV6_TCLASS		61 /* int; send traffic class value */
486f95d4633SHajimu UMEMOTO #define IPV6_DONTFRAG		62 /* bool; disable IPv6 fragmentation */
487f95d4633SHajimu UMEMOTO 
488f95d4633SHajimu UMEMOTO #define IPV6_PREFER_TEMPADDR	63 /* int; prefer temporary addresses as
489f95d4633SHajimu UMEMOTO 				    * the source address.
490f95d4633SHajimu UMEMOTO 				    */
491f95d4633SHajimu UMEMOTO 
492f44270e7SPawel Jakub Dawidek #define	IPV6_BINDANY		64 /* bool: allow bind to any address */
493f44270e7SPawel Jakub Dawidek 
4946e4405ceSAdrian Chadd #define	IPV6_BINDMULTI		65 /* bool; allow multibind to same addr/port */
4956e4405ceSAdrian Chadd #define	IPV6_RSS_LISTEN_BUCKET	66 /* int; set RSS listen bucket */
4966e4405ceSAdrian Chadd #define	IPV6_FLOWID		67 /* int; flowid of given socket */
4976e4405ceSAdrian Chadd #define	IPV6_FLOWTYPE		68 /* int; flowtype of given socket */
4986e4405ceSAdrian Chadd #define	IPV6_RSSBUCKETID	69 /* int; RSS bucket ID of given socket */
49968bb8d62SAdrian Chadd #define	IPV6_RECVFLOWID		70 /* bool; receive IP6 flowid/flowtype w/ datagram */
50068bb8d62SAdrian Chadd #define	IPV6_RECVRSSBUCKETID	71 /* bool; receive IP6 RSS bucket id w/ datagram */
5016e4405ceSAdrian Chadd 
502dce33a45SErmal Luçi #define	IPV6_ORIGDSTADDR	72 /* bool: allow getting dstaddr /port info */
503dce33a45SErmal Luçi #define	IPV6_RECVORIGDSTADDR	IPV6_ORIGDSTADDR
504dce33a45SErmal Luçi 
50571498f30SBruce M Simpson /*
50671498f30SBruce M Simpson  * The following option is private; do not use it from user applications.
50771498f30SBruce M Simpson  * It is deliberately defined to the same value as IP_MSFILTER.
50871498f30SBruce M Simpson  */
50971498f30SBruce M Simpson #define	IPV6_MSFILTER		74 /* struct __msfilterreq;
51071498f30SBruce M Simpson 				    * set/get multicast source filter list.
51171498f30SBruce M Simpson 				    */
51271498f30SBruce M Simpson 
51306f879c7SJun-ichiro itojun Hagino /* to define items, should talk with KAME guys first, for *BSD compatibility */
51476429de4SYoshinobu Inoue 
51576429de4SYoshinobu Inoue #define IPV6_RTHDR_LOOSE     0 /* this hop need not be a neighbor. XXX old spec */
51676429de4SYoshinobu Inoue #define IPV6_RTHDR_STRICT    1 /* this hop must be a neighbor. XXX old spec */
51776429de4SYoshinobu Inoue #define IPV6_RTHDR_TYPE_0    0 /* IPv6 routing header type 0 */
51876429de4SYoshinobu Inoue 
51976429de4SYoshinobu Inoue /*
52076429de4SYoshinobu Inoue  * Defaults and limits for options
52176429de4SYoshinobu Inoue  */
52276429de4SYoshinobu Inoue #define IPV6_DEFAULT_MULTICAST_HOPS 1	/* normally limit m'casts to 1 hop */
52376429de4SYoshinobu Inoue #define IPV6_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member */
52476429de4SYoshinobu Inoue 
52576429de4SYoshinobu Inoue /*
526ba970783SBruce M Simpson  * The im6o_membership vector for each socket is now dynamically allocated at
527ba970783SBruce M Simpson  * run-time, bounded by USHRT_MAX, and is reallocated when needed, sized
528ba970783SBruce M Simpson  * according to a power-of-two increment.
529ba970783SBruce M Simpson  */
530ba970783SBruce M Simpson #define	IPV6_MIN_MEMBERSHIPS	31
531ba970783SBruce M Simpson #define	IPV6_MAX_MEMBERSHIPS	4095
532ba970783SBruce M Simpson 
533ba970783SBruce M Simpson /*
534ba970783SBruce M Simpson  * Default resource limits for IPv6 multicast source filtering.
535ba970783SBruce M Simpson  * These may be modified by sysctl.
536ba970783SBruce M Simpson  */
537ba970783SBruce M Simpson #define	IPV6_MAX_GROUP_SRC_FILTER	512	/* sources per group */
538ba970783SBruce M Simpson #define	IPV6_MAX_SOCK_SRC_FILTER	128	/* sources per socket/group */
539ba970783SBruce M Simpson 
540ba970783SBruce M Simpson /*
54176429de4SYoshinobu Inoue  * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
54276429de4SYoshinobu Inoue  */
54376429de4SYoshinobu Inoue struct ipv6_mreq {
54476429de4SYoshinobu Inoue 	struct in6_addr	ipv6mr_multiaddr;
545686cdd19SJun-ichiro itojun Hagino 	unsigned int	ipv6mr_interface;
54676429de4SYoshinobu Inoue };
54776429de4SYoshinobu Inoue 
54876429de4SYoshinobu Inoue /*
54976429de4SYoshinobu Inoue  * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
55076429de4SYoshinobu Inoue  */
55176429de4SYoshinobu Inoue struct in6_pktinfo {
55276429de4SYoshinobu Inoue 	struct in6_addr	ipi6_addr;	/* src/dst IPv6 address */
553686cdd19SJun-ichiro itojun Hagino 	unsigned int	ipi6_ifindex;	/* send/recv interface index */
55476429de4SYoshinobu Inoue };
55576429de4SYoshinobu Inoue 
55676429de4SYoshinobu Inoue /*
557f95d4633SHajimu UMEMOTO  * Control structure for IPV6_RECVPATHMTU socket option.
558f95d4633SHajimu UMEMOTO  */
559f95d4633SHajimu UMEMOTO struct ip6_mtuinfo {
560f95d4633SHajimu UMEMOTO 	struct sockaddr_in6 ip6m_addr;	/* or sockaddr_storage? */
5610021a485SHajimu UMEMOTO 	uint32_t ip6m_mtu;
562f95d4633SHajimu UMEMOTO };
563f95d4633SHajimu UMEMOTO 
564f95d4633SHajimu UMEMOTO /*
56576429de4SYoshinobu Inoue  * Argument for IPV6_PORTRANGE:
56676429de4SYoshinobu Inoue  * - which range to search when port is unspecified at bind() or connect()
56776429de4SYoshinobu Inoue  */
56876429de4SYoshinobu Inoue #define	IPV6_PORTRANGE_DEFAULT	0	/* default range */
56976429de4SYoshinobu Inoue #define	IPV6_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
57076429de4SYoshinobu Inoue #define	IPV6_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
57176429de4SYoshinobu Inoue 
572f95d4633SHajimu UMEMOTO #if __BSD_VISIBLE
57376429de4SYoshinobu Inoue /*
57476429de4SYoshinobu Inoue  * Definitions for inet6 sysctl operations.
57576429de4SYoshinobu Inoue  *
57676429de4SYoshinobu Inoue  * Third level is protocol number.
57776429de4SYoshinobu Inoue  * Fourth level is desired variable within that protocol.
57876429de4SYoshinobu Inoue  */
57976429de4SYoshinobu Inoue #define IPV6PROTO_MAXID	(IPPROTO_PIM + 1)	/* don't list to IPV6PROTO_MAX */
58076429de4SYoshinobu Inoue 
58176429de4SYoshinobu Inoue /*
58276429de4SYoshinobu Inoue  * Names for IP sysctl objects
58376429de4SYoshinobu Inoue  */
58476429de4SYoshinobu Inoue #define IPV6CTL_FORWARDING	1	/* act as router */
58576429de4SYoshinobu Inoue #define IPV6CTL_SENDREDIRECTS	2	/* may send redirects when forwarding*/
58676429de4SYoshinobu Inoue #define IPV6CTL_DEFHLIM		3	/* default Hop-Limit */
58776429de4SYoshinobu Inoue #ifdef notyet
58876429de4SYoshinobu Inoue #define IPV6CTL_DEFMTU		4	/* default MTU */
58976429de4SYoshinobu Inoue #endif
59076429de4SYoshinobu Inoue #define IPV6CTL_FORWSRCRT	5	/* forward source-routed dgrams */
59176429de4SYoshinobu Inoue #define IPV6CTL_STATS		6	/* stats */
59276429de4SYoshinobu Inoue #define IPV6CTL_MRTSTATS	7	/* multicast forwarding stats */
59376429de4SYoshinobu Inoue #define IPV6CTL_MRTPROTO	8	/* multicast routing protocol */
59476429de4SYoshinobu Inoue #define IPV6CTL_MAXFRAGPACKETS	9	/* max packets reassembly queue */
59576429de4SYoshinobu Inoue #define IPV6CTL_SOURCECHECK	10	/* verify source route and intf */
59676429de4SYoshinobu Inoue #define IPV6CTL_SOURCECHECK_LOGINT 11	/* minimume logging interval */
59776429de4SYoshinobu Inoue #define IPV6CTL_ACCEPT_RTADV	12
598603eaf79SAlexander V. Chernikov 					/* 13; unused; was: IPV6CTL_KEEPFAITH */
59976429de4SYoshinobu Inoue #define IPV6CTL_LOG_INTERVAL	14
60076429de4SYoshinobu Inoue #define IPV6CTL_HDRNESTLIMIT	15
60176429de4SYoshinobu Inoue #define IPV6CTL_DAD_COUNT	16
60276429de4SYoshinobu Inoue #define IPV6CTL_AUTO_FLOWLABEL	17
60376429de4SYoshinobu Inoue #define IPV6CTL_DEFMCASTHLIM	18
60476429de4SYoshinobu Inoue #define IPV6CTL_GIF_HLIM	19	/* default HLIM for gif encap packet */
605cfa1ca9dSYoshinobu Inoue #define IPV6CTL_KAME_VERSION	20
60676429de4SYoshinobu Inoue #define IPV6CTL_USE_DEPRECATED	21	/* use deprecated addr (RFC2462 5.5.4) */
60776429de4SYoshinobu Inoue #define IPV6CTL_RR_PRUNE	22	/* walk timer for router renumbering */
60833841545SHajimu UMEMOTO #if 0	/* obsolete */
60976429de4SYoshinobu Inoue #define IPV6CTL_MAPPED_ADDR	23
6107ee982bcSJun-ichiro itojun Hagino #endif
61133841545SHajimu UMEMOTO #define IPV6CTL_V6ONLY		24
612670e8b3bSAlexander V. Chernikov /*	IPV6CTL_RTEXPIRE	25	deprecated */
613670e8b3bSAlexander V. Chernikov /*	IPV6CTL_RTMINEXPIRE	26	deprecated */
614670e8b3bSAlexander V. Chernikov /*	IPV6CTL_RTMAXCACHE	27	deprecated */
61533841545SHajimu UMEMOTO 
61633841545SHajimu UMEMOTO #define IPV6CTL_USETEMPADDR	32	/* use temporary addresses (RFC3041) */
61733841545SHajimu UMEMOTO #define IPV6CTL_TEMPPLTIME	33	/* preferred lifetime for tmpaddrs */
61833841545SHajimu UMEMOTO #define IPV6CTL_TEMPVLTIME	34	/* valid lifetime for tmpaddrs */
61933841545SHajimu UMEMOTO #define IPV6CTL_AUTO_LINKLOCAL	35	/* automatic link-local addr assign */
62033841545SHajimu UMEMOTO #define IPV6CTL_RIP6STATS	36	/* raw_ip6 stats */
621d6385b1cSHajimu UMEMOTO #define IPV6CTL_PREFER_TEMPADDR	37	/* prefer temporary addr as src */
6227fc91b3fSHajimu UMEMOTO #define IPV6CTL_ADDRCTLPOLICY	38	/* get/set address selection policy */
623a1f7e5f8SHajimu UMEMOTO #define IPV6CTL_USE_DEFAULTZONE	39	/* use default scope zone */
6247fc91b3fSHajimu UMEMOTO 
6259888c401SHajimu UMEMOTO #define IPV6CTL_MAXFRAGS	41	/* max fragments */
6265af09736SHajimu UMEMOTO #if 0
6275af09736SHajimu UMEMOTO #define IPV6CTL_IFQ		42	/* ip6intrq node */
6285af09736SHajimu UMEMOTO #define IPV6CTL_ISATAPRTR	43	/* isatap router */
6295af09736SHajimu UMEMOTO #endif
6305af09736SHajimu UMEMOTO #define IPV6CTL_MCAST_PMTU	44	/* enable pMTU discovery for multicast? */
6319888c401SHajimu UMEMOTO 
63276429de4SYoshinobu Inoue /* New entries should be added here from current IPV6CTL_MAXID value. */
63306f879c7SJun-ichiro itojun Hagino /* to define items, should talk with KAME guys first, for *BSD compatibility */
634f8a8f9caSSUZUKI Shinsuke #define IPV6CTL_STEALTH		45
63529a6d781SColin Percival 
63629a6d781SColin Percival #define	ICMPV6CTL_ND6_ONLINKNSRFC4861	47
637e7fa8d0aSHiroki Sato #define	IPV6CTL_NO_RADR		48	/* No defroute from RA */
638e7fa8d0aSHiroki Sato #define	IPV6CTL_NORBIT_RAIF	49	/* Disable R-bit in NA on RA
639e7fa8d0aSHiroki Sato 					 * receiving IF. */
640049087a0SHiroki Sato #define	IPV6CTL_RFC6204W3	50	/* Accept defroute even when forwarding
641049087a0SHiroki Sato 					   enabled */
6427aeccebcSAndrey V. Elsukov #define	IPV6CTL_INTRQMAXLEN	51	/* max length of IPv6 netisr queue */
6437aeccebcSAndrey V. Elsukov #define	IPV6CTL_INTRDQMAXLEN	52	/* max length of direct IPv6 netisr
6447aeccebcSAndrey V. Elsukov 					 * queue */
6457aeccebcSAndrey V. Elsukov #define	IPV6CTL_MAXID		53
646f95d4633SHajimu UMEMOTO #endif /* __BSD_VISIBLE */
64733841545SHajimu UMEMOTO 
64882cd038dSYoshinobu Inoue /*
649aa69c612SGleb Smirnoff  * Since both netinet/ and netinet6/ call into netipsec/ and netpfil/,
650aa69c612SGleb Smirnoff  * the protocol specific mbuf flags are shared between them.
65182cd038dSYoshinobu Inoue  */
652aa69c612SGleb Smirnoff #define	M_FASTFWD_OURS		M_PROTO1	/* changed dst to local */
653aa69c612SGleb Smirnoff #define	M_IP6_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
654aa69c612SGleb Smirnoff #define	M_IP_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
655aa69c612SGleb Smirnoff #define	M_SKIP_FIREWALL		M_PROTO3	/* skip firewall processing */
656aa69c612SGleb Smirnoff #define	M_AUTHIPHDR		M_PROTO4
657aa69c612SGleb Smirnoff #define	M_DECRYPTED		M_PROTO5
658aa69c612SGleb Smirnoff #define	M_LOOP			M_PROTO6
659aa69c612SGleb Smirnoff #define	M_AUTHIPDGM		M_PROTO7
660aa69c612SGleb Smirnoff #define	M_RTALERT_MLD		M_PROTO8
66182cd038dSYoshinobu Inoue 
66276429de4SYoshinobu Inoue #ifdef _KERNEL
66376429de4SYoshinobu Inoue struct cmsghdr;
664ecade87eSBjoern A. Zeeb struct ip6_hdr;
66576429de4SYoshinobu Inoue 
666ecade87eSBjoern A. Zeeb int	in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
6676f56329aSXin LI int	in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
66876b96fbcSMichael Tuexen int	in6_cksum_partial(struct mbuf *, u_int8_t, u_int32_t, u_int32_t,
66976b96fbcSMichael Tuexen 			  u_int32_t);
6706f56329aSXin LI int	in6_localaddr(struct in6_addr *);
67190bc35deSBjoern A. Zeeb int	in6_localip(struct in6_addr *);
67228ebe80cSGleb Smirnoff int	in6_ifhasaddr(struct ifnet *, struct in6_addr *);
673573791d0SAndrey V. Elsukov int	in6_addrscope(const struct in6_addr *);
67420778ab5SGleb Smirnoff char	*ip6_sprintf(char *, const struct in6_addr *);
6756f56329aSXin LI struct	in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
6766f56329aSXin LI extern void in6_if_up(struct ifnet *);
67776429de4SYoshinobu Inoue struct sockaddr;
678620fa9ebSDarren Reed extern	u_char	ip6_protox[];
67976429de4SYoshinobu Inoue 
6806f56329aSXin LI void	in6_sin6_2_sin(struct sockaddr_in *sin,
6816f56329aSXin LI 			    struct sockaddr_in6 *sin6);
6826f56329aSXin LI void	in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
6836f56329aSXin LI 				 struct sockaddr_in6 *sin6);
6846f56329aSXin LI void	in6_sin6_2_sin_in_sock(struct sockaddr *nam);
6856f56329aSXin LI void	in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam);
6866f56329aSXin LI extern void addrsel_policy_init(void);
68776429de4SYoshinobu Inoue 
68876429de4SYoshinobu Inoue #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
68976429de4SYoshinobu Inoue #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
69076429de4SYoshinobu Inoue #define	ifatoia6(ifa)	((struct in6_ifaddr *)(ifa))
6919494d596SBrooks Davis 
69276429de4SYoshinobu Inoue #endif /* _KERNEL */
69376429de4SYoshinobu Inoue 
694abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED
695abbd8902SMike Barcroft typedef	__size_t	size_t;
696abbd8902SMike Barcroft #define	_SIZE_T_DECLARED
6979e2e036fSMike Barcroft #endif
6989e2e036fSMike Barcroft 
69916cd67e9SHajimu UMEMOTO #ifndef _SOCKLEN_T_DECLARED
70016cd67e9SHajimu UMEMOTO typedef	__socklen_t	socklen_t;
70116cd67e9SHajimu UMEMOTO #define	_SOCKLEN_T_DECLARED
70216cd67e9SHajimu UMEMOTO #endif
70316cd67e9SHajimu UMEMOTO 
704f95d4633SHajimu UMEMOTO #if __BSD_VISIBLE
705f95d4633SHajimu UMEMOTO 
70676429de4SYoshinobu Inoue __BEGIN_DECLS
70776429de4SYoshinobu Inoue struct cmsghdr;
70876429de4SYoshinobu Inoue 
7096f56329aSXin LI extern int inet6_option_space(int);
7106f56329aSXin LI extern int inet6_option_init(void *, struct cmsghdr **, int);
7116f56329aSXin LI extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
7126f56329aSXin LI 	int, int);
7136f56329aSXin LI extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
7146f56329aSXin LI extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
7156f56329aSXin LI extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
71676429de4SYoshinobu Inoue 
7176f56329aSXin LI extern size_t inet6_rthdr_space(int, int);
7186f56329aSXin LI extern struct cmsghdr *inet6_rthdr_init(void *, int);
7196f56329aSXin LI extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
7206f56329aSXin LI 	unsigned int);
7216f56329aSXin LI extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
72233841545SHajimu UMEMOTO #if 0 /* not implemented yet */
7236f56329aSXin LI extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
72433841545SHajimu UMEMOTO #endif
7256f56329aSXin LI extern int inet6_rthdr_segments(const struct cmsghdr *);
7266f56329aSXin LI extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
7276f56329aSXin LI extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
72833841545SHajimu UMEMOTO 
7296f56329aSXin LI extern int inet6_opt_init(void *, socklen_t);
7306f56329aSXin LI extern int inet6_opt_append(void *, socklen_t, int, uint8_t, socklen_t,
7316f56329aSXin LI 	uint8_t, void **);
7326f56329aSXin LI extern int inet6_opt_finish(void *, socklen_t, int);
7336f56329aSXin LI extern int inet6_opt_set_val(void *, int, void *, socklen_t);
73433841545SHajimu UMEMOTO 
7356f56329aSXin LI extern int inet6_opt_next(void *, socklen_t, int, uint8_t *, socklen_t *,
7366f56329aSXin LI 	void **);
7376f56329aSXin LI extern int inet6_opt_find(void *, socklen_t, int, uint8_t, socklen_t *,
7386f56329aSXin LI 	void **);
7396f56329aSXin LI extern int inet6_opt_get_val(void *, int, void *, socklen_t);
7406f56329aSXin LI extern socklen_t inet6_rth_space(int, int);
7416f56329aSXin LI extern void *inet6_rth_init(void *, socklen_t, int, int);
7426f56329aSXin LI extern int inet6_rth_add(void *, const struct in6_addr *);
7436f56329aSXin LI extern int inet6_rth_reverse(const void *, void *);
7446f56329aSXin LI extern int inet6_rth_segments(const void *);
7456f56329aSXin LI extern struct in6_addr *inet6_rth_getaddr(const void *, int);
74676429de4SYoshinobu Inoue __END_DECLS
74776429de4SYoshinobu Inoue 
7489e2e036fSMike Barcroft #endif /* __BSD_VISIBLE */
7499e2e036fSMike Barcroft 
75076429de4SYoshinobu Inoue #endif /* !_NETINET6_IN6_H_ */
751