ROHC compression/decompression library
Data Structures | Macros | Functions | Variables
c_tcp_opts_list.c File Reference

Handle the list of TCP options for the TCP compression profile. More...

#include "c_tcp_opts_list.h"
#include "schemes/tcp_ts.h"
#include "schemes/tcp_sack.h"
#include <string.h>
Include dependency graph for c_tcp_opts_list.c:

Data Structures

struct  c_tcp_opt
 

Macros

#define TCP_LIST_ITEM_MAP_LEN   16U
 

Functions

static bool c_tcp_opt_get_type_len (const uint8_t *const opts_data, const size_t opts_len, uint8_t *const opt_type, uint8_t *const opt_len)
 Get the type and length of the next TCP option. More...
 
static bool c_tcp_opt_changed (const struct c_tcp_opts_ctxt *const opts_ctxt, const uint8_t opt_idx, const uint8_t *const pkt_opt, const size_t pkt_opt_len)
 Does the TCP option changed since last packets? More...
 
static void c_tcp_opt_record (struct c_tcp_opts_ctxt *const opts_ctxt, const uint8_t opt_idx, const uint8_t *const pkt_opt, const size_t pkt_opt_len)
 Record the TCP option in context. More...
 
static void c_tcp_opt_trace (const struct rohc_comp_ctxt *const context, const uint8_t opt_type, const uint8_t *const opt_data, const size_t opt_len)
 Print a trace for the given TCP option. More...
 
static uint8_t c_tcp_get_opt_index (const struct rohc_comp_ctxt *const context, struct c_tcp_opts_ctxt *const opts_ctxt, const uint8_t opt_type, const bool indexes_in_use[MAX_TCP_OPTION_INDEX+1])
 Determine the index of the TCP option. More...
 
static int c_tcp_opt_compute_ps (const uint8_t idx_max)
 Determine PS for the compressed list of TCP options. More...
 
static size_t c_tcp_opt_compute_xi_len (const int ps, const size_t m)
 Determine the length of XI indexes for the list of TCP options. More...
 
static size_t c_tcp_opt_write_xi (const struct rohc_comp_ctxt *const context, uint8_t *const comp_opts, const int ps, const size_t opt_pos, const uint8_t opt_idx, const bool item_needed)
 Write the XI field for a TCP option. More...
 
bool c_tcp_is_list_item_needed (const struct rohc_comp_ctxt *const context, const bool is_dynamic_chain, const uint8_t opt_idx, const uint8_t opt_type, const uint8_t opt_len, const uint8_t *const opt, const struct c_tcp_opts_ctxt *const opts_ctxt)
 Shall the list item be transmitted or not? More...
 
static int c_tcp_build_nop_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP NOP option. More...
 
static int c_tcp_build_eol_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP EOL option. More...
 
static int c_tcp_build_mss_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP MSS option. More...
 
static int c_tcp_build_ws_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP WS option. More...
 
static int c_tcp_build_ts_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP TS option. More...
 
static int c_tcp_build_sack_perm_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP SACK Permitted option. More...
 
static int c_tcp_build_sack_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP SACK option. More...
 
static int c_tcp_build_generic_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint8_t *const uncomp_opt, const uint8_t uncomp_opt_len, uint8_t *const comp_opt, const size_t comp_opt_max_len)
 Build the list item for the TCP generic option. More...
 
bool rohc_comp_tcp_are_options_acceptable (const struct rohc_comp *const comp, const uint8_t *const opts, const size_t data_offset)
 Whether TCP options are acceptable for TCP profile or not. More...
 
bool tcp_detect_options_changes (struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, struct c_tcp_opts_ctxt *const opts_ctxt, size_t *const opts_len)
 Parse the uncompressed TCP options for changes. More...
 
int c_tcp_code_tcp_opts_list_item (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint16_t msn, const bool is_dynamic_chain, struct c_tcp_opts_ctxt *const opts_ctxt, uint8_t *const comp_opts, const size_t comp_opts_max_len)
 Build the list of TCP options items. More...
 
