DPDK  24.11.0-rc1
Data Structures | Macros | Enumerations | Functions
rte_ip6.h File Reference
#include <stdint.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip6.h>
#include <rte_byteorder.h>
#include <rte_cksum.h>
#include <rte_ether.h>
#include <rte_mbuf.h>

Go to the source code of this file.

Data Structures

struct  rte_ipv6_addr
 
struct  rte_ipv6_hdr
 
struct  rte_ipv6_routing_ext
 

Macros

#define RTE_IPV6_ADDR_SIZE   16
 
#define RTE_IPV6_MAX_DEPTH   (RTE_IPV6_ADDR_SIZE * CHAR_BIT)
 
#define RTE_IPV6_U16_SPLIT(x)
 
#define RTE_IPV6(a, b, c, d, e, f, g, h)
 
#define RTE_IPV6_ADDR_FMT   "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
 
#define RTE_IPV6_ADDR_SPLIT(ip)
 
#define RTE_IPV6_MASK_FULL   RTE_IPV6(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)
 
#define RTE_IPV6_ADDR_UNSPEC   RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 0)
 
#define RTE_IPV6_ADDR_LOOPBACK   RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 1)
 
#define RTE_IPV6_MIN_MTU   1280
 
#define RTE_IPV6_EHDR_MF_SHIFT   0
 
Well known multicast addresses
#define RTE_IPV6_ADDR_ALLNODES_IFACE_LOCAL   RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 1)
 
#define RTE_IPV6_ADDR_ALLNODES_LINK_LOCAL   RTE_IPV6(0xff02, 0, 0, 0, 0, 0, 0, 1)
 
#define RTE_IPV6_ADDR_ALLROUTERS_IFACE_LOCAL   RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 2)
 
#define RTE_IPV6_ADDR_ALLROUTERS_LINK_LOCAL   RTE_IPV6(0xff02, 0, 0, 0, 0, 0, 0, 2)
 
#define RTE_IPV6_ADDR_ALLROUTERS_SITE_LOCAL   RTE_IPV6(0xff05, 0, 0, 0, 0, 0, 0, 2)
 

Enumerations

enum  rte_ipv6_mc_scope {
  RTE_IPV6_MC_SCOPE_NONE = 0x00, RTE_IPV6_MC_SCOPE_IFACELOCAL = 0x01, RTE_IPV6_MC_SCOPE_LINKLOCAL = 0x02, RTE_IPV6_MC_SCOPE_SITELOCAL = 0x05,
  RTE_IPV6_MC_SCOPE_ORGLOCAL = 0x08, RTE_IPV6_MC_SCOPE_GLOBAL = 0x0e
}
 

Functions

static bool rte_ipv6_addr_eq (const struct rte_ipv6_addr *a, const struct rte_ipv6_addr *b)
 
static void rte_ipv6_addr_mask (struct rte_ipv6_addr *ip, uint8_t depth)
 
static bool rte_ipv6_addr_eq_prefix (const struct rte_ipv6_addr *a, const struct rte_ipv6_addr *b, uint8_t depth)
 
static uint8_t rte_ipv6_mask_depth (const struct rte_ipv6_addr *mask)
 
