---
name: "rte_ip4.h"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_ip4.h"
---

# rte\_ip4.h(3)

## NAME

rte\_ip4.h

## SYNOPSIS

`#include <stdint.h>`\
 `#include <sys/socket.h>`\
 `#include <sys/types.h>`\
 `#include <netinet/in.h>`\
 `#include <arpa/inet.h>`\
 `#include <netinet/ip.h>`\
 `#include <netinet/ip6.h>`\
 `#include <rte_byteorder.h>`\
 `#include <rte_cksum.h>`\
 `#include <rte_mbuf.h>`\

### Macros

\#define **RTE\_IPV4**(a,  b,  c,  d)\
 \#define **RTE\_IPV4\_MAX\_PKT\_LEN**   65535\
 \#define **RTE\_IPV4\_HDR\_IHL\_MASK**   (0x0f)\
 \#define **RTE\_IPV4\_IHL\_MULTIPLIER**   (4)\
 \#define **RTE\_IPV4\_ANY**   ((uint32\_t)0x00000000)\
 \#define **RTE\_IPV4\_LOOPBACK**   ((uint32\_t)0x7f000001)\
 \#define **RTE\_IPV4\_BROADCAST**   ((uint32\_t)0xe0000000)\
 \#define **RTE\_IPV4\_ALLHOSTS\_GROUP**   ((uint32\_t)0xe0000001)\
 \#define **RTE\_IPV4\_ALLRTRS\_GROUP**   ((uint32\_t)0xe0000002)\
 \#define **RTE\_IPV4\_MAX\_LOCAL\_GROUP**   ((uint32\_t)0xe00000ff)\
 \#define **RTE\_IPV4\_MIN\_MCAST**   	**RTE\_IPV4**(224, 0, 0, 0)\
 \#define **RTE\_IPV4\_MAX\_MCAST**   	**RTE\_IPV4**(239, 255, 255, 255)\
 \#define **RTE\_IPV4\_MIN\_IHL**   (0x5)\

### Functions

struct **\_\_rte\_aligned** (2) rte\_ipv4\_hdr\
 static uint8\_t **rte\_ipv4\_hdr\_len** (const struct rte\_ipv4\_hdr \*ipv4\_hdr)\
 static uint16\_t **rte\_ipv4\_cksum** (const struct rte\_ipv4\_hdr \*ipv4\_hdr)\
 static \_\_rte\_experimental uint16\_t **rte\_ipv4\_cksum\_simple** (const struct rte\_ipv4\_hdr \*ipv4\_hdr)\
 static uint16\_t **rte\_ipv4\_phdr\_cksum** (const struct rte\_ipv4\_hdr \*ipv4\_hdr, uint64\_t ol\_flags)\
 static uint16\_t **rte\_ipv4\_udptcp\_cksum** (const struct rte\_ipv4\_hdr \*ipv4\_hdr, const void \*l4\_hdr)\
 static uint16\_t **rte\_ipv4\_udptcp\_cksum\_mbuf** (const struct **rte\_mbuf** \*m, const struct rte\_ipv4\_hdr \*ipv4\_hdr, uint16\_t l4\_off)\
 static int **rte\_ipv4\_udptcp\_cksum\_verify** (const struct rte\_ipv4\_hdr \*ipv4\_hdr, const void \*l4\_hdr)\
 static int **rte\_ipv4\_udptcp\_cksum\_mbuf\_verify** (const struct **rte\_mbuf** \*m, const struct rte\_ipv4\_hdr \*ipv4\_hdr, uint16\_t l4\_off)\

## Detailed Description

IPv4-related defines

Definition in file **rte\_ip4.h**.

## Macro Definition Documentation

### #define RTE\_IPV4(a, b, c, d)

**Value:**.PP

```
                       ((uint32_t)(((a) & 0xff) << 24) | \
                       (((b) & 0xff) << 16) | \
                       (((c) & 0xff) << 8)  | \
                       ((d) & 0xff))
```

Create IPv4 address

Definition at line **68** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_MAX\_PKT\_LEN 65535

Maximal IPv4 packet length (including a header)

Definition at line **74** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_HDR\_IHL\_MASK (0x0f)

Internet header length mask for version\_ihl field

Definition at line **77** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_IHL\_MULTIPLIER (4)

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

Definition at line **82** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_ANY ((uint32\_t)0x00000000)

0\.0.0.0

Definition at line **110** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_LOOPBACK ((uint32\_t)0x7f000001)

127\.0.0.1

Definition at line **111** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_BROADCAST ((uint32\_t)0xe0000000)

224\.0.0.0

Definition at line **112** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_ALLHOSTS\_GROUP ((uint32\_t)0xe0000001)

224\.0.0.1

Definition at line **113** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_ALLRTRS\_GROUP ((uint32\_t)0xe0000002)

224\.0.0.2

Definition at line **114** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_MAX\_LOCAL\_GROUP ((uint32\_t)0xe00000ff)

224\.0.0.255

Definition at line **115** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_MIN\_MCAST RTE\_IPV4(224, 0, 0, 0)

Minimal IPv4-multicast address

