1 /** 2 * @file 3 * IPv6 protocol definitions 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_PROT_IP6_H 38 #define LWIP_HDR_PROT_IP6_H 39 40 #include "lwip/arch.h" 41 #include "lwip/ip6_addr.h" 42 43 #if defined (__cplusplus) && __cplusplus 44 extern "C" { 45 #endif 46 47 /** This is the packed version of ip6_addr_t, 48 used in network headers that are itself packed */ 49 #ifdef PACK_STRUCT_USE_INCLUDES 50 # include "arch/bpstruct.h" 51 #endif 52 PACK_STRUCT_BEGIN 53 struct ip6_addr_packed { 54 PACK_STRUCT_FIELD(u32_t addr[4]); 55 } PACK_STRUCT_STRUCT; 56 PACK_STRUCT_END 57 #ifdef PACK_STRUCT_USE_INCLUDES 58 # include "arch/epstruct.h" 59 #endif 60 typedef struct ip6_addr_packed ip6_addr_p_t; 61 62 #define IP6_HLEN 40 63 64 #define IP6_ADDR_LEN 128 // 128 bits 65 66 #define IP6_NEXTH_HOPBYHOP 0 67 #define IP6_NEXTH_TCP 6 68 #define IP6_NEXTH_UDP 17 69 #define IP6_NEXTH_ENCAPS 41 70 #define IP6_NEXTH_ROUTING 43 71 #define IP6_NEXTH_FRAGMENT 44 72 #define IP6_NEXTH_ICMP6 58 73 #define IP6_NEXTH_NONE 59 74 #define IP6_NEXTH_DESTOPTS 60 75 #define IP6_NEXTH_UDPLITE 136 76 77 /* 78 * include Next Header (8bits) and Hdr Ext Len (8bits) 79 */ 80 #define IP6_EXTENSION_HEADER_MIN_LEN 2 81 82 /* 83 * Extension Header 84 * Hdr Ext Len: 85 * 8-bit unsigned integer. Length of the Routing header in 8-octet units, not including the first 8 octets. 86 */ 87 #define IP6_HDR_EXT_LEN_UNIT 8 88 89 /** The IPv6 header. */ 90 #ifdef PACK_STRUCT_USE_INCLUDES 91 # include "arch/bpstruct.h" 92 #endif 93 PACK_STRUCT_BEGIN 94 struct ip6_hdr { 95 /** version / traffic class / flow label */ 96 PACK_STRUCT_FIELD(u32_t _v_tc_fl); 97 /** payload length */ 98 PACK_STRUCT_FIELD(u16_t _plen); 99 /** next header */ 100 PACK_STRUCT_FLD_8(u8_t _nexth); 101 /** hop limit */ 102 PACK_STRUCT_FLD_8(u8_t _hoplim); 103 /** source and destination IP addresses */ 104 PACK_STRUCT_FLD_S(ip6_addr_p_t src); 105 PACK_STRUCT_FLD_S(ip6_addr_p_t dest); 106 } PACK_STRUCT_STRUCT; 107 PACK_STRUCT_END 108 #ifdef PACK_STRUCT_USE_INCLUDES 109 # include "arch/epstruct.h" 110 #endif 111 112 /* Hop-by-hop router alert option. */ 113 #define IP6_HBH_HLEN 8 114 /* Hop-by-Hop header. */ 115 #define IP6_HBH_HALFHLEN 2 116 117 #define IP6_PAD1_OPTION 0 118 #define IP6_PADN_ALERT_OPTION 1 119 #define IP6_PADN_OPTION IP6_PADN_ALERT_OPTION 120 121 #define IP6_ROUTER_ALERT_OPTION 5 122 #define IP6_JUMBO_OPTION 194 123 #define IP6_ROUTER_ALERT_VALUE_MLD 0 124 125 #ifdef PACK_STRUCT_USE_INCLUDES 126 # include "arch/bpstruct.h" 127 #endif 128 PACK_STRUCT_BEGIN 129 struct ip6_opt_hdr { 130 /* router alert option type */ 131 PACK_STRUCT_FLD_8(u8_t _opt_type); 132 /* router alert option data len */ 133 PACK_STRUCT_FLD_8(u8_t _opt_dlen); 134 } PACK_STRUCT_STRUCT; 135 PACK_STRUCT_END 136 137 138 #ifdef PACK_STRUCT_USE_INCLUDES 139 # include "arch/epstruct.h" 140 #endif 141 #define IP6_OPT_HLEN 2 142 #define IP6_OPT_TYPE_ACTION(hdr) ((((hdr)->_opt_type) >> 6) & 0x3) 143 #define IP6_OPT_TYPE_CHANGE(hdr) ((((hdr)->_opt_type) >> 5) & 0x1) 144 #define IP6_OPT_TYPE(hdr) ((hdr)->_opt_type) 145 #define IP6_OPT_DLEN(hdr) ((hdr)->_opt_dlen) 146 147 #ifdef PACK_STRUCT_USE_INCLUDES 148 # include "arch/bpstruct.h" 149 #endif 150 PACK_STRUCT_BEGIN 151 struct ip6_hbh_hdr { 152 /* next header */ 153 PACK_STRUCT_FLD_8(u8_t _nexth); 154 /* header length */ 155 PACK_STRUCT_FLD_8(u8_t _hlen); 156 /* router alert option type */ 157 PACK_STRUCT_FLD_8(u8_t _ra_opt_type); 158 /* router alert option data len */ 159 PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen); 160 /* router alert option data */ 161 PACK_STRUCT_FIELD(u16_t _ra_opt_data); 162 /* PadN option type */ 163 PACK_STRUCT_FLD_8(u8_t _padn_opt_type); 164 /* PadN option data len */ 165 PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen); 166 } PACK_STRUCT_STRUCT; 167 PACK_STRUCT_END 168 #ifdef PACK_STRUCT_USE_INCLUDES 169 # include "arch/epstruct.h" 170 #endif 171 172 /* Destination header. */ 173 #define IP6_DEST_HLEN 2 174 175 #ifdef PACK_STRUCT_USE_INCLUDES 176 # include "arch/bpstruct.h" 177 #endif 178 PACK_STRUCT_BEGIN 179 struct ip6_dest_hdr { 180 /* next header */ 181 PACK_STRUCT_FLD_8(u8_t _nexth); 182 /* header length in 8-octet units */ 183 PACK_STRUCT_FLD_8(u8_t _hlen); 184 } PACK_STRUCT_STRUCT; 185 PACK_STRUCT_END 186 187 /* Fragment header. */ 188 #define IP6_FRAG_HLEN 8 189 #define IP6_FRAG_OFFSET_MASK 0xfff8 190 #define IP6_FRAG_MORE_FLAG 0x0001 191 #ifdef PACK_STRUCT_USE_INCLUDES 192 # include "arch/bpstruct.h" 193 #endif 194 PACK_STRUCT_BEGIN 195 struct ip6_frag_hdr { 196 /* next header */ 197 PACK_STRUCT_FLD_8(u8_t _nexth); 198 /* reserved */ 199 PACK_STRUCT_FLD_8(u8_t reserved); 200 /* fragment offset */ 201 PACK_STRUCT_FIELD(u16_t _fragment_offset); 202 /* fragmented packet identification */ 203 PACK_STRUCT_FIELD(u32_t _identification); 204 } PACK_STRUCT_STRUCT; 205 PACK_STRUCT_END 206 #ifdef PACK_STRUCT_USE_INCLUDES 207 # include "arch/epstruct.h" 208 #endif 209 210 #define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) 211 #define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) 212 #define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff) 213 #define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen)) 214 #define IP6H_NEXTH(hdr) ((hdr)->_nexth) 215 #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim) 216 217 #define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) 218 #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen) 219 #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) 220 #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) 221 222 223 #define IP6H_FRAG_MBIT(hdr) (lwip_ntohs((hdr)->_fragment_offset) & 0x1) 224 225 #if defined (__cplusplus) && __cplusplus 226 } 227 #endif 228 229 #endif /* LWIP_HDR_PROT_IP6_H */ 230 231