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

ROHC compression context for the UDP profile. More...

#include "c_udp.h"
#include "c_ip.h"
#include "rohc_traces_internal.h"
#include "rohc_packets.h"
#include "rohc_utils.h"
#include "crc.h"
#include "rohc_comp_rfc3095.h"
#include "protocols/udp.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Include dependency graph for c_udp.c:

Data Structures

struct  udp_tmp_vars
 Define the UDP-specific temporary variables in the profile compression context. More...
 
struct  sc_udp_context
 Define the UDP part of the profile decompression context. More...
 

Functions

static bool c_udp_create (struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
 Create a new UDP context and initialize it thanks to the given IP/UDP packet. More...
 
static void udp_decide_state (struct rohc_comp_ctxt *const context)
 Decide the state that should be used for the next packet compressed with the ROHC UDP profile. More...
 
static int c_udp_encode (struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt, uint8_t *const rohc_pkt, const size_t rohc_pkt_max_len, rohc_packet_t *const packet_type, size_t *const payload_offset)
 Encode an IP/UDP packet according to a pattern decided by several different factors. More...
 
static size_t udp_code_dynamic_udp_part (const struct rohc_comp_ctxt *const context, const uint8_t *const next_header, uint8_t *const dest, const size_t counter)
 Build the dynamic part of the UDP header. More...
 
static int udp_changed_udp_dynamic (const struct rohc_comp_ctxt *context, const struct udphdr *udp)
 Check if the dynamic part of the UDP header changed. More...
 
bool c_udp_check_profile (const struct rohc_comp *const comp, const struct net_pkt *const packet)
 Check if the given packet corresponds to the UDP profile. More...
 
bool c_udp_check_context (const struct rohc_comp_ctxt *const context, const struct net_pkt *const packet, size_t *const cr_score)
 Check if the IP/UDP packet belongs to the context. More...
 
size_t udp_code_uo_remainder (const struct rohc_comp_ctxt *const context, const uint8_t *const next_header, uint8_t *const dest, const size_t counter)
 Build UDP-related fields in the tail of the UO packets. More...
 
size_t udp_code_static_udp_part (const struct rohc_comp_ctxt *const context, const uint8_t *const next_header, uint8_t *const dest, const size_t counter)
 Build the static part of the UDP header. More...
 

Variables

const struct rohc_comp_profile c_udp_profile
 Define the compression part of the UDP profile as described in the RFC 3095. More...
 

Detailed Description

ROHC compression context for the UDP profile.

Author
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
Didier Barvaux didie.nosp@m.r@ba.nosp@m.rvaux.nosp@m..org

Function Documentation

◆ c_udp_check_context()

bool c_udp_check_context ( const struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  packet,
size_t *const  cr_score 
)

Check if the IP/UDP packet belongs to the context.

Conditions are:

  • the number of IP headers must be the same as in context
  • IP version of the two IP headers must be the same as in context
  • IP packets must not be fragmented
  • the source and destination addresses of the two IP headers must match the ones in the context
  • the transport protocol must be UDP
  • the source and destination ports of the UDP header must match the ones in the context
  • IPv6 only: the Flow Label of the two IP headers must match the ones the context

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

Parameters
contextThe compression context
packetThe IP/UDP packet to check
[out]cr_scoreThe score of the context for Context Replication (CR)
Returns
true if the IP/UDP packet belongs to the context false if it does not belong to the context

◆ c_udp_check_profile()

bool c_udp_check_profile ( const struct rohc_comp *const  comp,
const struct net_pkt *const  packet 
)

Check if the given packet corresponds to the UDP profile.

Conditions are:

  • the transport protocol is UDP
  • the version of the outer IP header is 4 or 6
  • 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, the inner IP header is not an IP fragment
  • the inner IP payload is at least 8-byte long for UDP header
  • the UDP Length field and the UDP payload match
See also
rohc_comp_rfc3095_check_profile

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

Parameters
compThe ROHC compressor
packetThe packet to check
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

◆ c_udp_create()

static bool c_udp_create ( struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  packet 
)
static

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

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

Parameters
contextThe compression context
packetThe IP/UDP packet given to initialize the new context
Returns
true if successful, false otherwise

◆ c_udp_encode()

static int c_udp_encode ( struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  uncomp_pkt,
uint8_t *const  rohc_pkt,
const size_t  rohc_pkt_max_len,
rohc_packet_t *const  packet_type,
size_t *const  payload_offset 
)
static

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

Parameters
contextThe compression context
uncomp_pktThe uncompressed packet to encode
rohc_pktOUT: The ROHC packet
rohc_pkt_max_lenThe maximum length of the ROHC packet
packet_typeOUT: The type of ROHC packet that is created
payload_offsetOUT: The offset for the payload in the IP packet
Returns
The length of the ROHC packet if successful, -1 otherwise

◆ udp_changed_udp_dynamic()

static int udp_changed_udp_dynamic ( const struct rohc_comp_ctxt context,
const struct udphdr udp 
)
static

Check if the dynamic part of the UDP header changed.

Parameters
contextThe compression context
udpThe UDP header
Returns
The number of UDP fields that changed

◆ udp_code_dynamic_udp_part()

static size_t udp_code_dynamic_udp_part ( const struct rohc_comp_ctxt *const  context,
const uint8_t *const  next_header,
uint8_t *const  dest,
const size_t  counter 
)
static

Build the dynamic part of the UDP header.

 Dynamic part of UDP header (5.7.7.5):

    +---+---+---+---+---+---+---+---+
 1  /           Checksum            /   2 octets
    +---+---+---+---+---+---+---+---+
Parameters
contextThe compression context
next_headerThe UDP header
destThe rohc-packet-under-build buffer
counterThe current position in the rohc-packet-under-build buffer
Returns
The new position in the rohc-packet-under-build buffer

◆ udp_code_static_udp_part()

size_t udp_code_static_udp_part ( const struct rohc_comp_ctxt *const  context,
const uint8_t *const  next_header,
uint8_t *const  dest,
const size_t  counter 
)

Build the static part of the UDP header.

 Static part of UDP header (5.7.7.5):

    +---+---+---+---+---+---+---+---+
 1  /          Source Port          /   2 octets
    +---+---+---+---+---+---+---+---+
 2  /       Destination Port        /   2 octets
    +---+---+---+---+---+---+---+---+
Parameters
contextThe compression context
next_headerThe UDP header
destThe rohc-packet-under-build buffer
counterThe current position in the rohc-packet-under-build buffer
Returns
The new position in the rohc-packet-under-build buffer

◆ udp_code_uo_remainder()

size_t udp_code_uo_remainder ( const struct rohc_comp_ctxt *const  context,
const uint8_t *const  next_header,
uint8_t *const  dest,
const size_t  counter 
)

Build UDP-related fields in the tail of the UO packets.

     --- --- --- --- --- --- --- ---
    :                               :
 13 +         UDP Checksum          +  2 octets,
    :                               :  if context(UDP Checksum) != 0
     --- --- --- --- --- --- --- ---
Parameters
contextThe compression context
next_headerThe UDP header
destThe rohc-packet-under-build buffer
counterThe current position in the rohc-packet-under-build buffer
Returns
The new position in the rohc-packet-under-build buffer

◆ udp_decide_state()

static void udp_decide_state ( struct rohc_comp_ctxt *const  context)
static

Decide the state that should be used for the next packet compressed with the ROHC UDP profile.

The three states are:

  • Initialization and Refresh (IR),
  • First Order (FO),
  • Second Order (SO).
Parameters
contextThe compression context

Variable Documentation

◆ c_udp_profile

const struct rohc_comp_profile c_udp_profile
Initial value:
=
{
.protocol = ROHC_IPPROTO_UDP,
.create = c_udp_create,
.check_profile = c_udp_check_profile,
.check_context = c_udp_check_context,
.encode = c_udp_encode,
.reinit_context = rohc_comp_reinit_context,
}
bool c_udp_check_profile(const struct rohc_comp *const comp, const struct net_pkt *const packet)
Check if the given packet corresponds to the UDP profile.
Definition: c_udp.c:214
void rohc_comp_rfc3095_destroy(struct rohc_comp_ctxt *const context)
Destroy the context.
Definition: rohc_comp_rfc3095.c:620
Definition: ip_numbers.h:58
bool c_udp_check_context(const struct rohc_comp_ctxt *const context, const struct net_pkt *const packet, size_t *const cr_score)
Check if the IP/UDP packet belongs to the context.
Definition: c_udp.c:282
bool rohc_comp_rfc3095_feedback(struct rohc_comp_ctxt *const context, const enum rohc_feedback_type feedback_type, const uint8_t *const packet, const size_t packet_len, const uint8_t *const feedback_data, const size_t feedback_data_len)
Update the profile when feedback is received.
Definition: rohc_comp_rfc3095.c:881
static int c_udp_encode(struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt, uint8_t *const rohc_pkt, const size_t rohc_pkt_max_len, rohc_packet_t *const packet_type, size_t *const payload_offset)
Encode an IP/UDP packet according to a pattern decided by several different factors.
Definition: c_udp.c:330
bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
Re-initialize the given context.
Definition: rohc_comp.c:2986
static bool c_udp_create(struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
Create a new UDP context and initialize it thanks to the given IP/UDP packet.
Definition: c_udp.c:120
Definition: rohc.h:217

Define the compression part of the UDP profile as described in the RFC 3095.