Helper Reference Manual  1.7.1
ODPH PROTOCOLS

API Description

Network protocols.

Data Structures

struct  ODP_PACKED
 Ethernet MAC address. More...
 

Macros

#define ODPH_ETHADDR_LEN   6
 Ethernet address length.
 
#define ODPH_ETHHDR_LEN   14
 Ethernet header length.
 
#define ODPH_VLANHDR_LEN   4
 VLAN header length.
 
#define ODPH_ETH_LEN_MIN   60
 Min frame length (excl CRC 4 bytes)
 
#define ODPH_ETH_LEN_MIN_CRC   64
 Min frame length (incl CRC 4 bytes)
 
#define ODPH_ETH_LEN_MAX   1514
 Max frame length (excl CRC 4 bytes)
 
#define ODPH_ETH_LEN_MAX_CRC   1518
 Max frame length (incl CRC 4 bytes)
 
#define ODPH_VLANHDR_MAX_PRIO   7
 Max value of the 3 bit priority.
 
#define ODPH_VLANHDR_PCP_MASK   0xE000
 PCP field bit mask.
 
#define ODPH_VLANHDR_PCP_SHIFT   13
 PCP field shift.
 
#define ODPH_VLANHDR_DEI_MASK   0x1000
 DEI field bit mask.
 
#define ODPH_VLANHDR_DEI_SHIFT   12
 DEI field shift.
 
#define ODPH_VLANHDR_MAX_VID   0x0FFF
 Max value of the 12 bit VID field.
 
#define ODPH_VLANHDR_VID_MASK   0x0FFF
 VID field bit mask.
 
#define ODPH_VLANHDR_VID_SHIFT   0
 VID field shift.
 
#define ODPH_ETHTYPE_IPV4   0x0800
 Internet Protocol version 4.
 
#define ODPH_ETHTYPE_ARP   0x0806
 Address Resolution Protocol.
 
#define ODPH_ETHTYPE_RARP   0x8035
 Reverse Address Resolution Protocol.
 
#define ODPH_ETHTYPE_VLAN   0x8100
 VLAN-tagged frame IEEE 802.1Q.
 
#define ODPH_ETHTYPE_VLAN_OUTER   0x88A8
 Stacked VLANs/QinQ, outer-tag/S-TAG.
 
#define ODPH_ETHTYPE_IPV6   0x86dd
 Internet Protocol version 6.
 
#define ODPH_ETHTYPE_FLOW_CTRL   0x8808
 Ethernet flow control.
 
#define ODPH_ETHTYPE_MPLS   0x8847
 MPLS unicast.
 
#define ODPH_ETHTYPE_MPLS_MCAST   0x8848
 MPLS multicast.
 
#define ODPH_ETHTYPE_MACSEC   0x88E5
 MAC security IEEE 802.1AE.
 
#define ODPH_ETHTYPE_1588   0x88F7
 Precision Time Protocol IEEE 1588.
 
#define ODPH_GTP_HLEN   sizeof(odph_gtphdr_t)
 GTP header length.
 
#define ODPH_ICMPHDR_LEN   8
 ICMP header length.
 
#define ODPH_ICMP_ECHOREPLY   0
 Echo Reply.
 
#define ODPH_ICMP_ECHO   8
 Echo Request.
 
#define ODPH_IGMP_HLEN   sizeof(odph_igmphdr_t)
 IGMP header length.
 
#define ODPH_IPV4   4
 IP version 4.
 
#define ODPH_IPV4HDR_LEN   20
 Min length of IP header (no options)
 
#define ODPH_IPV4HDR_IHL_MIN   5
 Minimum IHL value.
 
#define ODPH_IPV4ADDR_LEN   4
 IPv4 address length in bytes.
 
#define ODPH_IP_TOS_MAX_DSCP   63
 The one byte IPv4 tos or IPv6 tc field is composed of the following two subfields - a six bit Differentiated Service Code Point (DSCP) and a two bit Explicit Congestion Notification (ECN) subfield. More...
 
#define ODPH_IP_TOS_DSCP_MASK   0xFC
 DSCP field is in bits <7:2>

 
#define ODPH_IP_TOS_DSCP_SHIFT   2
 DSCP field is shifted letf by 2

 
