in6.h revision 139826
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 139826 2005-01-07 02:30:35Z imp $ */ 278064Sume/* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ */ 362587Sitojun 4139826Simp/*- 552904Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 652904Sshin * All rights reserved. 753541Sshin * 852904Sshin * Redistribution and use in source and binary forms, with or without 952904Sshin * modification, are permitted provided that the following conditions 1052904Sshin * are met: 1152904Sshin * 1. Redistributions of source code must retain the above copyright 1252904Sshin * notice, this list of conditions and the following disclaimer. 1352904Sshin * 2. Redistributions in binary form must reproduce the above copyright 1452904Sshin * notice, this list of conditions and the following disclaimer in the 1552904Sshin * documentation and/or other materials provided with the distribution. 1652904Sshin * 3. Neither the name of the project nor the names of its contributors 1752904Sshin * may be used to endorse or promote products derived from this software 1852904Sshin * without specific prior written permission. 1953541Sshin * 2052904Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2152904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2252904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2352904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2452904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2552904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2652904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2752904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2852904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2952904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3052904Sshin * SUCH DAMAGE. 3152904Sshin */ 3252904Sshin 33139826Simp/*- 3452904Sshin * Copyright (c) 1982, 1986, 1990, 1993 3552904Sshin * The Regents of the University of California. All rights reserved. 3652904Sshin * 3752904Sshin * Redistribution and use in source and binary forms, with or without 3852904Sshin * modification, are permitted provided that the following conditions 3952904Sshin * are met: 4052904Sshin * 1. Redistributions of source code must retain the above copyright 4152904Sshin * notice, this list of conditions and the following disclaimer. 4252904Sshin * 2. Redistributions in binary form must reproduce the above copyright 4352904Sshin * notice, this list of conditions and the following disclaimer in the 4452904Sshin * documentation and/or other materials provided with the distribution. 4552904Sshin * 4. Neither the name of the University nor the names of its contributors 4652904Sshin * may be used to endorse or promote products derived from this software 4752904Sshin * without specific prior written permission. 4852904Sshin * 4952904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5052904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5152904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5252904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5352904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5452904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5552904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5652904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5752904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5852904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5952904Sshin * SUCH DAMAGE. 6052904Sshin * 6152904Sshin * @(#)in.h 8.3 (Berkeley) 1/3/94 6252904Sshin */ 6352904Sshin 6462587Sitojun#ifndef __KAME_NETINET_IN_H_INCLUDED_ 6578064Sume#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 6657120Sshin#endif 6757120Sshin 6862587Sitojun#ifndef _NETINET6_IN6_H_ 6962587Sitojun#define _NETINET6_IN6_H_ 7062587Sitojun 7152904Sshin/* 7252904Sshin * Identification of the network protocol stack 7378064Sume * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE 7478064Sume * has the table of implementation/integration differences. 7552904Sshin */ 7662587Sitojun#define __KAME__ 7778064Sume#define __KAME_VERSION "20010528/FreeBSD" 7852904Sshin 7952904Sshin/* 8052904Sshin * Local port number conventions: 8152904Sshin * 8252904Sshin * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), 8352904Sshin * unless a kernel is compiled with IPNOPRIVPORTS defined. 8452904Sshin * 8552904Sshin * When a user does a bind(2) or connect(2) with a port number of zero, 8652904Sshin * a non-conflicting local port address is chosen. 8752904Sshin * 8862587Sitojun * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although 8952904Sshin * that is settable by sysctl(3); net.inet.ip.anonportmin and 9052904Sshin * net.inet.ip.anonportmax respectively. 9152904Sshin * 9252904Sshin * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 9352904Sshin * default assignment range. 9452904Sshin * 9552904Sshin * The value IP_PORTRANGE_DEFAULT causes the default behavior. 9652904Sshin * 9752904Sshin * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, 9852904Sshin * and exists only for FreeBSD compatibility purposes. 9952904Sshin * 10052904Sshin * The value IP_PORTRANGE_LOW changes the range to the "low" are 10152904Sshin * that is (by convention) restricted to privileged processes. 10252904Sshin * This convention is based on "vouchsafe" principles only. 10352904Sshin * It is only secure if you trust the remote host to restrict these ports. 10452904Sshin * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. 10552904Sshin */ 10697181Smike#if __BSD_VISIBLE 10752904Sshin#define IPV6PORT_RESERVED 1024 10852904Sshin#define IPV6PORT_ANONMIN 49152 10952904Sshin#define IPV6PORT_ANONMAX 65535 11052904Sshin#define IPV6PORT_RESERVEDMIN 600 11152904Sshin#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) 11297181Smike#endif 11352904Sshin 11452904Sshin/* 11552904Sshin * IPv6 address 11652904Sshin */ 11752904Sshinstruct in6_addr { 11852904Sshin union { 11997181Smike uint8_t __u6_addr8[16]; 12097181Smike uint16_t __u6_addr16[8]; 12197181Smike uint32_t __u6_addr32[4]; 12252904Sshin } __u6_addr; /* 128-bit IP6 address */ 12352904Sshin}; 12452904Sshin 12562587Sitojun#define s6_addr __u6_addr.__u6_addr8 12695023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 12762587Sitojun#define s6_addr8 __u6_addr.__u6_addr8 12862587Sitojun#define s6_addr16 __u6_addr.__u6_addr16 12962587Sitojun#define s6_addr32 __u6_addr.__u6_addr32 13052904Sshin#endif 13152904Sshin 13262587Sitojun#define INET6_ADDRSTRLEN 46 13352904Sshin 13452904Sshin/* 13597181Smike * XXX missing POSIX.1-2001 macro IPPROTO_IPV6. 13697181Smike */ 13797181Smike 13897181Smike/* 13952904Sshin * Socket address for IPv6 14052904Sshin */ 14197181Smike#if __BSD_VISIBLE 14262587Sitojun#define SIN6_LEN 14352904Sshin#endif 14497181Smike 14552904Sshinstruct sockaddr_in6 { 146100503Sume uint8_t sin6_len; /* length of this struct */ 14797181Smike sa_family_t sin6_family; /* AF_INET6 */ 14897181Smike in_port_t sin6_port; /* Transport layer port # */ 14997181Smike uint32_t sin6_flowinfo; /* IP6 flow information */ 15062587Sitojun struct in6_addr sin6_addr; /* IP6 address */ 15197181Smike uint32_t sin6_scope_id; /* scope zone index */ 15252904Sshin}; 15352904Sshin 15452904Sshin/* 15552904Sshin * Local definition for masks 15652904Sshin */ 15795023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 15862587Sitojun#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 15962587Sitojun#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 16052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16162587Sitojun#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16252904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16362587Sitojun#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16452904Sshin 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 16562587Sitojun#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16652904Sshin 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 16752904Sshin#endif 16852904Sshin 16952904Sshin#ifdef _KERNEL 17078064Sumeextern const struct sockaddr_in6 sa6_any; 17178064Sume 17252904Sshinextern const struct in6_addr in6mask0; 17352904Sshinextern const struct in6_addr in6mask32; 17452904Sshinextern const struct in6_addr in6mask64; 17552904Sshinextern const struct in6_addr in6mask96; 17652904Sshinextern const struct in6_addr in6mask128; 17752904Sshin#endif /* _KERNEL */ 17852904Sshin 17952904Sshin/* 18052904Sshin * Macros started with IPV6_ADDR is KAME local 18152904Sshin */ 18295023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 18397181Smike#if _BYTE_ORDER == _BIG_ENDIAN 18462587Sitojun#define IPV6_ADDR_INT32_ONE 1 18562587Sitojun#define IPV6_ADDR_INT32_TWO 2 18662587Sitojun#define IPV6_ADDR_INT32_MNL 0xff010000 18762587Sitojun#define IPV6_ADDR_INT32_MLL 0xff020000 18862587Sitojun#define IPV6_ADDR_INT32_SMP 0x0000ffff 18962587Sitojun#define IPV6_ADDR_INT16_ULL 0xfe80 19062587Sitojun#define IPV6_ADDR_INT16_USL 0xfec0 19162587Sitojun#define IPV6_ADDR_INT16_MLL 0xff02 19297181Smike#elif _BYTE_ORDER == _LITTLE_ENDIAN 19362587Sitojun#define IPV6_ADDR_INT32_ONE 0x01000000 19462587Sitojun#define IPV6_ADDR_INT32_TWO 0x02000000 19562587Sitojun#define IPV6_ADDR_INT32_MNL 0x000001ff 19662587Sitojun#define IPV6_ADDR_INT32_MLL 0x000002ff 19762587Sitojun#define IPV6_ADDR_INT32_SMP 0xffff0000 19862587Sitojun#define IPV6_ADDR_INT16_ULL 0x80fe 19962587Sitojun#define IPV6_ADDR_INT16_USL 0xc0fe 20062587Sitojun#define IPV6_ADDR_INT16_MLL 0x02ff 20152904Sshin#endif 20252904Sshin#endif 20352904Sshin 20452904Sshin/* 20552904Sshin * Definition of some useful macros to handle IP6 addresses 20652904Sshin */ 20797181Smike#if __BSD_VISIBLE 20862587Sitojun#define IN6ADDR_ANY_INIT \ 20952904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 21162587Sitojun#define IN6ADDR_LOOPBACK_INIT \ 21252904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21352904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21462587Sitojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 21552904Sshin {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21652904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 217121315Sume#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ 218121315Sume {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 219121315Sume 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22062587Sitojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 22152904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22252904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22362587Sitojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 22452904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22552904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 22697181Smike#endif 22752904Sshin 22852904Sshinextern const struct in6_addr in6addr_any; 22952904Sshinextern const struct in6_addr in6addr_loopback; 23097181Smike#if __BSD_VISIBLE 23152904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 23252904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 23352904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 23497181Smike#endif 23552904Sshin 23652904Sshin/* 23752904Sshin * Equality 23853877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 23953877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 24053877Sitojun * in ANSI standard. 24152904Sshin */ 24253877Sitojun#ifdef _KERNEL 24362587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24462587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 24553877Sitojun#else 24697181Smike#if __BSD_VISIBLE 24762587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24862587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 24953877Sitojun#endif 25097181Smike#endif 25152904Sshin 25278064Sume#ifdef _KERNEL /* non standard */ 25378064Sume/* see if two addresses are equal in a scope-conscious manner. */ 25478064Sume#define SA6_ARE_ADDR_EQUAL(a, b) \ 25578064Sume (((a)->sin6_scope_id == 0 || (b)->sin6_scope_id == 0 || \ 25678064Sume ((a)->sin6_scope_id == (b)->sin6_scope_id)) && \ 25778064Sume (bcmp(&(a)->sin6_addr, &(b)->sin6_addr, sizeof(struct in6_addr)) == 0)) 25878064Sume#endif 25978064Sume 26052904Sshin/* 26152904Sshin * Unspecified 26252904Sshin */ 26362587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 26478064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 26678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 26778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 26852904Sshin 26952904Sshin/* 27052904Sshin * Loopback 27152904Sshin */ 27262587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 27378064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 27478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 27578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 27678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 27752904Sshin 27852904Sshin/* 27952904Sshin * IPv4 compatible 28052904Sshin */ 28162587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 28278064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 28378064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 28478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 28578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 28678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 28752904Sshin 28852904Sshin/* 28952904Sshin * Mapped 29052904Sshin */ 29162587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 29278064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 29378064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 29478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 29552904Sshin 29652904Sshin/* 29752904Sshin * KAME Scope Values 29852904Sshin */ 29952904Sshin 30095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 30162587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 302121315Sume#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 30362587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 30462587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 30562587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 30662587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 30752904Sshin#else 30862587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 309121315Sume#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 31062587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 31162587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 31262587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 31362587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 31452904Sshin#endif 31552904Sshin 31652904Sshin/* 31752904Sshin * Unicast Scope 31852904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 31952904Sshin */ 32062587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 32152904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 32262587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 32352904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 32452904Sshin 32552904Sshin/* 32652904Sshin * Multicast 32752904Sshin */ 32852904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 32952904Sshin 33095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 33162587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33252904Sshin#else 33362587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33452904Sshin#endif 33552904Sshin 33652904Sshin/* 33752904Sshin * Multicast Scope 33852904Sshin */ 33995023Ssuz#ifdef _KERNEL /* refers nonstandard items */ 34062587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 34152904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34252904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 343121315Sume#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 344121315Sume (IN6_IS_ADDR_MULTICAST(a) && \ 345121315Sume (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) 34662587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 34752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34852904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 34962587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 35052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35152904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 35262587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 35352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35452904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 35562587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 35652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35752904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 35852904Sshin#else 35962587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 36052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36152904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 36262587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 36352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36452904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 36562587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 36652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 36862587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 36952904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 37052904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 37162587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 37252904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 37352904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 37452904Sshin#endif 37552904Sshin 37695023Ssuz#ifdef _KERNEL /* nonstandard */ 37778064Sume/* 37852904Sshin * KAME Scope 37952904Sshin */ 38062587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 38152904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 38252904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 38352904Sshin 38478064Sume#define IFA6_IS_DEPRECATED(a) \ 38578064Sume ((a)->ia6_lifetime.ia6t_preferred != 0 && \ 38678064Sume (a)->ia6_lifetime.ia6t_preferred < time_second) 38778064Sume#define IFA6_IS_INVALID(a) \ 38878064Sume ((a)->ia6_lifetime.ia6t_expire != 0 && \ 38978064Sume (a)->ia6_lifetime.ia6t_expire < time_second) 39078064Sume#endif /* _KERNEL */ 39178064Sume 39252904Sshin/* 39352904Sshin * IP6 route structure 39452904Sshin */ 39597181Smike#if __BSD_VISIBLE 39652904Sshinstruct route_in6 { 39752904Sshin struct rtentry *ro_rt; 39852904Sshin struct sockaddr_in6 ro_dst; 39952904Sshin}; 40052904Sshin#endif 40152904Sshin 40252904Sshin/* 40352904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 40452904Sshin * First word of comment is data type; bool is stored in int. 40552904Sshin */ 40652904Sshin/* no hdrincl */ 40762587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 40862587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 40962587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 41062587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 41162587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 41262587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 41362587Sitojun#endif 41462587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 415121472Sume#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 416121472Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 417121472Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 418121472Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 419121472Sume#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 420121472Sume#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 42162587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 42262587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 42378064Sume/* RFC2292 options */ 424121472Sume#ifdef _KERNEL 425121472Sume#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 426121472Sume#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 427121472Sume#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 428121472Sume#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 429121472Sume#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */ 430121472Sume#define IPV6_2292RTHDR 24 /* bool; routing header */ 431121472Sume#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 432121472Sume#endif 43378064Sume 43462587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 435121472Sume#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 43678064Sume#ifndef _KERNEL 43778064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 43878064Sume#endif 43952904Sshin 44095023Ssuz#if 1 /* IPSEC */ 44162587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 44278064Sume#endif 44362587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 44452904Sshin 44595023Ssuz#if 1 /* IPV6FIREWALL */ 44662587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 44762587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 44862587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 44962587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 45062587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 45178064Sume#endif 45278064Sume 453121472Sume/* new socket options introduced in RFC2292bis */ 454121472Sume#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 455121472Sume 456121472Sume#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 457121472Sume#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 458121472Sume#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 459121472Sume#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 460121472Sume#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 461121472Sume#ifdef _KERNEL 462121472Sume#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 463121472Sume#endif 464121472Sume 465121472Sume#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 466121472Sume#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 467121472Sume 468121472Sume#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 469121472Sume 4 bytes int; MTU notification (cmsg) */ 470121472Sume#if 0 /*obsoleted during 2292bis -> 3542*/ 471121472Sume#define IPV6_REACHCONF 45 /* no data; ND reachability confirm 472121472Sume (cmsg only/not in of RFC3542) */ 473121472Sume#endif 474121472Sume 475121472Sume/* more new socket options introduced in RFC2292bis */ 476121472Sume#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 477121472Sume#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 478121472Sume#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 479121472Sume#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 480121472Sume#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 481121472Sume#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 482121472Sume#if 0 483121472Sume#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */ 484121472Sume /* obsoleted by 2292bis */ 485121472Sume#endif 486121472Sume 487121472Sume#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 488121472Sume 489121472Sume#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 490121472Sume 491121472Sume#define IPV6_TCLASS 61 /* int; send traffic class value */ 492121472Sume#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 493121472Sume 494121472Sume#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as 495121472Sume * the source address. 496121472Sume */ 497121472Sume 49865124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 49952904Sshin 50062587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 50162587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 50262587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 50352904Sshin 50452904Sshin/* 50552904Sshin * Defaults and limits for options 50652904Sshin */ 50795023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 50895023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 50952904Sshin 51052904Sshin/* 51152904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 51252904Sshin */ 51352904Sshinstruct ipv6_mreq { 51462587Sitojun struct in6_addr ipv6mr_multiaddr; 51562587Sitojun unsigned int ipv6mr_interface; 51652904Sshin}; 51752904Sshin 51852904Sshin/* 51952904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 52052904Sshin */ 52152904Sshinstruct in6_pktinfo { 52262587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 52362587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 52452904Sshin}; 52552904Sshin 52652904Sshin/* 527121472Sume * Control structure for IPV6_RECVPATHMTU socket option. 528121472Sume */ 529121472Sumestruct ip6_mtuinfo { 530121472Sume struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 531121569Sume uint32_t ip6m_mtu; 532121472Sume}; 533121472Sume 534121472Sume/* 53552904Sshin * Argument for IPV6_PORTRANGE: 53652904Sshin * - which range to search when port is unspecified at bind() or connect() 53752904Sshin */ 53852904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 53952904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 54052904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 54152904Sshin 542121472Sume#if __BSD_VISIBLE 54352904Sshin/* 54452904Sshin * Definitions for inet6 sysctl operations. 54552904Sshin * 54652904Sshin * Third level is protocol number. 54752904Sshin * Fourth level is desired variable within that protocol. 54852904Sshin */ 54962587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 55052904Sshin 55152904Sshin/* 55252904Sshin * Names for IP sysctl objects 55352904Sshin */ 55462587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 55562587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 55662587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 55752904Sshin#ifdef notyet 55862587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 55952904Sshin#endif 56062587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 56162587Sitojun#define IPV6CTL_STATS 6 /* stats */ 56262587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 56362587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 56462587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 56562587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 56662587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 56762587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 56862587Sitojun#define IPV6CTL_KEEPFAITH 13 56962587Sitojun#define IPV6CTL_LOG_INTERVAL 14 57062587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 57162587Sitojun#define IPV6CTL_DAD_COUNT 16 57262587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 57362587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 57462587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 57562587Sitojun#define IPV6CTL_KAME_VERSION 20 57662587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 57762587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 57895023Ssuz#if 0 /* obsolete */ 57962587Sitojun#define IPV6CTL_MAPPED_ADDR 23 58062604Sitojun#endif 58178064Sume#define IPV6CTL_V6ONLY 24 58262604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 58362604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 58462604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 58578064Sume 58678064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 58778064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 58878064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 58978064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 59078064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 591122077Sume#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */ 592121742Sume#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */ 593121742Sume 594121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 595121345Sume 59652904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 59765124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 598121345Sume#define IPV6CTL_MAXID 42 599121472Sume#endif /* __BSD_VISIBLE */ 60078064Sume 60153541Sshin/* 60253541Sshin * Redefinition of mbuf flags 60353541Sshin */ 60478064Sume#define M_AUTHIPHDR M_PROTO2 60578064Sume#define M_DECRYPTED M_PROTO3 60678064Sume#define M_LOOP M_PROTO4 60778064Sume#define M_AUTHIPDGM M_PROTO5 60853541Sshin 60952904Sshin#ifdef _KERNEL 61078064Sumestruct cmsghdr; 61152904Sshin 61262587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 61352904Sshinint in6_localaddr __P((struct in6_addr *)); 61452904Sshinint in6_addrscope __P((struct in6_addr *)); 61552904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 61678064Sumeextern void in6_if_up __P((struct ifnet *)); 61778064Sumestruct sockaddr; 61892700Sdarrenrextern u_char ip6_protox[]; 61952904Sshin 62052904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 62152904Sshin struct sockaddr_in6 *sin6)); 62252904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 62352904Sshin struct sockaddr_in6 *sin6)); 62452904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 62552904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 626121742Sumeextern void addrsel_policy_init __P((void)); 62752904Sshin 62878064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 62978064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 63078064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 63183934Sbrooks 63283934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 63352904Sshin#endif /* _KERNEL */ 63452904Sshin 635102227Smike#ifndef _SIZE_T_DECLARED 636102227Smiketypedef __size_t size_t; 637102227Smike#define _SIZE_T_DECLARED 63897181Smike#endif 63997181Smike 640121498Sume#ifndef _SOCKLEN_T_DECLARED 641121498Sumetypedef __socklen_t socklen_t; 642121498Sume#define _SOCKLEN_T_DECLARED 643121498Sume#endif 644121498Sume 645121472Sume#if __BSD_VISIBLE 646121472Sume 64752904Sshin__BEGIN_DECLS 64852904Sshinstruct cmsghdr; 64952904Sshin 65078064Sumeextern int inet6_option_space __P((int)); 65178064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 65297181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 65378064Sume int, int)); 654121499Sumeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 655121499Sumeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 656121499Sumeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 65752904Sshin 65878064Sumeextern size_t inet6_rthdr_space __P((int, int)); 65978064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 66078064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 661121472Sume unsigned int)); 66278064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 66378064Sume#if 0 /* not implemented yet */ 66478064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 66578064Sume#endif 66678064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 66778064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 66878064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 66978064Sume 670121472Sumeextern int inet6_opt_init __P((void *, socklen_t)); 671121499Sumeextern int inet6_opt_append __P((void *, socklen_t, int, uint8_t, socklen_t, 672121499Sume uint8_t, void **)); 673121472Sumeextern int inet6_opt_finish __P((void *, socklen_t, int)); 674121472Sumeextern int inet6_opt_set_val __P((void *, int, void *, socklen_t)); 67578064Sume 676121499Sumeextern int inet6_opt_next __P((void *, socklen_t, int, uint8_t *, socklen_t *, 677121472Sume void **)); 678121499Sumeextern int inet6_opt_find __P((void *, socklen_t, int, uint8_t, socklen_t *, 679121472Sume void **)); 680121472Sumeextern int inet6_opt_get_val __P((void *, int, void *, socklen_t)); 681121472Sumeextern socklen_t inet6_rth_space __P((int, int)); 682121472Sumeextern void *inet6_rth_init __P((void *, socklen_t, int, int)); 68378064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 68478064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 68578064Sumeextern int inet6_rth_segments __P((const void *)); 68678064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 68752904Sshin__END_DECLS 68852904Sshin 68997181Smike#endif /* __BSD_VISIBLE */ 69097181Smike 69152904Sshin#endif /* !_NETINET6_IN6_H_ */ 692