ROHC compression/decompression library
Data Structures | Defines | Functions
c_generic.h File Reference

ROHC generic compression context for IP-only, UDP and UDP Lite profiles. More...

#include "rohc_comp_internals.h"
#include "rohc_packets.h"
#include "comp_list.h"
#include "ip.h"
#include "crc.h"
#include <stdlib.h>
Include dependency graph for c_generic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ipv4_header_info
 Store information about an IPv4 header between the different compressions of IP packets. More...
struct  ipv6_header_info
 Store information about an IPv6 header between the different compressions of IP packets. More...
struct  ip_header_info
 Store information about an IP (IPv4 or IPv6) header between the different compressions of IP packets. More...
struct  generic_tmp_vars
 Structure that contains variables that are used during one single compression of packet. More...
struct  c_generic_context
 The generic compression context. More...
struct  list_comp
 The list compressor. More...

Defines

#define MAX_ITEM   15
 The number of compression list items.
#define L   5

Functions

int c_generic_create (struct c_context *const context, const rohc_lsb_shift_t sn_shift, const struct ip_packet *ip)
 Create a new context and initialize it thanks to the given IP packet.
void c_generic_destroy (struct c_context *const context)
 Destroy the context.
bool c_generic_check_profile (const struct rohc_comp *const comp, const struct ip_packet *const outer_ip, const struct ip_packet *const inner_ip, const uint8_t protocol, rohc_ctxt_key_t *const ctxt_key)
 Check if the given packet corresponds to an IP-based profile.
void change_mode (struct c_context *const context, const rohc_mode new_mode)
 Change the mode of the context.
void change_state (struct c_context *const context, const rohc_c_state new_state)
 Change the state of the context.
rohc_ext_t decide_extension (const struct c_context *context)
 Decide what extension shall be used in the UO-1/UO-2 packet.
int c_generic_encode (struct c_context *const context, const struct ip_packet *ip, const size_t packet_size, unsigned char *const dest, const size_t dest_size, rohc_packet_t *const packet_type, int *const payload_offset)
 Encode an IP packet according to a pattern decided by several different factors.
bool c_generic_reinit_context (struct c_context *const context)
 Re-initialize the given context.
void c_generic_feedback (struct c_context *const context, const struct c_feedback *feedback)
 Update the profile when feedback arrives.
bool c_generic_use_udp_port (const struct c_context *const context, const unsigned int port)
 Whether the profile uses the given UDP port.
void decide_state (struct c_context *const context)
 Decide the state that should be used for the next packet.
void rohc_get_ipid_bits (const struct c_context *context, size_t *const nr_innermost_bits, size_t *const nr_outermost_bits)
 Get the number of non-random outer/inner IP-ID bits.

Detailed Description

ROHC generic compression context for IP-only, UDP and UDP Lite profiles.

Author:
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
Didier Barvaux <didier@barvaux.org>
The hackers from ROHC for Linux

Define Documentation

#define L   5

The number of compressed list to send to make the reference list L is the name specified in the RFC

#define MAX_ITEM   15

The number of compression list items.


Function Documentation

bool c_generic_check_profile ( const struct rohc_comp *const  comp,
const struct ip_packet *const  outer_ip,
const struct ip_packet *const  inner_ip,
const uint8_t  protocol,
rohc_ctxt_key_t *const  ctxt_key 
)

Check if the given packet corresponds to an IP-based profile.

Conditions are:

  • the version of the outer IP header is 4 or 6
  • if the outer IP header is IPv4, it does not contain options
  • the outer IP header is not an IP fragment
  • if there are at least 2 IP headers, the version of the inner IP header is 4 or 6
  • if there are at least 2 IP headers and if the inner IP header is IPv4, it does not contain options
  • if there are at least 2 IP headers, the inner IP header is not an IP fragment

This function is one of the functions that must exist in one profile for the framework to work.

Parameters:
compThe ROHC compressor
outer_ipThe outer IP header of the IP packet to check
inner_ip
  • The inner IP header of the IP packet to check if the IP packet contains at least 2 IP headers,
  • NULL if the IP packet to check contains only one IP header
protocolThe transport protocol carried by the IP packet:
  • the protocol carried by the outer IP header if there is only one IP header,
  • the protocol carried by the inner IP header if there are at least two IP headers.
ctxt_keyThe key to help finding the context associated with packet
Returns:
Whether the IP packet corresponds to the profile:
  • true if the IP packet corresponds to the profile,
  • false if the IP packet does not correspond to the profile