int c_tcp_code_tcp_opts_irreg (const struct rohc_comp_ctxt *const context, const struct tcphdr *const tcp, const uint16_t msn, struct c_tcp_opts_ctxt *const opts_ctxt, uint8_t *const comp_opts, const size_t comp_opts_max_len)
 Build the list of TCP options for the irregular chain. More...
 

Variables

static struct c_tcp_opt c_tcp_opts [MAX_TCP_OPTION_INDEX+1]
 
static int c_tcp_type2index [TCP_LIST_ITEM_MAP_LEN]
 Table of TCP option index, from option Id. More...
 

Detailed Description

Handle the list of TCP options for the TCP compression profile.

Author
FWX rohc_.nosp@m.team.nosp@m.@dial.nosp@m.ine..nosp@m.fr
Didier Barvaux didie.nosp@m.r@ba.nosp@m.rvaux.nosp@m..org
Didier Barvaux didie.nosp@m.r.ba.nosp@m.rvaux.nosp@m.@tou.nosp@m.louse.nosp@m..viv.nosp@m.eris..nosp@m.com

Macro Definition Documentation

#define TCP_LIST_ITEM_MAP_LEN   16U

The length of the table mapping for TCP options

Function Documentation

static int c_tcp_build_eol_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP EOL option.

   pad_len =:= compressed_value(8, nbits-8) [ 8 ];
Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_generic_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP generic option.

   type          =:= irregular(8)      [ 8 ];
   option_static =:= one_bit_choice    [ 1 ];
   length_lsb    =:= irregular(7)      [ 7 ];
   contents      =:=
     irregular(length_lsb.UVALUE*8-16) [ length_lsb.UVALUE*8-16 ];
Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_mss_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP MSS option.

   mss =:= irregular(16) [ 16 ];
Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_nop_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP NOP option.

Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_sack_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP SACK option.

See RFC4996 page 67.

Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_sack_perm_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP SACK Permitted option.

Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_ts_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP TS option.

   tsval  =:= irregular(32) [ 32 ];
   tsecho =:= irregular(32) [ 32 ];
Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
static int c_tcp_build_ws_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint8_t *const  uncomp_opt,
const uint8_t  uncomp_opt_len,
uint8_t *const  comp_opt,
const size_t  comp_opt_max_len 
)
static

Build the list item for the TCP WS option.

   wscale =:= irregular(8) [ 8 ];
Parameters
contextThe compression context
tcpThe TCP header
uncomp_optThe uncompressed TCP option to compress
uncomp_opt_lenThe length of the uncompressed TCP option to compress
[out]comp_optThe compressed TCP option
comp_opt_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP option in case of success, -1 in case of failure
int c_tcp_code_tcp_opts_irreg ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint16_t  msn,
struct c_tcp_opts_ctxt *const  opts_ctxt,
uint8_t *const  comp_opts,
const size_t  comp_opts_max_len 
)

Build the list of TCP options for the irregular chain.

All the CO packets contains an irregular chain.

Parameters
contextThe compression context
tcpThe TCP header
msnThe Master Sequence Number (MSN) of the packet to compress
[in,out]opts_ctxtThe compression context for TCP options
[out]comp_optsThe compressed TCP options
comp_opts_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP options in case of success, -1 in case of failure
Todo:
TODO: defines 'options profiles' the same way as for decompressor
int c_tcp_code_tcp_opts_list_item ( const struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
const uint16_t  msn,
const bool  is_dynamic_chain,
struct c_tcp_opts_ctxt *const  opts_ctxt,
uint8_t *const  comp_opts,
const size_t  comp_opts_max_len 
)

Build the list of TCP options items.

The list of TCP options is used in the dynamic chain of the IR and IR-DYN packets, but also at the end of the rnd_8, seq_8, and co_common packets.

