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$ 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) \ 238230584Sglebius ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 239230584Sglebius (a)->__u6_addr.__u6_addr32[1] == 0 && \ 240230584Sglebius (a)->__u6_addr.__u6_addr32[2] == 0 && \ 241230584Sglebius (a)->__u6_addr.__u6_addr32[3] == 0) 24252904Sshin 24352904Sshin/* 24452904Sshin * Loopback 24552904Sshin */ 24662587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 247230584Sglebius ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 248230584Sglebius (a)->__u6_addr.__u6_addr32[1] == 0 && \ 249230584Sglebius (a)->__u6_addr.__u6_addr32[2] == 0 && \ 250230584Sglebius (a)->__u6_addr.__u6_addr32[3] == ntohl(1)) 25152904Sshin 25252904Sshin/* 25352904Sshin * IPv4 compatible 25452904Sshin */ 25562587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 256230584Sglebius ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 257230584Sglebius (a)->__u6_addr.__u6_addr32[1] == 0 && \ 258230584Sglebius (a)->__u6_addr.__u6_addr32[2] == 0 && \ 259230584Sglebius (a)->__u6_addr.__u6_addr32[3] != 0 && \ 260230584Sglebius (a)->__u6_addr.__u6_addr32[3] != ntohl(1)) 26152904Sshin 26252904Sshin/* 26352904Sshin * Mapped 26452904Sshin */ 26562587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 266230584Sglebius ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 267230584Sglebius (a)->__u6_addr.__u6_addr32[1] == 0 && \ 268230584Sglebius (a)->__u6_addr.__u6_addr32[2] == 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 && \ 364253970Shrs (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \ 365151539Ssuz (a)->ia6_lifetime.ia6t_pltime) 36678064Sume#define IFA6_IS_INVALID(a) \ 367151539Ssuz ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ 368253970Shrs (u_int32_t)((time_uptime - (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; 379225698Skmacy struct in6_addr *ro_ia6; 380225698Skmacy int ro_flags; 38152904Sshin struct sockaddr_in6 ro_dst; 38252904Sshin}; 38352904Sshin#endif 38452904Sshin 38552904Sshin/* 38652904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 38752904Sshin * First word of comment is data type; bool is stored in int. 38852904Sshin */ 38952904Sshin/* no hdrincl */ 39062587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 39162587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 39262587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 39362587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 39462587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 39562587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 39662587Sitojun#endif 39762587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 398121472Sume#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 399121472Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 400121472Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 401121472Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 402221009Sticso#define IPV6_JOIN_GROUP 12 /* ipv6_mreq; join a group membership */ 403221009Sticso#define IPV6_LEAVE_GROUP 13 /* ipv6_mreq; leave a group membership */ 40462587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 40562587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 40678064Sume/* RFC2292 options */ 407121472Sume#ifdef _KERNEL 408121472Sume#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 409121472Sume#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 410121472Sume#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 411121472Sume#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 412121472Sume#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */ 413121472Sume#define IPV6_2292RTHDR 24 /* bool; routing header */ 414121472Sume#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 415121472Sume#endif 41678064Sume 41762587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 418121472Sume#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 41978064Sume#ifndef _KERNEL 42078064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 42178064Sume#endif 42252904Sshin 423171496Sbz#if 1 /* IPSEC */ 42462587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 425171167Sgnn#endif /* IPSEC */ 426171133Sgnn 42762587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 42852904Sshin 42995023Ssuz#if 1 /* IPV6FIREWALL */ 43062587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 43162587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 43262587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 43362587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 43462587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 43578064Sume#endif 43678064Sume 437148169Sume/* new socket options introduced in RFC3542 */ 438121472Sume#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 439121472Sume 440121472Sume#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 441121472Sume#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 442121472Sume#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 443121472Sume#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 444121472Sume#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 445121472Sume#ifdef _KERNEL 446121472Sume#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 447121472Sume#endif 448121472Sume 449121472Sume#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 450121472Sume#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 451121472Sume 452121472Sume#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 453121472Sume 4 bytes int; MTU notification (cmsg) */ 454121472Sume#if 0 /*obsoleted during 2292bis -> 3542*/ 455121472Sume#define IPV6_REACHCONF 45 /* no data; ND reachability confirm 456121472Sume (cmsg only/not in of RFC3542) */ 457121472Sume#endif 458121472Sume 459148169Sume/* more new socket options introduced in RFC3542 */ 460121472Sume#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 461121472Sume#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 462121472Sume#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 463121472Sume#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 464121472Sume#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 465121472Sume#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 466121472Sume#if 0 467121472Sume#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */ 468148169Sume /* obsoleted by RFC3542 */ 469121472Sume#endif 470121472Sume 471121472Sume#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 472121472Sume 473121472Sume#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 474121472Sume 475121472Sume#define IPV6_TCLASS 61 /* int; send traffic class value */ 476121472Sume#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 477121472Sume 478121472Sume#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as 479121472Sume * the source address. 480121472Sume */ 481121472Sume 482193217Spjd#define IPV6_BINDANY 64 /* bool: allow bind to any address */ 483193217Spjd 484170613Sbms/* 485170613Sbms * The following option is private; do not use it from user applications. 486170613Sbms * It is deliberately defined to the same value as IP_MSFILTER. 487170613Sbms */ 488170613Sbms#define IPV6_MSFILTER 74 /* struct __msfilterreq; 489170613Sbms * set/get multicast source filter list. 490170613Sbms */ 491170613Sbms 49265124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 49352904Sshin 49462587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 49562587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 49662587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 49752904Sshin 49852904Sshin/* 49952904Sshin * Defaults and limits for options 50052904Sshin */ 50195023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 50295023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 50352904Sshin 50452904Sshin/* 505191662Sbms * The im6o_membership vector for each socket is now dynamically allocated at 506191662Sbms * run-time, bounded by USHRT_MAX, and is reallocated when needed, sized 507191662Sbms * according to a power-of-two increment. 508191662Sbms */ 509191662Sbms#define IPV6_MIN_MEMBERSHIPS 31 510191662Sbms#define IPV6_MAX_MEMBERSHIPS 4095 511191662Sbms 512191662Sbms/* 513191662Sbms * Default resource limits for IPv6 multicast source filtering. 514191662Sbms * These may be modified by sysctl. 515191662Sbms */ 516191662Sbms#define IPV6_MAX_GROUP_SRC_FILTER 512 /* sources per group */ 517191662Sbms#define IPV6_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */ 518191662Sbms 519191662Sbms/* 52052904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 52152904Sshin */ 52252904Sshinstruct ipv6_mreq { 52362587Sitojun struct in6_addr ipv6mr_multiaddr; 52462587Sitojun unsigned int ipv6mr_interface; 52552904Sshin}; 52652904Sshin 52752904Sshin/* 52852904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 52952904Sshin */ 53052904Sshinstruct in6_pktinfo { 53162587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 53262587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 53352904Sshin}; 53452904Sshin 53552904Sshin/* 536121472Sume * Control structure for IPV6_RECVPATHMTU socket option. 537121472Sume */ 538121472Sumestruct ip6_mtuinfo { 539121472Sume struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 540121569Sume uint32_t ip6m_mtu; 541121472Sume}; 542121472Sume 543121472Sume/* 54452904Sshin * Argument for IPV6_PORTRANGE: 54552904Sshin * - which range to search when port is unspecified at bind() or connect() 54652904Sshin */ 54752904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 54852904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 54952904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 55052904Sshin 551121472Sume#if __BSD_VISIBLE 55252904Sshin/* 55352904Sshin * Definitions for inet6 sysctl operations. 55452904Sshin * 55552904Sshin * Third level is protocol number. 55652904Sshin * Fourth level is desired variable within that protocol. 55752904Sshin */ 55862587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 55952904Sshin 56052904Sshin/* 56152904Sshin * Names for IP sysctl objects 56252904Sshin */ 56362587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 56462587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 56562587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 56652904Sshin#ifdef notyet 56762587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 56852904Sshin#endif 56962587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 57062587Sitojun#define IPV6CTL_STATS 6 /* stats */ 57162587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 57262587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 57362587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 57462587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 57562587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 57662587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 57762587Sitojun#define IPV6CTL_KEEPFAITH 13 57862587Sitojun#define IPV6CTL_LOG_INTERVAL 14 57962587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 58062587Sitojun#define IPV6CTL_DAD_COUNT 16 58162587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 58262587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 58362587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 58462587Sitojun#define IPV6CTL_KAME_VERSION 20 58562587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 58662587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 58795023Ssuz#if 0 /* obsolete */ 58862587Sitojun#define IPV6CTL_MAPPED_ADDR 23 58962604Sitojun#endif 59078064Sume#define IPV6CTL_V6ONLY 24 59162604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 59262604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 59362604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 59478064Sume 59578064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 59678064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 59778064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 59878064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 59978064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 600122077Sume#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */ 601121742Sume#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */ 602148385Sume#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */ 603121742Sume 604121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 605149033Sume#if 0 606149033Sume#define IPV6CTL_IFQ 42 /* ip6intrq node */ 607149033Sume#define IPV6CTL_ISATAPRTR 43 /* isatap router */ 608149033Sume#endif 609149033Sume#define IPV6CTL_MCAST_PMTU 44 /* enable pMTU discovery for multicast? */ 610121345Sume 61152904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 61265124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 613148921Ssuz#define IPV6CTL_STEALTH 45 614183529Scperciva 615183529Scperciva#define ICMPV6CTL_ND6_ONLINKNSRFC4861 47 616222728Shrs#define IPV6CTL_NO_RADR 48 /* No defroute from RA */ 617222728Shrs#define IPV6CTL_NORBIT_RAIF 49 /* Disable R-bit in NA on RA 618222728Shrs * receiving IF. */ 619225521Shrs#define IPV6CTL_RFC6204W3 50 /* Accept defroute even when forwarding 620225521Shrs enabled */ 621225521Shrs#define IPV6CTL_MAXID 51 622121472Sume#endif /* __BSD_VISIBLE */ 62378064Sume 62453541Sshin/* 62553541Sshin * Redefinition of mbuf flags 62653541Sshin */ 62778064Sume#define M_AUTHIPHDR M_PROTO2 62878064Sume#define M_DECRYPTED M_PROTO3 62978064Sume#define M_LOOP M_PROTO4 63078064Sume#define M_AUTHIPDGM M_PROTO5 631192923Sbms#define M_RTALERT_MLD M_PROTO6 63253541Sshin 63352904Sshin#ifdef _KERNEL 63478064Sumestruct cmsghdr; 635235924Sbzstruct ip6_hdr; 63652904Sshin 637235924Sbzint in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t); 638241916Sdelphijint in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t); 639241916Sdelphijint in6_localaddr(struct in6_addr *); 640225043Sbzint in6_localip(struct in6_addr *); 641241916Sdelphijint in6_addrscope(struct in6_addr *); 642241916Sdelphijstruct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); 643241916Sdelphijextern void in6_if_up(struct ifnet *); 64478064Sumestruct sockaddr; 64592700Sdarrenrextern u_char ip6_protox[]; 64652904Sshin 647241916Sdelphijvoid in6_sin6_2_sin(struct sockaddr_in *sin, 648241916Sdelphij struct sockaddr_in6 *sin6); 649241916Sdelphijvoid in6_sin_2_v4mapsin6(struct sockaddr_in *sin, 650241916Sdelphij struct sockaddr_in6 *sin6); 651241916Sdelphijvoid in6_sin6_2_sin_in_sock(struct sockaddr *nam); 652241916Sdelphijvoid in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam); 653241916Sdelphijextern void addrsel_policy_init(void); 65452904Sshin 65578064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 65678064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 65778064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 65883934Sbrooks 65983934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 66052904Sshin#endif /* _KERNEL */ 66152904Sshin 662102227Smike#ifndef _SIZE_T_DECLARED 663102227Smiketypedef __size_t size_t; 664102227Smike#define _SIZE_T_DECLARED 66597181Smike#endif 66697181Smike 667121498Sume#ifndef _SOCKLEN_T_DECLARED 668121498Sumetypedef __socklen_t socklen_t; 669121498Sume#define _SOCKLEN_T_DECLARED 670121498Sume#endif 671121498Sume 672121472Sume#if __BSD_VISIBLE 673121472Sume 67452904Sshin__BEGIN_DECLS 67552904Sshinstruct cmsghdr; 67652904Sshin 677241916Sdelphijextern int inet6_option_space(int); 678241916Sdelphijextern int inet6_option_init(void *, struct cmsghdr **, int); 679241916Sdelphijextern int inet6_option_append(struct cmsghdr *, const uint8_t *, 680241916Sdelphij int, int); 681241916Sdelphijextern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int); 682241916Sdelphijextern int inet6_option_next(const struct cmsghdr *, uint8_t **); 683241916Sdelphijextern int inet6_option_find(const struct cmsghdr *, uint8_t **, int); 68452904Sshin 685241916Sdelphijextern size_t inet6_rthdr_space(int, int); 686241916Sdelphijextern struct cmsghdr *inet6_rthdr_init(void *, int); 687241916Sdelphijextern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *, 688241916Sdelphij unsigned int); 689241916Sdelphijextern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int); 69078064Sume#if 0 /* not implemented yet */ 691241916Sdelphijextern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *); 69278064Sume#endif 693241916Sdelphijextern int inet6_rthdr_segments(const struct cmsghdr *); 694241916Sdelphijextern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int); 695241916Sdelphijextern int inet6_rthdr_getflags(const struct cmsghdr *, int); 69678064Sume 697241916Sdelphijextern int inet6_opt_init(void *, socklen_t); 698241916Sdelphijextern int inet6_opt_append(void *, socklen_t, int, uint8_t, socklen_t, 699241916Sdelphij uint8_t, void **); 700241916Sdelphijextern int inet6_opt_finish(void *, socklen_t, int); 701241916Sdelphijextern int inet6_opt_set_val(void *, int, void *, socklen_t); 70278064Sume 703241916Sdelphijextern int inet6_opt_next(void *, socklen_t, int, uint8_t *, socklen_t *, 704241916Sdelphij void **); 705241916Sdelphijextern int inet6_opt_find(void *, socklen_t, int, uint8_t, socklen_t *, 706241916Sdelphij void **); 707241916Sdelphijextern int inet6_opt_get_val(void *, int, void *, socklen_t); 708241916Sdelphijextern socklen_t inet6_rth_space(int, int); 709241916Sdelphijextern void *inet6_rth_init(void *, socklen_t, int, int); 710241916Sdelphijextern int inet6_rth_add(void *, const struct in6_addr *); 711241916Sdelphijextern int inet6_rth_reverse(const void *, void *); 712241916Sdelphijextern int inet6_rth_segments(const void *); 713241916Sdelphijextern struct in6_addr *inet6_rth_getaddr(const void *, int); 71452904Sshin__END_DECLS 71552904Sshin 71697181Smike#endif /* __BSD_VISIBLE */ 71797181Smike 71852904Sshin#endif /* !_NETINET6_IN6_H_ */ 719