References ipv6_addr::addr, daddr, ip_packet::data, ip_get_hdrlen(), ip_get_version(), ip_is_fragment(), IPV4, ipv4_get_daddr(), ipv4_get_saddr(), IPV6, ipv6_get_daddr(), ipv6_get_saddr(), rohc_debug, ROHC_PROFILE_GENERAL, ROHC_TRACE_COMP, saddr, ipv6_addr::u32, version, and ip_packet::version.

Referenced by c_esp_check_profile(), and c_udp_check_profile().

int c_generic_create ( struct c_context *const  context,
const rohc_lsb_shift_t  sn_shift,
const struct ip_packet ip 
)

Create a new context and initialize it thanks to the given IP packet.

Parameters:
contextThe compression context
sn_shiftThe shift parameter (p) to use for encoding SN with W-LSB
ipThe IP packet given to initialize the new context
Returns:
1 if successful, 0 otherwise

References c_create_wlsb(), c_destroy_wlsb(), c_init_header_info(), c_init_tmp_variables(), c_generic_context::code_dynamic_part, c_generic_context::code_static_part, c_generic_context::code_UO_packet_head, c_generic_context::code_uo_remainder, c_context::compressor, c_generic_context::compute_crc_dynamic, compute_crc_dynamic(), c_generic_context::compute_crc_static, compute_crc_static(), c_generic_context::decide_extension, c_generic_context::decide_FO_packet, c_generic_context::decide_SO_packet, c_generic_context::decide_state, decide_state(), c_generic_context::fo_count, c_generic_context::get_next_sn, c_generic_context::go_back_fo_count, c_generic_context::go_back_ir_count, c_profile::id, c_generic_context::init_at_IR, c_generic_context::ip_flags, ip_get_inner_packet(), ip_get_protocol(), c_generic_context::ir_count, c_generic_context::is_ip2_initialized, c_generic_context::next_header_len, c_generic_context::next_header_proto, c_context::profile, rohc_comp_debug, rohc_error, ROHC_IPPROTO_IPIP, ROHC_IPPROTO_IPV6, ROHC_TRACE_COMP, c_generic_context::sn_window, c_generic_context::so_count, c_generic_context::specific, c_context::specific, c_generic_context::tmp, rohc_comp::trace_callback, and rohc_comp::wlsb_window_width.

void c_generic_destroy ( struct c_context *const  context)
int c_generic_encode ( struct c_context *const  context,
const struct ip_packet ip,
const size_t  packet_size,
unsigned char *const  dest,
const size_t  dest_size,
rohc_packet_t *const  packet_type,
int *const  payload_offset 
)

Encode an IP packet according to a pattern decided by several different factors.

1. Check if we have double IP headers.
2. Check if the IP-ID fields are random and if they are in NBO.
3. Decide in which state to go (IR, FO or SO).
4. Decide how many bits are needed to send the IP-ID and SN fields and more important update the sliding windows.
5. Decide which packet type to send.
6. Code the packet.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters:
contextThe compression context
ipThe IP packet to encode
packet_sizeThe length of the IP packet to encode
destThe rohc-packet-under-build buffer
dest_sizeThe length of the rohc-packet-under-build buffer
packet_typeOUT: The type of ROHC packet that is created
payload_offsetThe offset for the payload in the IP packet
Returns:
The length of the created ROHC packet or -1 in case of failure