Definition at line **121** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_MAX\_MCAST RTE\_IPV4(239, 255, 255, 255)

Maximum IPv4 multicast address

Definition at line **123** of file **rte\_ip4.h**.

### #define RTE\_IPV4\_MIN\_IHL (0x5)

\< check if IPv4 address is multicast

Definition at line **130** of file **rte\_ip4.h**.

## Function Documentation

### struct \_\_rte\_aligned (2)

IPv4 Header \< version and header length

\< header length

\< version

\< type of service

\< length of packet

\< packet ID

\< fragmentation offset

\< time to live

\< protocol ID

\< header checksum

\< source address

\< destination address

Definition at line **1** of file **rte\_ip4.h**.

### static uint8\_t rte\_ipv4\_hdr\_len (const struct rte\_ipv4\_hdr \* ipv4\_hdr)` [inline]`, ` [static]`

Get the length of an IPv4 header.

**Parameters**

*ipv4\_hdr* Pointer to the IPv4 header.

**Returns**

The length of the IPv4 header (with options if present) in bytes.

Definition at line **142** of file **rte\_ip4.h**.

### static uint16\_t rte\_ipv4\_cksum (const struct rte\_ipv4\_hdr \* ipv4\_hdr)` [inline]`, ` [static]`

Process the IPv4 checksum of an IPv4 header.

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

**Parameters**

*ipv4\_hdr* The pointer to the contiguous IPv4 header.

**Returns**

The complemented checksum to set in the IP packet.

Definition at line **159** of file **rte\_ip4.h**.

### static \_\_rte\_experimental uint16\_t rte\_ipv4\_cksum\_simple (const struct rte\_ipv4\_hdr \* ipv4\_hdr)` [inline]`, ` [static]`

**Warning**

**EXPERIMENTAL:** this API may change without prior notice.

Process the IPv4 checksum of an IPv4 header without any extensions.

The checksum field does NOT have to be set by the caller, the field is skipped by the calculation.

**Parameters**

*ipv4\_hdr* The pointer to the contiguous IPv4 header.

**Returns**

The complemented checksum to set in the IP packet.

Definition at line **182** of file **rte\_ip4.h**.

### static uint16\_t rte\_ipv4\_phdr\_cksum (const struct rte\_ipv4\_hdr \* ipv4\_hdr, uint64\_t ol\_flags)` [inline]`, ` [static]`

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\_hdr* The pointer to the contiguous IPv4 header. \
 *ol\_flags* The ol\_flags of the associated mbuf.

**Returns**

The non-complemented checksum to set in the L4 header.

Definition at line **220** of file **rte\_ip4.h**.

### static uint16\_t rte\_ipv4\_udptcp\_cksum (const struct rte\_ipv4\_hdr \* ipv4\_hdr, const void \* l4\_hdr)` [inline]`, ` [static]`

Process the IPv4 UDP or TCP checksum.

The layer 4 checksum must be set to 0 in the L4 header by the caller.

**Parameters**

*ipv4\_hdr* The pointer to the contiguous IPv4 header. \
 *l4\_hdr* The pointer to the beginning of the L4 header.

**Returns**

The complemented checksum to set in the L4 header.

Definition at line **284** of file **rte\_ip4.h**.

### static uint16\_t rte\_ipv4\_udptcp\_cksum\_mbuf (const struct rte\_mbuf \* m, const struct rte\_ipv4\_hdr \* ipv4\_hdr, uint16\_t l4\_off)` [inline]`, ` [static]`

Compute the IPv4 UDP/TCP checksum of a packet.

**Parameters**

*m* The pointer to the mbuf. \
 *ipv4\_hdr* The pointer to the contiguous IPv4 header. \
 *l4\_off* The offset in bytes to start L4 checksum.

**Returns**

The complemented checksum to set in the L4 header.

Definition at line **341** of file **rte\_ip4.h**.

### static int rte\_ipv4\_udptcp\_cksum\_verify (const struct rte\_ipv4\_hdr \* ipv4\_hdr, const void \* l4\_hdr)` [inline]`, ` [static]`

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\_hdr* The pointer to the contiguous IPv4 header. \
 *l4\_hdr* The pointer to the beginning of the L4 header.

**Returns**

Return 0 if the checksum is correct, else -1.

Definition at line **373** of file **rte\_ip4.h**.

### static int rte\_ipv4\_udptcp\_cksum\_mbuf\_verify (const struct rte\_mbuf \* m, const struct rte\_ipv4\_hdr \* ipv4\_hdr, uint16\_t l4\_off)` [inline]`, ` [static]`

Verify the IPv4 UDP/TCP checksum of a packet.

In case of UDP, the caller must first check if udp\_hdr-\>dgram\_cksum is 0 (i.e. no checksum).

**Parameters**

*m* The pointer to the mbuf. \
 *ipv4\_hdr* The pointer to the contiguous IPv4 header. \
 *l4\_off* The offset in bytes to start L4 checksum.

**Returns**

Return 0 if the checksum is correct, else -1.

Definition at line **400** of file **rte\_ip4.h**.

## Author

Generated automatically by Doxygen for DPDK from the source code.
