CNDP  22.08.0
cne_ip.h File Reference
#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <cne_byteorder.h>
#include <pktmbuf.h>

Go to the source code of this file.

Data Structures

struct  cne_ipv4_hdr
 
struct  cne_ipv6_hdr
 

Macros

#define CNE_IPV4(a, b, c, d)    ((uint32_t)(((a)&0xff) << 24) | (((b)&0xff) << 16) | (((c)&0xff) << 8) | ((d)&0xff))
 
#define CNE_IPV4_MAX_PKT_LEN   65535
 
#define CNE_IPV4_HDR_IHL_MASK   (0x0f)
 
#define CNE_IPV4_IHL_MULTIPLIER   (4)
 
#define CNE_IPV4_ANY   ((uint32_t)0x00000000)
 
#define CNE_IPV4_LOOPBACK   ((uint32_t)0x7f000001)
 
#define CNE_IPV4_BROADCAST   ((uint32_t)0xe0000000)
 
#define CNE_IPV4_ALLHOSTS_GROUP   ((uint32_t)0xe0000001)
 
#define CNE_IPV4_ALLRTRS_GROUP   ((uint32_t)0xe0000002)
 
#define CNE_IPV4_MAX_LOCAL_GROUP   ((uint32_t)0xe00000ff)
 
#define CNE_IPV4_MIN_MCAST   CNE_IPV4(224, 0, 0, 0)
 
#define CNE_IPV4_MAX_MCAST    CNE_IPV4(239, 255, 255, 255)
 
#define CNE_IS_IPV4_MCAST(x)   ((x) >= CNE_IPV4_MIN_MCAST && (x) <= CNE_IPV4_MAX_MCAST)
 
#define CNE_IPV6_MIN_MTU   1280
 
#define CNE_IPV6_EHDR_MF_SHIFT   0
 

Functions

static uint8_t cne_ipv4_hdr_len (const struct cne_ipv4_hdr *ipv4_hdr)
 
static uint16_t cne_raw_cksum (const void *buf, size_t len)
 
static uint16_t cne_raw_cksum_mbuf (const pktmbuf_t *m, uint32_t off, uint32_t len)
 
static uint16_t cne_ipv4_cksum (const struct cne_ipv4_hdr *ipv4_hdr)
 