#define ODPH_IP_TOS_MAX_ECN   3
 2-bit ECN field has max value 3

 
#define ODPH_IP_TOS_ECN_MASK   0x03
 ECN field is in bits <1:0>

 
#define ODPH_IP_TOS_ECN_SHIFT   0
 ECN field is not shifted. More...
 
#define ODPH_IP_ECN_NOT_ECT   0
 The following constants give names to the four possible ECN values, as described in RFC 3168. More...
 
#define ODPH_IP_ECN_ECT1   1
 Indicates no congestion seen yet.
 
#define ODPH_IP_ECN_ECT0   2
 Indicates no congestion seen yet.
 
#define ODPH_IP_ECN_CE   3
 Used to signal Congestion Experienced.
 
#define ODPH_IPV4HDR_VER(ver_ihl)   (((ver_ihl) & 0xf0) >> 4)
 
#define ODPH_IPV4HDR_IHL(ver_ihl)   ((ver_ihl) & 0x0f)
 
#define ODPH_IPV4HDR_DSCP(tos)   (((tos) & 0xfc) >> 2)
 
#define ODPH_IPV4HDR_FLAGS_DONT_FRAG(frag_offset)   ((frag_offset) & 0x4000)
 
#define ODPH_IPV4HDR_FLAGS_MORE_FRAGS(frag_offset)   ((frag_offset) & 0x2000)
 
#define ODPH_IPV4HDR_FRAG_OFFSET(frag_offset)   ((frag_offset) & 0x1fff)
 
#define ODPH_IPV4HDR_IS_FRAGMENT(frag_offset)   ((frag_offset) & 0x3fff)
 
#define ODPH_IPV4HDR_CSUM_OFFSET   10
 
#define ODPH_IPV6   6
 IPv6 version.
 
#define ODPH_IPV6HDR_LEN   40
 IPv6 header length.
 
#define ODPH_IPV6ADDR_LEN   16
 IPv6 address length in bytes.
 
#define ODPH_IPV6HDR_VERSION_MASK   0xF0000000
 The following constants can be used to access the three subfields of the 4 byte ver_tc_flow field - namely the four bit Version subfield, the eight bit Traffic Class subfield (TC) and the twenty bit Flow Label subfield. More...
 
#define ODPH_IPV6HDR_VERSION_SHIFT   28
 Version field shift.
 
#define ODPH_IPV6HDR_TC_MASK   0x0FF00000
 TC field bit mask.
 
#define ODPH_IPV6HDR_TC_SHIFT   20
 TC field shift.
 
#define ODPH_IPV6HDR_FLOW_LABEL_MASK   0x000FFFFF
 Flow Label bit mask.
 
#define ODPH_IPV6HDR_FLOW_LABEL_SHIFT   0
 Flow Label shift.
 
#define ODPH_IPV6HDR_DSCP(ver_tc_flow)    (uint8_t)((((ver_tc_flow) & 0x0fc00000) >> 22) & 0xff)
 
#define ODPH_IPPROTO_HOPOPTS   0x00
 IPv6 hop-by-hop options.
 
#define ODPH_IPPROTO_ICMPV4   0x01
 Internet Control Message Protocol (1)
 
#define ODPH_IPPROTO_IGMP   0x02
 Internet Group Message Protocol (1)
 
#define ODPH_IPPROTO_TCP   0x06
 Transmission Control Protocol (6)
 
#define ODPH_IPPROTO_UDP   0x11
 User Datagram Protocol (17)
 
#define ODPH_IPPROTO_ROUTE   0x2B
 IPv6 Routing header (43)
 
#define ODPH_IPPROTO_FRAG   0x2C
 IPv6 Fragment (44)
 
#define ODPH_IPPROTO_AH   0x33
 Authentication Header (51)
 
#define ODPH_IPPROTO_ESP   0x32
 Encapsulating Security Payload (50)
 
#define ODPH_IPPROTO_ICMPV6   0x3A
 Internet Control Message Protocol (58)
 
#define ODPH_IPPROTO_SCTP   0x84
 Stream Control Transmission protocol (132)
 
#define ODPH_IPPROTO_INVALID   0xFF
 Reserved invalid by IANA.
 
