1*cfb92d14SAndroid Build Coastguard Worker /* $FreeBSD$ */ 2*cfb92d14SAndroid Build Coastguard Worker /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $ */ 3*cfb92d14SAndroid Build Coastguard Worker 4*cfb92d14SAndroid Build Coastguard Worker /*- 5*cfb92d14SAndroid Build Coastguard Worker * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6*cfb92d14SAndroid Build Coastguard Worker * All rights reserved. 7*cfb92d14SAndroid Build Coastguard Worker * 8*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 9*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 10*cfb92d14SAndroid Build Coastguard Worker * are met: 11*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 12*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 13*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 14*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 15*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 16*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the project nor the names of its contributors 17*cfb92d14SAndroid Build Coastguard Worker * may be used to endorse or promote products derived from this software 18*cfb92d14SAndroid Build Coastguard Worker * without specific prior written permission. 19*cfb92d14SAndroid Build Coastguard Worker * 20*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21*cfb92d14SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24*cfb92d14SAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25*cfb92d14SAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26*cfb92d14SAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27*cfb92d14SAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28*cfb92d14SAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29*cfb92d14SAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30*cfb92d14SAndroid Build Coastguard Worker * SUCH DAMAGE. 31*cfb92d14SAndroid Build Coastguard Worker */ 32*cfb92d14SAndroid Build Coastguard Worker 33*cfb92d14SAndroid Build Coastguard Worker /*- 34*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 1982, 1986, 1993 35*cfb92d14SAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved. 36*cfb92d14SAndroid Build Coastguard Worker * 37*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 38*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 39*cfb92d14SAndroid Build Coastguard Worker * are met: 40*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 41*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 42*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 43*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 44*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 45*cfb92d14SAndroid Build Coastguard Worker * 4. Neither the name of the University nor the names of its contributors 46*cfb92d14SAndroid Build Coastguard Worker * may be used to endorse or promote products derived from this software 47*cfb92d14SAndroid Build Coastguard Worker * without specific prior written permission. 48*cfb92d14SAndroid Build Coastguard Worker * 49*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50*cfb92d14SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53*cfb92d14SAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54*cfb92d14SAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55*cfb92d14SAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56*cfb92d14SAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57*cfb92d14SAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58*cfb92d14SAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59*cfb92d14SAndroid Build Coastguard Worker * SUCH DAMAGE. 60*cfb92d14SAndroid Build Coastguard Worker * 61*cfb92d14SAndroid Build Coastguard Worker * @(#)ip.h 8.1 (Berkeley) 6/10/93 62*cfb92d14SAndroid Build Coastguard Worker */ 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Worker #ifndef TCPLP_NETINET_IP6_H_ 65*cfb92d14SAndroid Build Coastguard Worker #define TCPLP_NETINET_IP6_H_ 66*cfb92d14SAndroid Build Coastguard Worker 67*cfb92d14SAndroid Build Coastguard Worker #include "types.h" 68*cfb92d14SAndroid Build Coastguard Worker 69*cfb92d14SAndroid Build Coastguard Worker /* samkumar: Copied from netinet/in6.h */ 70*cfb92d14SAndroid Build Coastguard Worker struct in6_addr { 71*cfb92d14SAndroid Build Coastguard Worker union { 72*cfb92d14SAndroid Build Coastguard Worker uint8_t __u6_addr8[16]; 73*cfb92d14SAndroid Build Coastguard Worker uint16_t __u6_addr16[8]; 74*cfb92d14SAndroid Build Coastguard Worker uint32_t __u6_addr32[4]; 75*cfb92d14SAndroid Build Coastguard Worker } __u6_addr; /* 128-bit IP6 address */ 76*cfb92d14SAndroid Build Coastguard Worker } __attribute__((packed)); // added this to allow unaligned access 77*cfb92d14SAndroid Build Coastguard Worker #define s6_addr __u6_addr.__u6_addr8 78*cfb92d14SAndroid Build Coastguard Worker 79*cfb92d14SAndroid Build Coastguard Worker struct sockaddr_in6 { 80*cfb92d14SAndroid Build Coastguard Worker uint8_t sin6_len; /* length of this struct */ 81*cfb92d14SAndroid Build Coastguard Worker int sin6_family; /* AF_INET6 */ 82*cfb92d14SAndroid Build Coastguard Worker uint16_t sin6_port; /* Transport layer port # */ 83*cfb92d14SAndroid Build Coastguard Worker uint32_t sin6_flowinfo; /* IP6 flow information */ 84*cfb92d14SAndroid Build Coastguard Worker struct in6_addr sin6_addr; /* IP6 address */ 85*cfb92d14SAndroid Build Coastguard Worker uint32_t sin6_scope_id; /* scope zone index */ 86*cfb92d14SAndroid Build Coastguard Worker }; 87*cfb92d14SAndroid Build Coastguard Worker 88*cfb92d14SAndroid Build Coastguard Worker /* 89*cfb92d14SAndroid Build Coastguard Worker * Definition for internet protocol version 6. 90*cfb92d14SAndroid Build Coastguard Worker * RFC 2460 91*cfb92d14SAndroid Build Coastguard Worker */ 92*cfb92d14SAndroid Build Coastguard Worker struct ip6_hdr { 93*cfb92d14SAndroid Build Coastguard Worker union { 94*cfb92d14SAndroid Build Coastguard Worker struct ip6_hdrctl { 95*cfb92d14SAndroid Build Coastguard Worker u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ 96*cfb92d14SAndroid Build Coastguard Worker u_int16_t ip6_un1_plen; /* payload length */ 97*cfb92d14SAndroid Build Coastguard Worker u_int8_t ip6_un1_nxt; /* next header */ 98*cfb92d14SAndroid Build Coastguard Worker u_int8_t ip6_un1_hlim; /* hop limit */ 99*cfb92d14SAndroid Build Coastguard Worker } ip6_un1; 100*cfb92d14SAndroid Build Coastguard Worker u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ 101*cfb92d14SAndroid Build Coastguard Worker } ip6_ctlun; 102*cfb92d14SAndroid Build Coastguard Worker struct in6_addr ip6_src; /* source address */ 103*cfb92d14SAndroid Build Coastguard Worker struct in6_addr ip6_dst; /* destination address */ 104*cfb92d14SAndroid Build Coastguard Worker } __attribute__((packed)); 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Worker #define ip6_vfc ip6_ctlun.ip6_un2_vfc 107*cfb92d14SAndroid Build Coastguard Worker #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 108*cfb92d14SAndroid Build Coastguard Worker #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 109*cfb92d14SAndroid Build Coastguard Worker #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 110*cfb92d14SAndroid Build Coastguard Worker #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 111*cfb92d14SAndroid Build Coastguard Worker #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Worker #define IPV6_VERSION 0x60 114*cfb92d14SAndroid Build Coastguard Worker #define IPV6_VERSION_MASK 0xf0 115*cfb92d14SAndroid Build Coastguard Worker 116*cfb92d14SAndroid Build Coastguard Worker /* samkumar: Removed #if guard since ECN is enabled in TCPlp. */ 117*cfb92d14SAndroid Build Coastguard Worker /* ECN bits proposed by Sally Floyd */ 118*cfb92d14SAndroid Build Coastguard Worker #define IP6TOS_CE 0x01 /* congestion experienced */ 119*cfb92d14SAndroid Build Coastguard Worker #define IP6TOS_ECT 0x02 /* ECN-capable transport */ 120*cfb92d14SAndroid Build Coastguard Worker 121*cfb92d14SAndroid Build Coastguard Worker // samkumar: Copied from in6.h 122*cfb92d14SAndroid Build Coastguard Worker #define IN6_ARE_ADDR_EQUAL(a, b) \ 123*cfb92d14SAndroid Build Coastguard Worker (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 124*cfb92d14SAndroid Build Coastguard Worker 125*cfb92d14SAndroid Build Coastguard Worker /* Multicast */ 126*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 127*cfb92d14SAndroid Build Coastguard Worker 128*cfb92d14SAndroid Build Coastguard Worker /* 129*cfb92d14SAndroid Build Coastguard Worker * Unspecified 130*cfb92d14SAndroid Build Coastguard Worker */ 131*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_UNSPECIFIED(a) \ 132*cfb92d14SAndroid Build Coastguard Worker ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 133*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[1] == 0 && \ 134*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[2] == 0 && \ 135*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[3] == 0) 136*cfb92d14SAndroid Build Coastguard Worker 137*cfb92d14SAndroid Build Coastguard Worker /* 138*cfb92d14SAndroid Build Coastguard Worker * Loopback 139*cfb92d14SAndroid Build Coastguard Worker */ 140*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_LOOPBACK(a) \ 141*cfb92d14SAndroid Build Coastguard Worker ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 142*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[1] == 0 && \ 143*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[2] == 0 && \ 144*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[3] == ntohl(1)) 145*cfb92d14SAndroid Build Coastguard Worker 146*cfb92d14SAndroid Build Coastguard Worker /* 147*cfb92d14SAndroid Build Coastguard Worker * Unicast Scope 148*cfb92d14SAndroid Build Coastguard Worker * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 149*cfb92d14SAndroid Build Coastguard Worker */ 150*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_LINKLOCAL(a) \ 151*cfb92d14SAndroid Build Coastguard Worker (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 152*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_SITELOCAL(a) \ 153*cfb92d14SAndroid Build Coastguard Worker (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 154*cfb92d14SAndroid Build Coastguard Worker 155*cfb92d14SAndroid Build Coastguard Worker /* 156*cfb92d14SAndroid Build Coastguard Worker * Mapped 157*cfb92d14SAndroid Build Coastguard Worker */ 158*cfb92d14SAndroid Build Coastguard Worker 159*cfb92d14SAndroid Build Coastguard Worker #define IN6_IS_ADDR_V4MAPPED(a) \ 160*cfb92d14SAndroid Build Coastguard Worker ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 161*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[1] == 0 && \ 162*cfb92d14SAndroid Build Coastguard Worker (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff)) 163*cfb92d14SAndroid Build Coastguard Worker 164*cfb92d14SAndroid Build Coastguard Worker #endif /* not _NETINET_IP6_H_ */ 165