static uint16_t cne_ipv4_phdr_cksum (const struct cne_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
 
static uint16_t __ipv4_udptcp_cksum (const struct cne_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
 
static uint16_t cne_ipv4_udptcp_cksum (const struct cne_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
 
static int cne_ipv4_udptcp_cksum_verify (const struct cne_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
 
static uint16_t cne_ipv6_phdr_cksum (const struct cne_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
 
static uint16_t cne_ipv6_udptcp_cksum (const struct cne_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
 
static int cne_ipv6_get_next_ext (const uint8_t *p, int proto, size_t *ext_len)
 

Detailed Description

IP-related defines

Definition in file cne_ip.h.

Macro Definition Documentation

◆ CNE_IPV4

#define CNE_IPV4 (   a,
  b,
  c,
 
)     ((uint32_t)(((a)&0xff) << 24) | (((b)&0xff) << 16) | (((c)&0xff) << 8) | ((d)&0xff))

Create IPv4 address

Examples
examples/cndpfwd/acl-func.c, and examples/l3fwd-graph/fwd.c.

Definition at line 47 of file cne_ip.h.

◆ CNE_IPV4_MAX_PKT_LEN

#define CNE_IPV4_MAX_PKT_LEN   65535

Maximal IPv4 packet length (including a header)

Definition at line 51 of file cne_ip.h.

◆ CNE_IPV4_HDR_IHL_MASK

#define CNE_IPV4_HDR_IHL_MASK   (0x0f)

Internet header length mask for version_ihl field

Definition at line 54 of file cne_ip.h.

◆ CNE_IPV4_IHL_MULTIPLIER

#define CNE_IPV4_IHL_MULTIPLIER   (4)

Internet header length field multiplier (IHL field specifies overall header length in number of 4-byte words)

Definition at line 59 of file cne_ip.h.

◆ CNE_IPV4_ANY

#define CNE_IPV4_ANY   ((uint32_t)0x00000000)

0.0.0.0

Definition at line 81 of file cne_ip.h.

◆ CNE_IPV4_LOOPBACK

#define CNE_IPV4_LOOPBACK   ((uint32_t)0x7f000001)

127.0.0.1

Definition at line 82 of file cne_ip.h.

◆ CNE_IPV4_BROADCAST

#define CNE_IPV4_BROADCAST   ((uint32_t)0xe0000000)

224.0.0.0

Definition at line 83 of file cne_ip.h.

◆ CNE_IPV4_ALLHOSTS_GROUP

#define CNE_IPV4_ALLHOSTS_GROUP   ((uint32_t)0xe0000001)

224.0.0.1

Definition at line 84 of file cne_ip.h.

◆ CNE_IPV4_ALLRTRS_GROUP

#define CNE_IPV4_ALLRTRS_GROUP   ((uint32_t)0xe0000002)

224.0.0.2

Definition at line 85 of file cne_ip.h.

◆ CNE_IPV4_MAX_LOCAL_GROUP

#define CNE_IPV4_MAX_LOCAL_GROUP   ((uint32_t)0xe00000ff)

224.0.0.255

Definition at line 86 of file cne_ip.h.

◆ CNE_IPV4_MIN_MCAST

#define CNE_IPV4_MIN_MCAST   CNE_IPV4(224, 0, 0, 0)

Minimal IPv4-multicast address

Definition at line 91 of file cne_ip.h.

◆ CNE_IPV4_MAX_MCAST

#define CNE_IPV4_MAX_MCAST    CNE_IPV4(239, 255, 255, 255)

Maximum IPv4 multicast address \

Definition at line 94 of file cne_ip.h.

◆ CNE_IS_IPV4_MCAST

#define CNE_IS_IPV4_MCAST (   x)    ((x) >= CNE_IPV4_MIN_MCAST && (x) <= CNE_IPV4_MAX_MCAST)

check if IPv4 address is multicast

Definition at line 98 of file cne_ip.h.

◆ CNE_IPV6_MIN_MTU

#define CNE_IPV6_MIN_MTU   1280

Minimum MTU for IPv6, see RFC 8200.

Definition at line 390 of file cne_ip.h.

◆ CNE_IPV6_EHDR_MF_SHIFT

#define CNE_IPV6_EHDR_MF_SHIFT   0

IPv6 fragment extension header.

Definition at line 459 of file cne_ip.h.

Function Documentation

◆ cne_ipv4_hdr_len()

static uint8_t cne_ipv4_hdr_len ( const struct cne_ipv4_hdr ipv4_hdr)
inlinestatic

Get the length of an IPv4 header.

Parameters
ipv4_hdrPointer to the IPv4 header.
Returns
The length of the IPv4 header (with options if present) in bytes.

Definition at line 113 of file cne_ip.h.

◆ cne_raw_cksum()

static uint16_t cne_raw_cksum ( const void *  buf,
size_t  len 
)
inlinestatic

Process the non-complemented checksum of a buffer.

Parameters
bufPointer to the buffer.
lenLength of the buffer.
Returns
The non-complemented checksum.

Definition at line 191 of file cne_ip.h.

◆ cne_raw_cksum_mbuf()

static uint16_t cne_raw_cksum_mbuf ( const pktmbuf_t m,
uint32_t  off,
uint32_t  len 
)
inlinestatic

Compute the raw (non complemented) checksum of a packet.

Parameters
mThe pointer to the mbuf.
offThe offset in bytes to start the checksum.
lenThe length in bytes of the data to checksum.
Returns
checksum value

Definition at line 212 of file cne_ip.h.

◆ cne_ipv4_cksum()

static uint16_t cne_ipv4_cksum ( const struct cne_ipv4_hdr ipv4_hdr)
inlinestatic

Process the IPv4 checksum of an IPv4 header.

The checksum field must be set to 0 by the caller.

Parameters
ipv4_hdrThe pointer to the contiguous IPv4 header.
Returns
The complemented checksum to set in the IP packet.

Definition at line 228 of file cne_ip.h.

◆ cne_ipv4_phdr_cksum()

static uint16_t cne_ipv4_phdr_cksum ( const struct cne_ipv4_hdr ipv4_hdr,
uint64_t  ol_flags 
)
inlinestatic

Process the pseudo-header checksum of an IPv4 header.

The checksum field must be set to 0 by the caller.

Depending on the ol_flags, the pseudo-header checksum expected by the drivers is not the same. For instance, when TSO is enabled, the IP payload length must not be included in the packet.

When ol_flags is 0, it computes the standard pseudo-header checksum.

Parameters
ipv4_hdrThe pointer to the contiguous IPv4 header.
ol_flagsThe ol_flags of the associated mbuf.
Returns
The non-complemented checksum to set in the L4 header.

Definition at line 254 of file cne_ip.h.

◆ __ipv4_udptcp_cksum()

static uint16_t __ipv4_udptcp_cksum ( const struct cne_ipv4_hdr ipv4_hdr,
const void *  l4_hdr 
)
inlinestatic

Process the IPv4 UDP or TCP checksum.

The IP and layer 4 checksum must be set to 0 in the packet by the caller.

Parameters
ipv4_hdrThe pointer to the contiguous IPv4 header.
l4_hdrThe pointer to the beginning of the L4 header.
Returns
The complemented checksum to set in the IP packet.

Definition at line 294 of file cne_ip.h.

◆ cne_ipv4_udptcp_cksum()

static uint16_t cne_ipv4_udptcp_cksum ( const struct cne_ipv4_hdr ipv4_hdr,
const void *  l4_hdr 
)
inlinestatic

Process the IPv4 UDP or TCP checksum.

The IP and layer 4 checksum must be set to 0 in the packet by the caller.

Parameters
ipv4_hdrThe pointer to the contiguous IPv4 header.
l4_hdrThe pointer to the beginning of the L4 header.
Returns
The complemented checksum to set in the IP packet.

Definition at line 329 of file cne_ip.h.

◆ cne_ipv4_udptcp_cksum_verify()

static int cne_ipv4_udptcp_cksum_verify ( const struct cne_ipv4_hdr ipv4_hdr,
const void *  l4_hdr 
)
inlinestatic

Validate the IPv4 UDP or TCP checksum.

In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0 (i.e. no checksum).

Parameters
ipv4_hdrThe pointer to the contiguous IPv4 header.
l4_hdrThe pointer to the beginning of the L4 header.
Returns
Return 0 if the checksum is correct, else -1.

Definition at line 359 of file cne_ip.h.

◆ cne_ipv6_phdr_cksum()

static uint16_t cne_ipv6_phdr_cksum ( const struct cne_ipv6_hdr ipv6_hdr,
uint64_t  ol_flags 
)
inlinestatic

Process the pseudo-header checksum of an IPv6 header.

Depending on the ol_flags, the pseudo-header checksum expected by the drivers is not the same. For instance, when TSO is enabled, the IPv6 payload length must not be included in the packet.

When ol_flags is 0, it computes the standard pseudo-header checksum.

Parameters
ipv6_hdrThe pointer to the contiguous IPv6 header.
ol_flagsThe ol_flags of the associated mbuf.
Returns
The non-complemented checksum to set in the L4 header.

Definition at line 409 of file cne_ip.h.

◆ cne_ipv6_udptcp_cksum()

static uint16_t cne_ipv6_udptcp_cksum ( const struct cne_ipv6_hdr ipv6_hdr,
const void *  l4_hdr 
)
inlinestatic

Process the IPv6 UDP or TCP checksum.

The IPv4 header should not contains options. The layer 4 checksum must be set to 0 in the packet by the caller.

Parameters
ipv6_hdrThe pointer to the contiguous IPv6 header.
l4_hdrThe pointer to the beginning of the L4 header.
Returns
The complemented checksum to set in the IP packet.

Definition at line 440 of file cne_ip.h.

◆ cne_ipv6_get_next_ext()

static int cne_ipv6_get_next_ext ( const uint8_t *  p,
int  proto,
size_t *  ext_len 
)
inlinestatic

Parse next IPv6 header extension

This function checks if proto number is an IPv6 extensions and parses its data if so, providing information on next header and extension length.

Parameters
pPointer to an extension raw data.
protoProtocol number extracted from the "next header" field from the IPv6 header or the previous extension.
ext_lenExtension data length.
Returns
next protocol number if proto is an IPv6 extension, -EINVAL otherwise

Definition at line 500 of file cne_ip.h.