#define ODPH_ESPHDR_LEN   8
 IPSec ESP header length.
 
#define ODPH_ESPTRL_LEN   2
 IPSec ESP trailer length.
 
#define ODPH_AHHDR_LEN   12
 IPSec AH header length.
 
#define ODPH_SCTPHDR_LEN   12
 SCTP header length.
 
#define ODPH_TCPHDR_LEN   20
 Min length of TCP header (no options)
 
#define ODPH_UDPHDR_LEN   8
 UDP header length.
 

Typedefs

typedef struct ODP_PACKED odph_ethaddr_t
 Ethernet MAC address.
 
typedef struct ODP_PACKED odph_ethhdr_t
 Ethernet header.
 
typedef struct ODP_PACKED odph_vlanhdr_t
 IEEE 802.1Q VLAN header. More...
 
typedef struct ODP_PACKED odph_gtphdr_t
 Simplified GTP protocol header. More...
 
typedef struct ODP_PACKED odph_icmphdr_t
 ICMP header.
 
typedef struct ODP_PACKED odph_igmphdr_t
 Simplified IGMP protocol header. More...
 
typedef struct ODP_PACKED odph_ipv4hdr_t
 IPv4 header.
 
typedef struct ODP_PACKED odph_ipv6hdr_t
 IPv6 header.
 
typedef struct ODP_PACKED odph_ipv6hdr_ext_t
 IPv6 Header extensions.
 
typedef struct ODP_PACKED odph_esphdr_t
 IPSec ESP header.
 
typedef struct ODP_PACKED odph_esptrl_t
 IPSec ESP trailer.
 
typedef struct ODP_PACKED odph_ahhdr_t
 IPSec AH header.
 
typedef struct ODP_PACKED odph_sctphdr_t
 SCTP header.
 
typedef struct ODP_PACKED odph_tcphdr_t
 TCP header.
 
typedef struct ODP_PACKED odph_udphdr_t
 UDP header.
 

Functions

int odph_eth_addr_parse (odph_ethaddr_t *mac, const char *str)
 Parse Ethernet from a string. More...
 
static int odph_ipv4_csum (odp_packet_t pkt, uint32_t offset, odph_ipv4hdr_t *ip, odp_u16sum_t *chksum)
 Calculate IPv4 header checksum. More...
 
static int odph_ipv4_csum_valid (odp_packet_t pkt)
 Check if IPv4 checksum is valid. More...
 
static int odph_ipv4_csum_update (odp_packet_t pkt)
 Calculate and fill in IPv4 checksum. More...
 
int odph_ipv4_addr_parse (uint32_t *ip_addr, const char *str)
 Parse IPv4 address from a string. More...
 
int odph_ipsec_alg_check (const odp_ipsec_capability_t *capa, odp_cipher_alg_t cipher_alg, uint32_t cipher_key_len, odp_auth_alg_t auth_alg, uint32_t auth_key_len)
 Check IPSEC algorithm support. More...
 
uint32_t odph_ipsec_auth_icv_len_default (odp_auth_alg_t auth_alg)
 Return the default ICV length of an algorithm. More...
 
static uint16_t odph_ipv4_udp_chksum (odp_packet_t pkt)
 UDP checksum. More...
 

Macro Definition Documentation

◆ ODPH_IP_TOS_MAX_DSCP

#define ODPH_IP_TOS_MAX_DSCP   63

The one byte IPv4 tos or IPv6 tc field is composed of the following two subfields - a six bit Differentiated Service Code Point (DSCP) and a two bit Explicit Congestion Notification (ECN) subfield.

The following constants can be used to extract or modify these fields. Despite the name prefix being ODPH_IP_TOS_* these constants apply equally well for the IPv6 Traffic Class (tc) field. 6-bit DSCP field has max value 63

Definition at line 40 of file ip.h.

◆ ODPH_IP_TOS_ECN_SHIFT

#define ODPH_IP_TOS_ECN_SHIFT   0

ECN field is not shifted.


Definition at line 45 of file ip.h.

◆ ODPH_IP_ECN_NOT_ECT

#define ODPH_IP_ECN_NOT_ECT   0

The following constants give names to the four possible ECN values, as described in RFC 3168.

