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