static bool rte_ipv6_addr_is_unspec (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_loopback (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_linklocal (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_sitelocal (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_v4compat (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_v4mapped (const struct rte_ipv6_addr *ip)
 
static bool rte_ipv6_addr_is_mcast (const struct rte_ipv6_addr *ip)
 
static enum rte_ipv6_mc_scope rte_ipv6_mc_scope (const struct rte_ipv6_addr *ip)
 
static void rte_ipv6_solnode_from_addr (struct rte_ipv6_addr *sol, const struct rte_ipv6_addr *ip)
 
static void rte_ether_mcast_from_ipv6 (struct rte_ether_addr *mac, const struct rte_ipv6_addr *ip)
 
static int rte_ipv6_check_version (const struct rte_ipv6_hdr *ip)
 
static uint16_t rte_ipv6_phdr_cksum (const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
 
static uint16_t rte_ipv6_udptcp_cksum (const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
 
static uint16_t rte_ipv6_udptcp_cksum_mbuf (const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
 
static int rte_ipv6_udptcp_cksum_verify (const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
 
static int rte_ipv6_udptcp_cksum_mbuf_verify (const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
 
static int rte_ipv6_get_next_ext (const uint8_t *p, int proto, size_t *ext_len)
 

Detailed Description

IPv6-related defines

Definition in file rte_ip6.h.

Macro Definition Documentation

◆ RTE_IPV6_ADDR_SIZE

#define RTE_IPV6_ADDR_SIZE   16

Maximum IPv6 address size in bytes.

Definition at line 43 of file rte_ip6.h.

◆ RTE_IPV6_MAX_DEPTH

#define RTE_IPV6_MAX_DEPTH   (RTE_IPV6_ADDR_SIZE * CHAR_BIT)

Maximum IPv6 address size in bits.

Definition at line 48 of file rte_ip6.h.

◆ RTE_IPV6_U16_SPLIT

#define RTE_IPV6_U16_SPLIT (   x)
Value:
(uint8_t)((uint16_t)(x) & UINT16_C(0xff)), \
(uint8_t)(((uint16_t)(x) >> 8) & UINT16_C(0xff))

Split a literal 16 bit unsigned integer into two bytes separated by a comma according to the platform endianness.

Parameters
xA uint16_t literal value.
Returns
Two uint8_t literals separated by a coma.

Definition at line 161 of file rte_ip6.h.

◆ RTE_IPV6

#define RTE_IPV6 (   a,
  b,
  c,
  d,
  e,
  f,
  g,
 
)
Value:
{{ \
RTE_IPV6_U16_SPLIT(a), \
RTE_IPV6_U16_SPLIT(b), \
RTE_IPV6_U16_SPLIT(c), \
RTE_IPV6_U16_SPLIT(d), \
RTE_IPV6_U16_SPLIT(e), \
RTE_IPV6_U16_SPLIT(f), \
RTE_IPV6_U16_SPLIT(g), \
RTE_IPV6_U16_SPLIT(h) \
}}

Shorthand to define a literal IPv6 address based on 16bit unsigned integers.

Parameters
a,b,c,d,e,f,g,huint8_t literals that will be passed to RTE_IPV6_U16_SPLIT(x).
Returns
A literal rte_ipv6_addr value suitable for static initialization.
Examples:
examples/ip_fragmentation/main.c, examples/ip_reassembly/main.c, examples/l3fwd-graph/main.c, and examples/l3fwd/main.c.

Definition at line 178 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_FMT

#define RTE_IPV6_ADDR_FMT   "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"

printf() format element for rte_ipv6_addr structures. To be used along with RTE_IPV6_ADDR_SPLIT(ip).

Examples:
examples/cmdline/commands.c, examples/ip_pipeline/cli.c, examples/ipsec-secgw/flow.c, and examples/ipsec-secgw/sa.c.

Definition at line 194 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_SPLIT

#define RTE_IPV6_ADDR_SPLIT (   ip)
Value:
((uint8_t)(ip)->a[0]), \
((uint8_t)(ip)->a[1]), \
((uint8_t)(ip)->a[2]), \
((uint8_t)(ip)->a[3]), \
((uint8_t)(ip)->a[4]), \
((uint8_t)(ip)->a[5]), \
((uint8_t)(ip)->a[6]), \
((uint8_t)(ip)->a[7]), \
((uint8_t)(ip)->a[8]), \
((uint8_t)(ip)->a[9]), \
((uint8_t)(ip)->a[10]), \
((uint8_t)(ip)->a[11]), \
((uint8_t)(ip)->a[12]), \
((uint8_t)(ip)->a[13]), \
((uint8_t)(ip)->a[14]), \
((uint8_t)(ip)->a[15])

For use with RTE_IPV6_ADDR_FMT. E.g.:

Parameters
ipA struct rte_ipv6_addr pointer.
Returns
A set of 16 uint8_t values separated by comas for use in printf().
Examples:
examples/cmdline/commands.c, examples/ip_pipeline/cli.c, examples/ipsec-secgw/flow.c, and examples/ipsec-secgw/sa.c.

Definition at line 209 of file rte_ip6.h.

◆ RTE_IPV6_MASK_FULL

#define RTE_IPV6_MASK_FULL   RTE_IPV6(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff)

Full IPv6 mask. NB: this is not a valid/routable IPv6 address.

Definition at line 228 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_UNSPEC

#define RTE_IPV6_ADDR_UNSPEC   RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 0)

Unspecified IPv6 address as defined in RFC 4291, section 2.5.2.

Examples:
examples/ipsec-secgw/sp6.c.

Definition at line 232 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_LOOPBACK

#define RTE_IPV6_ADDR_LOOPBACK   RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 1)

Loopback IPv6 address as defined in RFC 4291, section 2.5.3.

Definition at line 250 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_ALLNODES_IFACE_LOCAL

#define RTE_IPV6_ADDR_ALLNODES_IFACE_LOCAL   RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 1)

Interface-local all-nodes multicast address as defined in RFC 4291, section 2.7.1.

Definition at line 382 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_ALLNODES_LINK_LOCAL

#define RTE_IPV6_ADDR_ALLNODES_LINK_LOCAL   RTE_IPV6(0xff02, 0, 0, 0, 0, 0, 0, 1)

Link-local all-nodes multicast address as defined in RFC 4291, section 2.7.1.

Definition at line 384 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_ALLROUTERS_IFACE_LOCAL

#define RTE_IPV6_ADDR_ALLROUTERS_IFACE_LOCAL   RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 2)

Interface-local all-routers multicast address as defined in RFC 4291, section 2.7.1.

Definition at line 386 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_ALLROUTERS_LINK_LOCAL

#define RTE_IPV6_ADDR_ALLROUTERS_LINK_LOCAL   RTE_IPV6(0xff02, 0, 0, 0, 0, 0, 0, 2)

Link-local all-routers multicast address as defined in RFC 4291, section 2.7.1.

Definition at line 388 of file rte_ip6.h.

◆ RTE_IPV6_ADDR_ALLROUTERS_SITE_LOCAL

#define RTE_IPV6_ADDR_ALLROUTERS_SITE_LOCAL   RTE_IPV6(0xff05, 0, 0, 0, 0, 0, 0, 2)

Site-local all-routers multicast address as defined in RFC 4291, section 2.7.1.

Definition at line 390 of file rte_ip6.h.

◆ RTE_IPV6_MIN_MTU

#define RTE_IPV6_MIN_MTU   1280

Minimum MTU for IPv6, see RFC 8200.

Definition at line 536 of file rte_ip6.h.

◆ RTE_IPV6_EHDR_MF_SHIFT

#define RTE_IPV6_EHDR_MF_SHIFT   0

IPv6 fragment extension header.

Definition at line 740 of file rte_ip6.h.

Enumeration Type Documentation

◆ rte_ipv6_mc_scope

IPv6 multicast scope values as defined in RFC 4291, section 2.7.

Enumerator
RTE_IPV6_MC_SCOPE_NONE 

Invalid multicast scope.

RTE_IPV6_MC_SCOPE_IFACELOCAL 

Interface-local multicast scope.

RTE_IPV6_MC_SCOPE_LINKLOCAL 

Link-local multicast scope.

RTE_IPV6_MC_SCOPE_SITELOCAL 

Site-local multicast scope.

RTE_IPV6_MC_SCOPE_ORGLOCAL 

Organizational-local multicast scope.

RTE_IPV6_MC_SCOPE_GLOBAL 

Global multicast scope.

Definition at line 347 of file rte_ip6.h.

Function Documentation

◆ rte_ipv6_addr_eq()

static bool rte_ipv6_addr_eq ( const struct rte_ipv6_addr a,
const struct rte_ipv6_addr b 
)
inlinestatic

Check if two IPv6 Addresses are equal.

Parameters
aThe first address.
bThe second address.
Returns
true if both addresses are identical.

Definition at line 68 of file rte_ip6.h.

◆ rte_ipv6_addr_mask()

static void rte_ipv6_addr_mask ( struct rte_ipv6_addr ip,
uint8_t  depth 
)
inlinestatic

Mask an IPv6 address using the specified depth.

Leave untouched one bit per unit in the depth variable and set the rest to 0.

Parameters
[in]ipThe address to mask.
[out]depthAll bits starting from this bit number will be set to zero.

Definition at line 84 of file rte_ip6.h.

◆ rte_ipv6_addr_eq_prefix()

static bool rte_ipv6_addr_eq_prefix ( const struct rte_ipv6_addr a,
const struct rte_ipv6_addr b,
uint8_t  depth 
)
inlinestatic

Check if two IPv6 addresses belong to the same network prefix.

Parameters
aThe first address or network.
bThe second address or network.
depthThe network prefix length.
Returns
true if the first depth bits of both addresses are identical.

Definition at line 108 of file rte_ip6.h.

◆ rte_ipv6_mask_depth()

static uint8_t rte_ipv6_mask_depth ( const struct rte_ipv6_addr mask)
inlinestatic

Get the depth of a given IPv6 address mask.

Parameters
maskThe address mask.
Returns
The number of consecutive bits set to 1 starting from the beginning of the mask.

Definition at line 131 of file rte_ip6.h.

◆ rte_ipv6_addr_is_unspec()

static bool rte_ipv6_addr_is_unspec ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is unspecified as defined in RFC 4291, section 2.5.2.

Parameters
ipThe address to check.
Returns
true if the address is the unspecified address (all zeroes).
Examples:
examples/ipsec-secgw/sa.c.

Definition at line 243 of file rte_ip6.h.

◆ rte_ipv6_addr_is_loopback()

static bool rte_ipv6_addr_is_loopback ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is the loopback address as defined in RFC 4291, section 2.5.3.

Parameters
ipThe address to check.
Returns
true if the address is the loopback address (all zeroes except the last bit).

Definition at line 262 of file rte_ip6.h.

◆ rte_ipv6_addr_is_linklocal()

static bool rte_ipv6_addr_is_linklocal ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is link-local as defined in RFC 4291, section 2.5.6.

Parameters
ipThe address to check.
Returns
true if the address is a link-local address.

Definition at line 277 of file rte_ip6.h.

◆ rte_ipv6_addr_is_sitelocal()

static bool rte_ipv6_addr_is_sitelocal ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is site-local as defined in RFC 4291, section 2.5.7.

Parameters
ipThe address to check.
Returns
true if the address is a site-local address.

Definition at line 291 of file rte_ip6.h.

◆ rte_ipv6_addr_is_v4compat()

static bool rte_ipv6_addr_is_v4compat ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is an IPv4-compatible address as defined in RFC 4291, section 2.5.5.1.

Parameters
ipThe address to check.
Returns
true if the address is an IPv4-compatible address.

Definition at line 306 of file rte_ip6.h.

◆ rte_ipv6_addr_is_v4mapped()

static bool rte_ipv6_addr_is_v4mapped ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is an IPv4-mapped address as defined in RFC 4291, section 2.5.5.2.

Parameters
ipThe address to check.
Returns
true if the address is an IPv4-mapped address.

Definition at line 324 of file rte_ip6.h.

◆ rte_ipv6_addr_is_mcast()

static bool rte_ipv6_addr_is_mcast ( const struct rte_ipv6_addr ip)
inlinestatic

Check if an IPv6 address is multicast as defined in RFC 4291, section 2.7.

Parameters
ipThe address to check.
Returns
true if the address is multicast.

Definition at line 339 of file rte_ip6.h.

◆ rte_ipv6_mc_scope()

static enum rte_ipv6_mc_scope rte_ipv6_mc_scope ( const struct rte_ipv6_addr ip)
inlinestatic

Extract the IPv6 multicast scope value as defined in RFC 4291, section 2.7.

Parameters
ipThe address from which to get the multicast scope.
Returns
The multicast scope of the address, or RTE_IPV6_MC_SCOPE_NONE if the address is not multicast.

Definition at line 372 of file rte_ip6.h.

◆ rte_ipv6_solnode_from_addr()

static void rte_ipv6_solnode_from_addr ( struct rte_ipv6_addr sol,
const struct rte_ipv6_addr ip 
)
inlinestatic

Convert a unicast or anycast IPv6 address to a solicited-node multicast address as defined in RFC 4291, section 2.7.1.

Parameters
[out]solThe IPv6 solicited-node multicast address to generate.
[in]ipA unicast or anycast address.

Definition at line 428 of file rte_ip6.h.

◆ rte_ether_mcast_from_ipv6()

static void rte_ether_mcast_from_ipv6 ( struct rte_ether_addr *  mac,
const struct rte_ipv6_addr ip 
)
inlinestatic

Generate a multicast Ethernet address from a multicast IPv6 address as defined in RFC 2464, section 7.

Parameters
[out]macThe multicast Ethernet address to generate.
[in]ipA multicast IPv6 address.

Definition at line 450 of file rte_ip6.h.

◆ rte_ipv6_check_version()

static int rte_ipv6_check_version ( const struct rte_ipv6_hdr ip)
inlinestatic

Check that the IPv6 header version field is valid according to RFC 8200 section 3.

Parameters
ipThe IPv6 header.
Returns
0 if the version field is valid. -EINVAL otherwise.

Definition at line 496 of file rte_ip6.h.

◆ rte_ipv6_phdr_cksum()

static uint16_t rte_ipv6_phdr_cksum ( const struct rte_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.
Examples:
examples/vhost/main.c.

Definition at line 555 of file rte_ip6.h.

◆ rte_ipv6_udptcp_cksum()

static uint16_t rte_ipv6_udptcp_cksum ( const struct rte_ipv6_hdr ipv6_hdr,
const void *  l4_hdr 
)
inlinestatic

Process the IPv6 UDP or TCP checksum.

The IPv6 header must not be followed by extension headers. The layer 4 checksum must be set to 0 in the L4 header 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 L4 header.

Definition at line 609 of file rte_ip6.h.

◆ rte_ipv6_udptcp_cksum_mbuf()

static uint16_t rte_ipv6_udptcp_cksum_mbuf ( const struct rte_mbuf m,
const struct rte_ipv6_hdr ipv6_hdr,
uint16_t  l4_off 
)
inlinestatic

Process the IPv6 UDP or TCP checksum of a packet.

The IPv6 header must not be followed by extension headers. The layer 4 checksum must be set to 0 in the L4 header by the caller.

Parameters
mThe pointer to the mbuf.
ipv6_hdrThe pointer to the contiguous IPv6 header.
l4_offThe offset in bytes to start L4 checksum.
Returns
The complemented checksum to set in the L4 header.

Definition at line 666 of file rte_ip6.h.

◆ rte_ipv6_udptcp_cksum_verify()

static int rte_ipv6_udptcp_cksum_verify ( const struct rte_ipv6_hdr ipv6_hdr,
const void *  l4_hdr 
)
inlinestatic

Validate the IPv6 UDP or TCP checksum.

In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0: this is either invalid or means no checksum in some situations. See 8.1 (Upper-Layer Checksums) in RFC 8200.

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

Definition at line 699 of file rte_ip6.h.

◆ rte_ipv6_udptcp_cksum_mbuf_verify()

static int rte_ipv6_udptcp_cksum_mbuf_verify ( const struct rte_mbuf m,
const struct rte_ipv6_hdr ipv6_hdr,
uint16_t  l4_off 
)
inlinestatic

Validate the IPv6 UDP or TCP checksum of a packet.

In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0: this is either invalid or means no checksum in some situations. See 8.1 (Upper-Layer Checksums) in RFC 8200.

Parameters
mThe pointer to the mbuf.
ipv6_hdrThe pointer to the contiguous IPv6 header.
l4_offThe offset in bytes to start L4 checksum.
Returns
Return 0 if the checksum is correct, else -1.

Definition at line 727 of file rte_ip6.h.

◆ rte_ipv6_get_next_ext()

static int rte_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
Examples:
examples/ipsec-secgw/ipsec-secgw.c, and examples/ipsec-secgw/ipsec_worker.c.

Definition at line 781 of file rte_ip6.h.