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 /**
113  * @brief The maximum of TCP options supported by the TCP profile
114  *
115  * One TCP header may contain up to 40 bytes of options, so it may contain
116  * up 40 1-byte options, so the ROHC (de)compressors should expect such TCP
117  * packets. However the m field in the compressed list of TCP options (see
118  * RFC 6846, section 6.3.3 for more details) cannot be larger than 15, so
119  * restrict the number of TCP options that value. One TCP packet with more
120  * than 15 TCP options will be compressed with the IP-only profile.
121  *
122  * @see ROHC_TCP_OPTS_MAX_PROTO
123  */
124 #define ROHC_TCP_OPTS_MAX 15U
125 
126 
127 /** The length of the header of one TCP option */
128 #define ROHC_TCP_OPT_HDR_LEN 2U
129 
130 
131 /** The maximum length of TCP options supported by the TCP protocol */
132 #define ROHC_TCP_OPT_MAX_LEN_PROTO 0xffU
133 
134 
135 /** The different TCP options */
136 typedef enum
137 {
138  TCP_OPT_EOL = 0U, /**< The End of Option List (EOL) TCP option */
139  TCP_OPT_NOP = 1U, /**< The No OPeration (NOP) TCP option */
140  TCP_OPT_MSS = 2U, /**< The Maximum Segment Size (MSS) TCP option */
141 #define TCP_OLEN_MSS 4U
142  TCP_OPT_WS = 3U, /**< The Window Scale (WS) TCP option */
143 #define TCP_OLEN_WS 3U
144  TCP_OPT_SACK_PERM = 4U, /**< The SACK Permitted TCP option */
145 #define TCP_OLEN_SACK_PERM 2U
146  TCP_OPT_SACK = 5U, /**< The Selective ACKnowledgement (SACK) TCP option */
147  TCP_OPT_TS = 8U, /**< The TimeStamp (TS) TCP option */
148 #define TCP_OLEN_TS 10U
149  TCP_OPT_MAX = 255U /**< The maximum TCP option */
150 
152 
153 
154 /**
155  * @brief The Selective Acknowlegment TCP option
156  *
157  * See RFC2018 for TCP Selective Acknowledgement Options
158  * See RFC4996 page 66
159  */
160 typedef struct
161 {
162  uint32_t block_start;
163  uint32_t block_end;
164 } __attribute__((packed)) sack_block_t;
165 
166 
167 /** The maximum number of SACK blocks in the TCP SACK option */
168 #define TCP_SACK_BLOCKS_MAX_NR 4U
169 
170 
171 /** The Timestamp option of the TCP header */
173 {
174  uint32_t ts; /**< The timestamp value */
175  uint32_t ts_reply; /**< The timestamp echo reply value */
176 } __attribute__((packed));
177 
178 
179 
180 /************************************************************************
181  * Helper functions *
182  ************************************************************************/
183 
184 static inline char * tcp_opt_get_descr(const uint8_t opt_type)
185  __attribute__((warn_unused_result, const));
186 
187 
188 /**
189  * @brief Get a string that describes the given option type
190  *
191  * @param opt_type The type of the option to get a description for
192  * @return The description of the option
193  */
194 static inline char * tcp_opt_get_descr(const uint8_t opt_type)
195 {
196  switch(opt_type)
197  {
198  case TCP_OPT_EOL:
199  return "EOL";
200  case TCP_OPT_NOP:
201  return "NOP";
202  case TCP_OPT_MSS:
203  return "MSS";
204  case TCP_OPT_WS:
205  return "Window Scale";
206  case TCP_OPT_SACK_PERM:
207  return "SACK permitted";
208  case TCP_OPT_SACK:
209  return "SACK";
210  case TCP_OPT_TS:
211  return "Timestamp";
212  default:
213  return "generic";
214  }
215 }
216 
217 #endif /* ROHC_PROTOCOLS_TCP_H */
218 
uint8_t ecn_flags
Definition: tcp.h:71
uint32_t ts
Definition: tcp.h:174
uint16_t window
Definition: tcp.h:73
The Selective Acknowlegment TCP option.
Definition: tcp.h:160
Definition: tcp.h:138
uint32_t block_end
Definition: tcp.h:163
Definition: tcp.h:140
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:136
uint16_t checksum
Definition: tcp.h:74
uint32_t block_start
Definition: tcp.h:162
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:194
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:147
uint8_t rsf_flags
Definition: tcp.h:67
Definition: tcp.h:149
Definition: tcp.h:146
Definition: tcp.h:139
uint8_t psh_flag
Definition: tcp.h:68
Definition: tcp.h:142
Definition: tcp.h:172
uint8_t ack_flag
Definition: tcp.h:69
uint32_t ts_reply
Definition: tcp.h:175
Definition: tcp.h:144