in6.h revision 225521
1139826Simp/*- 252904Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 352904Sshin * All rights reserved. 453541Sshin * 552904Sshin * Redistribution and use in source and binary forms, with or without 652904Sshin * modification, are permitted provided that the following conditions 752904Sshin * are met: 852904Sshin * 1. Redistributions of source code must retain the above copyright 952904Sshin * notice, this list of conditions and the following disclaimer. 1052904Sshin * 2. Redistributions in binary form must reproduce the above copyright 1152904Sshin * notice, this list of conditions and the following disclaimer in the 1252904Sshin * documentation and/or other materials provided with the distribution. 1352904Sshin * 3. Neither the name of the project nor the names of its contributors 1452904Sshin * may be used to endorse or promote products derived from this software 1552904Sshin * without specific prior written permission. 1653541Sshin * 1752904Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1852904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1952904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2052904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2152904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2252904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2352904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2452904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2552904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2652904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2752904Sshin * SUCH DAMAGE. 28174510Sobrien * 29174510Sobrien * $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ 3052904Sshin */ 3152904Sshin 32139826Simp/*- 3352904Sshin * Copyright (c) 1982, 1986, 1990, 1993 3452904Sshin * The Regents of the University of California. All rights reserved. 3552904Sshin * 3652904Sshin * Redistribution and use in source and binary forms, with or without 3752904Sshin * modification, are permitted provided that the following conditions 3852904Sshin * are met: 3952904Sshin * 1. Redistributions of source code must retain the above copyright 4052904Sshin * notice, this list of conditions and the following disclaimer. 4152904Sshin * 2. Redistributions in binary form must reproduce the above copyright 4252904Sshin * notice, this list of conditions and the following disclaimer in the 4352904Sshin * documentation and/or other materials provided with the distribution. 4452904Sshin * 4. Neither the name of the University nor the names of its contributors 4552904Sshin * may be used to endorse or promote products derived from this software 4652904Sshin * without specific prior written permission. 4752904Sshin * 4852904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 4952904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5052904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5152904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5252904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5352904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5452904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5552904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5652904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5752904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5852904Sshin * SUCH DAMAGE. 5952904Sshin * 6052904Sshin * @(#)in.h 8.3 (Berkeley) 1/3/94 61174510Sobrien * $FreeBSD: head/sys/netinet6/in6.h 225521 2011-09-13 00:06:11Z hrs $ 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__ 77156865Ssuz#define __KAME_VERSION "FreeBSD" 7852904Sshin 7952904Sshin/* 80157209Sdwmalone * IPv6 port allocation rules should mirror the IPv4 rules and are controlled 81218909Sbrucec * by the net.inet.ip.portrange sysctl tree. The following defines exist 82157209Sdwmalone * for compatibility with userland applications that need them. 8352904Sshin */ 8497181Smike#if __BSD_VISIBLE 8552904Sshin#define IPV6PORT_RESERVED 1024 8652904Sshin#define IPV6PORT_ANONMIN 49152 8752904Sshin#define IPV6PORT_ANONMAX 65535 8852904Sshin#define IPV6PORT_RESERVEDMIN 600 8952904Sshin#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) 9097181Smike#endif 9152904Sshin 9252904Sshin/* 9352904Sshin * IPv6 address 9452904Sshin */ 9552904Sshinstruct in6_addr { 9652904Sshin union { 9797181Smike uint8_t __u6_addr8[16]; 9897181Smike uint16_t __u6_addr16[8]; 9997181Smike uint32_t __u6_addr32[4]; 10052904Sshin } __u6_addr; /* 128-bit IP6 address */ 10152904Sshin}; 10252904Sshin 10362587Sitojun#define s6_addr __u6_addr.__u6_addr8 10495023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 10562587Sitojun#define s6_addr8 __u6_addr.__u6_addr8 10662587Sitojun#define s6_addr16 __u6_addr.__u6_addr16 10762587Sitojun#define s6_addr32 __u6_addr.__u6_addr32 10852904Sshin#endif 10952904Sshin 11062587Sitojun#define INET6_ADDRSTRLEN 46 11152904Sshin 11252904Sshin/* 11397181Smike * XXX missing POSIX.1-2001 macro IPPROTO_IPV6. 11497181Smike */ 11597181Smike 11697181Smike/* 11752904Sshin * Socket address for IPv6 11852904Sshin */ 11997181Smike#if __BSD_VISIBLE 12062587Sitojun#define SIN6_LEN 12152904Sshin#endif 12297181Smike 12352904Sshinstruct sockaddr_in6 { 124100503Sume uint8_t sin6_len; /* length of this struct */ 12597181Smike sa_family_t sin6_family; /* AF_INET6 */ 12697181Smike in_port_t sin6_port; /* Transport layer port # */ 12797181Smike uint32_t sin6_flowinfo; /* IP6 flow information */ 12862587Sitojun struct in6_addr sin6_addr; /* IP6 address */ 12997181Smike uint32_t sin6_scope_id; /* scope zone index */ 13052904Sshin}; 13152904Sshin 13252904Sshin/* 13352904Sshin * Local definition for masks 13452904Sshin */ 13595023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 13662587Sitojun#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 13762587Sitojun#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 13852904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 13962587Sitojun#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 14052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 14162587Sitojun#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 14252904Sshin 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 14362587Sitojun#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 14452904Sshin 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 14552904Sshin#endif 14652904Sshin 14752904Sshin#ifdef _KERNEL 14878064Sumeextern const struct sockaddr_in6 sa6_any; 14978064Sume 15052904Sshinextern const struct in6_addr in6mask0; 15152904Sshinextern const struct in6_addr in6mask32; 15252904Sshinextern const struct in6_addr in6mask64; 15352904Sshinextern const struct in6_addr in6mask96; 15452904Sshinextern const struct in6_addr in6mask128; 15552904Sshin#endif /* _KERNEL */ 15652904Sshin 15752904Sshin/* 15852904Sshin * Macros started with IPV6_ADDR is KAME local 15952904Sshin */ 16095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 16197181Smike#if _BYTE_ORDER == _BIG_ENDIAN 16262587Sitojun#define IPV6_ADDR_INT32_ONE 1 16362587Sitojun#define IPV6_ADDR_INT32_TWO 2 16462587Sitojun#define IPV6_ADDR_INT32_MNL 0xff010000 16562587Sitojun#define IPV6_ADDR_INT32_MLL 0xff020000 16662587Sitojun#define IPV6_ADDR_INT32_SMP 0x0000ffff 16762587Sitojun#define IPV6_ADDR_INT16_ULL 0xfe80 16862587Sitojun#define IPV6_ADDR_INT16_USL 0xfec0 16962587Sitojun#define IPV6_ADDR_INT16_MLL 0xff02 17097181Smike#elif _BYTE_ORDER == _LITTLE_ENDIAN 17162587Sitojun#define IPV6_ADDR_INT32_ONE 0x01000000 17262587Sitojun#define IPV6_ADDR_INT32_TWO 0x02000000 17362587Sitojun#define IPV6_ADDR_INT32_MNL 0x000001ff 17462587Sitojun#define IPV6_ADDR_INT32_MLL 0x000002ff 17562587Sitojun#define IPV6_ADDR_INT32_SMP 0xffff0000 17662587Sitojun#define IPV6_ADDR_INT16_ULL 0x80fe 17762587Sitojun#define IPV6_ADDR_INT16_USL 0xc0fe 17862587Sitojun#define IPV6_ADDR_INT16_MLL 0x02ff 17952904Sshin#endif 18052904Sshin#endif 18152904Sshin 18252904Sshin/* 18352904Sshin * Definition of some useful macros to handle IP6 addresses 18452904Sshin */ 18597181Smike#if __BSD_VISIBLE 18662587Sitojun#define IN6ADDR_ANY_INIT \ 18752904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 18852904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 18962587Sitojun#define IN6ADDR_LOOPBACK_INIT \ 19052904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 19152904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 19262587Sitojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 19352904Sshin {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 19452904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 195121315Sume#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ 196121315Sume {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 197121315Sume 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 19862587Sitojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 19952904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 20052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 20162587Sitojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 20252904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 20352904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 204191662Sbms#define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \ 205191662Sbms {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 206191662Sbms 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}} 20797181Smike#endif 20852904Sshin 20952904Sshinextern const struct in6_addr in6addr_any; 21052904Sshinextern const struct in6_addr in6addr_loopback; 21197181Smike#if __BSD_VISIBLE 21252904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 21352904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 21452904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 215191662Sbmsextern const struct in6_addr in6addr_linklocal_allv2routers; 21697181Smike#endif 21752904Sshin 21852904Sshin/* 21952904Sshin * Equality 22053877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 22153877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 22253877Sitojun * in ANSI standard. 22352904Sshin */ 22453877Sitojun#ifdef _KERNEL 22562587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 22662587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 22753877Sitojun#else 22897181Smike#if __BSD_VISIBLE 22962587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 23062587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 23153877Sitojun#endif 23297181Smike#endif 23352904Sshin 23452904Sshin/* 23552904Sshin * Unspecified 23652904Sshin */ 23762587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 23878064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 23978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 24078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 24178064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 24252904Sshin 24352904Sshin/* 24452904Sshin * Loopback 24552904Sshin */ 24662587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 24778064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 24878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 24978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 25078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 25152904Sshin 25252904Sshin/* 25352904Sshin * IPv4 compatible 25452904Sshin */ 25562587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 25678064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 25778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 25878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 25978064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 26078064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 26152904Sshin 26252904Sshin/* 26352904Sshin * Mapped 26452904Sshin */ 26562587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 26678064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 26878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 26952904Sshin 27052904Sshin/* 27152904Sshin * KAME Scope Values 27252904Sshin */ 27352904Sshin 27495023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 27562587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 276121315Sume#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 27762587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 27862587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 27962587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 28062587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 28152904Sshin#else 28262587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 283121315Sume#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 28462587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 28562587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 28662587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 28762587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 28852904Sshin#endif 28952904Sshin 29052904Sshin/* 29152904Sshin * Unicast Scope 29252904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 29352904Sshin */ 29462587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 29552904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 29662587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 29752904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 29852904Sshin 29952904Sshin/* 30052904Sshin * Multicast 30152904Sshin */ 30252904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 30352904Sshin 30495023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 30562587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 30652904Sshin#else 30762587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 30852904Sshin#endif 30952904Sshin 31052904Sshin/* 31152904Sshin * Multicast Scope 31252904Sshin */ 31395023Ssuz#ifdef _KERNEL /* refers nonstandard items */ 31462587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 31552904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 31652904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 317121315Sume#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 318121315Sume (IN6_IS_ADDR_MULTICAST(a) && \ 319121315Sume (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) 32062587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 32152904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 32252904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 32362587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 324171260Sdelphij (IN6_IS_ADDR_MULTICAST(a) && \ 32552904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 32662587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 32752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 32852904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 32962587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 33052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33152904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 33252904Sshin#else 33362587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 33452904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33552904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 33662587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 33752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33852904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 33962587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 340171260Sdelphij (IN6_IS_ADDR_MULTICAST(a) && \ 34152904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 34262587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 34352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34452904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 34562587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 34652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 34852904Sshin#endif 34952904Sshin 35095023Ssuz#ifdef _KERNEL /* nonstandard */ 35178064Sume/* 35252904Sshin * KAME Scope 35352904Sshin */ 35462587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 35552904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 35652904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 357171173Smlaier#define IN6_IS_SCOPE_EMBED(a) \ 358171173Smlaier ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 359171260Sdelphij (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \ 360171173Smlaier (IN6_IS_ADDR_MC_INTFACELOCAL(a))) 361171260Sdelphij 36278064Sume#define IFA6_IS_DEPRECATED(a) \ 363151539Ssuz ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ 364151539Ssuz (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ 365151539Ssuz (a)->ia6_lifetime.ia6t_pltime) 36678064Sume#define IFA6_IS_INVALID(a) \ 367151539Ssuz ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ 368151539Ssuz (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ 369151539Ssuz (a)->ia6_lifetime.ia6t_vltime) 37078064Sume#endif /* _KERNEL */ 37178064Sume 37252904Sshin/* 37352904Sshin * IP6 route structure 37452904Sshin */ 37597181Smike#if __BSD_VISIBLE 37652904Sshinstruct route_in6 { 37752904Sshin struct rtentry *ro_rt; 378191117Skmacy struct llentry *ro_lle; 37952904Sshin struct sockaddr_in6 ro_dst; 38052904Sshin}; 38152904Sshin#endif 38252904Sshin 38352904Sshin/* 38452904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 38552904Sshin * First word of comment is data type; bool is stored in int. 38652904Sshin */ 38752904Sshin/* no hdrincl */ 38862587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 38962587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 39062587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 39162587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 39262587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 39362587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 39462587Sitojun#endif 39562587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 396121472Sume#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 397121472Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 398121472Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 399121472Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 400221009Sticso#define IPV6_JOIN_GROUP 12 /* ipv6_mreq; join a group membership */ 401221009Sticso#define IPV6_LEAVE_GROUP 13 /* ipv6_mreq; leave a group membership */ 40262587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 40362587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 40478064Sume/* RFC2292 options */ 405121472Sume#ifdef _KERNEL 406121472Sume#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 407121472Sume#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 408121472Sume#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 409121472Sume#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 410121472Sume#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */ 411121472Sume#define IPV6_2292RTHDR 24 /* bool; routing header */ 412121472Sume#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 413121472Sume#endif 41478064Sume 41562587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 416121472Sume#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 41778064Sume#ifndef _KERNEL 41878064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 41978064Sume#endif 42052904Sshin 421171496Sbz#if 1 /* IPSEC */ 42262587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 423171167Sgnn#endif /* IPSEC */ 424171133Sgnn 42562587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 42652904Sshin 42795023Ssuz#if 1 /* IPV6FIREWALL */ 42862587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 42962587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 43062587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 43162587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 43262587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 43378064Sume#endif 43478064Sume 435148169Sume/* new socket options introduced in RFC3542 */ 436121472Sume#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 437121472Sume 438121472Sume#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 439121472Sume#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 440121472Sume#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 441121472Sume#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 442121472Sume#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 443121472Sume#ifdef _KERNEL 444121472Sume#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 445121472Sume#endif 446121472Sume 447121472Sume#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 448121472Sume#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 449121472Sume 450121472Sume#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 451121472Sume 4 bytes int; MTU notification (cmsg) */ 452121472Sume#if 0 /*obsoleted during 2292bis -> 3542*/ 453121472Sume#define IPV6_REACHCONF 45 /* no data; ND reachability confirm 454121472Sume (cmsg only/not in of RFC3542) */ 455121472Sume#endif 456121472Sume 457148169Sume/* more new socket options introduced in RFC3542 */ 458121472Sume#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 459121472Sume#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 460121472Sume#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 461121472Sume#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 462121472Sume#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 463121472Sume#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 464121472Sume#if 0 465121472Sume#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */ 466148169Sume /* obsoleted by RFC3542 */ 467121472Sume#endif 468121472Sume 469121472Sume#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 470121472Sume 471121472Sume#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 472121472Sume 473121472Sume#define IPV6_TCLASS 61 /* int; send traffic class value */ 474121472Sume#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 475121472Sume 476121472Sume#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as 477121472Sume * the source address. 478121472Sume */ 479121472Sume 480193217Spjd#define IPV6_BINDANY 64 /* bool: allow bind to any address */ 481193217Spjd 482170613Sbms/* 483170613Sbms * The following option is private; do not use it from user applications. 484170613Sbms * It is deliberately defined to the same value as IP_MSFILTER. 485170613Sbms */ 486170613Sbms#define IPV6_MSFILTER 74 /* struct __msfilterreq; 487170613Sbms * set/get multicast source filter list. 488170613Sbms */ 489170613Sbms 49065124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 49152904Sshin 49262587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 49362587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 49462587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 49552904Sshin 49652904Sshin/* 49752904Sshin * Defaults and limits for options 49852904Sshin */ 49995023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 50095023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 50152904Sshin 50252904Sshin/* 503191662Sbms * The im6o_membership vector for each socket is now dynamically allocated at 504191662Sbms * run-time, bounded by USHRT_MAX, and is reallocated when needed, sized 505191662Sbms * according to a power-of-two increment. 506191662Sbms */ 507191662Sbms#define IPV6_MIN_MEMBERSHIPS 31 508191662Sbms#define IPV6_MAX_MEMBERSHIPS 4095 509191662Sbms 510191662Sbms/* 511191662Sbms * Default resource limits for IPv6 multicast source filtering. 512191662Sbms * These may be modified by sysctl. 513191662Sbms */ 514191662Sbms#define IPV6_MAX_GROUP_SRC_FILTER 512 /* sources per group */ 515191662Sbms#define IPV6_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */ 516191662Sbms 517191662Sbms/* 51852904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 51952904Sshin */ 52052904Sshinstruct ipv6_mreq { 52162587Sitojun struct in6_addr ipv6mr_multiaddr; 52262587Sitojun unsigned int ipv6mr_interface; 52352904Sshin}; 52452904Sshin 52552904Sshin/* 52652904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 52752904Sshin */ 52852904Sshinstruct in6_pktinfo { 52962587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 53062587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 53152904Sshin}; 53252904Sshin 53352904Sshin/* 534121472Sume * Control structure for IPV6_RECVPATHMTU socket option. 535121472Sume */ 536121472Sumestruct ip6_mtuinfo { 537121472Sume struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 538121569Sume uint32_t ip6m_mtu; 539121472Sume}; 540121472Sume 541121472Sume/* 54252904Sshin * Argument for IPV6_PORTRANGE: 54352904Sshin * - which range to search when port is unspecified at bind() or connect() 54452904Sshin */ 54552904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 54652904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 54752904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 54852904Sshin 549121472Sume#if __BSD_VISIBLE 55052904Sshin/* 55152904Sshin * Definitions for inet6 sysctl operations. 55252904Sshin * 55352904Sshin * Third level is protocol number. 55452904Sshin * Fourth level is desired variable within that protocol. 55552904Sshin */ 55662587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 55752904Sshin 55852904Sshin/* 55952904Sshin * Names for IP sysctl objects 56052904Sshin */ 56162587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 56262587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 56362587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 56452904Sshin#ifdef notyet 56562587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 56652904Sshin#endif 56762587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 56862587Sitojun#define IPV6CTL_STATS 6 /* stats */ 56962587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 57062587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 57162587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 57262587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 57362587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 57462587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 57562587Sitojun#define IPV6CTL_KEEPFAITH 13 57662587Sitojun#define IPV6CTL_LOG_INTERVAL 14 57762587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 57862587Sitojun#define IPV6CTL_DAD_COUNT 16 57962587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 58062587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 58162587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 58262587Sitojun#define IPV6CTL_KAME_VERSION 20 58362587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 58462587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 58595023Ssuz#if 0 /* obsolete */ 58662587Sitojun#define IPV6CTL_MAPPED_ADDR 23 58762604Sitojun#endif 58878064Sume#define IPV6CTL_V6ONLY 24 58962604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 59062604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 59162604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 59278064Sume 59378064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 59478064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 59578064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 59678064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 59778064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 598122077Sume#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */ 599121742Sume#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */ 600148385Sume#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */ 601121742Sume 602121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 603149033Sume#if 0 604149033Sume#define IPV6CTL_IFQ 42 /* ip6intrq node */ 605149033Sume#define IPV6CTL_ISATAPRTR 43 /* isatap router */ 606149033Sume#endif 607149033Sume#define IPV6CTL_MCAST_PMTU 44 /* enable pMTU discovery for multicast? */ 608121345Sume 60952904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 61065124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 611148921Ssuz#define IPV6CTL_STEALTH 45 612183529Scperciva 613183529Scperciva#define ICMPV6CTL_ND6_ONLINKNSRFC4861 47 614222728Shrs#define IPV6CTL_NO_RADR 48 /* No defroute from RA */ 615222728Shrs#define IPV6CTL_NORBIT_RAIF 49 /* Disable R-bit in NA on RA 616222728Shrs * receiving IF. */ 617225521Shrs#define IPV6CTL_RFC6204W3 50 /* Accept defroute even when forwarding 618225521Shrs enabled */ 619225521Shrs#define IPV6CTL_MAXID 51 620121472Sume#endif /* __BSD_VISIBLE */ 62178064Sume 62253541Sshin/* 62353541Sshin * Redefinition of mbuf flags 62453541Sshin */ 62578064Sume#define M_AUTHIPHDR M_PROTO2 62678064Sume#define M_DECRYPTED M_PROTO3 62778064Sume#define M_LOOP M_PROTO4 62878064Sume#define M_AUTHIPDGM M_PROTO5 629192923Sbms#define M_RTALERT_MLD M_PROTO6 63053541Sshin 63152904Sshin#ifdef _KERNEL 63278064Sumestruct cmsghdr; 63352904Sshin 63462587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 63552904Sshinint in6_localaddr __P((struct in6_addr *)); 636225043Sbzint in6_localip(struct in6_addr *); 63752904Sshinint in6_addrscope __P((struct in6_addr *)); 63852904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 63978064Sumeextern void in6_if_up __P((struct ifnet *)); 64078064Sumestruct sockaddr; 64192700Sdarrenrextern u_char ip6_protox[]; 64252904Sshin 64352904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 64452904Sshin struct sockaddr_in6 *sin6)); 64552904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 64652904Sshin struct sockaddr_in6 *sin6)); 64752904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 64852904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 649121742Sumeextern void addrsel_policy_init __P((void)); 65052904Sshin 65178064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 65278064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 65378064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 65483934Sbrooks 65583934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 65652904Sshin#endif /* _KERNEL */ 65752904Sshin 658102227Smike#ifndef _SIZE_T_DECLARED 659102227Smiketypedef __size_t size_t; 660102227Smike#define _SIZE_T_DECLARED 66197181Smike#endif 66297181Smike 663121498Sume#ifndef _SOCKLEN_T_DECLARED 664121498Sumetypedef __socklen_t socklen_t; 665121498Sume#define _SOCKLEN_T_DECLARED 666121498Sume#endif 667121498Sume 668121472Sume#if __BSD_VISIBLE 669121472Sume 67052904Sshin__BEGIN_DECLS 67152904Sshinstruct cmsghdr; 67252904Sshin 67378064Sumeextern int inet6_option_space __P((int)); 67478064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 67597181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 67678064Sume int, int)); 677121499Sumeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 678121499Sumeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 679121499Sumeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 68052904Sshin 68178064Sumeextern size_t inet6_rthdr_space __P((int, int)); 68278064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 68378064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 684121472Sume unsigned int)); 68578064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 68678064Sume#if 0 /* not implemented yet */ 68778064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 68878064Sume#endif 68978064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 69078064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 69178064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 69278064Sume 693121472Sumeextern int inet6_opt_init __P((void *, socklen_t)); 694121499Sumeextern int inet6_opt_append __P((void *, socklen_t, int, uint8_t, socklen_t, 695121499Sume uint8_t, void **)); 696121472Sumeextern int inet6_opt_finish __P((void *, socklen_t, int)); 697121472Sumeextern int inet6_opt_set_val __P((void *, int, void *, socklen_t)); 69878064Sume 699121499Sumeextern int inet6_opt_next __P((void *, socklen_t, int, uint8_t *, socklen_t *, 700121472Sume void **)); 701121499Sumeextern int inet6_opt_find __P((void *, socklen_t, int, uint8_t, socklen_t *, 702121472Sume void **)); 703121472Sumeextern int inet6_opt_get_val __P((void *, int, void *, socklen_t)); 704121472Sumeextern socklen_t inet6_rth_space __P((int, int)); 705121472Sumeextern void *inet6_rth_init __P((void *, socklen_t, int, int)); 70678064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 70778064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 70878064Sumeextern int inet6_rth_segments __P((const void *)); 70978064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 71052904Sshin__END_DECLS 71152904Sshin 71297181Smike#endif /* __BSD_VISIBLE */ 71397181Smike 71452904Sshin#endif /* !_NETINET6_IN6_H_ */ 715