Parameters
contextThe compression context
tcpThe TCP header
msnThe Master Sequence Number (MSN) of the packet to compress
is_dynamic_chainWhether the list of items is for the dynamic chain or not
[in,out]opts_ctxtThe compression context for TCP options
[out]comp_optsThe compressed TCP options
comp_opts_max_lenThe max remaining length in the ROHC buffer
Returns
The length (in bytes) of compressed TCP options in case of success, -1 in case of failure
static uint8_t c_tcp_get_opt_index ( const struct rohc_comp_ctxt *const  context,
struct c_tcp_opts_ctxt *const  opts_ctxt,
const uint8_t  opt_type,
const bool  indexes_in_use[MAX_TCP_OPTION_INDEX+1] 
)
static

Determine the index of the TCP option.

Parameters
contextThe compression context
[in,out]opts_ctxtThe compression context for TCP options
opt_typeThe type of the option
indexes_in_useWhat indexes are used by the current packet?
Returns
true if the TCP options were successfully parsed and can be compressed, false otherwise
bool c_tcp_is_list_item_needed ( const struct rohc_comp_ctxt *const  context,
const bool  is_dynamic_chain,
const uint8_t  opt_idx,
const uint8_t  opt_type,
const uint8_t  opt_len,
const uint8_t *const  opt,
const struct c_tcp_opts_ctxt *const  opts_ctxt 
)

Shall the list item be transmitted or not?

Parameters
contextThe compression context
is_dynamic_chainWhether the list of items is for the dynamic chain or not
opt_idxThe compression index of the TCP option to compress
opt_typeThe type of the TCP option to compress
opt_lenThe length of the TCP option to compress
optThe TCP option to compress
opts_ctxtThe compression context for TCP options
Returns
true if the list item shall be transmitted, false if it shall not
static bool c_tcp_opt_changed ( const struct c_tcp_opts_ctxt *const  opts_ctxt,
const uint8_t  opt_idx,
const uint8_t *const  pkt_opt,
const size_t  pkt_opt_len 
)
static

Does the TCP option changed since last packets?

The TCP option changed if the packet TCP option do not match the TCP option that was recorded in the compression context.

Parameters
opts_ctxtThe compression context of the TCP options
opt_idxThe index of the TCP option in the TCP compression context
pkt_optThe TCP option as found in the TCP packet
pkt_opt_lenThe length of the TCP option as found in the TCP packet
Returns
true if the TCP option changed, false if it doesn't
static int c_tcp_opt_compute_ps ( const uint8_t  idx_max)
static

Determine PS for the compressed list of TCP options.

According to RFC6846, §6.3.3, PS indicates size of XI fields:

  • PS = 0 indicates 4-bit XI fields;
  • PS = 1 indicates 8-bit XI fields.

The rational to choose is: use 4-bit XI fields if the largest option index may fit in 4 bits, otherwise fallback on the 8-bit XI fields

Parameters
idx_maxThe largest option index used in the compressed packet
Returns
The PS value
static size_t c_tcp_opt_compute_xi_len ( const int  ps,
const size_t  m 
)
static

Determine the length of XI indexes for the list of TCP options.

The length of the XI indexes depends on the type of XI fields we use. According to RFC6846, §6.3.3, PS indicates size of XI fields:

  • PS = 0 indicates 4-bit XI fields;
  • PS = 1 indicates 8-bit XI fields.

The computed XI length includes the first byte that contain the reserved bits, the PS flag and the number of XI indexes (m).

Parameters
psThe PS value
mThe number of elements in the list
Returns
The length (in bytes) of the XI indexes
static bool c_tcp_opt_get_type_len ( const uint8_t *const  opts_data,
const size_t  opts_len,
uint8_t *const  opt_type,
uint8_t *const  opt_len 
)
static

Get the type and length of the next TCP option.

Parameters
opts_dataThe remaining data in the TCP options
opts_lenThe length of the remaining data in the TCP options
[out]opt_typeThe type of the TCP option
[out]opt_lenThe length (in bytes) of the TCP option
Returns
true if one well-formed TCP option was found, false if the TCP option is malformed
static void c_tcp_opt_record ( struct c_tcp_opts_ctxt *const  opts_ctxt,
const uint8_t  opt_idx,
const uint8_t *const  pkt_opt,
const size_t  pkt_opt_len 
)
static

