in6.h revision 121499
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 121499 2003-10-25 10:57:08Z ume $ */ 278064Sume/* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ */ 362587Sitojun 452904Sshin/* 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 3352904Sshin/* 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 * 3. All advertising materials mentioning features or use of this software 4652904Sshin * must display the following acknowledgement: 4752904Sshin * This product includes software developed by the University of 4852904Sshin * California, Berkeley and its contributors. 4952904Sshin * 4. Neither the name of the University nor the names of its contributors 5052904Sshin * may be used to endorse or promote products derived from this software 5152904Sshin * without specific prior written permission. 5252904Sshin * 5352904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5452904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5552904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5652904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5752904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5852904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5952904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6052904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6152904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6252904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6352904Sshin * SUCH DAMAGE. 6452904Sshin * 6552904Sshin * @(#)in.h 8.3 (Berkeley) 1/3/94 6652904Sshin */ 6752904Sshin 6862587Sitojun#ifndef __KAME_NETINET_IN_H_INCLUDED_ 6978064Sume#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 7057120Sshin#endif 7157120Sshin 7262587Sitojun#ifndef _NETINET6_IN6_H_ 7362587Sitojun#define _NETINET6_IN6_H_ 7462587Sitojun 7552904Sshin/* 7652904Sshin * Identification of the network protocol stack 7778064Sume * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE 7878064Sume * has the table of implementation/integration differences. 7952904Sshin */ 8062587Sitojun#define __KAME__ 8178064Sume#define __KAME_VERSION "20010528/FreeBSD" 8252904Sshin 8352904Sshin/* 8452904Sshin * Local port number conventions: 8552904Sshin * 8652904Sshin * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), 8752904Sshin * unless a kernel is compiled with IPNOPRIVPORTS defined. 8852904Sshin * 8952904Sshin * When a user does a bind(2) or connect(2) with a port number of zero, 9052904Sshin * a non-conflicting local port address is chosen. 9152904Sshin * 9262587Sitojun * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although 9352904Sshin * that is settable by sysctl(3); net.inet.ip.anonportmin and 9452904Sshin * net.inet.ip.anonportmax respectively. 9552904Sshin * 9652904Sshin * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 9752904Sshin * default assignment range. 9852904Sshin * 9952904Sshin * The value IP_PORTRANGE_DEFAULT causes the default behavior. 10052904Sshin * 10152904Sshin * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, 10252904Sshin * and exists only for FreeBSD compatibility purposes. 10352904Sshin * 10452904Sshin * The value IP_PORTRANGE_LOW changes the range to the "low" are 10552904Sshin * that is (by convention) restricted to privileged processes. 10652904Sshin * This convention is based on "vouchsafe" principles only. 10752904Sshin * It is only secure if you trust the remote host to restrict these ports. 10852904Sshin * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. 10952904Sshin */ 11097181Smike#if __BSD_VISIBLE 11152904Sshin#define IPV6PORT_RESERVED 1024 11252904Sshin#define IPV6PORT_ANONMIN 49152 11352904Sshin#define IPV6PORT_ANONMAX 65535 11452904Sshin#define IPV6PORT_RESERVEDMIN 600 11552904Sshin#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) 11697181Smike#endif 11752904Sshin 11852904Sshin/* 11952904Sshin * IPv6 address 12052904Sshin */ 12152904Sshinstruct in6_addr { 12252904Sshin union { 12397181Smike uint8_t __u6_addr8[16]; 12497181Smike uint16_t __u6_addr16[8]; 12597181Smike uint32_t __u6_addr32[4]; 12652904Sshin } __u6_addr; /* 128-bit IP6 address */ 12752904Sshin}; 12852904Sshin 12962587Sitojun#define s6_addr __u6_addr.__u6_addr8 13095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 13162587Sitojun#define s6_addr8 __u6_addr.__u6_addr8 13262587Sitojun#define s6_addr16 __u6_addr.__u6_addr16 13362587Sitojun#define s6_addr32 __u6_addr.__u6_addr32 13452904Sshin#endif 13552904Sshin 13662587Sitojun#define INET6_ADDRSTRLEN 46 13752904Sshin 13852904Sshin/* 13997181Smike * XXX missing POSIX.1-2001 macro IPPROTO_IPV6. 14097181Smike */ 14197181Smike 14297181Smike/* 14352904Sshin * Socket address for IPv6 14452904Sshin */ 14597181Smike#if __BSD_VISIBLE 14662587Sitojun#define SIN6_LEN 14752904Sshin#endif 14897181Smike 14952904Sshinstruct sockaddr_in6 { 150100503Sume uint8_t sin6_len; /* length of this struct */ 15197181Smike sa_family_t sin6_family; /* AF_INET6 */ 15297181Smike in_port_t sin6_port; /* Transport layer port # */ 15397181Smike uint32_t sin6_flowinfo; /* IP6 flow information */ 15462587Sitojun struct in6_addr sin6_addr; /* IP6 address */ 15597181Smike uint32_t sin6_scope_id; /* scope zone index */ 15652904Sshin}; 15752904Sshin 15852904Sshin/* 15952904Sshin * Local definition for masks 16052904Sshin */ 16195023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 16262587Sitojun#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 16362587Sitojun#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 16452904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16562587Sitojun#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16652904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16762587Sitojun#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16852904Sshin 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 16962587Sitojun#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 17052904Sshin 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 17152904Sshin#endif 17252904Sshin 17352904Sshin#ifdef _KERNEL 17478064Sumeextern const struct sockaddr_in6 sa6_any; 17578064Sume 17652904Sshinextern const struct in6_addr in6mask0; 17752904Sshinextern const struct in6_addr in6mask32; 17852904Sshinextern const struct in6_addr in6mask64; 17952904Sshinextern const struct in6_addr in6mask96; 18052904Sshinextern const struct in6_addr in6mask128; 18152904Sshin#endif /* _KERNEL */ 18252904Sshin 18352904Sshin/* 18452904Sshin * Macros started with IPV6_ADDR is KAME local 18552904Sshin */ 18695023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 18797181Smike#if _BYTE_ORDER == _BIG_ENDIAN 18862587Sitojun#define IPV6_ADDR_INT32_ONE 1 18962587Sitojun#define IPV6_ADDR_INT32_TWO 2 19062587Sitojun#define IPV6_ADDR_INT32_MNL 0xff010000 19162587Sitojun#define IPV6_ADDR_INT32_MLL 0xff020000 19262587Sitojun#define IPV6_ADDR_INT32_SMP 0x0000ffff 19362587Sitojun#define IPV6_ADDR_INT16_ULL 0xfe80 19462587Sitojun#define IPV6_ADDR_INT16_USL 0xfec0 19562587Sitojun#define IPV6_ADDR_INT16_MLL 0xff02 19697181Smike#elif _BYTE_ORDER == _LITTLE_ENDIAN 19762587Sitojun#define IPV6_ADDR_INT32_ONE 0x01000000 19862587Sitojun#define IPV6_ADDR_INT32_TWO 0x02000000 19962587Sitojun#define IPV6_ADDR_INT32_MNL 0x000001ff 20062587Sitojun#define IPV6_ADDR_INT32_MLL 0x000002ff 20162587Sitojun#define IPV6_ADDR_INT32_SMP 0xffff0000 20262587Sitojun#define IPV6_ADDR_INT16_ULL 0x80fe 20362587Sitojun#define IPV6_ADDR_INT16_USL 0xc0fe 20462587Sitojun#define IPV6_ADDR_INT16_MLL 0x02ff 20552904Sshin#endif 20652904Sshin#endif 20752904Sshin 20852904Sshin/* 20952904Sshin * Definition of some useful macros to handle IP6 addresses 21052904Sshin */ 21197181Smike#if __BSD_VISIBLE 21262587Sitojun#define IN6ADDR_ANY_INIT \ 21352904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21452904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 21562587Sitojun#define IN6ADDR_LOOPBACK_INIT \ 21652904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21752904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21862587Sitojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 21952904Sshin {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 221121315Sume#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ 222121315Sume {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 223121315Sume 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22462587Sitojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 22552904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22652904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22762587Sitojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 22852904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22952904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 23097181Smike#endif 23152904Sshin 23252904Sshinextern const struct in6_addr in6addr_any; 23352904Sshinextern const struct in6_addr in6addr_loopback; 23497181Smike#if __BSD_VISIBLE 23552904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 23652904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 23752904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 23897181Smike#endif 23952904Sshin 24052904Sshin/* 24152904Sshin * Equality 24253877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 24353877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 24453877Sitojun * in ANSI standard. 24552904Sshin */ 24653877Sitojun#ifdef _KERNEL 24762587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24862587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 24953877Sitojun#else 25097181Smike#if __BSD_VISIBLE 25162587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 25262587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 25353877Sitojun#endif 25497181Smike#endif 25552904Sshin 25678064Sume#ifdef _KERNEL /* non standard */ 25778064Sume/* see if two addresses are equal in a scope-conscious manner. */ 25878064Sume#define SA6_ARE_ADDR_EQUAL(a, b) \ 25978064Sume (((a)->sin6_scope_id == 0 || (b)->sin6_scope_id == 0 || \ 26078064Sume ((a)->sin6_scope_id == (b)->sin6_scope_id)) && \ 26178064Sume (bcmp(&(a)->sin6_addr, &(b)->sin6_addr, sizeof(struct in6_addr)) == 0)) 26278064Sume#endif 26378064Sume 26452904Sshin/* 26552904Sshin * Unspecified 26652904Sshin */ 26762587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 26878064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 27078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 27178064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 27252904Sshin 27352904Sshin/* 27452904Sshin * Loopback 27552904Sshin */ 27662587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 27778064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 27878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 27978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 28078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 28152904Sshin 28252904Sshin/* 28352904Sshin * IPv4 compatible 28452904Sshin */ 28562587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 28678064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 28778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 28878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 28978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 29078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 29152904Sshin 29252904Sshin/* 29352904Sshin * Mapped 29452904Sshin */ 29562587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 29678064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 29778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 29878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 29952904Sshin 30052904Sshin/* 30152904Sshin * KAME Scope Values 30252904Sshin */ 30352904Sshin 30495023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 30562587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 306121315Sume#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 30762587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 30862587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 30962587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 31062587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 31152904Sshin#else 31262587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 313121315Sume#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 31462587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 31562587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 31662587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 31762587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 31852904Sshin#endif 31952904Sshin 32052904Sshin/* 32152904Sshin * Unicast Scope 32252904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 32352904Sshin */ 32462587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 32552904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 32662587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 32752904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 32852904Sshin 32952904Sshin/* 33052904Sshin * Multicast 33152904Sshin */ 33252904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 33352904Sshin 33495023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 33562587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33652904Sshin#else 33762587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33852904Sshin#endif 33952904Sshin 34052904Sshin/* 34152904Sshin * Multicast Scope 34252904Sshin */ 34395023Ssuz#ifdef _KERNEL /* refers nonstandard items */ 34462587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 34552904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34652904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 347121315Sume#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 348121315Sume (IN6_IS_ADDR_MULTICAST(a) && \ 349121315Sume (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) 35062587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 35152904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35252904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 35362587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 35452904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35552904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 35662587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 35752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35852904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 35962587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 36052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36152904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 36252904Sshin#else 36362587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 36452904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36552904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 36662587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 36752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36852904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 36962587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 37052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 37152904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 37262587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 37352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 37452904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 37562587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 37652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 37752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 37852904Sshin#endif 37952904Sshin 38095023Ssuz#ifdef _KERNEL /* nonstandard */ 38178064Sume/* 38252904Sshin * KAME Scope 38352904Sshin */ 38462587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 38552904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 38652904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 38752904Sshin 38878064Sume#define IFA6_IS_DEPRECATED(a) \ 38978064Sume ((a)->ia6_lifetime.ia6t_preferred != 0 && \ 39078064Sume (a)->ia6_lifetime.ia6t_preferred < time_second) 39178064Sume#define IFA6_IS_INVALID(a) \ 39278064Sume ((a)->ia6_lifetime.ia6t_expire != 0 && \ 39378064Sume (a)->ia6_lifetime.ia6t_expire < time_second) 39478064Sume#endif /* _KERNEL */ 39578064Sume 39652904Sshin/* 39752904Sshin * IP6 route structure 39852904Sshin */ 39997181Smike#if __BSD_VISIBLE 40052904Sshinstruct route_in6 { 40152904Sshin struct rtentry *ro_rt; 40252904Sshin struct sockaddr_in6 ro_dst; 40352904Sshin}; 40452904Sshin#endif 40552904Sshin 40652904Sshin/* 40752904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 40852904Sshin * First word of comment is data type; bool is stored in int. 40952904Sshin */ 41052904Sshin/* no hdrincl */ 41162587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 41262587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 41362587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 41462587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 41562587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 41662587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 41762587Sitojun#endif 41862587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 419121472Sume#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 420121472Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 421121472Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 422121472Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 423121472Sume#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 424121472Sume#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 42562587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 42662587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 42778064Sume/* RFC2292 options */ 428121472Sume#ifdef _KERNEL 429121472Sume#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 430121472Sume#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 431121472Sume#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 432121472Sume#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 433121472Sume#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */ 434121472Sume#define IPV6_2292RTHDR 24 /* bool; routing header */ 435121472Sume#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 436121472Sume#endif 43778064Sume 43862587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 439121472Sume#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 44078064Sume#ifndef _KERNEL 44178064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 44278064Sume#endif 44352904Sshin 44495023Ssuz#if 1 /* IPSEC */ 44562587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 44678064Sume#endif 44762587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 44852904Sshin 44995023Ssuz#if 1 /* IPV6FIREWALL */ 45062587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 45162587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 45262587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 45362587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 45462587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 45578064Sume#endif 45678064Sume 457121472Sume/* new socket options introduced in RFC2292bis */ 458121472Sume#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 459121472Sume 460121472Sume#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 461121472Sume#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 462121472Sume#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 463121472Sume#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 464121472Sume#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 465121472Sume#ifdef _KERNEL 466121472Sume#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 467121472Sume#endif 468121472Sume 469121472Sume#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 470121472Sume#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 471121472Sume 472121472Sume#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 473121472Sume 4 bytes int; MTU notification (cmsg) */ 474121472Sume#if 0 /*obsoleted during 2292bis -> 3542*/ 475121472Sume#define IPV6_REACHCONF 45 /* no data; ND reachability confirm 476121472Sume (cmsg only/not in of RFC3542) */ 477121472Sume#endif 478121472Sume 479121472Sume/* more new socket options introduced in RFC2292bis */ 480121472Sume#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 481121472Sume#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 482121472Sume#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 483121472Sume#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 484121472Sume#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 485121472Sume#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 486121472Sume#if 0 487121472Sume#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */ 488121472Sume /* obsoleted by 2292bis */ 489121472Sume#endif 490121472Sume 491121472Sume#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 492121472Sume 493121472Sume#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 494121472Sume 495121472Sume#define IPV6_TCLASS 61 /* int; send traffic class value */ 496121472Sume#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 497121472Sume 498121472Sume#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as 499121472Sume * the source address. 500121472Sume */ 501121472Sume 50265124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 50352904Sshin 50462587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 50562587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 50662587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 50752904Sshin 50852904Sshin/* 50952904Sshin * Defaults and limits for options 51052904Sshin */ 51195023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 51295023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 51352904Sshin 51452904Sshin/* 51552904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 51652904Sshin */ 51752904Sshinstruct ipv6_mreq { 51862587Sitojun struct in6_addr ipv6mr_multiaddr; 51962587Sitojun unsigned int ipv6mr_interface; 52052904Sshin}; 52152904Sshin 52252904Sshin/* 52352904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 52452904Sshin */ 52552904Sshinstruct in6_pktinfo { 52662587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 52762587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 52852904Sshin}; 52952904Sshin 53052904Sshin/* 531121472Sume * Control structure for IPV6_RECVPATHMTU socket option. 532121472Sume */ 533121472Sumestruct ip6_mtuinfo { 534121472Sume struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 535121472Sume u_int32_t ip6m_mtu; 536121472Sume}; 537121472Sume 538121472Sume/* 53952904Sshin * Argument for IPV6_PORTRANGE: 54052904Sshin * - which range to search when port is unspecified at bind() or connect() 54152904Sshin */ 54252904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 54352904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 54452904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 54552904Sshin 546121472Sume#if __BSD_VISIBLE 54752904Sshin/* 54852904Sshin * Definitions for inet6 sysctl operations. 54952904Sshin * 55052904Sshin * Third level is protocol number. 55152904Sshin * Fourth level is desired variable within that protocol. 55252904Sshin */ 55362587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 55452904Sshin 55552904Sshin/* 55652904Sshin * Names for IP sysctl objects 55752904Sshin */ 55862587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 55962587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 56062587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 56152904Sshin#ifdef notyet 56262587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 56352904Sshin#endif 56462587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 56562587Sitojun#define IPV6CTL_STATS 6 /* stats */ 56662587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 56762587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 56862587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 56962587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 57062587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 57162587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 57262587Sitojun#define IPV6CTL_KEEPFAITH 13 57362587Sitojun#define IPV6CTL_LOG_INTERVAL 14 57462587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 57562587Sitojun#define IPV6CTL_DAD_COUNT 16 57662587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 57762587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 57862587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 57962587Sitojun#define IPV6CTL_KAME_VERSION 20 58062587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 58162587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 58295023Ssuz#if 0 /* obsolete */ 58362587Sitojun#define IPV6CTL_MAPPED_ADDR 23 58462604Sitojun#endif 58578064Sume#define IPV6CTL_V6ONLY 24 58662604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 58762604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 58862604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 58978064Sume 59078064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 59178064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 59278064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 59378064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 59478064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 59578064Sume 596121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 597121345Sume 59852904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 59965124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 600121345Sume#define IPV6CTL_MAXID 42 601121472Sume#endif /* __BSD_VISIBLE */ 60278064Sume 60353541Sshin/* 60453541Sshin * Redefinition of mbuf flags 60553541Sshin */ 60678064Sume#define M_AUTHIPHDR M_PROTO2 60778064Sume#define M_DECRYPTED M_PROTO3 60878064Sume#define M_LOOP M_PROTO4 60978064Sume#define M_AUTHIPDGM M_PROTO5 61053541Sshin 61152904Sshin#ifdef _KERNEL 61278064Sumestruct cmsghdr; 61352904Sshin 61462587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 61552904Sshinint in6_localaddr __P((struct in6_addr *)); 61652904Sshinint in6_addrscope __P((struct in6_addr *)); 61752904Sshinstruct in6_ifaddr *in6_ifawithscope __P((struct ifnet *, struct in6_addr *)); 61852904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 61978064Sumeextern void in6_if_up __P((struct ifnet *)); 62078064Sumestruct sockaddr; 62192700Sdarrenrextern u_char ip6_protox[]; 62252904Sshin 62352904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 62452904Sshin struct sockaddr_in6 *sin6)); 62552904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 62652904Sshin struct sockaddr_in6 *sin6)); 62752904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 62852904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 62952904Sshin 63078064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 63178064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 63278064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 63383934Sbrooks 63483934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 63552904Sshin#endif /* _KERNEL */ 63652904Sshin 637102227Smike#ifndef _SIZE_T_DECLARED 638102227Smiketypedef __size_t size_t; 639102227Smike#define _SIZE_T_DECLARED 64097181Smike#endif 64197181Smike 642121498Sume#ifndef _SOCKLEN_T_DECLARED 643121498Sumetypedef __socklen_t socklen_t; 644121498Sume#define _SOCKLEN_T_DECLARED 645121498Sume#endif 646121498Sume 647121472Sume#if __BSD_VISIBLE 648121472Sume 64952904Sshin__BEGIN_DECLS 65052904Sshinstruct cmsghdr; 65152904Sshin 65278064Sumeextern int inet6_option_space __P((int)); 65378064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 65497181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 65578064Sume int, int)); 656121499Sumeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 657121499Sumeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 658121499Sumeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 65952904Sshin 66078064Sumeextern size_t inet6_rthdr_space __P((int, int)); 66178064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 66278064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 663121472Sume unsigned int)); 66478064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 66578064Sume#if 0 /* not implemented yet */ 66678064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 66778064Sume#endif 66878064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 66978064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 67078064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 67178064Sume 672121472Sumeextern int inet6_opt_init __P((void *, socklen_t)); 673121499Sumeextern int inet6_opt_append __P((void *, socklen_t, int, uint8_t, socklen_t, 674121499Sume uint8_t, void **)); 675121472Sumeextern int inet6_opt_finish __P((void *, socklen_t, int)); 676121472Sumeextern int inet6_opt_set_val __P((void *, int, void *, socklen_t)); 67778064Sume 678121499Sumeextern int inet6_opt_next __P((void *, socklen_t, int, uint8_t *, socklen_t *, 679121472Sume void **)); 680121499Sumeextern int inet6_opt_find __P((void *, socklen_t, int, uint8_t, socklen_t *, 681121472Sume void **)); 682121472Sumeextern int inet6_opt_get_val __P((void *, int, void *, socklen_t)); 683121472Sumeextern socklen_t inet6_rth_space __P((int, int)); 684121472Sumeextern void *inet6_rth_init __P((void *, socklen_t, int, int)); 68578064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 68678064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 68778064Sumeextern int inet6_rth_segments __P((const void *)); 68878064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 68952904Sshin__END_DECLS 69052904Sshin 69197181Smike#endif /* __BSD_VISIBLE */ 69297181Smike 69352904Sshin#endif /* !_NETINET6_IN6_H_ */ 694