References c_init_header_info(), changed_dynamic_both_hdr(), generic_tmp_vars::changed_fields, changed_fields(), generic_tmp_vars::changed_fields2, changed_static_both_hdr(), code_packet(), c_context::compressor, c_generic_context::decide_state, c_generic_context::encode_uncomp_fields, c_generic_context::get_next_sn, c_profile::id, ip_header_info::info, c_generic_context::ip2_flags, c_generic_context::ip_flags, ip_get_hdrlen(), ip_get_inner_packet(), ip_get_next_layer(), ip_get_protocol(), ip_get_total_extension_size(), ip_get_version(), IPV4, ipv4_get_header(), ipv4_get_id(), ipv6_get_header(), ip_header_info::is_first_header, c_generic_context::is_ip2_initialized, generic_tmp_vars::max_size, ipv4_header_info::nbo, c_generic_context::next_header_len, generic_tmp_vars::nr_ip_id_bits2, generic_tmp_vars::nr_of_ip_hdr, c_context::num_sent_ir, c_context::num_sent_ir_dyn, ipv4_header_info::old_ip, ipv6_header_info::old_ip, ipv4_header_info::old_nbo, ipv4_header_info::old_rnd, ipv4_header_info::old_sid, PACKET_IR, PACKET_IR_DYN, generic_tmp_vars::packet_type, PACKET_UNKNOWN, c_context::profile, ipv4_header_info::rnd, rohc_comp_debug, ROHC_IPPROTO_IPIP, ROHC_IPPROTO_IPV6, rohc_ntoh16(), ROHC_OK, ROHC_TRACE_COMP, rohc_warning, generic_tmp_vars::send_dynamic, generic_tmp_vars::send_static, ipv4_header_info::sid, ip_packet::size, c_generic_context::sn, c_context::specific, c_generic_context::tmp, rohc_comp::trace_callback, ip_header_info::v4, ip_header_info::v6, and rohc_comp::wlsb_window_width.

void c_generic_feedback ( struct c_context *const  context,
const struct c_feedback feedback 
)
bool c_generic_reinit_context ( struct c_context *const  context)

Re-initialize the given context.

Make the context restart its initialization with decompressor, ie. it goes in the lowest compression state.

Parameters:
contextThe compression context to re-initialize
Returns:
true in case of success, false otherwise

References change_mode(), change_state(), IR, and U_MODE.

bool c_generic_use_udp_port ( const struct c_context *const  context,
const unsigned int  port 
)

Whether the profile uses the given UDP port.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters:
contextThe compression context
portThe UDP port number to check
Returns:
always return true, it is used by non-RTP profiles
void change_mode ( struct c_context *const  context,
const rohc_mode  new_mode 
)

Change the mode of the context.

Parameters:
contextThe compression context
new_modeThe new mode the context must enter in

References change_state(), c_context::cid, c_context::compressor, c_profile::id, IR, c_context::mode, c_context::profile, rohc_info, and ROHC_TRACE_COMP.

Referenced by c_generic_feedback(), and c_generic_reinit_context().

void change_state ( struct c_context *const  context,
const rohc_c_state  new_state 
)
rohc_ext_t decide_extension ( const struct c_context context)

Decide what extension shall be used in the UO-1/UO-2 packet.

Extensions 0, 1 & 2 are IPv4 only because of the IP-ID.

Parameters:
contextThe compression context
Returns:
The extension code among PACKET_NOEXT, PACKET_EXT_0, PACKET_EXT_1 and PACKET_EXT_3 if successful, PACKET_EXT_UNKNOWN otherwise

References c_context::compressor, c_profile::id, generic_tmp_vars::nr_of_ip_hdr, generic_tmp_vars::nr_sn_bits, rtp_tmp_vars::nr_ts_bits, PACKET_EXT_0, PACKET_EXT_1, PACKET_EXT_2, PACKET_EXT_3, PACKET_EXT_UNKNOWN, PACKET_NOEXT, generic_tmp_vars::packet_type, PACKET_UOR_2, PACKET_UOR_2_ID, PACKET_UOR_2_RTP, PACKET_UOR_2_TS, c_context::profile, rohc_assert, rohc_comp_debug, rohc_get_ipid_bits(), ROHC_TRACE_COMP, generic_tmp_vars::send_dynamic, generic_tmp_vars::send_static, c_generic_context::specific, c_context::specific, sc_rtp_context::tmp, and c_generic_context::tmp.

void decide_state ( struct c_context *const  context)
void rohc_get_ipid_bits ( const struct c_context context,
size_t *const  nr_innermost_bits,
size_t *const  nr_outermost_bits 
)

Get the number of non-random outer/inner IP-ID bits.

Parameters:
contextThe compression context
nr_innermost_bitsOUT: the maximum number of IP-ID bits for the innermost IPv4 header
nr_outermost_bitsOUT: the maximum number of IP-ID bits for the outermost IP header

References ip_header_info::info, c_generic_context::ip2_flags, c_generic_context::ip_flags, IPV4, generic_tmp_vars::nr_ip_id_bits, generic_tmp_vars::nr_ip_id_bits2, generic_tmp_vars::nr_of_ip_hdr, ipv4_header_info::rnd, c_context::specific, c_generic_context::tmp, ip_header_info::v4, and ip_header_info::version.

Referenced by decide_extension().