Record the TCP option in context.

Parameters
[out]opts_ctxtThe TCP compression context
opt_idxThe index of the TCP option in the TCP compression context
pkt_optThe TCP option as found in the TCP packet
pkt_opt_lenThe length of the TCP option as found in the TCP packet
static void c_tcp_opt_trace ( const struct rohc_comp_ctxt *const  context,
const uint8_t  opt_type,
const uint8_t *const  opt_data,
const size_t  opt_len 
)
static

Print a trace for the given TCP option.

Parameters
contextThe compression context
opt_typeThe type of the TCP option to print a trace for
opt_dataThe data of the TCP option to print a trace for
opt_lenThe length (in bytes) of the TCP option to print a trace for
static size_t c_tcp_opt_write_xi ( const struct rohc_comp_ctxt *const  context,
uint8_t *const  comp_opts,
const int  ps,
const size_t  opt_pos,
const uint8_t  opt_idx,
const bool  item_needed 
)
static

Write the XI field for a TCP option.

The room available in comp_opts shall have been checked before calling this function.

Parameters
contextThe compression context
[in,out]comp_optsThe compressed options
ps0 to use 4-bit XI fields, or 1 to use 8-bit XI fields
opt_posThe position of the TCP option in the list (opt_pos starts at 0)
opt_idxThe index of the TCP option
item_neededWhether the TCP option requires its related item to be present or not
Returns
The number of bytes completed
bool rohc_comp_tcp_are_options_acceptable ( const struct rohc_comp *const  comp,
const uint8_t *const  opts,
const size_t  data_offset 
)

Whether TCP options are acceptable for TCP profile or not.

TCP options are acceptable for the TCP profile if:

  • the last TCP option is not truncated,
  • well-known TCP options got the expected length (see below),
  • no more than ROHC_TCP_OPTS_MAX options are present,
  • each TCP options is present only once (except EOL and NOP).

The following well-known TCP options shall have expected lengthes:

  • MSS shall be TCP_OLEN_MSS long,
  • WS shall be TCP_OLEN_WS long,
  • SACK Permitted shall be TCP_OLEN_SACK_PERM long,
  • SACK shall be 2 + N * 8 with N in range [1, 4]
  • TS shall be TCP_OLEN_TS long.
Parameters
compThe ROHC compressor
optsThe beginning of the TCP options
data_offsetThe length (in 32-bit words) of the full TCP header
Returns
true if the TCP options are acceptable, false if they are not
See also
ROHC_TCP_OPTS_MAX
bool tcp_detect_options_changes ( struct rohc_comp_ctxt *const  context,
const struct tcphdr *const  tcp,
struct c_tcp_opts_ctxt *const  opts_ctxt,
size_t *const  opts_len 
)

Parse the uncompressed TCP options for changes.

Parameters
contextThe compression context
tcpThe TCP header
[in,out]opts_ctxtThe compression context for TCP options
[out]opts_lenThe length (in bytes) of the TCP options
Returns
true if the TCP options were successfully parsed and can be compressed, false otherwise

Variable Documentation

struct c_tcp_opt c_tcp_opts[MAX_TCP_OPTION_INDEX+1]
static
int c_tcp_type2index[TCP_LIST_ITEM_MAP_LEN]
static
Initial value:
=
{
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
}
#define TCP_INDEX_TS
Definition: tcp.h:180
#define TCP_INDEX_NOP
Definition: tcp.h:176
#define TCP_INDEX_SACK
Definition: tcp.h:182
#define TCP_INDEX_WS
Definition: tcp.h:179
#define TCP_INDEX_SACK_PERM
Definition: tcp.h:181
#define TCP_INDEX_EOL
Definition: tcp.h:177
#define TCP_INDEX_MSS
Definition: tcp.h:178

Table of TCP option index, from option Id.

See RFC4996 §6.3.4 Return item index of TCP option