ROHC compression/decompression library
rohc_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Didier Barvaux
3  * Copyright 2017 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file rohc_internal.h
22  * @brief ROHC private common definitions and routines
23  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
24  * @author Didier Barvaux <didier@barvaux.org>
25  */
26 
27 #ifndef ROHC_INTERNAL_H
28 #define ROHC_INTERNAL_H
29 
30 #include <stdint.h>
31 
32 /**
33  * \mainpage
34  *
35  * <h2>Introduction</h2>
36  * <p>The <a href="https://rohc-lib.org/" title="Official website">ROHC library</a>
37  * provides an easy and robust way for applications to reduce their bandwidth
38  * usage on network links with limited capacity. Headers of network packets are
39  * compressed with the ROHC protocol and algorithms.</p>
40  * <p><a href="https://rohc-lib.org/support/wiki/doku.php?id=rohc-protocol"
41  * title="An introduction to the ROHC protocol">RObust Header Compression
42  * (ROHC)</a> is a set of standards defined by the <a href="http://www.ietf.org/"
43  * title="The IETF website">IETF</a>. The ROHC library is a free, opensource and
44  * efficient implementation of them.
45  * <a href="https://rohc-lib.org/support/wiki/doku.php?id=library-compliance-rfcs">Many
46  * features</a>are implemented.</p>
47  * <ul>
48  * <li><a href="https://rohc-lib.org/">Official website</a></li>
49  * <li><a href="https://github.com/didier-barvaux/rohc">Project page on
50  * GitHub</a></li>
51  * <li><a href="https://launchpad.net/rohc">Project page on Launchpad</a></li>
52  * <li><a href="mailto:rohc@lists.launchpad.net">Mailing list:
53  * rohc@lists.launchpad.net</a></li>
54  * <li><a href="https://lists.launchpad.net/rohc/">Mailing list archives</a></li>
55  * <li><a href="https://bugs.launchpad.net/rohc">Bugtracker</a></li>
56  * </ul>
57  *
58  * <h2>License</h2>
59  * <p>The project is licensed under LGPL2.1+.
60  * See the <a href="https://github.com/didier-barvaux/rohc/blob/master/COPYING">COPYING</a>
61  * and <a href="https://github.com/didier-barvaux/rohc/blob/master/AUTHORS.md">AUTHORS.md</a>
62  * files for more details.</p>
63  *
64  * <h2>Library</h2>
65  * <p>
66  * The sources are in the src subdirectory. The sources are separated into
67  * three sub-directories:
68  * <ul>
69  * <li>the common/ sub-directory contains the routines used for both the
70  * compression and the decompression processes,</li>
71  * <li>the comp/ sub-directory handles the compression process,</li>
72  * <li>the decomp/ sub-directory handles the decompression process.</li>
73  * </ul>
74  * </p>
75  * <p>See the <a href="https://github.com/didier-barvaux/rohc/blob/master/INSTALL.md">INSTALL.md file</a>
76  * to learn to build the libraries. See also the <a href="https://rohc-lib.org/support/wiki/">Wiki
77  * of the project</a>.</p>
78  *
79  * <h2>API documentation, tutorials and examples</h2>
80  * <p>The APIs for ROHC common, compression and decompression parts are available on
81  * separate pages:
82  * <ul>
83  * <li>\ref rohc</li>
84  * <li>\ref rohc_comp</li>
85  * <li>\ref rohc_decomp</li>
86  * </ul>
87  * </p>
88  * <p><a href="https://rohc-lib.org/presentation/getting-started/">Some</a>
89  * <a href="https://rohc-lib.org/support/wiki/doku.php?id=library-first-application">tutorials</a>
90  * are available on the website and wiki.</p>
91  * <p><a href="https://github.com/didier-barvaux/rohc/tree/master/examples">Some examples</a>
92  * are available in the examples/ sub-directory in the sources.</p>
93  *
94  * <h2>Tests</h2>
95  * <p>
96  * Several tests may be run to check the library behaviour. See the
97  * <a href="https://github.com/didier-barvaux/rohc/blob/master/INSTALL.md">INSTALL.md file</a>
98  * to learn how to use these tools.</p>
99  *
100  * <h2>References</h2>
101  * <dl style="padding-bottom: 1em;">
102  * <dt><a href="https://tools.ietf.org/html/rfc3095">RFC&nbsp;3095</a></dt>
103  * <dd>ROHC: Framework and four profiles: RTP, UDP, ESP, and uncompressed.</dd>
104  * <dt><a href="https://tools.ietf.org/html/rfc3096">RFC&nbsp;3096</a></dt>
105  * <dd>Requirements for robust IP/UDP/RTP header compression.</dd>
106  * <dt><a href="https://tools.ietf.org/html/rfc3241">RFC&nbsp;3241</a></dt>
107  * <dd>ROHC over PPP</dd>
108  * <dt><a href="https://tools.ietf.org/html/rfc3242">RFC&nbsp;3242</a></dt>
109  * <dd>ROHC: A Link-Layer Assisted Profile for IP/UDP/RTP</dd>
110  * <dt><a href="https://tools.ietf.org/html/rfc3243">RFC&nbsp;3243</a></dt>
111  * <dd>ROHC: Requirements and Assumptions for 0-byte IP/UDP/RTP Compression</dd>
112  * <dt><a href="https://tools.ietf.org/html/rfc3408">RFC&nbsp;3408</a></dt>
113  * <dd>ROHC: Zero-byte Support for R-mode in Extended Link-Layer Assisted ROHC Profile</dd>
114  * <dt><a href="https://tools.ietf.org/html/rfc3409">RFC&nbsp;3409</a></dt>
115  * <dd>ROHC: Lower Layer Guidelines for Robust RTP/UDP/IP Header Compression</dd>
116  * <dt><a href="https://tools.ietf.org/html/rfc3759">RFC&nbsp;3759</a></dt>
117  * <dd>ROHC: Terminology and Channel Mapping Examples</dd>
118  * <dt><a href="https://tools.ietf.org/html/rfc3816">RFC&nbsp;3816</a></dt>
119  * <dd>ROHC: Definitions of Managed Objects (SNMP MIB) for ROHC</dd>
120  * <dt><a href="https://tools.ietf.org/html/rfc3828">RFC&nbsp;3828</a></dt>
121  * <dd>The Lightweight User Datagram Protocol (UDP-Lite)</dd>
122  * <dt><a href="https://tools.ietf.org/html/rfc3843">RFC&nbsp;3843</a></dt>
123  * <dd>ROHC: A Compression Profile for IP.</dd>
124  * <dt><a href="https://tools.ietf.org/html/rfc4019">RFC&nbsp;4019</a></dt>
125  * <dd>ROHC: Profiles for User Datagram Protocol (UDP) Lite.</dd>
126  * <dt><a href="https://tools.ietf.org/html/rfc4163">RFC&nbsp;4163</a></dt>
127  * <dd>ROHC: Requirements on TCP/IP Header Compression</dd>
128  * <dt><a href="https://tools.ietf.org/html/rfc4224">RFC&nbsp;4224</a></dt>
129  * <dd>ROHC over Channels That Can Reorder Packets</dd>
130  * <dt><a href="https://tools.ietf.org/html/rfc4362">RFC&nbsp;4362</a></dt>
131  * <dd>ROHC: A Link-Layer Assisted Profile for IP/UDP/RTP</dd>
132  * <dt><a href="https://tools.ietf.org/html/rfc4995">RFC&nbsp;4995</a></dt>
133  * <dd>The RObust Header Compression (ROHC) Framework</dd>
134  * <dt><a href="https://tools.ietf.org/html/rfc4996">RFC&nbsp;4996</a></dt>
135  * <dd>ROHC: A Profile for TCP/IP (ROHC-TCP)</dd>
136  * <dt><a href="https://tools.ietf.org/html/rfc4997">RFC&nbsp;4997</a></dt>
137  * <dd>Formal Notation for RObust Header Compression (ROHC-FN)</dd>
138  * <dt><a href="https://tools.ietf.org/html/rfc5225">RFC&nbsp;5225</a></dt>
139  * <dd>ROHCv2: Profiles for RTP, UDP, IP, ESP and UDP-Lite</dt>
140  * <dt><a href="https://tools.ietf.org/html/rfc5795">RFC&nbsp;5795</a></dt>
141  * <dd>The RObust Header Compression (ROHC) Framework</dd>
142  * <dt><a href="https://tools.ietf.org/html/rfc5856">RFC&nbsp;5856</a></dt>
143  * <dd>ROHC: Integration of ROHC over IPsec Security Associations</dd>
144  * <dt><a href="https://tools.ietf.org/html/rfc5857">RFC&nbsp;5857</a></dt>
145  * <dd>ROHC: IKEv2 Extensions to Support ROHC over IPsec</dd>
146  * <dt><a href="https://tools.ietf.org/html/rfc5858">RFC&nbsp;5858</a></dt>
147  * <dd>ROHC: IPsec Extensions to Support ROHC over IPsec</dd>
148  * <dt><a href="https://tools.ietf.org/html/rfc6846">RFC&nbsp;6846</a></dt>
149  * <dd>ROHC: A Profile for TCP/IP (ROHC-TCP)</dd>
150  * <dt><a href="https://rohc-lib.org/">ROHC library</a></dt>
151  * <dd>The Open Source ROHC library described by the documentation you are
152  * currently reading.</dd>
153  * <dt><a href="http://rohc.sourceforge.net/">ROHC Linux</a></dt>
154  * <dd>A GPL-licensed implementation of ROHC over PPP for the 2.4 Linux kernel.
155  * The ROHC library started as a fork of this project.</dd>
156  * </dl>
157  */
158 
159 
160 #include "rohc.h"
161 
162 
163 /**
164  * @brief Be strict while parsing ROHC packet?
165  *
166  * Do we respect the robustness principle as stated in 'The Tao of IETF':
167  *
168  * Be conservative in what you send and liberal in what you accept
169  *
170  * Source: https://www.ietf.org/about/participate/tao/
171  *
172  * Being 'liberal in what you accept' is great for production environments.
173  * Being 'strict in what you accept' is great for dev & testing environments.
174  */
175 #define ROHC_RFC_STRICT_DECOMPRESSOR
176 /* uncomment the next line to enable strict parsing */
177 #undef ROHC_RFC_STRICT_DECOMPRESSOR
178 
179 
180 /** The maximal value for MRRU */
181 #define ROHC_MAX_MRRU 65535
182 
183 
184 /**
185  * @brief The padding field defined by the ROHC protocol
186  *
187  * See RFC 3095, ยง5.2:
188  * \verbatim
189 
190  Padding Octet
191 
192  0 1 2 3 4 5 6 7
193  +---+---+---+---+---+---+---+---+
194  | 1 1 1 0 0 0 0 0 |
195  +---+---+---+---+---+---+---+---+
196 
197 \endverbatim
198  */
199 #define ROHC_PADDING_BYTE 0xe0
200 
201 
202 /**
203  * @brief A number of bits required or retrieved
204  */
205 typedef uint8_t bits_nr_t;
206 
207 
208 /**
209  * @brief ROHC medium (CID characteristics)
210  */
212 {
213  /** The CID type: large or small */
215 
216  /// The maximum CID value
218 };
219 
220 
221 /**
222  * @brief The different chains used by the ROHCv1 TCP and ROHCv2 profiles
223  */
224 typedef enum
225 {
226  ROHC_CHAIN_STATIC = 0, /**< The TCP static chain */
227  ROHC_CHAIN_DYNAMIC = 1, /**< The TCP dynamic chain */
228  ROHC_CHAIN_REPLICATE = 2, /**< The TCP replicate chain */
229  ROHC_CHAIN_IRREGULAR = 3, /**< The TCP irregular chain */
230  ROHC_CHAIN_CO = 4, /**< Not a chain, but in CO packet */
231 
232 } rohc_chain_t;
233 
234 
235 /** The different IP-ID behaviors */
236 typedef enum
237 {
238  ROHC_IP_ID_BEHAVIOR_SEQ = 0, /**< IP-ID increases */
239  ROHC_IP_ID_BEHAVIOR_SEQ_SWAP = 1, /**< IP-ID increases in little endian */
240  ROHC_IP_ID_BEHAVIOR_RAND = 2, /**< IP-ID is random */
241  ROHC_IP_ID_BEHAVIOR_ZERO = 3, /**< IP-ID is constant zero */
243 
244 
245 
246 /************************************************************************
247  * Helper functions *
248  ************************************************************************/
249 
250 static inline char * rohc_ip_id_behavior_get_descr(const rohc_ip_id_behavior_t behavior)
251  __attribute__((warn_unused_result, const));
252 
253 
254 /**
255  * @brief Get a string that describes the given IP-ID behavior
256  *
257  * @param behavior The type of the option to get a description for
258  * @return The description of the option
259  */
260 static inline char * rohc_ip_id_behavior_get_descr(const rohc_ip_id_behavior_t behavior)
261 {
262  switch(behavior)
263  {
265  return "sequential";
267  return "sequential swapped";
269  return "random";
271  return "constant zero";
272  default:
273  return "unknown IP-ID behavior";
274  }
275 }
276 
277 
278 #endif
279 
Definition: rohc_internal.h:228
Definition: rohc_internal.h:226
rohc_cid_type_t
The different types of Context IDs (CID)
Definition: rohc.h:177
Definition: rohc_internal.h:239
Definition: rohc_internal.h:241
rohc_chain_t
The different chains used by the ROHCv1 TCP and ROHCv2 profiles.
Definition: rohc_internal.h:224
ROHC common definitions and routines.
rohc_cid_t max_cid
The maximum CID value.
Definition: rohc_internal.h:217
Definition: rohc_internal.h:227
static char * rohc_ip_id_behavior_get_descr(const rohc_ip_id_behavior_t behavior)
Get a string that describes the given IP-ID behavior.
Definition: rohc_internal.h:260
rohc_cid_type_t cid_type
Definition: rohc_internal.h:214
rohc_ip_id_behavior_t
Definition: rohc_internal.h:236
Definition: rohc_internal.h:240
uint8_t bits_nr_t
A number of bits required or retrieved.
Definition: rohc_internal.h:205
uint16_t rohc_cid_t
Definition: rohc.h:196
ROHC medium (CID characteristics)
Definition: rohc_internal.h:211
Definition: rohc_internal.h:230
Definition: rohc_internal.h:229
Definition: rohc_internal.h:238