0 indicates not participating in ECN

Definition at line 50 of file ip.h.

◆ ODPH_IPV4HDR_VER

#define ODPH_IPV4HDR_VER (   ver_ihl)    (((ver_ihl) & 0xf0) >> 4)

Returns IPv4 version

Definition at line 56 of file ip.h.

◆ ODPH_IPV4HDR_IHL

#define ODPH_IPV4HDR_IHL (   ver_ihl)    ((ver_ihl) & 0x0f)

Returns IPv4 header length

Definition at line 59 of file ip.h.

◆ ODPH_IPV4HDR_DSCP

#define ODPH_IPV4HDR_DSCP (   tos)    (((tos) & 0xfc) >> 2)

Returns IPv4 DSCP

Definition at line 62 of file ip.h.

◆ ODPH_IPV4HDR_FLAGS_DONT_FRAG

#define ODPH_IPV4HDR_FLAGS_DONT_FRAG (   frag_offset)    ((frag_offset) & 0x4000)

Returns IPv4 Don't fragment

Definition at line 65 of file ip.h.

◆ ODPH_IPV4HDR_FLAGS_MORE_FRAGS

#define ODPH_IPV4HDR_FLAGS_MORE_FRAGS (   frag_offset)    ((frag_offset) & 0x2000)

Returns IPv4 more fragments

Definition at line 68 of file ip.h.

◆ ODPH_IPV4HDR_FRAG_OFFSET

#define ODPH_IPV4HDR_FRAG_OFFSET (   frag_offset)    ((frag_offset) & 0x1fff)

Returns IPv4 fragment offset

Definition at line 71 of file ip.h.

◆ ODPH_IPV4HDR_IS_FRAGMENT

#define ODPH_IPV4HDR_IS_FRAGMENT (   frag_offset)    ((frag_offset) & 0x3fff)

Returns true if IPv4 packet is a fragment

Definition at line 74 of file ip.h.

◆ ODPH_IPV4HDR_CSUM_OFFSET

#define ODPH_IPV4HDR_CSUM_OFFSET   10

Checksum offset in IPv4 header

Definition at line 77 of file ip.h.

◆ ODPH_IPV6HDR_VERSION_MASK

#define ODPH_IPV6HDR_VERSION_MASK   0xF0000000

The following constants can be used to access the three subfields of the 4 byte ver_tc_flow field - namely the four bit Version subfield, the eight bit Traffic Class subfield (TC) and the twenty bit Flow Label subfield.

Note that the IPv6 TC field is analogous to the IPv4 TOS field and is composed of the DSCP and ECN subfields. Use the ODPH_IP_TOS_* constants above to access these subfields. Version field bit mask

Definition at line 213 of file ip.h.

◆ ODPH_IPV6HDR_DSCP

#define ODPH_IPV6HDR_DSCP (   ver_tc_flow)     (uint8_t)((((ver_tc_flow) & 0x0fc00000) >> 22) & 0xff)

Returns IPv6 DSCP

Definition at line 221 of file ip.h.

Typedef Documentation

◆ odph_vlanhdr_t

typedef struct ODP_PACKED odph_vlanhdr_t

IEEE 802.1Q VLAN header.

This field is present when the EtherType (the odph_ethhdr_t type field) of the preceding ethernet header is ODPH_ETHTYPE_VLAN. The inner EtherType (the odph_vlanhdr_t type field) then indicates what comes next. Note that the so called TPID field isn't here because it overlaps with the odph_ethhdr_t type field.

◆ odph_gtphdr_t

typedef struct ODP_PACKED odph_gtphdr_t

Simplified GTP protocol header.

Contains 8-bit gtp_hdr_info, 8-bit msg_type, 16-bit plen, 32-bit teid. No optional fields and next extension header.

◆ odph_igmphdr_t

typedef struct ODP_PACKED odph_igmphdr_t

Simplified IGMP protocol header.

Contains 8-bit type, 8-bit code, 16-bit csum, 32-bit group. No optional fields and next extension header.

Function Documentation

◆ odph_eth_addr_parse()

int odph_eth_addr_parse ( odph_ethaddr_t mac,
const char *  str 
)

Parse Ethernet from a string.

