00001 /* 00002 * Copyright 2012,2013,2014 Didier Barvaux 00003 * Copyright 2013,2014 Viveris Technologies 00004 * Copyright 2012 WBX 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /** 00022 * @file d_tcp_defines.h 00023 * @brief Main definitions for the TCP decompression profile 00024 * @author FWX <rohc_team@dialine.fr> 00025 * @author Didier Barvaux <didier@barvaux.org> 00026 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00027 */ 00028 00029 #ifndef ROHC_DECOMP_TCP_DEFINES_H 00030 #define ROHC_DECOMP_TCP_DEFINES_H 00031 00032 #include "ip.h" 00033 #include "interval.h" 00034 #include "protocols/tcp.h" 00035 #include "schemes/decomp_wlsb.h" 00036 #include "schemes/tcp_ts.h" 00037 #include "schemes/tcp_sack.h" 00038 00039 #include <stdint.h> 00040 00041 /** 00042 * @brief Define the IPv6 option context for Destination, Hop-by-Hop 00043 * and Routing option 00044 */ 00045 typedef struct __attribute__((packed)) 00046 { 00047 size_t data_len; 00048 uint8_t data[IPV6_OPT_CTXT_LEN_MAX]; 00049 00050 } ipv6_generic_option_context_t; 00051 00052 00053 /** 00054 * @brief Define the IPv6 option context for GRE option 00055 */ 00056 typedef struct __attribute__((packed)) ipv6_gre_option_context 00057 { 00058 uint8_t c_flag:1; 00059 uint8_t k_flag:1; 00060 uint8_t s_flag:1; 00061 uint8_t protocol:1; 00062 uint8_t padding:4; 00063 00064 uint32_t key; // if k_flag set 00065 uint32_t sequence_number; // if s_flag set 00066 00067 } ipv6_gre_option_context_t; 00068 00069 00070 /** 00071 * @brief Define the IPv6 option context for MIME option 00072 */ 00073 typedef struct __attribute__((packed)) ipv6_mime_option_context 00074 { 00075 uint8_t s_bit:1; 00076 uint8_t res_bits:7; 00077 uint32_t orig_dest; 00078 uint32_t orig_src; // if s_bit set 00079 00080 } ipv6_mime_option_context_t; 00081 00082 00083 /** 00084 * @brief Define the IPv6 option context for AH option 00085 */ 00086 typedef struct __attribute__((packed)) ipv6_ah_option_context 00087 { 00088 uint32_t spi; 00089 uint32_t sequence_number; 00090 uint32_t auth_data[1]; 00091 } ipv6_ah_option_context_t; 00092 00093 00094 /** The decompression context for one IP extension header */ 00095 typedef struct 00096 { 00097 size_t len; /**< The length (in bytes) of the extension header */ 00098 uint8_t proto; /**< The protocol of the extension header */ 00099 uint8_t nh_proto; /**< The protocol of the next header */ 00100 00101 union 00102 { 00103 ipv6_generic_option_context_t generic; /**< IPv6 generic extension header */ 00104 ipv6_gre_option_context_t gre; /**< IPv6 GRE extension header */ 00105 ipv6_mime_option_context_t mime; /**< IPv6 MIME extension header */ 00106 ipv6_ah_option_context_t ah; /**< IPv6 AH extension header */ 00107 }; 00108 00109 } ip_option_context_t; 00110 00111 00112 /** 00113 * @brief Define the common IP header context to IPv4 and IPv6. 00114 */ 00115 typedef struct __attribute__((packed)) ipvx_context 00116 { 00117 uint8_t version:4; 00118 uint8_t unused:4; 00119 00120 uint8_t dscp:6; 00121 uint8_t ip_ecn_flags:2; 00122 00123 uint8_t next_header; 00124 00125 uint8_t ttl_hopl; 00126 00127 uint8_t ip_id_behavior; 00128 00129 } ipvx_context_t; 00130 00131 00132 /** 00133 * @brief Define the IPv4 header context. 00134 */ 00135 typedef struct __attribute__((packed)) ipv4_context 00136 { 00137 uint8_t version:4; 00138 uint8_t df:1; 00139 uint8_t unused:3; 00140 00141 uint8_t dscp:6; 00142 uint8_t ip_ecn_flags:2; 00143 00144 uint8_t protocol; 00145 00146 uint8_t ttl_hopl; 00147 00148 uint8_t ip_id_behavior; 00149 uint16_t ip_id; 00150 00151 uint32_t src_addr; 00152 uint32_t dst_addr; 00153 00154 } ipv4_context_t; 00155 00156 00157 /** 00158 * @brief Define the IPv6 header context. 00159 */ 00160 typedef struct __attribute__((packed)) ipv6_context 00161 { 00162 uint8_t version:4; 00163 uint8_t unused:4; 00164 00165 uint8_t dscp:6; 00166 uint8_t ip_ecn_flags:2; 00167 00168 uint8_t next_header; 00169 00170 uint8_t ttl_hopl; 00171 00172 uint8_t ip_id_behavior; 00173 00174 uint32_t flow_label:20; /**< IPv6 Flow Label */ 00175 00176 uint32_t src_addr[4]; 00177 uint32_t dest_addr[4]; 00178 00179 } ipv6_context_t; 00180 00181 00182 /** 00183 * @brief Define union of IP contexts 00184 */ 00185 typedef struct 00186 { 00187 ip_version version; 00188 union 00189 { 00190 ipvx_context_t vx; 00191 ipv4_context_t v4; 00192 ipv6_context_t v6; 00193 } ctxt; 00194 00195 size_t opts_nr; 00196 size_t opts_len; 00197 ip_option_context_t opts[ROHC_TCP_MAX_IP_EXT_HDRS]; 00198 00199 } ip_context_t; 00200 00201 00202 /** The decompression context for one TCP option */ 00203 struct d_tcp_opt_ctxt /* TODO: doxygen */ 00204 { 00205 bool used; 00206 uint8_t type; 00207 union 00208 { 00209 struct 00210 { 00211 bool is_static; 00212 uint8_t len; 00213 } eol; 00214 struct 00215 { 00216 bool is_static; 00217 uint16_t value; 00218 } mss; 00219 struct 00220 { 00221 bool is_static; 00222 uint8_t value; 00223 } ws; 00224 struct 00225 { 00226 struct rohc_lsb_field32 req; /**< The context for the TS request field */ 00227 struct rohc_lsb_field32 rep; /**< The context for the TS reply field */ 00228 } ts; 00229 struct d_tcp_opt_sack sack; /* TODO: ptr inside is not needed */ 00230 struct 00231 { 00232 enum 00233 { 00234 TCP_GENERIC_OPT_STATIC, 00235 TCP_GENERIC_OPT_STABLE, 00236 TCP_GENERIC_OPT_FULL, 00237 } type; 00238 uint8_t load_len; 00239 #define ROHC_TCP_OPT_HDR_LEN 2U 00240 #define ROHC_TCP_OPT_MAX_LEN 0xffU 00241 #define ROHC_TCP_OPT_GENERIC_DATA_MAX_LEN \ 00242 (ROHC_TCP_OPT_MAX_LEN - ROHC_TCP_OPT_HDR_LEN) 00243 uint8_t load[ROHC_TCP_OPT_GENERIC_DATA_MAX_LEN]; 00244 } generic; 00245 } data; 00246 }; 00247 00248 00249 /** The decompression context for TCP options */ 00250 struct d_tcp_opts_ctxt 00251 { 00252 /** The number of options in the list of TCP options */ 00253 size_t nr; 00254 00255 /** The structure of the list of TCP options */ 00256 uint8_t structure[ROHC_TCP_OPTS_MAX]; 00257 /** Whether the TCP options are expected in the dynamic part? */ 00258 bool expected_dynamic[ROHC_TCP_OPTS_MAX]; 00259 /** The TCP options that were found or not */ 00260 bool found[ROHC_TCP_OPTS_MAX]; 00261 00262 /** The bits of TCP options extracted from the dynamic chain, the tail of 00263 * co_common/seq_8/rnd_8 packets, or the irregular chain */ 00264 struct d_tcp_opt_ctxt bits[MAX_TCP_OPTION_INDEX + 1]; 00265 }; 00266 00267 00268 /** Define the TCP part of the decompression profile context */ 00269 struct d_tcp_context 00270 { 00271 /** The LSB decoding context of MSN */ 00272 struct rohc_lsb_decode *msn_lsb_ctxt; 00273 00274 /** The LSB decoding context of innermost IP-ID */ 00275 struct rohc_lsb_decode *ip_id_lsb_ctxt; 00276 /** The LSB decoding context of innermost TTL/HL */ 00277 struct rohc_lsb_decode *ttl_hl_lsb_ctxt; 00278 00279 /* TCP static part */ 00280 uint16_t tcp_src_port; /**< The TCP source port */ 00281 uint16_t tcp_dst_port; /**< The TCP dest port */ 00282 00283 uint32_t seq_num_residue; 00284 struct rohc_lsb_decode *seq_lsb_ctxt; 00285 struct rohc_lsb_decode *seq_scaled_lsb_ctxt; 00286 00287 uint16_t ack_stride; 00288 uint16_t ack_num_residue; 00289 struct rohc_lsb_decode *ack_lsb_ctxt; 00290 struct rohc_lsb_decode *ack_scaled_lsb_ctxt; 00291 00292 /* TCP flags */ 00293 uint8_t res_flags:4; /**< The TCP reserved flags */ 00294 bool ecn_used; /**< Whether ECN flag is used */ 00295 uint8_t ecn_flags:2; /**< The TCP ECN flags */ 00296 bool urg_flag; /**< The TCP URG flag */ 00297 bool ack_flag; /**< The TCP ACK flag */ 00298 uint8_t rsf_flags:3; /**< The TCP RSF flag */ 00299 00300 /** The LSB decoding context of TCP window */ 00301 struct rohc_lsb_decode *window_lsb_ctxt; 00302 00303 /** The URG pointer */ 00304 uint16_t urg_ptr; 00305 00306 /** The decoded values of TCP options */ 00307 struct d_tcp_opts_ctxt tcp_opts; 00308 /* TCP TS option */ 00309 struct rohc_lsb_decode *opt_ts_req_lsb_ctxt; 00310 struct rohc_lsb_decode *opt_ts_rep_lsb_ctxt; 00311 /* TCP SACK option */ 00312 struct d_tcp_opt_sack opt_sack_blocks; /**< The TCP SACK blocks */ 00313 00314 size_t ip_contexts_nr; 00315 ip_context_t ip_contexts[ROHC_TCP_MAX_IP_HDRS]; 00316 }; 00317 00318 00319 /** The outer or inner IP bits extracted from ROHC headers */ 00320 struct rohc_tcp_extr_ip_bits 00321 { 00322 uint8_t version:4; /**< The version bits found in static chain of IR header */ 00323 00324 uint8_t dscp_bits:6; /**< The IP DSCP bits */ 00325 size_t dscp_bits_nr; /**< The number of IP DSCP bits */ 00326 uint8_t ecn_flags_bits:2; /**< The IP ECN flag bits */ 00327 size_t ecn_flags_bits_nr; /**< The number of IP ECN flag bits */ 00328 00329 uint8_t id_behavior:2; /**< The IP-ID behavior bits */ 00330 size_t id_behavior_nr; /**< The number of IP-ID behavior bits */ 00331 struct rohc_lsb_field16 id; /**< The IP-ID bits */ 00332 00333 uint8_t df:1; /**< The DF bits found in dynamic chain of IR/IR-DYN 00334 header or in extension header */ 00335 size_t df_nr; /**< The number of DF bits found */ 00336 00337 struct rohc_lsb_field8 ttl_hl; /**< The IP TTL/HL bits */ 00338 uint8_t proto; /**< The protocol/next header bits found static chain 00339 of IR header or in extension header */ 00340 size_t proto_nr; /**< The number of protocol/next header bits */ 00341 00342 uint32_t flowid:20; /**< The IPv6 flow ID bits found in static chain of 00343 IR header */ 00344 size_t flowid_nr; /**< The number of flow label bits */ 00345 00346 uint8_t saddr[16]; /**< The source address bits found in static chain of 00347 IR header */ 00348 size_t saddr_nr; /**< The number of source address bits */ 00349 00350 uint8_t daddr[16]; /**< The destination address bits found in static 00351 chain of IR header */ 00352 size_t daddr_nr; /**< The number of source address bits */ 00353 00354 /** The parsed IP extension headers */ 00355 ip_option_context_t opts[ROHC_TCP_MAX_IP_EXT_HDRS]; 00356 size_t opts_nr; /**< The number of parsed IP extension headers */ 00357 size_t opts_len; /**< The length of the parsed IP extension headers */ 00358 }; 00359 00360 00361 /** The bits extracted from ROHC TCP header */ 00362 struct rohc_tcp_extr_bits 00363 { 00364 /** The extracted bits related to the IP headers */ 00365 struct rohc_tcp_extr_ip_bits ip[ROHC_TCP_MAX_IP_HDRS]; 00366 size_t ip_nr; /**< The number of parsed IP headers */ 00367 00368 /** The extracted bits of the Master Sequence Number (MSN) of the packet */ 00369 struct rohc_lsb_field16 msn; 00370 00371 /** Whether TTL/HL of outer IP headers is included in the dynamic chain */ 00372 bool ttl_dyn_chain_flag; 00373 /** Whether TTL/HL of outer IP headers is included in the irregular chain */ 00374 bool ttl_irreg_chain_flag; 00375 00376 /* TCP header */ 00377 uint16_t src_port; /**< The TCP source port bits found in static chain */ 00378 size_t src_port_nr; /**< The number of TCP source port bits */ 00379 uint16_t dst_port; /**< The TCP destination port bits in static chain */ 00380 size_t dst_port_nr; /**< The number of TCP destination port bits */ 00381 struct rohc_lsb_field32 seq; /**< The TCP sequence number bits */ 00382 struct rohc_lsb_field32 seq_scaled; /**< The TCP scaled sequence number bits */ 00383 struct rohc_lsb_field32 ack; /**< The TCP acknowledgment number bits */ 00384 struct rohc_lsb_field16 ack_stride; /**< The TCP ACK stride bits */ 00385 struct rohc_lsb_field32 ack_scaled; /**< The TCP scaled ACK number bits */ 00386 uint8_t ecn_used_bits; /**< The TCP ECN used flag bits */ 00387 size_t ecn_used_bits_nr; /**< The number of ECN used flag bits */ 00388 uint8_t res_flags_bits; /**< The TCP reserved flag bits */ 00389 size_t res_flags_bits_nr; /**< The number of TCP reserved flag bits */ 00390 uint8_t ecn_flags_bits; /**< The TCP ECN flag bits */ 00391 size_t ecn_flags_bits_nr; /**< The number of TCP ECN flag bits */ 00392 uint8_t urg_flag_bits; /**< The TCP URG flag bits */ 00393 size_t urg_flag_bits_nr; /**< The number of TCP URG flag bits */ 00394 uint8_t ack_flag_bits; /**< The TCP ACK flag bits */ 00395 size_t ack_flag_bits_nr; /**< The number of TCP ACK flag bits */ 00396 uint8_t psh_flag_bits; /**< The TCP PSH flag bits */ 00397 size_t psh_flag_bits_nr; /**< The number of TCP PSG flag bits */ 00398 uint8_t rsf_flags_bits; /**< The TCP RSF flag bits */ 00399 size_t rsf_flags_bits_nr; /**< The number of TCP RSF flag bits */ 00400 struct rohc_lsb_field16 window; /**< The TCP window bits */ 00401 uint16_t tcp_check; /**< The TCP checksum bits found in dynamic chain of 00402 IR/IR-DYN header or in irregular chain of CO header */ 00403 struct rohc_lsb_field16 urg_ptr; /**< The TCP Urgent pointer bits */ 00404 00405 /** The bits of TCP options extracted from the dynamic chain, the tail of 00406 * co_common/seq_8/rnd_8 packets, or the irregular chain */ 00407 struct d_tcp_opts_ctxt tcp_opts; 00408 }; 00409 00410 00411 /** The IP values decoded from the extracted ROHC bits */ 00412 struct rohc_tcp_decoded_ip_values 00413 { 00414 uint8_t version:4; /**< The decoded version field */ 00415 uint8_t ecn_flags:2; /**< The decoded ECN flags */ 00416 uint8_t dscp:6; /**< The decoded DSCP field */ 00417 tcp_ip_id_behavior_t id_behavior; /**< The decoded IP-ID behavior (Ipv4 only) */ 00418 uint16_t id; /**< The decoded IP-ID field (IPv4 only) */ 00419 uint8_t df:1; /**< The decoded DF field (IPv4 only) */ 00420 uint8_t ttl; /**< The decoded TTL/HL field */ 00421 uint8_t proto; /**< The decoded protocol/NH field */ 00422 uint8_t nbo:1; /**< The decoded NBO field (IPv4 only) */ 00423 uint8_t rnd:1; /**< The decoded RND field (IPv4 only) */ 00424 uint8_t sid:1; /**< The decoded SID field (IPv4 only) */ 00425 uint32_t flowid:20; /**< The decoded flow ID field (IPv6 only) */ 00426 uint8_t saddr[16]; /**< The decoded source address field */ 00427 uint8_t daddr[16]; /**< The decoded destination address field */ 00428 00429 /** The decoded IP extension headers */ 00430 ip_option_context_t opts[ROHC_TCP_MAX_IP_EXT_HDRS]; 00431 size_t opts_nr; /**< The number of decoded IP extension headers */ 00432 size_t opts_len; /**< The length of the decoded IP extension headers */ 00433 }; 00434 00435 00436 /** The values decoded from the bits extracted from ROHC TCP header */ 00437 struct rohc_tcp_decoded_values 00438 { 00439 /** The decoded values related to the IP headers */ 00440 struct rohc_tcp_decoded_ip_values ip[ROHC_TCP_MAX_IP_HDRS]; 00441 size_t ip_nr; /**< The number of the decoded IP headers */ 00442 00443 /** The Master Sequence Number (MSN) of the packet */ 00444 uint16_t msn; 00445 00446 /** Whether TTL/HL of outer IP headers is included in the dynamic chain */ 00447 bool ttl_dyn_chain_flag; 00448 /** Whether TTL/HL of outer IP headers is included in the irregular chain */ 00449 bool ttl_irreg_chain_flag; 00450 00451 /* TCP source & destination ports */ 00452 uint16_t src_port; /**< The TCP source port */ 00453 uint16_t dst_port; /**< The TCP destination port */ 00454 00455 /* TCP sequence & acknowledgment numbers */ 00456 uint32_t seq_num; /**< The TCP sequence number */ 00457 uint32_t seq_num_scaled; /**< The scaled TCP sequence number */ 00458 uint32_t seq_num_residue; /**< The residue of the scaled TCP sequence number */ 00459 uint32_t ack_num; /**< The TCP acknowledgment number */ 00460 uint32_t ack_num_scaled; /**< The scaled TCP acknowledgment number */ 00461 uint16_t ack_num_residue; /**< The residue of the scaled TCP ACK number */ 00462 uint16_t ack_stride; /**< The ACK stride */ 00463 00464 /* TCP flags */ 00465 bool ecn_used; /**< Whether the TCP ECN flags are used */ 00466 uint8_t res_flags:4; /**< The TCP reserved flags */ 00467 uint8_t ecn_flags:2; /**< The TCP ECN flags */ 00468 bool urg_flag; /**< The TCP URG flag */ 00469 bool ack_flag; /**< The TCP ACK flag */ 00470 bool psh_flag; /**< The TCP PSH flag */ 00471 uint8_t rsf_flags:3; /**< The TCP RSF flags */ 00472 00473 /* TCP window, checksum and Urgent pointer */ 00474 uint16_t window; /**< The TCP window */ 00475 uint16_t tcp_check; /**< The TCP checksum */ 00476 uint16_t urg_ptr; /**< The TCP Urgent pointer */ 00477 00478 /** The decoded values of TCP options */ 00479 struct d_tcp_opts_ctxt tcp_opts; 00480 /* TCP TS option */ 00481 uint32_t opt_ts_req; /**< The echo request value of the TCP TS option */ 00482 uint32_t opt_ts_rep; /**< The echo reply value of the TCP TS option */ 00483 /* TCP SACK option */ 00484 struct d_tcp_opt_sack opt_sack_blocks; /**< The TCP SACK blocks */ 00485 }; 00486 00487 #endif /* ROHC_DECOMP_TCP_DEFINES_H */ 00488
1.6.1