in6.h revision 157209
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 157209 2006-03-28 12:51:22Z dwmalone $ */ 278064Sume/* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ */ 362587Sitojun 4139826Simp/*- 552904Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 652904Sshin * All rights reserved. 753541Sshin * 852904Sshin * Redistribution and use in source and binary forms, with or without 952904Sshin * modification, are permitted provided that the following conditions 1052904Sshin * are met: 1152904Sshin * 1. Redistributions of source code must retain the above copyright 1252904Sshin * notice, this list of conditions and the following disclaimer. 1352904Sshin * 2. Redistributions in binary form must reproduce the above copyright 1452904Sshin * notice, this list of conditions and the following disclaimer in the 1552904Sshin * documentation and/or other materials provided with the distribution. 1652904Sshin * 3. Neither the name of the project nor the names of its contributors 1752904Sshin * may be used to endorse or promote products derived from this software 1852904Sshin * without specific prior written permission. 1953541Sshin * 2052904Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2152904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2252904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2352904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2452904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2552904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2652904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2752904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2852904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2952904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3052904Sshin * SUCH DAMAGE. 3152904Sshin */ 3252904Sshin 33139826Simp/*- 3452904Sshin * Copyright (c) 1982, 1986, 1990, 1993 3552904Sshin * The Regents of the University of California. All rights reserved. 3652904Sshin * 3752904Sshin * Redistribution and use in source and binary forms, with or without 3852904Sshin * modification, are permitted provided that the following conditions 3952904Sshin * are met: 4052904Sshin * 1. Redistributions of source code must retain the above copyright 4152904Sshin * notice, this list of conditions and the following disclaimer. 4252904Sshin * 2. Redistributions in binary form must reproduce the above copyright 4352904Sshin * notice, this list of conditions and the following disclaimer in the 4452904Sshin * documentation and/or other materials provided with the distribution. 4552904Sshin * 4. Neither the name of the University nor the names of its contributors 4652904Sshin * may be used to endorse or promote products derived from this software 4752904Sshin * without specific prior written permission. 4852904Sshin * 4952904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5052904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5152904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5252904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5352904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5452904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5552904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5652904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5752904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5852904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5952904Sshin * SUCH DAMAGE. 6052904Sshin * 6152904Sshin * @(#)in.h 8.3 (Berkeley) 1/3/94 6252904Sshin */ 6352904Sshin 6462587Sitojun#ifndef __KAME_NETINET_IN_H_INCLUDED_ 6578064Sume#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 6657120Sshin#endif 6757120Sshin 6862587Sitojun#ifndef _NETINET6_IN6_H_ 6962587Sitojun#define _NETINET6_IN6_H_ 7062587Sitojun 7152904Sshin/* 7252904Sshin * Identification of the network protocol stack 7378064Sume * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE 7478064Sume * has the table of implementation/integration differences. 7552904Sshin */ 7662587Sitojun#define __KAME__ 77156865Ssuz#define __KAME_VERSION "FreeBSD" 7852904Sshin 7952904Sshin/* 80157209Sdwmalone * IPv6 port allocation rules should mirror the IPv4 rules and are controlled 81157209Sdwmalone * by the 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 }}} 20497181Smike#endif 20552904Sshin 20652904Sshinextern const struct in6_addr in6addr_any; 20752904Sshinextern const struct in6_addr in6addr_loopback; 20897181Smike#if __BSD_VISIBLE 20952904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 21052904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 21152904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 21297181Smike#endif 21352904Sshin 21452904Sshin/* 21552904Sshin * Equality 21653877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 21753877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 21853877Sitojun * in ANSI standard. 21952904Sshin */ 22053877Sitojun#ifdef _KERNEL 22162587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 22262587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 22353877Sitojun#else 22497181Smike#if __BSD_VISIBLE 22562587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 22662587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 22753877Sitojun#endif 22897181Smike#endif 22952904Sshin 23052904Sshin/* 23152904Sshin * Unspecified 23252904Sshin */ 23362587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 23478064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 23578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 23678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 23778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 23852904Sshin 23952904Sshin/* 24052904Sshin * Loopback 24152904Sshin */ 24262587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 24378064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 24478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 24578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 24678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 24752904Sshin 24852904Sshin/* 24952904Sshin * IPv4 compatible 25052904Sshin */ 25162587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 25278064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 25378064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 25478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 25578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 25678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 25752904Sshin 25852904Sshin/* 25952904Sshin * Mapped 26052904Sshin */ 26162587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 26278064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26378064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 26478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 26552904Sshin 26652904Sshin/* 26752904Sshin * KAME Scope Values 26852904Sshin */ 26952904Sshin 27095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 27162587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 272121315Sume#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 27362587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 27462587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 27562587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 27662587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 27752904Sshin#else 27862587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 279121315Sume#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 28062587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 28162587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 28262587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 28362587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 28452904Sshin#endif 28552904Sshin 28652904Sshin/* 28752904Sshin * Unicast Scope 28852904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 28952904Sshin */ 29062587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 29152904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 29262587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 29352904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 29452904Sshin 29552904Sshin/* 29652904Sshin * Multicast 29752904Sshin */ 29852904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 29952904Sshin 30095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 30162587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 30252904Sshin#else 30362587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 30452904Sshin#endif 30552904Sshin 30652904Sshin/* 30752904Sshin * Multicast Scope 30852904Sshin */ 30995023Ssuz#ifdef _KERNEL /* refers nonstandard items */ 31062587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 31152904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 31252904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 313121315Sume#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 314121315Sume (IN6_IS_ADDR_MULTICAST(a) && \ 315121315Sume (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) 31662587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 31752904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 31852904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 31962587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 32052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 32152904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 32262587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 32352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 32452904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 32562587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 32652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 32752904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 32852904Sshin#else 32962587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 33052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33152904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 33262587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 33352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33452904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 33562587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 33652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 33752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 33862587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 33952904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34052904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 34162587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 34252904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34352904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 34452904Sshin#endif 34552904Sshin 34695023Ssuz#ifdef _KERNEL /* nonstandard */ 34778064Sume/* 34852904Sshin * KAME Scope 34952904Sshin */ 35062587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 35152904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 35252904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 35352904Sshin 35478064Sume#define IFA6_IS_DEPRECATED(a) \ 355151539Ssuz ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ 356151539Ssuz (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ 357151539Ssuz (a)->ia6_lifetime.ia6t_pltime) 35878064Sume#define IFA6_IS_INVALID(a) \ 359151539Ssuz ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ 360151539Ssuz (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ 361151539Ssuz (a)->ia6_lifetime.ia6t_vltime) 36278064Sume#endif /* _KERNEL */ 36378064Sume 36452904Sshin/* 36552904Sshin * IP6 route structure 36652904Sshin */ 36797181Smike#if __BSD_VISIBLE 36852904Sshinstruct route_in6 { 36952904Sshin struct rtentry *ro_rt; 37052904Sshin struct sockaddr_in6 ro_dst; 37152904Sshin}; 37252904Sshin#endif 37352904Sshin 37452904Sshin/* 37552904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 37652904Sshin * First word of comment is data type; bool is stored in int. 37752904Sshin */ 37852904Sshin/* no hdrincl */ 37962587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 38062587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 38162587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 38262587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 38362587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 38462587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 38562587Sitojun#endif 38662587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 387121472Sume#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 388121472Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 389121472Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 390121472Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 391121472Sume#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 392121472Sume#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 39362587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 39462587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 39578064Sume/* RFC2292 options */ 396121472Sume#ifdef _KERNEL 397121472Sume#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 398121472Sume#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 399121472Sume#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 400121472Sume#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 401121472Sume#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */ 402121472Sume#define IPV6_2292RTHDR 24 /* bool; routing header */ 403121472Sume#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 404121472Sume#endif 40578064Sume 40662587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 407121472Sume#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 40878064Sume#ifndef _KERNEL 40978064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 41078064Sume#endif 41152904Sshin 41295023Ssuz#if 1 /* IPSEC */ 41362587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 41478064Sume#endif 41562587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 41652904Sshin 41795023Ssuz#if 1 /* IPV6FIREWALL */ 41862587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 41962587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 42062587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 42162587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 42262587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 42378064Sume#endif 42478064Sume 425148169Sume/* new socket options introduced in RFC3542 */ 426121472Sume#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 427121472Sume 428121472Sume#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 429121472Sume#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 430121472Sume#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 431121472Sume#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 432121472Sume#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 433121472Sume#ifdef _KERNEL 434121472Sume#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 435121472Sume#endif 436121472Sume 437121472Sume#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 438121472Sume#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 439121472Sume 440121472Sume#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 441121472Sume 4 bytes int; MTU notification (cmsg) */ 442121472Sume#if 0 /*obsoleted during 2292bis -> 3542*/ 443121472Sume#define IPV6_REACHCONF 45 /* no data; ND reachability confirm 444121472Sume (cmsg only/not in of RFC3542) */ 445121472Sume#endif 446121472Sume 447148169Sume/* more new socket options introduced in RFC3542 */ 448121472Sume#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 449121472Sume#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 450121472Sume#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 451121472Sume#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 452121472Sume#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 453121472Sume#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 454121472Sume#if 0 455121472Sume#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */ 456148169Sume /* obsoleted by RFC3542 */ 457121472Sume#endif 458121472Sume 459121472Sume#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 460121472Sume 461121472Sume#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 462121472Sume 463121472Sume#define IPV6_TCLASS 61 /* int; send traffic class value */ 464121472Sume#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 465121472Sume 466121472Sume#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as 467121472Sume * the source address. 468121472Sume */ 469121472Sume 47065124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 47152904Sshin 47262587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 47362587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 47462587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 47552904Sshin 47652904Sshin/* 47752904Sshin * Defaults and limits for options 47852904Sshin */ 47995023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 48095023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 48152904Sshin 48252904Sshin/* 48352904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 48452904Sshin */ 48552904Sshinstruct ipv6_mreq { 48662587Sitojun struct in6_addr ipv6mr_multiaddr; 48762587Sitojun unsigned int ipv6mr_interface; 48852904Sshin}; 48952904Sshin 49052904Sshin/* 49152904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 49252904Sshin */ 49352904Sshinstruct in6_pktinfo { 49462587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 49562587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 49652904Sshin}; 49752904Sshin 49852904Sshin/* 499121472Sume * Control structure for IPV6_RECVPATHMTU socket option. 500121472Sume */ 501121472Sumestruct ip6_mtuinfo { 502121472Sume struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 503121569Sume uint32_t ip6m_mtu; 504121472Sume}; 505121472Sume 506121472Sume/* 50752904Sshin * Argument for IPV6_PORTRANGE: 50852904Sshin * - which range to search when port is unspecified at bind() or connect() 50952904Sshin */ 51052904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 51152904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 51252904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 51352904Sshin 514121472Sume#if __BSD_VISIBLE 51552904Sshin/* 51652904Sshin * Definitions for inet6 sysctl operations. 51752904Sshin * 51852904Sshin * Third level is protocol number. 51952904Sshin * Fourth level is desired variable within that protocol. 52052904Sshin */ 52162587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 52252904Sshin 52352904Sshin/* 52452904Sshin * Names for IP sysctl objects 52552904Sshin */ 52662587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 52762587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 52862587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 52952904Sshin#ifdef notyet 53062587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 53152904Sshin#endif 53262587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 53362587Sitojun#define IPV6CTL_STATS 6 /* stats */ 53462587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 53562587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 53662587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 53762587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 53862587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 53962587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 54062587Sitojun#define IPV6CTL_KEEPFAITH 13 54162587Sitojun#define IPV6CTL_LOG_INTERVAL 14 54262587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 54362587Sitojun#define IPV6CTL_DAD_COUNT 16 54462587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 54562587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 54662587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 54762587Sitojun#define IPV6CTL_KAME_VERSION 20 54862587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 54962587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 55095023Ssuz#if 0 /* obsolete */ 55162587Sitojun#define IPV6CTL_MAPPED_ADDR 23 55262604Sitojun#endif 55378064Sume#define IPV6CTL_V6ONLY 24 55462604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 55562604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 55662604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 55778064Sume 55878064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 55978064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 56078064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 56178064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 56278064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 563122077Sume#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */ 564121742Sume#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */ 565148385Sume#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */ 566121742Sume 567121345Sume#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 568149033Sume#if 0 569149033Sume#define IPV6CTL_IFQ 42 /* ip6intrq node */ 570149033Sume#define IPV6CTL_ISATAPRTR 43 /* isatap router */ 571149033Sume#endif 572149033Sume#define IPV6CTL_MCAST_PMTU 44 /* enable pMTU discovery for multicast? */ 573121345Sume 57452904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 57565124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 576148921Ssuz#define IPV6CTL_STEALTH 45 577148921Ssuz#define IPV6CTL_MAXID 46 578121472Sume#endif /* __BSD_VISIBLE */ 57978064Sume 58053541Sshin/* 58153541Sshin * Redefinition of mbuf flags 58253541Sshin */ 58378064Sume#define M_AUTHIPHDR M_PROTO2 58478064Sume#define M_DECRYPTED M_PROTO3 58578064Sume#define M_LOOP M_PROTO4 58678064Sume#define M_AUTHIPDGM M_PROTO5 58753541Sshin 58852904Sshin#ifdef _KERNEL 58978064Sumestruct cmsghdr; 59052904Sshin 59162587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 59252904Sshinint in6_localaddr __P((struct in6_addr *)); 59352904Sshinint in6_addrscope __P((struct in6_addr *)); 59452904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 59578064Sumeextern void in6_if_up __P((struct ifnet *)); 59678064Sumestruct sockaddr; 59792700Sdarrenrextern u_char ip6_protox[]; 59852904Sshin 59952904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 60052904Sshin struct sockaddr_in6 *sin6)); 60152904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 60252904Sshin struct sockaddr_in6 *sin6)); 60352904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 60452904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 605121742Sumeextern void addrsel_policy_init __P((void)); 60652904Sshin 60778064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 60878064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 60978064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 61083934Sbrooks 61183934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 61252904Sshin#endif /* _KERNEL */ 61352904Sshin 614102227Smike#ifndef _SIZE_T_DECLARED 615102227Smiketypedef __size_t size_t; 616102227Smike#define _SIZE_T_DECLARED 61797181Smike#endif 61897181Smike 619121498Sume#ifndef _SOCKLEN_T_DECLARED 620121498Sumetypedef __socklen_t socklen_t; 621121498Sume#define _SOCKLEN_T_DECLARED 622121498Sume#endif 623121498Sume 624121472Sume#if __BSD_VISIBLE 625121472Sume 62652904Sshin__BEGIN_DECLS 62752904Sshinstruct cmsghdr; 62852904Sshin 62978064Sumeextern int inet6_option_space __P((int)); 63078064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 63197181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 63278064Sume int, int)); 633121499Sumeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 634121499Sumeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 635121499Sumeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 63652904Sshin 63778064Sumeextern size_t inet6_rthdr_space __P((int, int)); 63878064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 63978064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 640121472Sume unsigned int)); 64178064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 64278064Sume#if 0 /* not implemented yet */ 64378064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 64478064Sume#endif 64578064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 64678064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 64778064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 64878064Sume 649121472Sumeextern int inet6_opt_init __P((void *, socklen_t)); 650121499Sumeextern int inet6_opt_append __P((void *, socklen_t, int, uint8_t, socklen_t, 651121499Sume uint8_t, void **)); 652121472Sumeextern int inet6_opt_finish __P((void *, socklen_t, int)); 653121472Sumeextern int inet6_opt_set_val __P((void *, int, void *, socklen_t)); 65478064Sume 655121499Sumeextern int inet6_opt_next __P((void *, socklen_t, int, uint8_t *, socklen_t *, 656121472Sume void **)); 657121499Sumeextern int inet6_opt_find __P((void *, socklen_t, int, uint8_t, socklen_t *, 658121472Sume void **)); 659121472Sumeextern int inet6_opt_get_val __P((void *, int, void *, socklen_t)); 660121472Sumeextern socklen_t inet6_rth_space __P((int, int)); 661121472Sumeextern void *inet6_rth_init __P((void *, socklen_t, int, int)); 66278064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 66378064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 66478064Sumeextern int inet6_rth_segments __P((const void *)); 66578064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 66652904Sshin__END_DECLS 66752904Sshin 66897181Smike#endif /* __BSD_VISIBLE */ 66997181Smike 67052904Sshin#endif /* !_NETINET6_IN6_H_ */ 671