12b54eeaimp/*-
24736ccfpfg * SPDX-License-Identifier: BSD-3-Clause
34736ccfpfg *
47efc91cshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
57efc91cshin * All rights reserved.
6cad2014shin *
77efc91cshin * Redistribution and use in source and binary forms, with or without
87efc91cshin * modification, are permitted provided that the following conditions
97efc91cshin * are met:
107efc91cshin * 1. Redistributions of source code must retain the above copyright
117efc91cshin *    notice, this list of conditions and the following disclaimer.
127efc91cshin * 2. Redistributions in binary form must reproduce the above copyright
137efc91cshin *    notice, this list of conditions and the following disclaimer in the
147efc91cshin *    documentation and/or other materials provided with the distribution.
157efc91cshin * 3. Neither the name of the project nor the names of its contributors
167efc91cshin *    may be used to endorse or promote products derived from this software
177efc91cshin *    without specific prior written permission.
18cad2014shin *
197efc91cshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
207efc91cshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
217efc91cshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
227efc91cshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
237efc91cshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
247efc91cshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
257efc91cshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
267efc91cshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
277efc91cshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
287efc91cshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
297efc91cshin * SUCH DAMAGE.
300d684d9obrien *
310d684d9obrien *	$KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $
327efc91cshin */
337efc91cshin
342b54eeaimp/*-
357efc91cshin * Copyright (c) 1982, 1986, 1990, 1993
367efc91cshin *	The Regents of the University of California.  All rights reserved.
377efc91cshin *
387efc91cshin * Redistribution and use in source and binary forms, with or without
397efc91cshin * modification, are permitted provided that the following conditions
407efc91cshin * are met:
417efc91cshin * 1. Redistributions of source code must retain the above copyright
427efc91cshin *    notice, this list of conditions and the following disclaimer.
437efc91cshin * 2. Redistributions in binary form must reproduce the above copyright
447efc91cshin *    notice, this list of conditions and the following disclaimer in the
457efc91cshin *    documentation and/or other materials provided with the distribution.
467e6cabdimp * 3. Neither the name of the University nor the names of its contributors
477efc91cshin *    may be used to endorse or promote products derived from this software
487efc91cshin *    without specific prior written permission.
497efc91cshin *
507efc91cshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
517efc91cshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
527efc91cshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
537efc91cshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
547efc91cshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
557efc91cshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
567efc91cshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
577efc91cshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
587efc91cshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
597efc91cshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
607efc91cshin * SUCH DAMAGE.
617efc91cshin *
627efc91cshin *	@(#)in.h	8.3 (Berkeley) 1/3/94
630d684d9obrien * $FreeBSD$
647efc91cshin */
657efc91cshin
665f4e854itojun#ifndef __KAME_NETINET_IN_H_INCLUDED_
67832f8d2ume#error "do not include netinet6/in6.h directly, include netinet/in.h.  see RFC2553"
68a0c9acashin#endif
69a0c9acashin
705f4e854itojun#ifndef _NETINET6_IN6_H_
715f4e854itojun#define _NETINET6_IN6_H_
725f4e854itojun
737efc91cshin/*
747efc91cshin * Identification of the network protocol stack
75832f8d2ume * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
76832f8d2ume * has the table of implementation/integration differences.
777efc91cshin */
785f4e854itojun#define __KAME__
799a911c0suz#define __KAME_VERSION		"FreeBSD"
807efc91cshin
817efc91cshin/*
82b5db288dwmalone * IPv6 port allocation rules should mirror the IPv4 rules and are controlled
836d9b42bbrucec * by the net.inet.ip.portrange sysctl tree. The following defines exist
84b5db288dwmalone * for compatibility with userland applications that need them.
857efc91cshin */
86b0b9b58mike#if __BSD_VISIBLE
877efc91cshin#define	IPV6PORT_RESERVED	1024
887efc91cshin#define	IPV6PORT_ANONMIN	49152
897efc91cshin#define	IPV6PORT_ANONMAX	65535
907efc91cshin#define	IPV6PORT_RESERVEDMIN	600
917efc91cshin#define	IPV6PORT_RESERVEDMAX	(IPV6PORT_RESERVED-1)
92b0b9b58mike#endif
937efc91cshin
947efc91cshin/*
957efc91cshin * IPv6 address
967efc91cshin */
977efc91cshinstruct in6_addr {
987efc91cshin	union {
99b0b9b58mike		uint8_t		__u6_addr8[16];
100b0b9b58mike		uint16_t	__u6_addr16[8];
101b0b9b58mike		uint32_t	__u6_addr32[4];
1027efc91cshin	} __u6_addr;			/* 128-bit IP6 address */
1037efc91cshin};
1047efc91cshin
1055f4e854itojun#define s6_addr   __u6_addr.__u6_addr8
106553226esuz#ifdef _KERNEL	/* XXX nonstandard */
1075f4e854itojun#define s6_addr8  __u6_addr.__u6_addr8
1085f4e854itojun#define s6_addr16 __u6_addr.__u6_addr16
1095f4e854itojun#define s6_addr32 __u6_addr.__u6_addr32
1107efc91cshin#endif
1117efc91cshin
1125f4e854itojun#define INET6_ADDRSTRLEN	46
1137efc91cshin
1147efc91cshin/*
115b0b9b58mike * XXX missing POSIX.1-2001 macro IPPROTO_IPV6.
116b0b9b58mike */
117b0b9b58mike
118b0b9b58mike/*
1197efc91cshin * Socket address for IPv6
1207efc91cshin */
121b0b9b58mike#if __BSD_VISIBLE
1225f4e854itojun#define SIN6_LEN
1237efc91cshin#endif
124b0b9b58mike
1257efc91cshinstruct sockaddr_in6 {
126881112aume	uint8_t		sin6_len;	/* length of this struct */
127b0b9b58mike	sa_family_t	sin6_family;	/* AF_INET6 */
128b0b9b58mike	in_port_t	sin6_port;	/* Transport layer port # */
129b0b9b58mike	uint32_t	sin6_flowinfo;	/* IP6 flow information */
1305f4e854itojun	struct in6_addr	sin6_addr;	/* IP6 address */
131b0b9b58mike	uint32_t	sin6_scope_id;	/* scope zone index */
1327efc91cshin};
1337efc91cshin
1347efc91cshin/*
1357efc91cshin * Local definition for masks
1367efc91cshin */
137553226esuz#ifdef _KERNEL	/* XXX nonstandard */
1385f4e854itojun#define IN6MASK0	{{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
1395f4e854itojun#define IN6MASK32	{{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
1407efc91cshin			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
1415f4e854itojun#define IN6MASK64	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
1427efc91cshin			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
1435f4e854itojun#define IN6MASK96	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
1447efc91cshin			    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
1455f4e854itojun#define IN6MASK128	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
1467efc91cshin			    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
1477efc91cshin#endif
1487efc91cshin
1497efc91cshin#ifdef _KERNEL
150832f8d2umeextern const struct sockaddr_in6 sa6_any;
151832f8d2ume
1527efc91cshinextern const struct in6_addr in6mask0;
1537efc91cshinextern const struct in6_addr in6mask32;
1547efc91cshinextern const struct in6_addr in6mask64;
1557efc91cshinextern const struct in6_addr in6mask96;
1567efc91cshinextern const struct in6_addr in6mask128;
1577efc91cshin#endif /* _KERNEL */
1587efc91cshin
1597efc91cshin/*
1607efc91cshin * Macros started with IPV6_ADDR is KAME local
1617efc91cshin */
162553226esuz#ifdef _KERNEL	/* XXX nonstandard */
163b0b9b58mike#if _BYTE_ORDER == _BIG_ENDIAN
1645f4e854itojun#define IPV6_ADDR_INT32_ONE	1
1655f4e854itojun#define IPV6_ADDR_INT32_TWO	2
1665f4e854itojun#define IPV6_ADDR_INT32_MNL	0xff010000
1675f4e854itojun#define IPV6_ADDR_INT32_MLL	0xff020000
1685f4e854itojun#define IPV6_ADDR_INT32_SMP	0x0000ffff
1695f4e854itojun#define IPV6_ADDR_INT16_ULL	0xfe80
1705f4e854itojun#define IPV6_ADDR_INT16_USL	0xfec0
1715f4e854itojun#define IPV6_ADDR_INT16_MLL	0xff02
172b0b9b58mike#elif _BYTE_ORDER == _LITTLE_ENDIAN
1735f4e854itojun#define IPV6_ADDR_INT32_ONE	0x01000000
1745f4e854itojun#define IPV6_ADDR_INT32_TWO	0x02000000
1755f4e854itojun#define IPV6_ADDR_INT32_MNL	0x000001ff
1765f4e854itojun#define IPV6_ADDR_INT32_MLL	0x000002ff
1775f4e854itojun#define IPV6_ADDR_INT32_SMP	0xffff0000
1785f4e854itojun#define IPV6_ADDR_INT16_ULL	0x80fe
1795f4e854itojun#define IPV6_ADDR_INT16_USL	0xc0fe
1805f4e854itojun#define IPV6_ADDR_INT16_MLL	0x02ff
1817efc91cshin#endif
1827efc91cshin#endif
1837efc91cshin
1847efc91cshin/*
1857efc91cshin * Definition of some useful macros to handle IP6 addresses
1867efc91cshin */
187b0b9b58mike#if __BSD_VISIBLE
1885f4e854itojun#define IN6ADDR_ANY_INIT \
1897efc91cshin	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
1907efc91cshin	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
1915f4e854itojun#define IN6ADDR_LOOPBACK_INIT \
1927efc91cshin	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
1937efc91cshin	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
1945f4e854itojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \
1957efc91cshin	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
1967efc91cshin	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
1975199c86ume#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
1985199c86ume	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
1995199c86ume	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
2005f4e854itojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
2017efc91cshin	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
2027efc91cshin	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
2035f4e854itojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
2047efc91cshin	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
2057efc91cshin	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
206027b036bms#define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
207027b036bms	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
208027b036bms	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
209b0b9b58mike#endif
2107efc91cshin
2117efc91cshinextern const struct in6_addr in6addr_any;
2127efc91cshinextern const struct in6_addr in6addr_loopback;
213b0b9b58mike#if __BSD_VISIBLE
2147efc91cshinextern const struct in6_addr in6addr_nodelocal_allnodes;
2157efc91cshinextern const struct in6_addr in6addr_linklocal_allnodes;
2167efc91cshinextern const struct in6_addr in6addr_linklocal_allrouters;
217027b036bmsextern const struct in6_addr in6addr_linklocal_allv2routers;
218b0b9b58mike#endif
2197efc91cshin
2207efc91cshin/*
2217efc91cshin * Equality
2226081138itojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc)
2236081138itojun * does not supply memcmp().  For userland memcmp() is preferred as it is
2246081138itojun * in ANSI standard.
2257efc91cshin */
2266081138itojun#ifdef _KERNEL
2275f4e854itojun#define IN6_ARE_ADDR_EQUAL(a, b)			\
2285f4e854itojun    (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
2296081138itojun#else
230b0b9b58mike#if __BSD_VISIBLE
2315f4e854itojun#define IN6_ARE_ADDR_EQUAL(a, b)			\
2325f4e854itojun    (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
2336081138itojun#endif
234b0b9b58mike#endif
2357efc91cshin
2367efc91cshin/*
2377efc91cshin * Unspecified
2387efc91cshin */
2395f4e854itojun#define IN6_IS_ADDR_UNSPECIFIED(a)	\
240b1246dbglebius	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
241b1246dbglebius	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
242b1246dbglebius	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
243b1246dbglebius	 (a)->__u6_addr.__u6_addr32[3] == 0)
2447efc91cshin
2457efc91cshin/*
2467efc91cshin * Loopback
2477efc91cshin */
2485f4e854itojun#define IN6_IS_ADDR_LOOPBACK(a)		\
249b1246dbglebius	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
250b1246dbglebius	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
251b1246dbglebius	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
252b1246dbglebius	 (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
2537efc91cshin
2547efc91cshin/*
2557efc91cshin * IPv4 compatible
2567efc91cshin */
2575f4e854itojun#define IN6_IS_ADDR_V4COMPAT(a)		\
258b1246dbglebius	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
259b1246dbglebius	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
260b1246dbglebius	 (a)->__u6_addr.__u6_addr32[2] == 0 &&	\
261b1246dbglebius	 (a)->__u6_addr.__u6_addr32[3] != 0 &&	\
262b1246dbglebius	 (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
2637efc91cshin
2647efc91cshin/*
2657efc91cshin * Mapped
2667efc91cshin */
2675f4e854itojun#define IN6_IS_ADDR_V4MAPPED(a)		      \
268b1246dbglebius	((a)->__u6_addr.__u6_addr32[0] == 0 &&	\
269b1246dbglebius	 (a)->__u6_addr.__u6_addr32[1] == 0 &&	\
270b1246dbglebius	 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
2717efc91cshin
2727efc91cshin/*
2737efc91cshin * KAME Scope Values
2747efc91cshin */
2757efc91cshin
276553226esuz#ifdef _KERNEL	/* XXX nonstandard */
2775f4e854itojun#define IPV6_ADDR_SCOPE_NODELOCAL	0x01
2785199c86ume#define IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
2795f4e854itojun#define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
2805f4e854itojun#define IPV6_ADDR_SCOPE_SITELOCAL	0x05
2815f4e854itojun#define IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
2825f4e854itojun#define IPV6_ADDR_SCOPE_GLOBAL		0x0e
2837efc91cshin#else
2845f4e854itojun#define __IPV6_ADDR_SCOPE_NODELOCAL	0x01
2855199c86ume#define __IPV6_ADDR_SCOPE_INTFACELOCAL	0x01
2865f4e854itojun#define __IPV6_ADDR_SCOPE_LINKLOCAL	0x02
2875f4e854itojun#define __IPV6_ADDR_SCOPE_SITELOCAL	0x05
2885f4e854itojun#define __IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
2895f4e854itojun#define __IPV6_ADDR_SCOPE_GLOBAL	0x0e
2907efc91cshin#endif
2917efc91cshin
2927efc91cshin/*
2937efc91cshin * Unicast Scope
2947efc91cshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
2957efc91cshin */
2965f4e854itojun#define IN6_IS_ADDR_LINKLOCAL(a)	\
2977efc91cshin	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
2985f4e854itojun#define IN6_IS_ADDR_SITELOCAL(a)	\
2997efc91cshin	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
3007efc91cshin
3017efc91cshin/*
3027efc91cshin * Multicast
3037efc91cshin */
3047efc91cshin#define IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
3057efc91cshin
306553226esuz#ifdef _KERNEL	/* XXX nonstandard */
3075f4e854itojun#define IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
3087efc91cshin#else
3095f4e854itojun#define __IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
3107efc91cshin#endif
3117efc91cshin
3127efc91cshin/*
3137efc91cshin * Multicast Scope
3147efc91cshin */
315553226esuz#ifdef _KERNEL	/* refers nonstandard items */
3165f4e854itojun#define IN6_IS_ADDR_MC_NODELOCAL(a)	\
3177efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3187efc91cshin	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
3195199c86ume#define IN6_IS_ADDR_MC_INTFACELOCAL(a)	\
3205199c86ume	(IN6_IS_ADDR_MULTICAST(a) &&	\
3215199c86ume	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
3225f4e854itojun#define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
3237efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3247efc91cshin	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
3255f4e854itojun#define IN6_IS_ADDR_MC_SITELOCAL(a)	\
32642fe5e7delphij	(IN6_IS_ADDR_MULTICAST(a) &&	\
3277efc91cshin	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
3285f4e854itojun#define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
3297efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3307efc91cshin	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
3315f4e854itojun#define IN6_IS_ADDR_MC_GLOBAL(a)	\
3327efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3337efc91cshin	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
3347efc91cshin#else
3355f4e854itojun#define IN6_IS_ADDR_MC_NODELOCAL(a)	\
3367efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3377efc91cshin	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
3385f4e854itojun#define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
3397efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3407efc91cshin	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
3415f4e854itojun#define IN6_IS_ADDR_MC_SITELOCAL(a)	\
34242fe5e7delphij	(IN6_IS_ADDR_MULTICAST(a) &&	\
3437efc91cshin	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
3445f4e854itojun#define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
3457efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3467efc91cshin	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
3475f4e854itojun#define IN6_IS_ADDR_MC_GLOBAL(a)	\
3487efc91cshin	(IN6_IS_ADDR_MULTICAST(a) &&	\
3497efc91cshin	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
3507efc91cshin#endif
3517efc91cshin
352553226esuz#ifdef _KERNEL	/* nonstandard */
353832f8d2ume/*
354832f8d2ume * KAME Scope
355832f8d2ume */
3565f4e854itojun#define IN6_IS_SCOPE_LINKLOCAL(a)	\
3577efc91cshin	((IN6_IS_ADDR_LINKLOCAL(a)) ||	\
3587efc91cshin	 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
35983807ecmlaier#define	IN6_IS_SCOPE_EMBED(a)			\
36083807ecmlaier	((IN6_IS_ADDR_LINKLOCAL(a)) ||		\
36142fe5e7delphij	 (IN6_IS_ADDR_MC_LINKLOCAL(a)) ||	\
36283807ecmlaier	 (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
36342fe5e7delphij
364832f8d2ume#define IFA6_IS_DEPRECATED(a) \
365c2b19f2suz	((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
36613c1bcfhrs	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
367c2b19f2suz	 (a)->ia6_lifetime.ia6t_pltime)
368832f8d2ume#define IFA6_IS_INVALID(a) \
369c2b19f2suz	((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
37013c1bcfhrs	 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
371c2b19f2suz	 (a)->ia6_lifetime.ia6t_vltime)
372832f8d2ume#endif /* _KERNEL */
3737efc91cshin
3747efc91cshin/*
3757efc91cshin * IP6 route structure
3767efc91cshin */
377b0b9b58mike#if __BSD_VISIBLE
37807f4c41melifarostruct nhop_object;
3797efc91cshinstruct route_in6 {
38007f4c41melifaro	struct nhop_object *ro_nh;
381d75e0c4gnn	struct	llentry *ro_lle;
382d75e0c4gnn	/*
383d75e0c4gnn	 * ro_prepend and ro_plen are only used for bpf to pass in a
384d75e0c4gnn	 * preformed header.  They are not cacheable.
385d75e0c4gnn	 */
38693152c6melifaro	char		*ro_prepend;
38793152c6melifaro	uint16_t	ro_plen;
38893152c6melifaro	uint16_t	ro_flags;
389c0fd312melifaro	uint16_t	ro_mtu;	/* saved ro_rt mtu */
390c0fd312melifaro	uint16_t	spare;
3917efc91cshin	struct	sockaddr_in6 ro_dst;
3927efc91cshin};
3937efc91cshin#endif
3947efc91cshin
3957ba24aeadrian#ifdef _KERNEL
3967ba24aeadrian#define MTAG_ABI_IPV6		1444287380	/* IPv6 ABI */
3977ba24aeadrian#define IPV6_TAG_DIRECT		0		/* direct-dispatch IPv6 */
3987ba24aeadrian#endif /* _KERNEL */
3997ba24aeadrian
4007efc91cshin/*
4017efc91cshin * Options for use with [gs]etsockopt at the IPV6 level.
4027efc91cshin * First word of comment is data type; bool is stored in int.
4037efc91cshin */
4047efc91cshin/* no hdrincl */
4055f4e854itojun#if 0 /* the followings are relic in IPv4 and hence are disabled */
4065f4e854itojun#define IPV6_OPTIONS		1  /* buf/ip6_opts; set/get IP6 options */
4075f4e854itojun#define IPV6_RECVOPTS		5  /* bool; receive all IP6 opts w/dgram */
4085f4e854itojun#define IPV6_RECVRETOPTS	6  /* bool; receive IP6 opts for response */
4095f4e854itojun#define IPV6_RECVDSTADDR	7  /* bool; receive IP6 dst addr w/dgram */
4105f4e854itojun#define IPV6_RETOPTS		8  /* ip6_opts; set/get IP6 options */
4115f4e854itojun#endif
4125f4e854itojun#define IPV6_SOCKOPT_RESERVED1	3  /* reserved for future use */
413881c4faume#define IPV6_UNICAST_HOPS	4  /* int; IP6 hops */
414881c4faume#define IPV6_MULTICAST_IF	9  /* u_int; set/get IP6 multicast i/f  */
415881c4faume#define IPV6_MULTICAST_HOPS	10 /* int; set/get IP6 multicast hops */
416881c4faume#define IPV6_MULTICAST_LOOP	11 /* u_int; set/get IP6 multicast loopback */
4171aaffdaticso#define IPV6_JOIN_GROUP		12 /* ipv6_mreq; join a group membership */
4181aaffdaticso#define IPV6_LEAVE_GROUP	13 /* ipv6_mreq; leave a group membership */
4195f4e854itojun#define IPV6_PORTRANGE		14 /* int; range to choose for unspec port */
4205f4e854itojun#define ICMP6_FILTER		18 /* icmp6_filter; icmp6 filter */
421832f8d2ume/* RFC2292 options */
422881c4faume#ifdef _KERNEL
423881c4faume#define IPV6_2292PKTINFO	19 /* bool; send/recv if, src/dst addr */
424881c4faume#define IPV6_2292HOPLIMIT	20 /* bool; hop limit */
425881c4faume#define IPV6_2292NEXTHOP	21 /* bool; next hop addr */
426881c4faume#define IPV6_2292HOPOPTS	22 /* bool; hop-by-hop option */
427881c4faume#define IPV6_2292DSTOPTS	23 /* bool; destinaion option */
428881c4faume#define IPV6_2292RTHDR		24 /* bool; routing header */
429881c4faume#define IPV6_2292PKTOPTIONS	25 /* buf/cmsghdr; set/get IPv6 options */
430881c4faume#endif
431832f8d2ume
4325f4e854itojun#define IPV6_CHECKSUM		26 /* int; checksum offset for raw socket */
433881c4faume#define IPV6_V6ONLY		27 /* bool; make AF_INET6 sockets v6 only */
434832f8d2ume#ifndef _KERNEL
435832f8d2ume#define IPV6_BINDV6ONLY		IPV6_V6ONLY
436832f8d2ume#endif
4377efc91cshin
4385f4e854itojun#define IPV6_IPSEC_POLICY	28 /* struct; get/set security policy */
439b5d711dmelifaro				   /* 29; unused; was IPV6_FAITH */
440553226esuz#if 1 /* IPV6FIREWALL */
4415f4e854itojun#define IPV6_FW_ADD		30 /* add a firewall rule to chain */
4425f4e854itojun#define IPV6_FW_DEL		31 /* delete a firewall rule from chain */
4435f4e854itojun#define IPV6_FW_FLUSH		32 /* flush firewall rule chain */
4445f4e854itojun#define IPV6_FW_ZERO		33 /* clear single/all firewall counter(s) */
4455f4e854itojun#define IPV6_FW_GET		34 /* get entire firewall rule chain */
446832f8d2ume#endif
447832f8d2ume
448b8e17efume/* new socket options introduced in RFC3542 */
449881c4faume#define IPV6_RTHDRDSTOPTS	35 /* ip6_dest; send dst option before rthdr */
450881c4faume
451881c4faume#define IPV6_RECVPKTINFO	36 /* bool; recv if, dst addr */
452881c4faume#define IPV6_RECVHOPLIMIT	37 /* bool; recv hop limit */
453881c4faume#define IPV6_RECVRTHDR		38 /* bool; recv routing header */
454881c4faume#define IPV6_RECVHOPOPTS	39 /* bool; recv hop-by-hop option */
455881c4faume#define IPV6_RECVDSTOPTS	40 /* bool; recv dst option after rthdr */
456881c4faume#ifdef _KERNEL
457881c4faume#define IPV6_RECVRTHDRDSTOPTS	41 /* bool; recv dst option before rthdr */
458881c4faume#endif
459881c4faume
460881c4faume#define IPV6_USE_MIN_MTU	42 /* bool; send packets at the minimum MTU */
461881c4faume#define IPV6_RECVPATHMTU	43 /* bool; notify an according MTU */
462881c4faume
463881c4faume#define IPV6_PATHMTU		44 /* mtuinfo; get the current path MTU (sopt),
464881c4faume				      4 bytes int; MTU notification (cmsg) */
465881c4faume#if 0 /*obsoleted during 2292bis -> 3542*/
466881c4faume#define IPV6_REACHCONF		45 /* no data; ND reachability confirm
467881c4faume				      (cmsg only/not in of RFC3542) */
468881c4faume#endif
469881c4faume
470b8e17efume/* more new socket options introduced in RFC3542 */
471881c4faume#define IPV6_PKTINFO		46 /* in6_pktinfo; send if, src addr */
472881c4faume#define IPV6_HOPLIMIT		47 /* int; send hop limit */
473881c4faume#define IPV6_NEXTHOP		48 /* sockaddr; next hop addr */
474881c4faume#define IPV6_HOPOPTS		49 /* ip6_hbh; send hop-by-hop option */
475881c4faume#define IPV6_DSTOPTS		50 /* ip6_dest; send dst option befor rthdr */
476881c4faume#define IPV6_RTHDR		51 /* ip6_rthdr; send routing header */
477881c4faume#if 0
478881c4faume#define IPV6_PKTOPTIONS		52 /* buf/cmsghdr; set/get IPv6 options */
479b8e17efume				   /* obsoleted by RFC3542 */
480881c4faume#endif
481881c4faume
482881c4faume#define IPV6_RECVTCLASS		57 /* bool; recv traffic class values */
483881c4faume
484881c4faume#define IPV6_AUTOFLOWLABEL	59 /* bool; attach flowlabel automagically */
485881c4faume
486881c4faume#define IPV6_TCLASS		61 /* int; send traffic class value */
487881c4faume#define IPV6_DONTFRAG		62 /* bool; disable IPv6 fragmentation */
488881c4faume
489881c4faume#define IPV6_PREFER_TEMPADDR	63 /* int; prefer temporary addresses as
490881c4faume				    * the source address.
491881c4faume				    */
492881c4faume
4935243d2dpjd#define	IPV6_BINDANY		64 /* bool: allow bind to any address */
4945243d2dpjd
4956b615c4adrian#define	IPV6_BINDMULTI		65 /* bool; allow multibind to same addr/port */
4966b615c4adrian#define	IPV6_RSS_LISTEN_BUCKET	66 /* int; set RSS listen bucket */
4976b615c4adrian#define	IPV6_FLOWID		67 /* int; flowid of given socket */
4986b615c4adrian#define	IPV6_FLOWTYPE		68 /* int; flowtype of given socket */
4996b615c4adrian#define	IPV6_RSSBUCKETID	69 /* int; RSS bucket ID of given socket */
50043407a0adrian#define	IPV6_RECVFLOWID		70 /* bool; receive IP6 flowid/flowtype w/ datagram */
50143407a0adrian#define	IPV6_RECVRSSBUCKETID	71 /* bool; receive IP6 RSS bucket id w/ datagram */
5026b615c4adrian
503f2a480ceri#define	IPV6_ORIGDSTADDR	72 /* bool: allow getting dstaddr /port info */
504f2a480ceri#define	IPV6_RECVORIGDSTADDR	IPV6_ORIGDSTADDR
505f2a480ceri
506ffd77d9bms/*
507ffd77d9bms * The following option is private; do not use it from user applications.
508ffd77d9bms * It is deliberately defined to the same value as IP_MSFILTER.
509ffd77d9bms */
510ffd77d9bms#define	IPV6_MSFILTER		74 /* struct __msfilterreq;
511ffd77d9bms				    * set/get multicast source filter list.
512ffd77d9bms				    */
513ffd77d9bms
514bc11187itojun/* to define items, should talk with KAME guys first, for *BSD compatibility */
5157efc91cshin
5165f4e854itojun#define IPV6_RTHDR_LOOSE     0 /* this hop need not be a neighbor. XXX old spec */
5175f4e854itojun#define IPV6_RTHDR_STRICT    1 /* this hop must be a neighbor. XXX old spec */
5185f4e854itojun#define IPV6_RTHDR_TYPE_0    0 /* IPv6 routing header type 0 */
5197efc91cshin
5207efc91cshin/*
5217efc91cshin * Defaults and limits for options
5227efc91cshin */
523553226esuz#define IPV6_DEFAULT_MULTICAST_HOPS 1	/* normally limit m'casts to 1 hop */
524553226esuz#define IPV6_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member */
5257efc91cshin
5267efc91cshin/*
5271a5fd51hselasky * Limit for IPv6 multicast memberships
5287efc91cshin */
529027b036bms#define	IPV6_MAX_MEMBERSHIPS	4095
5307efc91cshin
531ffd77d9bms/*
532027b036bms * Default resource limits for IPv6 multicast source filtering.
533027b036bms * These may be modified by sysctl.
534ffd77d9bms */
535027b036bms#define	IPV6_MAX_GROUP_SRC_FILTER	512	/* sources per group */
536027b036bms#define	IPV6_MAX_SOCK_SRC_FILTER	128	/* sources per socket/group */
537027b036bms
538027b036bms/*
539027b036bms * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
540027b036bms */
541027b036bmsstruct ipv6_mreq {
542ffd77d9bms	struct in6_addr	ipv6mr_multiaddr;
543027b036bms	unsigned int	ipv6mr_interface;
544ffd77d9bms};
545ffd77d9bms
5467efc91cshin/*
5477efc91cshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
5487efc91cshin */
5497efc91cshinstruct in6_pktinfo {
5505f4e854itojun	struct in6_addr	ipi6_addr;	/* src/dst IPv6 address */
5515f4e854itojun	unsigned int	ipi6_ifindex;	/* send/recv interface index */
5527efc91cshin};
5537efc91cshin
5547efc91cshin/*
555881c4faume * Control structure for IPV6_RECVPATHMTU socket option.
556881c4faume */
557881c4faumestruct ip6_mtuinfo {
558881c4faume	struct sockaddr_in6 ip6m_addr;	/* or sockaddr_storage? */
559a06a598ume	uint32_t ip6m_mtu;
560881c4faume};
561881c4faume
562881c4faume/*
5637efc91cshin * Argument for IPV6_PORTRANGE:
5647efc91cshin * - which range to search when port is unspecified at bind() or connect()
5657efc91cshin */
5667efc91cshin#define	IPV6_PORTRANGE_DEFAULT	0	/* default range */
5677efc91cshin#define	IPV6_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
5687efc91cshin#define	IPV6_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
5697efc91cshin
570881c4faume#if __BSD_VISIBLE
5717efc91cshin/*
5727efc91cshin * Definitions for inet6 sysctl operations.
5737efc91cshin *
5747efc91cshin * Third level is protocol number.
5757efc91cshin * Fourth level is desired variable within that protocol.
5767efc91cshin */
5775f4e854itojun#define IPV6PROTO_MAXID	(IPPROTO_PIM + 1)	/* don't list to IPV6PROTO_MAX */
5787efc91cshin
5797efc91cshin/*
5807efc91cshin * Names for IP sysctl objects
5817efc91cshin */
5825f4e854itojun#define IPV6CTL_FORWARDING	1	/* act as router */
5835f4e854itojun#define IPV6CTL_SENDREDIRECTS	2	/* may send redirects when forwarding*/
5845f4e854itojun#define IPV6CTL_DEFHLIM		3	/* default Hop-Limit */
5857efc91cshin#ifdef notyet
5865f4e854itojun#define IPV6CTL_DEFMTU		4	/* default MTU */
5877efc91cshin#endif
5885f4e854itojun#define IPV6CTL_FORWSRCRT	5	/* forward source-routed dgrams */
5895f4e854itojun#define IPV6CTL_STATS		6	/* stats */
5905f4e854itojun#define IPV6CTL_MRTSTATS	7	/* multicast forwarding stats */
5915f4e854itojun#define IPV6CTL_MRTPROTO	8	/* multicast routing protocol */
5925f4e854itojun#define IPV6CTL_MAXFRAGPACKETS	9	/* max packets reassembly queue */
5935f4e854itojun#define IPV6CTL_SOURCECHECK	10	/* verify source route and intf */
5945f4e854itojun#define IPV6CTL_SOURCECHECK_LOGINT 11	/* minimume logging interval */
5955f4e854itojun#define IPV6CTL_ACCEPT_RTADV	12
596b5d711dmelifaro					/* 13; unused; was: IPV6CTL_KEEPFAITH */
5975f4e854itojun#define IPV6CTL_LOG_INTERVAL	14
5985f4e854itojun#define IPV6CTL_HDRNESTLIMIT	15
5995f4e854itojun#define IPV6CTL_DAD_COUNT	16
6005f4e854itojun#define IPV6CTL_AUTO_FLOWLABEL	17
6015f4e854itojun#define IPV6CTL_DEFMCASTHLIM	18
6025f4e854itojun#define IPV6CTL_GIF_HLIM	19	/* default HLIM for gif encap packet */
6035f4e854itojun#define IPV6CTL_KAME_VERSION	20
6045f4e854itojun#define IPV6CTL_USE_DEPRECATED	21	/* use deprecated addr (RFC2462 5.5.4) */
6055f4e854itojun#define IPV6CTL_RR_PRUNE	22	/* walk timer for router renumbering */
606553226esuz#if 0	/* obsolete */
6075f4e854itojun#define IPV6CTL_MAPPED_ADDR	23
608b2c4e4citojun#endif
609832f8d2ume#define IPV6CTL_V6ONLY		24
61012580bcmelifaro/*	IPV6CTL_RTEXPIRE	25	deprecated */
61112580bcmelifaro/*	IPV6CTL_RTMINEXPIRE	26	deprecated */
61212580bcmelifaro/*	IPV6CTL_RTMAXCACHE	27	deprecated */
613832f8d2ume
614832f8d2ume#define IPV6CTL_USETEMPADDR	32	/* use temporary addresses (RFC3041) */
615832f8d2ume#define IPV6CTL_TEMPPLTIME	33	/* preferred lifetime for tmpaddrs */
616832f8d2ume#define IPV6CTL_TEMPVLTIME	34	/* valid lifetime for tmpaddrs */
617832f8d2ume#define IPV6CTL_AUTO_LINKLOCAL	35	/* automatic link-local addr assign */
618832f8d2ume#define IPV6CTL_RIP6STATS	36	/* raw_ip6 stats */
61941930d5ume#define IPV6CTL_PREFER_TEMPADDR	37	/* prefer temporary addr as src */
620f06677cume#define IPV6CTL_ADDRCTLPOLICY	38	/* get/set address selection policy */
621da2cf62ume#define IPV6CTL_USE_DEFAULTZONE	39	/* use default scope zone */
622f06677cume
62355ad7e7ume#define IPV6CTL_MAXFRAGS	41	/* max fragments */
62408a5c34ume#if 0
62508a5c34ume#define IPV6CTL_IFQ		42	/* ip6intrq node */
62608a5c34ume#define IPV6CTL_ISATAPRTR	43	/* isatap router */
62708a5c34ume#endif
62808a5c34ume#define IPV6CTL_MCAST_PMTU	44	/* enable pMTU discovery for multicast? */
62955ad7e7ume
6307efc91cshin/* New entries should be added here from current IPV6CTL_MAXID value. */
631bc11187itojun/* to define items, should talk with KAME guys first, for *BSD compatibility */
63262a02b8suz#define IPV6CTL_STEALTH		45
633678568ecperciva
634678568ecperciva#define	ICMPV6CTL_ND6_ONLINKNSRFC4861	47
6354c2206bhrs#define	IPV6CTL_NO_RADR		48	/* No defroute from RA */
6364c2206bhrs#define	IPV6CTL_NORBIT_RAIF	49	/* Disable R-bit in NA on RA
6374c2206bhrs					 * receiving IF. */
6380832028hrs#define	IPV6CTL_RFC6204W3	50	/* Accept defroute even when forwarding
6390832028hrs					   enabled */
6407a18a4bae#define	IPV6CTL_INTRQMAXLEN	51	/* max length of IPv6 netisr queue */
6417a18a4bae#define	IPV6CTL_INTRDQMAXLEN	52	/* max length of direct IPv6 netisr
6427a18a4bae					 * queue */
643a7668fajtl#define	IPV6CTL_MAXFRAGSPERPACKET	53 /* Max fragments per packet */
644e5f23fbjtl#define	IPV6CTL_MAXFRAGBUCKETSIZE	54 /* Max reassembly queues per bucket */
645e5f23fbjtl#define	IPV6CTL_MAXID		55
646881c4faume#endif /* __BSD_VISIBLE */
647832f8d2ume
648cad2014shin/*
649d734bedglebius * Since both netinet/ and netinet6/ call into netipsec/ and netpfil/,
650d734bedglebius * the protocol specific mbuf flags are shared between them.
651d734bedglebius */
652d734bedglebius#define	M_FASTFWD_OURS		M_PROTO1	/* changed dst to local */
653d734bedglebius#define	M_IP6_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
654d734bedglebius#define	M_IP_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
655d734bedglebius#define	M_SKIP_FIREWALL		M_PROTO3	/* skip firewall processing */
656d734bedglebius#define	M_AUTHIPHDR		M_PROTO4
657d734bedglebius#define	M_DECRYPTED		M_PROTO5
658d734bedglebius#define	M_LOOP			M_PROTO6
659d734bedglebius#define	M_AUTHIPDGM		M_PROTO7
660d734bedglebius#define	M_RTALERT_MLD		M_PROTO8
6618ff989fae#define	M_FRAGMENTED		M_PROTO9	/* contained fragment header */
662cad2014shin
6637efc91cshin#ifdef _KERNEL
664832f8d2umestruct cmsghdr;
665d9ff82dbzstruct ip6_hdr;
6667efc91cshin
667d9ff82dbzint	in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
6683948ce7delphijint	in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
669e281e3dtuexenint	in6_cksum_partial(struct mbuf *, u_int8_t, u_int32_t, u_int32_t,
670e281e3dtuexen			  u_int32_t);
6713948ce7delphijint	in6_localaddr(struct in6_addr *);
672fa01a4abzint	in6_localip(struct in6_addr *);
67314b7122glebiusint	in6_ifhasaddr(struct ifnet *, struct in6_addr *);
6743275dabaeint	in6_addrscope(const struct in6_addr *);
67509c0e42glebiuschar	*ip6_sprintf(char *, const struct in6_addr *);
6763948ce7delphijstruct	in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
6773948ce7delphijextern void in6_if_up(struct ifnet *);
678832f8d2umestruct sockaddr;
679e8d1f23darrenrextern	u_char	ip6_protox[];
6807efc91cshin
6813948ce7delphijvoid	in6_sin6_2_sin(struct sockaddr_in *sin,
6823948ce7delphij			    struct sockaddr_in6 *sin6);
6833948ce7delphijvoid	in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
6843948ce7delphij				 struct sockaddr_in6 *sin6);
6853948ce7delphijvoid	in6_sin6_2_sin_in_sock(struct sockaddr *nam);
6863948ce7delphijvoid	in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam);
6873948ce7delphijextern void addrsel_policy_init(void);
6887efc91cshin
689832f8d2ume#define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
690832f8d2ume#define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
691832f8d2ume#define	ifatoia6(ifa)	((struct in6_ifaddr *)(ifa))
69274063ddbrooks
6937efc91cshin#endif /* _KERNEL */
6947efc91cshin
6959e6f796mike#ifndef _SIZE_T_DECLARED
6969e6f796miketypedef	__size_t	size_t;
6979e6f796mike#define	_SIZE_T_DECLARED
698b0b9b58mike#endif
699b0b9b58mike
700b3c1e80ume#ifndef _SOCKLEN_T_DECLARED
701b3c1e80umetypedef	__socklen_t	socklen_t;
702b3c1e80ume#define	_SOCKLEN_T_DECLARED
703b3c1e80ume#endif
704b3c1e80ume
705881c4faume#if __BSD_VISIBLE
706881c4faume
7077efc91cshin__BEGIN_DECLS
7087efc91cshinstruct cmsghdr;
7097efc91cshin
7103948ce7delphijextern int inet6_option_space(int);
7113948ce7delphijextern int inet6_option_init(void *, struct cmsghdr **, int);
7123948ce7delphijextern int inet6_option_append(struct cmsghdr *, const uint8_t *,
7133948ce7delphij	int, int);
7143948ce7delphijextern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
7153948ce7delphijextern int inet6_option_next(const struct cmsghdr *, uint8_t **);
7163948ce7delphijextern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
7173948ce7delphij
7183948ce7delphijextern size_t inet6_rthdr_space(int, int);
7193948ce7delphijextern struct cmsghdr *inet6_rthdr_init(void *, int);
7203948ce7delphijextern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
7213948ce7delphij	unsigned int);
7223948ce7delphijextern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
723832f8d2ume#if 0 /* not implemented yet */
7243948ce7delphijextern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
725832f8d2ume#endif
7263948ce7delphijextern int inet6_rthdr_segments(const struct cmsghdr *);
7273948ce7delphijextern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
7283948ce7delphijextern int inet6_rthdr_getflags(const struct cmsghdr *, int);
7293948ce7delphij
7303948ce7delphijextern int inet6_opt_init(void *, socklen_t);
7313948ce7delphijextern int inet6_opt_append(void *, socklen_t, int, uint8_t, socklen_t,
7323948ce7delphij	uint8_t, void **);
7333948ce7delphijextern int inet6_opt_finish(void *, socklen_t, int);
7343948ce7delphijextern int inet6_opt_set_val(void *, int, void *, socklen_t);
7353948ce7delphij
7363948ce7delphijextern int inet6_opt_next(void *, socklen_t, int, uint8_t *, socklen_t *,
7373948ce7delphij	void **);
7383948ce7delphijextern int inet6_opt_find(void *, socklen_t, int, uint8_t, socklen_t *,
7393948ce7delphij	void **);
7403948ce7delphijextern int inet6_opt_get_val(void *, int, void *, socklen_t);
7413948ce7delphijextern socklen_t inet6_rth_space(int, int);
7423948ce7delphijextern void *inet6_rth_init(void *, socklen_t, int, int);
7433948ce7delphijextern int inet6_rth_add(void *, const struct in6_addr *);
7443948ce7delphijextern int inet6_rth_reverse(const void *, void *);
7453948ce7delphijextern int