in6.h revision 102227
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 102227 2002-08-21 16:20:02Z mike $ */ 278064Sume/* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ */ 362587Sitojun 452904Sshin/* 552904Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 652904Sshin * All rights reserved. 753541Sshin * 852904Sshin * Redistribution and use in source and binary forms, with or without 952904Sshin * modification, are permitted provided that the following conditions 1052904Sshin * are met: 1152904Sshin * 1. Redistributions of source code must retain the above copyright 1252904Sshin * notice, this list of conditions and the following disclaimer. 1352904Sshin * 2. Redistributions in binary form must reproduce the above copyright 1452904Sshin * notice, this list of conditions and the following disclaimer in the 1552904Sshin * documentation and/or other materials provided with the distribution. 1652904Sshin * 3. Neither the name of the project nor the names of its contributors 1752904Sshin * may be used to endorse or promote products derived from this software 1852904Sshin * without specific prior written permission. 1953541Sshin * 2052904Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2152904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2252904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2352904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2452904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2552904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2652904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2752904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2852904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2952904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3052904Sshin * SUCH DAMAGE. 3152904Sshin */ 3252904Sshin 3352904Sshin/* 3452904Sshin * Copyright (c) 1982, 1986, 1990, 1993 3552904Sshin * The Regents of the University of California. All rights reserved. 3652904Sshin * 3752904Sshin * Redistribution and use in source and binary forms, with or without 3852904Sshin * modification, are permitted provided that the following conditions 3952904Sshin * are met: 4052904Sshin * 1. Redistributions of source code must retain the above copyright 4152904Sshin * notice, this list of conditions and the following disclaimer. 4252904Sshin * 2. Redistributions in binary form must reproduce the above copyright 4352904Sshin * notice, this list of conditions and the following disclaimer in the 4452904Sshin * documentation and/or other materials provided with the distribution. 4552904Sshin * 3. All advertising materials mentioning features or use of this software 4652904Sshin * must display the following acknowledgement: 4752904Sshin * This product includes software developed by the University of 4852904Sshin * California, Berkeley and its contributors. 4952904Sshin * 4. Neither the name of the University nor the names of its contributors 5052904Sshin * may be used to endorse or promote products derived from this software 5152904Sshin * without specific prior written permission. 5252904Sshin * 5352904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5452904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5552904Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5652904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5752904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5852904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5952904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6052904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6152904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6252904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6352904Sshin * SUCH DAMAGE. 6452904Sshin * 6552904Sshin * @(#)in.h 8.3 (Berkeley) 1/3/94 6652904Sshin */ 6752904Sshin 6862587Sitojun#ifndef __KAME_NETINET_IN_H_INCLUDED_ 6978064Sume#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 7057120Sshin#endif 7157120Sshin 7262587Sitojun#ifndef _NETINET6_IN6_H_ 7362587Sitojun#define _NETINET6_IN6_H_ 7462587Sitojun 7552904Sshin/* 7652904Sshin * Identification of the network protocol stack 7778064Sume * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE 7878064Sume * has the table of implementation/integration differences. 7952904Sshin */ 8062587Sitojun#define __KAME__ 8178064Sume#define __KAME_VERSION "20010528/FreeBSD" 8252904Sshin 8352904Sshin/* 8452904Sshin * Local port number conventions: 8552904Sshin * 8652904Sshin * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), 8752904Sshin * unless a kernel is compiled with IPNOPRIVPORTS defined. 8852904Sshin * 8952904Sshin * When a user does a bind(2) or connect(2) with a port number of zero, 9052904Sshin * a non-conflicting local port address is chosen. 9152904Sshin * 9262587Sitojun * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although 9352904Sshin * that is settable by sysctl(3); net.inet.ip.anonportmin and 9452904Sshin * net.inet.ip.anonportmax respectively. 9552904Sshin * 9652904Sshin * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 9752904Sshin * default assignment range. 9852904Sshin * 9952904Sshin * The value IP_PORTRANGE_DEFAULT causes the default behavior. 10052904Sshin * 10152904Sshin * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, 10252904Sshin * and exists only for FreeBSD compatibility purposes. 10352904Sshin * 10452904Sshin * The value IP_PORTRANGE_LOW changes the range to the "low" are 10552904Sshin * that is (by convention) restricted to privileged processes. 10652904Sshin * This convention is based on "vouchsafe" principles only. 10752904Sshin * It is only secure if you trust the remote host to restrict these ports. 10852904Sshin * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. 10952904Sshin */ 11097181Smike#if __BSD_VISIBLE 11152904Sshin#define IPV6PORT_RESERVED 1024 11252904Sshin#define IPV6PORT_ANONMIN 49152 11352904Sshin#define IPV6PORT_ANONMAX 65535 11452904Sshin#define IPV6PORT_RESERVEDMIN 600 11552904Sshin#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) 11697181Smike#endif 11752904Sshin 11852904Sshin/* 11952904Sshin * IPv6 address 12052904Sshin */ 12152904Sshinstruct in6_addr { 12252904Sshin union { 12397181Smike uint8_t __u6_addr8[16]; 12497181Smike uint16_t __u6_addr16[8]; 12597181Smike uint32_t __u6_addr32[4]; 12652904Sshin } __u6_addr; /* 128-bit IP6 address */ 12752904Sshin}; 12852904Sshin 12962587Sitojun#define s6_addr __u6_addr.__u6_addr8 13095023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 13162587Sitojun#define s6_addr8 __u6_addr.__u6_addr8 13262587Sitojun#define s6_addr16 __u6_addr.__u6_addr16 13362587Sitojun#define s6_addr32 __u6_addr.__u6_addr32 13452904Sshin#endif 13552904Sshin 13662587Sitojun#define INET6_ADDRSTRLEN 46 13752904Sshin 13852904Sshin/* 13997181Smike * XXX missing POSIX.1-2001 macro IPPROTO_IPV6. 14097181Smike */ 14197181Smike 14297181Smike/* 14352904Sshin * Socket address for IPv6 14452904Sshin */ 14597181Smike#if __BSD_VISIBLE 14662587Sitojun#define SIN6_LEN 14752904Sshin#endif 14897181Smike 14952904Sshinstruct sockaddr_in6 { 150100503Sume uint8_t sin6_len; /* length of this struct */ 15197181Smike sa_family_t sin6_family; /* AF_INET6 */ 15297181Smike in_port_t sin6_port; /* Transport layer port # */ 15397181Smike uint32_t sin6_flowinfo; /* IP6 flow information */ 15462587Sitojun struct in6_addr sin6_addr; /* IP6 address */ 15597181Smike uint32_t sin6_scope_id; /* scope zone index */ 15652904Sshin}; 15752904Sshin 15852904Sshin/* 15952904Sshin * Local definition for masks 16052904Sshin */ 16195023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 16262587Sitojun#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 16362587Sitojun#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 16452904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16562587Sitojun#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16652904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16762587Sitojun#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16852904Sshin 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 16962587Sitojun#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 17052904Sshin 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 17152904Sshin#endif 17252904Sshin 17352904Sshin#ifdef _KERNEL 17478064Sumeextern const struct sockaddr_in6 sa6_any; 17578064Sume 17652904Sshinextern const struct in6_addr in6mask0; 17752904Sshinextern const struct in6_addr in6mask32; 17852904Sshinextern const struct in6_addr in6mask64; 17952904Sshinextern const struct in6_addr in6mask96; 18052904Sshinextern const struct in6_addr in6mask128; 18152904Sshin#endif /* _KERNEL */ 18252904Sshin 18352904Sshin/* 18452904Sshin * Macros started with IPV6_ADDR is KAME local 18552904Sshin */ 18695023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 18797181Smike#if _BYTE_ORDER == _BIG_ENDIAN 18862587Sitojun#define IPV6_ADDR_INT32_ONE 1 18962587Sitojun#define IPV6_ADDR_INT32_TWO 2 19062587Sitojun#define IPV6_ADDR_INT32_MNL 0xff010000 19162587Sitojun#define IPV6_ADDR_INT32_MLL 0xff020000 19262587Sitojun#define IPV6_ADDR_INT32_SMP 0x0000ffff 19362587Sitojun#define IPV6_ADDR_INT16_ULL 0xfe80 19462587Sitojun#define IPV6_ADDR_INT16_USL 0xfec0 19562587Sitojun#define IPV6_ADDR_INT16_MLL 0xff02 19697181Smike#elif _BYTE_ORDER == _LITTLE_ENDIAN 19762587Sitojun#define IPV6_ADDR_INT32_ONE 0x01000000 19862587Sitojun#define IPV6_ADDR_INT32_TWO 0x02000000 19962587Sitojun#define IPV6_ADDR_INT32_MNL 0x000001ff 20062587Sitojun#define IPV6_ADDR_INT32_MLL 0x000002ff 20162587Sitojun#define IPV6_ADDR_INT32_SMP 0xffff0000 20262587Sitojun#define IPV6_ADDR_INT16_ULL 0x80fe 20362587Sitojun#define IPV6_ADDR_INT16_USL 0xc0fe 20462587Sitojun#define IPV6_ADDR_INT16_MLL 0x02ff 20552904Sshin#endif 20652904Sshin#endif 20752904Sshin 20852904Sshin/* 20952904Sshin * Definition of some useful macros to handle IP6 addresses 21052904Sshin */ 21197181Smike#if __BSD_VISIBLE 21262587Sitojun#define IN6ADDR_ANY_INIT \ 21352904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21452904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 21562587Sitojun#define IN6ADDR_LOOPBACK_INIT \ 21652904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21752904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21862587Sitojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 21952904Sshin {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22162587Sitojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 22252904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22352904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 22462587Sitojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 22552904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22652904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 22797181Smike#endif 22852904Sshin 22952904Sshinextern const struct in6_addr in6addr_any; 23052904Sshinextern const struct in6_addr in6addr_loopback; 23197181Smike#if __BSD_VISIBLE 23252904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 23352904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 23452904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 23597181Smike#endif 23652904Sshin 23752904Sshin/* 23852904Sshin * Equality 23953877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 24053877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 24153877Sitojun * in ANSI standard. 24252904Sshin */ 24353877Sitojun#ifdef _KERNEL 24462587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24562587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 24653877Sitojun#else 24797181Smike#if __BSD_VISIBLE 24862587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24962587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 25053877Sitojun#endif 25197181Smike#endif 25252904Sshin 25378064Sume#ifdef _KERNEL /* non standard */ 25478064Sume/* see if two addresses are equal in a scope-conscious manner. */ 25578064Sume#define SA6_ARE_ADDR_EQUAL(a, b) \ 25678064Sume (((a)->sin6_scope_id == 0 || (b)->sin6_scope_id == 0 || \ 25778064Sume ((a)->sin6_scope_id == (b)->sin6_scope_id)) && \ 25878064Sume (bcmp(&(a)->sin6_addr, &(b)->sin6_addr, sizeof(struct in6_addr)) == 0)) 25978064Sume#endif 26078064Sume 26152904Sshin/* 26252904Sshin * Unspecified 26352904Sshin */ 26462587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 26578064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 26778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 26878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 26952904Sshin 27052904Sshin/* 27152904Sshin * Loopback 27252904Sshin */ 27362587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 27478064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 27578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 27678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 27778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 27852904Sshin 27952904Sshin/* 28052904Sshin * IPv4 compatible 28152904Sshin */ 28262587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 28378064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 28478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 28578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 28678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 28778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 28852904Sshin 28952904Sshin/* 29052904Sshin * Mapped 29152904Sshin */ 29262587Sitojun#define IN6_IS_ADDR_V4MAPPED(a) \ 29378064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 29478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 29578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 29652904Sshin 29752904Sshin/* 29852904Sshin * KAME Scope Values 29952904Sshin */ 30052904Sshin 30195023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 30262587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 30362587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 30462587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 30562587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 30662587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 30752904Sshin#else 30862587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 30962587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 31062587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 31162587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 31262587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 31352904Sshin#endif 31452904Sshin 31552904Sshin/* 31652904Sshin * Unicast Scope 31752904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 31852904Sshin */ 31962587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 32052904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 32162587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 32252904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 32352904Sshin 32452904Sshin/* 32552904Sshin * Multicast 32652904Sshin */ 32752904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 32852904Sshin 32995023Ssuz#ifdef _KERNEL /* XXX nonstandard */ 33062587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33152904Sshin#else 33262587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 33352904Sshin#endif 33452904Sshin 33552904Sshin/* 33652904Sshin * Multicast Scope 33752904Sshin */ 33895023Ssuz#ifdef _KERNEL /* refers nonstandard items */ 33962587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 34052904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34152904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 34262587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 34352904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34452904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 34562587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 34652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34752904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 34862587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 34952904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35052904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 35162587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 35252904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35352904Sshin (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 35452904Sshin#else 35562587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 35652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 35862587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 35952904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36052904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 36162587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 36252904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36352904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 36462587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 36552904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36652904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 36762587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 36852904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 36952904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 37052904Sshin#endif 37152904Sshin 37295023Ssuz#ifdef _KERNEL /* nonstandard */ 37378064Sume/* 37452904Sshin * KAME Scope 37552904Sshin */ 37662587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 37752904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 37852904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 37952904Sshin 38078064Sume#define IFA6_IS_DEPRECATED(a) \ 38178064Sume ((a)->ia6_lifetime.ia6t_preferred != 0 && \ 38278064Sume (a)->ia6_lifetime.ia6t_preferred < time_second) 38378064Sume#define IFA6_IS_INVALID(a) \ 38478064Sume ((a)->ia6_lifetime.ia6t_expire != 0 && \ 38578064Sume (a)->ia6_lifetime.ia6t_expire < time_second) 38678064Sume#endif /* _KERNEL */ 38778064Sume 38852904Sshin/* 38952904Sshin * IP6 route structure 39052904Sshin */ 39197181Smike#if __BSD_VISIBLE 39252904Sshinstruct route_in6 { 39352904Sshin struct rtentry *ro_rt; 39452904Sshin struct sockaddr_in6 ro_dst; 39552904Sshin}; 39652904Sshin#endif 39752904Sshin 39852904Sshin/* 39952904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 40052904Sshin * First word of comment is data type; bool is stored in int. 40152904Sshin */ 40297181Smike#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 40397181Smike#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 404100688Sume#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 405100688Sume#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 406100688Sume#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 40797181Smike#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 40897181Smike#define IPV6_V6ONLY 27 /* bool; only bind INET6 at wildcard bind */ 40997181Smike 41097181Smike#if __BSD_VISIBLE 41152904Sshin/* no hdrincl */ 41262587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 41362587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 41462587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 41562587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 41662587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 41762587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 41862587Sitojun#endif 41962587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 42062587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 42162587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 42278064Sume/* RFC2292 options */ 42378064Sume#define IPV6_PKTINFO 19 /* bool; send/recv if, src/dst addr */ 42462587Sitojun#define IPV6_HOPLIMIT 20 /* bool; hop limit */ 42562587Sitojun#define IPV6_NEXTHOP 21 /* bool; next hop addr */ 42662587Sitojun#define IPV6_HOPOPTS 22 /* bool; hop-by-hop option */ 42762587Sitojun#define IPV6_DSTOPTS 23 /* bool; destination option */ 42862587Sitojun#define IPV6_RTHDR 24 /* bool; routing header */ 42962587Sitojun#define IPV6_PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 43078064Sume 43162587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 43278064Sume#ifndef _KERNEL 43378064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 43478064Sume#endif 43552904Sshin 43695023Ssuz#if 1 /* IPSEC */ 43762587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 43878064Sume#endif 43962587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 44052904Sshin 44195023Ssuz#if 1 /* IPV6FIREWALL */ 44262587Sitojun#define IPV6_FW_ADD 30 /* add a firewall rule to chain */ 44362587Sitojun#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */ 44462587Sitojun#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */ 44562587Sitojun#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */ 44662587Sitojun#define IPV6_FW_GET 34 /* get entire firewall rule chain */ 44778064Sume#endif 44878064Sume 44965124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 45052904Sshin 45162587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 45262587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 45362587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 45452904Sshin 45552904Sshin/* 45652904Sshin * Defaults and limits for options 45752904Sshin */ 45895023Ssuz#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 45995023Ssuz#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 46052904Sshin 46152904Sshin/* 46252904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 46352904Sshin */ 46452904Sshinstruct ipv6_mreq { 46562587Sitojun struct in6_addr ipv6mr_multiaddr; 46662587Sitojun unsigned int ipv6mr_interface; 46752904Sshin}; 46852904Sshin 46952904Sshin/* 47052904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 47152904Sshin */ 47252904Sshinstruct in6_pktinfo { 47362587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 47462587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 47552904Sshin}; 47652904Sshin 47752904Sshin/* 47852904Sshin * Argument for IPV6_PORTRANGE: 47952904Sshin * - which range to search when port is unspecified at bind() or connect() 48052904Sshin */ 48152904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 48252904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 48352904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 48452904Sshin 48552904Sshin/* 48652904Sshin * Definitions for inet6 sysctl operations. 48752904Sshin * 48852904Sshin * Third level is protocol number. 48952904Sshin * Fourth level is desired variable within that protocol. 49052904Sshin */ 49162587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 49252904Sshin 49362587Sitojun#define CTL_IPV6PROTO_NAMES { \ 49452904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49552904Sshin { 0, 0 }, \ 49652904Sshin { "tcp6", CTLTYPE_NODE }, \ 49752904Sshin { 0, 0 }, \ 49852904Sshin { 0, 0 }, \ 49952904Sshin { 0, 0 }, \ 50052904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 50152904Sshin { 0, 0 }, \ 50252904Sshin { 0, 0 }, \ 50352904Sshin { "udp6", CTLTYPE_NODE }, \ 50452904Sshin { 0, 0 }, \ 50552904Sshin { 0, 0 }, \ 50652904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 50752904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 50852904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 50952904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51052904Sshin { 0, 0 }, \ 51152904Sshin { "ip6", CTLTYPE_NODE }, \ 51252904Sshin { 0, 0 }, \ 51352904Sshin { 0, 0 }, \ 51452904Sshin { 0, 0 }, \ 51552904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51652904Sshin { 0, 0 }, \ 51752904Sshin { "ipsec6", CTLTYPE_NODE }, \ 51852904Sshin { 0, 0 }, \ 51952904Sshin { 0, 0 }, \ 52052904Sshin { 0, 0 }, \ 52152904Sshin { 0, 0 }, \ 52252904Sshin { 0, 0 }, \ 52352904Sshin { 0, 0 }, \ 52452904Sshin { "icmp6", CTLTYPE_NODE }, \ 52552904Sshin { 0, 0 }, \ 52652904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52752904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52852904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52952904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 53052904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 53152904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 53252904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 53352904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 53452904Sshin { 0, 0 }, \ 53552904Sshin { 0, 0 }, \ 53652904Sshin { 0, 0 }, \ 53752904Sshin { "pim6", CTLTYPE_NODE }, \ 53852904Sshin} 53952904Sshin 54052904Sshin/* 54152904Sshin * Names for IP sysctl objects 54252904Sshin */ 54362587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 54462587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 54562587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 54652904Sshin#ifdef notyet 54762587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 54852904Sshin#endif 54962587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 55062587Sitojun#define IPV6CTL_STATS 6 /* stats */ 55162587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 55262587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 55362587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 55462587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 55562587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 55662587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 55762587Sitojun#define IPV6CTL_KEEPFAITH 13 55862587Sitojun#define IPV6CTL_LOG_INTERVAL 14 55962587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 56062587Sitojun#define IPV6CTL_DAD_COUNT 16 56162587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 56262587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 56362587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 56462587Sitojun#define IPV6CTL_KAME_VERSION 20 56562587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 56662587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 56795023Ssuz#if 0 /* obsolete */ 56862587Sitojun#define IPV6CTL_MAPPED_ADDR 23 56962604Sitojun#endif 57078064Sume#define IPV6CTL_V6ONLY 24 57162604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 57262604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 57362604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 57478064Sume 57578064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 57678064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 57778064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 57878064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 57978064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 58078064Sume 58152904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 58265124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 58378064Sume#define IPV6CTL_MAXID 37 58478064Sume 58553541Sshin/* 58653541Sshin * Redefinition of mbuf flags 58753541Sshin */ 58878064Sume#define M_AUTHIPHDR M_PROTO2 58978064Sume#define M_DECRYPTED M_PROTO3 59078064Sume#define M_LOOP M_PROTO4 59178064Sume#define M_AUTHIPDGM M_PROTO5 59253541Sshin 59352904Sshin#ifdef _KERNEL 59478064Sumestruct cmsghdr; 59552904Sshin 59662587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 59752904Sshinint in6_localaddr __P((struct in6_addr *)); 59852904Sshinint in6_addrscope __P((struct in6_addr *)); 59952904Sshinstruct in6_ifaddr *in6_ifawithscope __P((struct ifnet *, struct in6_addr *)); 60052904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 60178064Sumeextern void in6_if_up __P((struct ifnet *)); 60278064Sumestruct sockaddr; 60392700Sdarrenrextern u_char ip6_protox[]; 60452904Sshin 60552904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 60652904Sshin struct sockaddr_in6 *sin6)); 60752904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 60852904Sshin struct sockaddr_in6 *sin6)); 60952904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 61052904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 61152904Sshin 61278064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 61378064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 61478064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 61583934Sbrooks 61683934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 61752904Sshin#endif /* _KERNEL */ 61852904Sshin 619102227Smike#ifndef _SIZE_T_DECLARED 620102227Smiketypedef __size_t size_t; 621102227Smike#define _SIZE_T_DECLARED 62297181Smike#endif 62397181Smike 62452904Sshin__BEGIN_DECLS 62552904Sshinstruct cmsghdr; 62652904Sshin 62778064Sumeextern int inet6_option_space __P((int)); 62878064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 62997181Smikeextern int inet6_option_append __P((struct cmsghdr *, const uint8_t *, 63078064Sume int, int)); 63197181Smikeextern uint8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 63297181Smikeextern int inet6_option_next __P((const struct cmsghdr *, uint8_t **)); 63397181Smikeextern int inet6_option_find __P((const struct cmsghdr *, uint8_t **, int)); 63452904Sshin 63578064Sumeextern size_t inet6_rthdr_space __P((int, int)); 63678064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 63778064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 63878064Sume unsigned int)); 63978064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 64078064Sume#if 0 /* not implemented yet */ 64178064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 64278064Sume#endif 64378064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 64478064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 64578064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 64678064Sume 64778064Sumeextern int inet6_opt_init __P((void *, size_t)); 64897181Smikeextern int inet6_opt_append __P((void *, size_t, int, uint8_t, 64997181Smike size_t, uint8_t, void **)); 65078064Sumeextern int inet6_opt_finish __P((void *, size_t, int)); 65178064Sumeextern int inet6_opt_set_val __P((void *, size_t, void *, int)); 65278064Sume 65397181Smikeextern int inet6_opt_next __P((void *, size_t, int, uint8_t *, 65478064Sume size_t *, void **)); 65597181Smikeextern int inet6_opt_find __P((void *, size_t, int, uint8_t, 65678064Sume size_t *, void **)); 65778064Sumeextern int inet6_opt_get_val __P((void *, size_t, void *, int)); 65878064Sumeextern size_t inet6_rth_space __P((int, int)); 65978064Sumeextern void *inet6_rth_init __P((void *, int, int, int)); 66078064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 66178064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 66278064Sumeextern int inet6_rth_segments __P((const void *)); 66378064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 66452904Sshin__END_DECLS 66552904Sshin 66697181Smike#endif /* __BSD_VISIBLE */ 66797181Smike 66852904Sshin#endif /* !_NETINET6_IN6_H_ */ 669