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

Defines

#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.
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?
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.
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.
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.
static int c_tcp_opt_compute_ps (const uint8_t idx_max)
 Determine PS for the compressed list of TCP options.
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.
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.
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?
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.

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.

Detailed Description

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

Author:
FWX <rohc_team@dialine.fr>
Didier Barvaux <didier@barvaux.org>
Didier Barvaux <didier.barvaux@toulouse.viveris.com>

Define 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
uncomp_opt The uncompressed TCP option to compress
uncomp_opt_len The length of the uncompressed TCP option to compress
[out] comp_opt The compressed TCP option
comp_opt_max_len The 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:
context The compression context
tcp The TCP header
msn The Master Sequence Number (MSN) of the packet to compress
[in,out] opts_ctxt The compression context for TCP options
[out] comp_opts The compressed TCP options
comp_opts_max_len The 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:
context The compression context
tcp The TCP header
msn The Master Sequence Number (MSN) of the packet to compress
is_dynamic_chain Whether the list of items is for the dynamic chain or not
[in,out] opts_ctxt The compression context for TCP options
[out] comp_opts The compressed TCP options
comp_opts_max_len The 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:
context The compression context
[in,out] opts_ctxt The compression context for TCP options
opt_type The type of the option
indexes_in_use What 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:
context The compression context
is_dynamic_chain Whether the list of items is for the dynamic chain or not
opt_idx The compression index of the TCP option to compress
opt_type The type of the TCP option to compress
opt_len The length of the TCP option to compress
opt The TCP option to compress
opts_ctxt The 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_ctxt The compression context of the TCP options
opt_idx The index of the TCP option in the TCP compression context
pkt_opt The TCP option as found in the TCP packet
pkt_opt_len The 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_max The 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:
ps The PS value
m The 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_data The remaining data in the TCP options
opts_len The length of the remaining data in the TCP options
[out] opt_type The type of the TCP option
[out] opt_len The 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_ctxt The TCP compression context
opt_idx The index of the TCP option in the TCP compression context
pkt_opt The TCP option as found in the TCP packet
pkt_opt_len The 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:
context The compression context
opt_type The type of the TCP option to print a trace for
opt_data The data of the TCP option to print a trace for
opt_len The 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:
context The compression context
[in,out] comp_opts The compressed options
ps 0 to use 4-bit XI fields, or 1 to use 8-bit XI fields
opt_pos The position of the TCP option in the list (opt_pos starts at 0)
opt_idx The index of the TCP option
item_needed Whether 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:
comp The ROHC compressor
opts The beginning of the TCP options
data_offset The 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:
context The compression context
tcp The TCP header
[in,out] opts_ctxt The compression context for TCP options
[out] opts_len The 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:

Table of TCP option index, from option Id.

See RFC4996 §6.3.4 Return item index of TCP option


Generated on 4 Jul 2018 for ROHC compression/decompression library by  doxygen 1.6.1