ROHC compression/decompression library
tcp.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012,2013,2014 Didier Barvaux
3  * Copyright 2013 Viveris Technologies
4  * Copyright 2012 WBX
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file tcp.h
23  * @brief TCP header description.
24  * @author FWX <rohc_team@dialine.fr>
25  * @author Didier Barvaux <didier@barvaux.org>
26  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
27  */
28 
29 #ifndef ROHC_PROTOCOLS_TCP_H
30 #define ROHC_PROTOCOLS_TCP_H
31 
32 #include <stdint.h>
33 
34 #ifdef __KERNEL__
35 # include <endian.h>
36 #else
37 # include "config.h" /* for WORDS_BIGENDIAN */
38 #endif
39 
40 
41 /************************************************************************
42  * Uncompressed TCP base header *
43  ************************************************************************/
44 
45 /**
46  * @brief The TCP base header without options
47  *
48  * See RFC4996 page 72/73
49  */
50 struct tcphdr
51 {
52  uint16_t src_port;
53  uint16_t dst_port;
54  uint32_t seq_num;
55  uint32_t ack_num;
56 #if WORDS_BIGENDIAN == 1
57  uint8_t data_offset:4;
58  uint8_t res_flags:4;
59  uint8_t ecn_flags:2;
60  uint8_t urg_flag:1;
61  uint8_t ack_flag:1;
62  uint8_t psh_flag:1;
63  uint8_t rsf_flags:3;
64 #else
65  uint8_t res_flags:4;
66  uint8_t data_offset:4;
67  uint8_t rsf_flags:3;
68  uint8_t psh_flag:1;
69  uint8_t ack_flag:1;
70  uint8_t urg_flag:1;
71  uint8_t ecn_flags:2;
72 #endif
73  uint16_t window;
74  uint16_t checksum;
75  uint16_t urg_ptr;
76  uint8_t options[0]; /**< The beginning of the TCP options */
77 } __attribute__((packed));
78 
79 
80 /* The RSF flags */
81 #define RSF_RST_ONLY 0x04
82 #define RSF_SYN_ONLY 0x02
83 #define RSF_FIN_ONLY 0x01
84 #define RSF_NONE 0x00
85 
86 
87 
88 /************************************************************************
89  * Uncompressed TCP options *
90  ************************************************************************/
91 
92 /**
93  * @brief The maximum length of TCP options supported by the TCP protocol
94  *
95  * The TCP data offset is coded on 32-bit words on 4 bits, so the whole TCP
96  * header may be up to 15*4=60 bytes. The base TCP header is 20-byte long.
97  */
98 #define ROHC_TCP_OPTS_LEN_MAX_PROTO (15U * 4U - (uint8_t) sizeof(struct tcphdr))
99 
100 
101 /**
102  * @brief The maximum of TCP options supported by the TCP protocol
103  *
104  * One TCP header may contain up to 40 bytes of options, so it may contain
105  * up 40 1-byte options.
106  *
107  * @see ROHC_TCP_OPTS_MAX
108  */
109 #define ROHC_TCP_OPTS_MAX_PROTO ROHC_TCP_OPTS_LEN_MAX_PROTO
110 
111 
112 /** The different TCP options */
113 typedef enum
114 {
115  TCP_OPT_EOL = 0U, /**< The End of Option List (EOL) TCP option */
116  TCP_OPT_NOP = 1U, /**< The No OPeration (NOP) TCP option */
117  TCP_OPT_MSS = 2U, /**< The Maximum Segment Size (MSS) TCP option */
118 #define TCP_OLEN_MSS 4U
119  TCP_OPT_WS = 3U, /**< The Window Scale (WS) TCP option */
120 #define TCP_OLEN_WS 3U
121  TCP_OPT_SACK_PERM = 4U, /**< The SACK Permitted TCP option */
122 #define TCP_OLEN_SACK_PERM 2U
123  TCP_OPT_SACK = 5U, /**< The Selective ACKnowledgement (SACK) TCP option */
124  TCP_OPT_TS = 8U, /**< The TimeStamp (TS) TCP option */
125 #define TCP_OLEN_TS 10U
126  TCP_OPT_MAX = 255U /**< The maximum TCP option */
127 
129 
130 
131 /**
132  * @brief The Selective Acknowlegment TCP option
133  *
134  * See RFC2018 for TCP Selective Acknowledgement Options
135  * See RFC4996 page 66
136  */
137 typedef struct
138 {
139  uint32_t block_start;
140  uint32_t block_end;
141 } __attribute__((packed)) sack_block_t;
142 
143 
144 /** The maximum number of SACK blocks in the TCP SACK option */
145 #define TCP_SACK_BLOCKS_MAX_NR 4U
146 
147 
148 /** The Timestamp option of the TCP header */
150 {
151  uint32_t ts; /**< The timestamp value */
152  uint32_t ts_reply; /**< The timestamp echo reply value */
153 } __attribute__((packed));
154 
155 
156 
157 /************************************************************************
158  * Helper functions *
159  ************************************************************************/
160 
161 static inline char * tcp_opt_get_descr(const uint8_t opt_type)
162  __attribute__((warn_unused_result, const));
163 
164 
165 /**
166  * @brief Get a string that describes the given option type
167  *
168  * @param opt_type The type of the option to get a description for
169  * @return The description of the option
170  */
171 static inline char * tcp_opt_get_descr(const uint8_t opt_type)
172 {
173  switch(opt_type)
174  {
175  case TCP_OPT_EOL:
176  return "EOL";
177  case TCP_OPT_NOP:
178  return "NOP";
179  case TCP_OPT_MSS:
180  return "MSS";
181  case TCP_OPT_WS:
182  return "Window Scale";
183  case TCP_OPT_SACK_PERM:
184  return "SACK permitted";
185  case TCP_OPT_SACK:
186  return "SACK";
187  case TCP_OPT_TS:
188  return "Timestamp";
189  default:
190  return "generic";
191  }
192 }
193 
194 #endif /* ROHC_PROTOCOLS_TCP_H */
195 
uint8_t ecn_flags
Definition: tcp.h:71
uint32_t ts
Definition: tcp.h:151
uint16_t window
Definition: tcp.h:73
The Selective Acknowlegment TCP option.
Definition: tcp.h:137
Definition: tcp.h:115
uint32_t block_end
Definition: tcp.h:140
Definition: tcp.h:117
uint16_t dst_port
Definition: tcp.h:53
uint8_t urg_flag
Definition: tcp.h:70
uint16_t src_port
Definition: tcp.h:52
uint16_t urg_ptr
Definition: tcp.h:75
rohc_tcp_option_type_t
Definition: tcp.h:113
uint16_t checksum
Definition: tcp.h:74
uint32_t block_start
Definition: tcp.h:139
uint8_t options[0]
Definition: tcp.h:76
static char * tcp_opt_get_descr(const uint8_t opt_type)
Get a string that describes the given option type.
Definition: tcp.h:171
uint8_t res_flags
Definition: tcp.h:65
uint8_t data_offset
Definition: tcp.h:66
The TCP base header without options.
Definition: tcp.h:50
uint32_t ack_num
Definition: tcp.h:55
uint32_t seq_num
Definition: tcp.h:54
Definition: tcp.h:124
uint8_t rsf_flags
Definition: tcp.h:67
Definition: tcp.h:126
Definition: tcp.h:123
Definition: tcp.h:116
uint8_t psh_flag
Definition: tcp.h:68
Definition: tcp.h:119
Definition: tcp.h:149
uint8_t ack_flag
Definition: tcp.h:69
uint32_t ts_reply
Definition: tcp.h:152
Definition: tcp.h:121