Parses Ethernet MAC address from the string which must be passed in format of six hexadecimal digits delimited by colons (xx:xx:xx:xx:xx:xx). Both upper and lower case characters are supported. All six digits have to be present and may have leading zeros. String does not have to be NULL terminated. The address is written only when successful.

This function may be called before ODP initialization.

Parameters
[out]macPointer to Ethernet address for output
strMAC address string to be parsed
Return values
0on success
<0on failure

◆ odph_ipv4_csum()

static int odph_ipv4_csum ( odp_packet_t  pkt,
uint32_t  offset,
odph_ipv4hdr_t ip,
odp_u16sum_t *  chksum 
)
inlinestatic

Calculate IPv4 header checksum.

Parameters
pktThe packet to be checksummed
offsetOffset into pkt of start of IP header
ipPointer to IPv4 header to be checksummed
[out]chksumField to receive checksum results
Return values
0On success
<0On failure

Definition at line 109 of file ip.h.

References ODP_PACKED::chksum, ODPH_IPV4HDR_IHL, and ODP_PACKED::ver_ihl.

Referenced by odph_ipv4_csum_update(), and odph_ipv4_csum_valid().

◆ odph_ipv4_csum_valid()

static int odph_ipv4_csum_valid ( odp_packet_t  pkt)
inlinestatic

Check if IPv4 checksum is valid.

Parameters
pktODP packet
Returns
1 if checksum is valid, otherwise 0

Definition at line 141 of file ip.h.

References ODP_PACKED::chksum, and odph_ipv4_csum().

Here is the call graph for this function:

◆ odph_ipv4_csum_update()

static int odph_ipv4_csum_update ( odp_packet_t  pkt)
inlinestatic

Calculate and fill in IPv4 checksum.

Parameters
pktODP packet
Return values
0on success
<0on failure

Definition at line 173 of file ip.h.

References odph_ipv4_csum(), and ODPH_IPV4HDR_CSUM_OFFSET.

Here is the call graph for this function:

◆ odph_ipv4_addr_parse()

int odph_ipv4_addr_parse ( uint32_t *  ip_addr,
const char *  str 
)

Parse IPv4 address from a string.

Parses IPv4 address from the string which must be passed in the format of four decimal digits delimited by dots (xxx.xxx.xxx.xxx). All four digits have to be present and may have leading zeros. String does not have to be NULL terminated. The address is written only when successful. The address byte order is CPU native.

This function may be called before ODP initialization.

Parameters
[out]ip_addrPointer to IPv4 address for output (in native endian)
strIPv4 address string to be parsed
Return values
0on success
<0on failure

◆ odph_ipsec_alg_check()

int odph_ipsec_alg_check ( const odp_ipsec_capability_t *  capa,
odp_cipher_alg_t  cipher_alg,
uint32_t  cipher_key_len,
odp_auth_alg_t  auth_alg,
uint32_t  auth_key_len 
)

Check IPSEC algorithm support.

Based on the capabilities exposed by the ODP implementation, check whether the specified IPSEC algorithm configuration with the default ICV length is supported by the implementation. The caller provides the IPSEC capability structure as an argument to the helper function.

Parameters
capaIPSEC capability structure
cipher_algCipher algorithm
cipher_key_lenLength of cipher key in bytes
auth_algAuthentication algorithm
auth_key_lenLength of authentication key in bytes
Return values
0on success
<0on failure

◆ odph_ipsec_auth_icv_len_default()

uint32_t odph_ipsec_auth_icv_len_default ( odp_auth_alg_t  auth_alg)

Return the default ICV length of an algorithm.

IPsec API specifies default ICV length for each authentication and combined mode algorithm. This function returns the default ICV length.

Parameters
auth_algAuthentication algorithm
Returns
The default ICV length in bytes

◆ odph_ipv4_udp_chksum()

static uint16_t odph_ipv4_udp_chksum ( odp_packet_t  pkt)
inlinestatic

UDP checksum.

This function calculates the UDP checksum given an odp packet.

Parameters
pktcalculate chksum for pkt
Returns
checksum value in BE endianness

Definition at line 45 of file udp.h.

References ODPH_CHKSUM_RETURN, and odph_udp_tcp_chksum().

Here is the call graph for this function: