in6.h revision 121345
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 121345 2003-10-22 15:29:42Z 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 */ 41097181Smike#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 41197181Smike#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 412100688Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 413100688Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 414100688Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 41597181Smike#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 41697181Smike#define IPV6_V6ONLY 27 /* bool; only bind INET6 at wildcard bind */ 41797181Smike 41897181Smike#if __BSD_VISIBLE 41952904Sshin/* no hdrincl */ 42062587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 42162587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 42262587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 42362587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 42462587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 42562587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 42662587Sitojun#endif 42762587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 42862587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 42962587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 43078064Sume/* RFC2292 options */ 43178064Sume#define IPV6_PKTINFO 19 /* bool; send/recv if, src/dst addr */ 43262587Sitojun#define IPV6_HOPLIMIT 20 /* bool; hop limit */ 43362587Sitojun#define IPV6_NEXTHOP 21 /* bool; next hop addr */ 43462587Sitojun#define IPV6_HOPOPTS 22 /* bool; hop-by-hop option */ 43562587Sitojun#define IPV6_DSTOPTS 23 /* bool; destination option */ 43662587Sitojun#define IPV6_RTHDR 24 /* bool; routing header */ 43762587Sitojun#define IPV6_PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 43878064Sume 43962587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 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 45765124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 45852904Sshin 45962587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 46062587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 46162587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 46252904Sshin 46352904Sshin/* 46452904Sshin * Defaults and limits for options 46552904Sshin */ 46695023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 46795023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 46852904Sshin 46952904Sshin/* 47052904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 47152904Sshin */ 47252904Sshinstruct ipv6_mreq { 47362587Sitojun struct in6_addr ipv6mr_multiaddr; 47462587Sitojun unsigned int ipv6mr_interface; 47552904Sshin}; 47652904Sshin 47752904Sshin/* 47852904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 47952904Sshin */ 48052904Sshinstruct in6_pktinfo { 48162587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 48262587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 48352904Sshin}; 48452904Sshin 48552904Sshin/* 48652904Sshin * Argument for IPV6_PORTRANGE: 48752904Sshin * - which range to search when port is unspecified at bind() or connect() 48852904Sshin */ 48952904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 49052904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 49152904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 49252904Sshin 49352904Sshin/* 49452904Sshin * Definitions for inet6 sysctl operations. 49552904Sshin * 49652904Sshin * Third level is protocol number. 49752904Sshin * Fourth level is desired variable within that protocol. 49852904Sshin */ 49962587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 50052904Sshin 50152904Sshin/* 50252904Sshin * Names for IP sysctl objects 50352904Sshin */ 50462587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 50562587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 50662587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 50752904Sshin#ifdef notyet 50862587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 50952904Sshin#endif 51062587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 51162587Sitojun#define IPV6CTL_STATS 6 /* stats */ 51262587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 51362587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 51462587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 51562587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 51662587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 51762587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 51862587Sitojun#define IPV6CTL_KEEPFAITH 13 51962587Sitojun#define IPV6CTL_LOG_INTERVAL 14 52062587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 52162587Sitojun#define IPV6CTL_DAD_COUNT 16 52262587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 52362587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 52462587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 52562587Sitojun#define IPV6CTL_KAME_VERSION 20 52662587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 52762587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 52895023Ssuz#if 0 /* obsolete */ 52962587Sitojun#define IPV6CTL_MAPPED_ADDR 23 53062604Sitojun#endif 53178064Sume#define IPV6CTL_V6ONLY 24 53262604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 53362604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 53462604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 53578064Sume 53678064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 53778064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 53878064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 53978064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 54078064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 54178064Sume 542121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 543121345Sume 54452904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 54565124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 546121345Sume#define IPV6CTL_MAXID 42 54778064Sume 54853541Sshin/* 54953541Sshin * Redefinition of mbuf flags 55053541Sshin */ 55178064Sume#define M_AUTHIPHDR M_PROTO2 55278064Sume#define M_DECRYPTED M_PROTO3 55378064Sume#define M_LOOP M_PROTO4 55478064Sume#define M_AUTHIPDGM M_PROTO5 55553541Sshin 55652904Sshin#ifdef _KERNEL 55778064Sumestruct cmsghdr; 55852904Sshin 55962587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 56052904Sshinint in6_localaddr __P((struct in6_addr *)); 56152904Sshinint in6_addrscope __P((struct in6_addr *)); 56252904Sshinstruct in6_ifaddr *in6_ifawithscope __P((struct ifnet *, struct in6_addr *)); 56352904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 56478064Sumeextern void in6_if_up __P((struct ifnet *)); 56578064Sumestruct sockaddr; 56692700Sdarrenrextern u_char ip6_protox[]; 56752904Sshin 56852904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 56952904Sshin struct sockaddr_in6 *sin6)); 57052904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 57152904Sshin struct sockaddr_in6 *sin6)); 57252904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 57352904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 57452904Sshin 57578064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 57678064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 57778064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 57883934Sbrooks 57983934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 58052904Sshin#endif /* _KERNEL */ 58152904Sshin 582102227Smike#ifndef _SIZE_T_DECLARED 583102227Smiketypedef __size_t size_t; 584102227Smike#define _SIZE_T_DECLARED 58597181Smike#endif 58697181Smike 58752904Sshin__BEGIN_DECLS 58852904Sshinstruct cmsghdr; 58952904Sshin 59078064Sumeextern int inet6_option_space __P((int)); 59178064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 59297181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 59378064Sume int, int)); 59497181Smikeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 59597181Smikeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 59697181Smikeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 59752904Sshin 59878064Sumeextern size_t inet6_rthdr_space __P((int, int)); 59978064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 60078064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 60178064Sume unsigned int)); 60278064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 60378064Sume#if 0 /* not implemented yet */ 60478064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 60578064Sume#endif 60678064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 60778064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 60878064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 60978064Sume 61078064Sumeextern int inet6_opt_init __P((void *, size_t)); 61197181Smikeextern int inet6_opt_append __P((void *, size_t, int, uint8_t, 61297181Smike size_t, uint8_t, void **)); 61378064Sumeextern int inet6_opt_finish __P((void *, size_t, int)); 61478064Sumeextern int inet6_opt_set_val __P((void *, size_t, void *, int)); 61578064Sume 61697181Smikeextern int inet6_opt_next __P((void *, size_t, int, uint8_t *, 61778064Sume size_t *, void **)); 61897181Smikeextern int inet6_opt_find __P((void *, size_t, int, uint8_t, 61978064Sume size_t *, void **)); 62078064Sumeextern int inet6_opt_get_val __P((void *, size_t, void *, int)); 62178064Sumeextern size_t inet6_rth_space __P((int, int)); 62278064Sumeextern void *inet6_rth_init __P((void *, int, int, int)); 62378064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 62478064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 62578064Sumeextern int inet6_rth_segments __P((const void *)); 62678064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 62752904Sshin__END_DECLS 62852904Sshin 62997181Smike#endif /* __BSD_VISIBLE */ 63097181Smike 63152904Sshin#endif /* !_NETINET6_IN6_H_ */ 632