in6.h revision 92700
162587Sitojun/* $FreeBSD: head/sys/netinet6/in6.h 92700 2002-03-19 15:01:21Z darrenr $ */ 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 */ 11052904Sshin 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) 11652904Sshin 11752904Sshin/* 11852904Sshin * IPv6 address 11952904Sshin */ 12052904Sshinstruct in6_addr { 12152904Sshin union { 12262587Sitojun u_int8_t __u6_addr8[16]; 12362587Sitojun u_int16_t __u6_addr16[8]; 12462587Sitojun u_int32_t __u6_addr32[4]; 12552904Sshin } __u6_addr; /* 128-bit IP6 address */ 12652904Sshin}; 12752904Sshin 12862587Sitojun#define s6_addr __u6_addr.__u6_addr8 12952904Sshin#ifdef _KERNEL /*XXX nonstandard*/ 13062587Sitojun#define s6_addr8 __u6_addr.__u6_addr8 13162587Sitojun#define s6_addr16 __u6_addr.__u6_addr16 13262587Sitojun#define s6_addr32 __u6_addr.__u6_addr32 13352904Sshin#endif 13452904Sshin 13591984Smike#ifndef INET6_ADDRSTRLEN 13662587Sitojun#define INET6_ADDRSTRLEN 46 13791984Smike#endif 13852904Sshin 13952904Sshin/* 14052904Sshin * Socket address for IPv6 14152904Sshin */ 14262587Sitojun#ifndef _XOPEN_SOURCE 14362587Sitojun#define SIN6_LEN 14452904Sshin#endif 14552904Sshinstruct sockaddr_in6 { 14662587Sitojun u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ 14762587Sitojun u_int8_t sin6_family; /* AF_INET6 (sa_family_t) */ 14852904Sshin u_int16_t sin6_port; /* Transport layer port # (in_port_t)*/ 14952904Sshin u_int32_t sin6_flowinfo; /* IP6 flow information */ 15062587Sitojun struct in6_addr sin6_addr; /* IP6 address */ 15178064Sume u_int32_t sin6_scope_id; /* scope zone index */ 15252904Sshin}; 15352904Sshin 15452904Sshin/* 15552904Sshin * Local definition for masks 15652904Sshin */ 15752904Sshin#ifdef _KERNEL /*XXX nonstandard*/ 15862587Sitojun#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 15962587Sitojun#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 16052904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16162587Sitojun#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16252904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 16362587Sitojun#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16452904Sshin 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 16562587Sitojun#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 16652904Sshin 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 16752904Sshin#endif 16852904Sshin 16952904Sshin#ifdef _KERNEL 17078064Sumeextern const struct sockaddr_in6 sa6_any; 17178064Sume 17252904Sshinextern const struct in6_addr in6mask0; 17352904Sshinextern const struct in6_addr in6mask32; 17452904Sshinextern const struct in6_addr in6mask64; 17552904Sshinextern const struct in6_addr in6mask96; 17652904Sshinextern const struct in6_addr in6mask128; 17752904Sshin#endif /* _KERNEL */ 17852904Sshin 17952904Sshin/* 18052904Sshin * Macros started with IPV6_ADDR is KAME local 18152904Sshin */ 18252904Sshin#ifdef _KERNEL /*XXX nonstandard*/ 18352904Sshin#if BYTE_ORDER == BIG_ENDIAN 18462587Sitojun#define IPV6_ADDR_INT32_ONE 1 18562587Sitojun#define IPV6_ADDR_INT32_TWO 2 18662587Sitojun#define IPV6_ADDR_INT32_MNL 0xff010000 18762587Sitojun#define IPV6_ADDR_INT32_MLL 0xff020000 18862587Sitojun#define IPV6_ADDR_INT32_SMP 0x0000ffff 18962587Sitojun#define IPV6_ADDR_INT16_ULL 0xfe80 19062587Sitojun#define IPV6_ADDR_INT16_USL 0xfec0 19162587Sitojun#define IPV6_ADDR_INT16_MLL 0xff02 19252904Sshin#elif BYTE_ORDER == LITTLE_ENDIAN 19362587Sitojun#define IPV6_ADDR_INT32_ONE 0x01000000 19462587Sitojun#define IPV6_ADDR_INT32_TWO 0x02000000 19562587Sitojun#define IPV6_ADDR_INT32_MNL 0x000001ff 19662587Sitojun#define IPV6_ADDR_INT32_MLL 0x000002ff 19762587Sitojun#define IPV6_ADDR_INT32_SMP 0xffff0000 19862587Sitojun#define IPV6_ADDR_INT16_ULL 0x80fe 19962587Sitojun#define IPV6_ADDR_INT16_USL 0xc0fe 20062587Sitojun#define IPV6_ADDR_INT16_MLL 0x02ff 20152904Sshin#endif 20252904Sshin#endif 20352904Sshin 20452904Sshin/* 20552904Sshin * Definition of some useful macros to handle IP6 addresses 20652904Sshin */ 20762587Sitojun#define IN6ADDR_ANY_INIT \ 20852904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 20952904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 21062587Sitojun#define IN6ADDR_LOOPBACK_INIT \ 21152904Sshin {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21252904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21362587Sitojun#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 21452904Sshin {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21552904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21662587Sitojun#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 21752904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 21852904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 21962587Sitojun#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 22052904Sshin {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 22152904Sshin 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 22252904Sshin 22352904Sshinextern const struct in6_addr in6addr_any; 22452904Sshinextern const struct in6_addr in6addr_loopback; 22552904Sshinextern const struct in6_addr in6addr_nodelocal_allnodes; 22652904Sshinextern const struct in6_addr in6addr_linklocal_allnodes; 22752904Sshinextern const struct in6_addr in6addr_linklocal_allrouters; 22852904Sshin 22952904Sshin/* 23052904Sshin * Equality 23153877Sitojun * NOTE: Some of kernel programming environment (for example, openbsd/sparc) 23253877Sitojun * does not supply memcmp(). For userland memcmp() is preferred as it is 23353877Sitojun * in ANSI standard. 23452904Sshin */ 23553877Sitojun#ifdef _KERNEL 23662587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 23762587Sitojun (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 23853877Sitojun#else 23962587Sitojun#define IN6_ARE_ADDR_EQUAL(a, b) \ 24062587Sitojun (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 24153877Sitojun#endif 24252904Sshin 24378064Sume#ifdef _KERNEL /* non standard */ 24478064Sume/* see if two addresses are equal in a scope-conscious manner. */ 24578064Sume#define SA6_ARE_ADDR_EQUAL(a, b) \ 24678064Sume (((a)->sin6_scope_id == 0 || (b)->sin6_scope_id == 0 || \ 24778064Sume ((a)->sin6_scope_id == (b)->sin6_scope_id)) && \ 24878064Sume (bcmp(&(a)->sin6_addr, &(b)->sin6_addr, sizeof(struct in6_addr)) == 0)) 24978064Sume#endif 25078064Sume 25152904Sshin/* 25252904Sshin * Unspecified 25352904Sshin */ 25462587Sitojun#define IN6_IS_ADDR_UNSPECIFIED(a) \ 25578064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 25678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 25778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 25878064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 25952904Sshin 26052904Sshin/* 26152904Sshin * Loopback 26252904Sshin */ 26362587Sitojun#define IN6_IS_ADDR_LOOPBACK(a) \ 26478064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 26578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 26678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 26778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) 26852904Sshin 26952904Sshin/* 27052904Sshin * IPv4 compatible 27152904Sshin */ 27262587Sitojun#define IN6_IS_ADDR_V4COMPAT(a) \ 27378064Sume ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 27478064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 27578064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 27678064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 27778064Sume (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) 27852904Sshin 27952904Sshin/* 28052904Sshin * Mapped 28152904Sshin */ 28262587Sitojun#define IN6_IS_ADDR_V4MAPPED(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]) == ntohl(0x0000ffff))) 28652904Sshin 28752904Sshin/* 28852904Sshin * KAME Scope Values 28952904Sshin */ 29052904Sshin 29152904Sshin#ifdef _KERNEL /*XXX nonstandard*/ 29262587Sitojun#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 29362587Sitojun#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 29462587Sitojun#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 29562587Sitojun#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 29662587Sitojun#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 29752904Sshin#else 29862587Sitojun#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 29962587Sitojun#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 30062587Sitojun#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 30162587Sitojun#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 30262587Sitojun#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 30352904Sshin#endif 30452904Sshin 30552904Sshin/* 30652904Sshin * Unicast Scope 30752904Sshin * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 30852904Sshin */ 30962587Sitojun#define IN6_IS_ADDR_LINKLOCAL(a) \ 31052904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 31162587Sitojun#define IN6_IS_ADDR_SITELOCAL(a) \ 31252904Sshin (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 31352904Sshin 31452904Sshin/* 31552904Sshin * Multicast 31652904Sshin */ 31752904Sshin#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 31852904Sshin 31952904Sshin#ifdef _KERNEL /*XXX nonstandard*/ 32062587Sitojun#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 32152904Sshin#else 32262587Sitojun#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 32352904Sshin#endif 32452904Sshin 32552904Sshin/* 32652904Sshin * Multicast Scope 32752904Sshin */ 32852904Sshin#ifdef _KERNEL /*refers nonstandard items */ 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#else 34562587Sitojun#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 34652904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 34752904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 34862587Sitojun#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 34952904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35052904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 35162587Sitojun#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 35252904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35352904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 35462587Sitojun#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 35552904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35652904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 35762587Sitojun#define IN6_IS_ADDR_MC_GLOBAL(a) \ 35852904Sshin (IN6_IS_ADDR_MULTICAST(a) && \ 35952904Sshin (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 36052904Sshin#endif 36152904Sshin 36278064Sume#ifdef _KERNEL /*nonstandard*/ 36378064Sume/* 36452904Sshin * KAME Scope 36552904Sshin */ 36662587Sitojun#define IN6_IS_SCOPE_LINKLOCAL(a) \ 36752904Sshin ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 36852904Sshin (IN6_IS_ADDR_MC_LINKLOCAL(a))) 36952904Sshin 37078064Sume#define IFA6_IS_DEPRECATED(a) \ 37178064Sume ((a)->ia6_lifetime.ia6t_preferred != 0 && \ 37278064Sume (a)->ia6_lifetime.ia6t_preferred < time_second) 37378064Sume#define IFA6_IS_INVALID(a) \ 37478064Sume ((a)->ia6_lifetime.ia6t_expire != 0 && \ 37578064Sume (a)->ia6_lifetime.ia6t_expire < time_second) 37678064Sume#endif /* _KERNEL */ 37778064Sume 37852904Sshin/* 37952904Sshin * IP6 route structure 38052904Sshin */ 38162587Sitojun#ifndef _XOPEN_SOURCE 38252904Sshinstruct route_in6 { 38352904Sshin struct rtentry *ro_rt; 38452904Sshin struct sockaddr_in6 ro_dst; 38552904Sshin}; 38652904Sshin#endif 38752904Sshin 38852904Sshin/* 38952904Sshin * Options for use with [gs]etsockopt at the IPV6 level. 39052904Sshin * First word of comment is data type; bool is stored in int. 39152904Sshin */ 39252904Sshin/* no hdrincl */ 39362587Sitojun#if 0 /* the followings are relic in IPv4 and hence are disabled */ 39462587Sitojun#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 39562587Sitojun#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 39662587Sitojun#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 39762587Sitojun#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 39862587Sitojun#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 39962587Sitojun#endif 40062587Sitojun#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 40162587Sitojun#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 40262587Sitojun#define IPV6_MULTICAST_IF 9 /* u_char; set/get IP6 multicast i/f */ 40362587Sitojun#define IPV6_MULTICAST_HOPS 10 /* u_char; set/get IP6 multicast hops */ 40462587Sitojun#define IPV6_MULTICAST_LOOP 11 /* u_char; set/get IP6 multicast loopback */ 40562587Sitojun#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 40662587Sitojun#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 40762587Sitojun#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 40862587Sitojun#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 40978064Sume/* RFC2292 options */ 41078064Sume#define IPV6_PKTINFO 19 /* bool; send/recv if, src/dst addr */ 41162587Sitojun#define IPV6_HOPLIMIT 20 /* bool; hop limit */ 41262587Sitojun#define IPV6_NEXTHOP 21 /* bool; next hop addr */ 41362587Sitojun#define IPV6_HOPOPTS 22 /* bool; hop-by-hop option */ 41462587Sitojun#define IPV6_DSTOPTS 23 /* bool; destination option */ 41562587Sitojun#define IPV6_RTHDR 24 /* bool; routing header */ 41662587Sitojun#define IPV6_PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 41778064Sume 41862587Sitojun#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 41978064Sume#define IPV6_V6ONLY 27 /* bool; only bind INET6 at wildcard bind */ 42078064Sume#ifndef _KERNEL 42178064Sume#define IPV6_BINDV6ONLY IPV6_V6ONLY 42278064Sume#endif 42352904Sshin 42478064Sume#if 1 /*IPSEC*/ 42562587Sitojun#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 42678064Sume#endif 42762587Sitojun#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 42852904Sshin 42978064Sume#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 43765124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 43852904Sshin 43962587Sitojun#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 44062587Sitojun#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 44162587Sitojun#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 44252904Sshin 44352904Sshin/* 44452904Sshin * Defaults and limits for options 44552904Sshin */ 44662587Sitojun#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 44762587Sitojun#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 44852904Sshin 44952904Sshin/* 45052904Sshin * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 45152904Sshin */ 45252904Sshinstruct ipv6_mreq { 45362587Sitojun struct in6_addr ipv6mr_multiaddr; 45462587Sitojun unsigned int ipv6mr_interface; 45552904Sshin}; 45652904Sshin 45752904Sshin/* 45852904Sshin * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 45952904Sshin */ 46052904Sshinstruct in6_pktinfo { 46162587Sitojun struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 46262587Sitojun unsigned int ipi6_ifindex; /* send/recv interface index */ 46352904Sshin}; 46452904Sshin 46552904Sshin/* 46652904Sshin * Argument for IPV6_PORTRANGE: 46752904Sshin * - which range to search when port is unspecified at bind() or connect() 46852904Sshin */ 46952904Sshin#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 47052904Sshin#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 47152904Sshin#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 47252904Sshin 47362587Sitojun#ifndef _XOPEN_SOURCE 47452904Sshin/* 47552904Sshin * Definitions for inet6 sysctl operations. 47652904Sshin * 47752904Sshin * Third level is protocol number. 47852904Sshin * Fourth level is desired variable within that protocol. 47952904Sshin */ 48062587Sitojun#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ 48152904Sshin 48262587Sitojun#define CTL_IPV6PROTO_NAMES { \ 48352904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 48452904Sshin { 0, 0 }, \ 48552904Sshin { "tcp6", CTLTYPE_NODE }, \ 48652904Sshin { 0, 0 }, \ 48752904Sshin { 0, 0 }, \ 48852904Sshin { 0, 0 }, \ 48952904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49052904Sshin { 0, 0 }, \ 49152904Sshin { 0, 0 }, \ 49252904Sshin { "udp6", CTLTYPE_NODE }, \ 49352904Sshin { 0, 0 }, \ 49452904Sshin { 0, 0 }, \ 49552904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49652904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49752904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49852904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 49952904Sshin { 0, 0 }, \ 50052904Sshin { "ip6", CTLTYPE_NODE }, \ 50152904Sshin { 0, 0 }, \ 50252904Sshin { 0, 0 }, \ 50352904Sshin { 0, 0 }, \ 50452904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 50552904Sshin { 0, 0 }, \ 50652904Sshin { "ipsec6", CTLTYPE_NODE }, \ 50752904Sshin { 0, 0 }, \ 50852904Sshin { 0, 0 }, \ 50952904Sshin { 0, 0 }, \ 51052904Sshin { 0, 0 }, \ 51152904Sshin { 0, 0 }, \ 51252904Sshin { 0, 0 }, \ 51352904Sshin { "icmp6", CTLTYPE_NODE }, \ 51452904Sshin { 0, 0 }, \ 51552904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51652904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51752904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51852904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 51952904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52052904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52152904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52252904Sshin { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 52352904Sshin { 0, 0 }, \ 52452904Sshin { 0, 0 }, \ 52552904Sshin { 0, 0 }, \ 52652904Sshin { "pim6", CTLTYPE_NODE }, \ 52752904Sshin} 52852904Sshin 52952904Sshin/* 53052904Sshin * Names for IP sysctl objects 53152904Sshin */ 53262587Sitojun#define IPV6CTL_FORWARDING 1 /* act as router */ 53362587Sitojun#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 53462587Sitojun#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 53552904Sshin#ifdef notyet 53662587Sitojun#define IPV6CTL_DEFMTU 4 /* default MTU */ 53752904Sshin#endif 53862587Sitojun#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 53962587Sitojun#define IPV6CTL_STATS 6 /* stats */ 54062587Sitojun#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 54162587Sitojun#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 54262587Sitojun#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 54362587Sitojun#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 54462587Sitojun#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 54562587Sitojun#define IPV6CTL_ACCEPT_RTADV 12 54662587Sitojun#define IPV6CTL_KEEPFAITH 13 54762587Sitojun#define IPV6CTL_LOG_INTERVAL 14 54862587Sitojun#define IPV6CTL_HDRNESTLIMIT 15 54962587Sitojun#define IPV6CTL_DAD_COUNT 16 55062587Sitojun#define IPV6CTL_AUTO_FLOWLABEL 17 55162587Sitojun#define IPV6CTL_DEFMCASTHLIM 18 55262587Sitojun#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 55362587Sitojun#define IPV6CTL_KAME_VERSION 20 55462587Sitojun#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 55562587Sitojun#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ 55678064Sume#if 0 /*obsolete*/ 55762587Sitojun#define IPV6CTL_MAPPED_ADDR 23 55862604Sitojun#endif 55978064Sume#define IPV6CTL_V6ONLY 24 56062604Sitojun#define IPV6CTL_RTEXPIRE 25 /* cloned route expiration time */ 56162604Sitojun#define IPV6CTL_RTMINEXPIRE 26 /* min value for expiration time */ 56262604Sitojun#define IPV6CTL_RTMAXCACHE 27 /* trigger level for dynamic expire */ 56378064Sume 56478064Sume#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */ 56578064Sume#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */ 56678064Sume#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */ 56778064Sume#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 56878064Sume#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */ 56978064Sume 57052904Sshin/* New entries should be added here from current IPV6CTL_MAXID value. */ 57165124Sitojun/* to define items, should talk with KAME guys first, for *BSD compatibility */ 57278064Sume#define IPV6CTL_MAXID 37 57378064Sume 57452904Sshin#endif /* !_XOPEN_SOURCE */ 57552904Sshin 57653541Sshin/* 57753541Sshin * Redefinition of mbuf flags 57853541Sshin */ 57978064Sume#define M_AUTHIPHDR M_PROTO2 58078064Sume#define M_DECRYPTED M_PROTO3 58178064Sume#define M_LOOP M_PROTO4 58278064Sume#define M_AUTHIPDGM M_PROTO5 58353541Sshin 58452904Sshin#ifdef _KERNEL 58578064Sumestruct cmsghdr; 58652904Sshin 58762587Sitojunint in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); 58852904Sshinint in6_localaddr __P((struct in6_addr *)); 58952904Sshinint in6_addrscope __P((struct in6_addr *)); 59052904Sshinstruct in6_ifaddr *in6_ifawithscope __P((struct ifnet *, struct in6_addr *)); 59152904Sshinstruct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); 59278064Sumeextern void in6_if_up __P((struct ifnet *)); 59378064Sumestruct sockaddr; 59492700Sdarrenrextern u_char ip6_protox[]; 59552904Sshin 59652904Sshinvoid in6_sin6_2_sin __P((struct sockaddr_in *sin, 59752904Sshin struct sockaddr_in6 *sin6)); 59852904Sshinvoid in6_sin_2_v4mapsin6 __P((struct sockaddr_in *sin, 59952904Sshin struct sockaddr_in6 *sin6)); 60052904Sshinvoid in6_sin6_2_sin_in_sock __P((struct sockaddr *nam)); 60152904Sshinvoid in6_sin_2_v4mapsin6_in_sock __P((struct sockaddr **nam)); 60252904Sshin 60378064Sume#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 60478064Sume#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 60578064Sume#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 60683934Sbrooks 60783934Sbrooksextern int (*faithprefix_p)(struct in6_addr *); 60852904Sshin#endif /* _KERNEL */ 60952904Sshin 61052904Sshin__BEGIN_DECLS 61152904Sshinstruct cmsghdr; 61252904Sshin 61378064Sumeextern int inet6_option_space __P((int)); 61478064Sumeextern int inet6_option_init __P((void *, struct cmsghdr **, int)); 61578064Sumeextern int inet6_option_append __P((struct cmsghdr *, const u_int8_t *, 61678064Sume int, int)); 61778064Sumeextern u_int8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int)); 61878064Sumeextern int inet6_option_next __P((const struct cmsghdr *, u_int8_t **)); 61978064Sumeextern int inet6_option_find __P((const struct cmsghdr *, u_int8_t **, int)); 62052904Sshin 62178064Sumeextern size_t inet6_rthdr_space __P((int, int)); 62278064Sumeextern struct cmsghdr *inet6_rthdr_init __P((void *, int)); 62378064Sumeextern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *, 62478064Sume unsigned int)); 62578064Sumeextern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int)); 62678064Sume#if 0 /* not implemented yet */ 62778064Sumeextern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *)); 62878064Sume#endif 62978064Sumeextern int inet6_rthdr_segments __P((const struct cmsghdr *)); 63078064Sumeextern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int)); 63178064Sumeextern int inet6_rthdr_getflags __P((const struct cmsghdr *, int)); 63278064Sume 63378064Sumeextern int inet6_opt_init __P((void *, size_t)); 63478064Sumeextern int inet6_opt_append __P((void *, size_t, int, u_int8_t, 63578064Sume size_t, u_int8_t, void **)); 63678064Sumeextern int inet6_opt_finish __P((void *, size_t, int)); 63778064Sumeextern int inet6_opt_set_val __P((void *, size_t, void *, int)); 63878064Sume 63978064Sumeextern int inet6_opt_next __P((void *, size_t, int, u_int8_t *, 64078064Sume size_t *, void **)); 64178064Sumeextern int inet6_opt_find __P((void *, size_t, int, u_int8_t, 64278064Sume size_t *, void **)); 64378064Sumeextern int inet6_opt_get_val __P((void *, size_t, void *, int)); 64478064Sumeextern size_t inet6_rth_space __P((int, int)); 64578064Sumeextern void *inet6_rth_init __P((void *, int, int, int)); 64678064Sumeextern int inet6_rth_add __P((void *, const struct in6_addr *)); 64778064Sumeextern int inet6_rth_reverse __P((const void *, void *)); 64878064Sumeextern int inet6_rth_segments __P((const void *)); 64978064Sumeextern struct in6_addr *inet6_rth_getaddr __P((const void *, int)); 65052904Sshin__END_DECLS 65152904Sshin 65252904Sshin#endif /* !_NETINET6_IN6_H_ */ 653