DPDK 26.11.0-rc2
Data Structures | Macros | Functions
rte_ether.h File Reference
#include <assert.h>
#include <stdalign.h>
#include <stdint.h>
#include <stdio.h>
#include <rte_random.h>
#include <rte_mbuf.h>
#include <rte_byteorder.h>

Go to the source code of this file.

Data Structures

struct  rte_ether_hdr
 
struct  rte_vlan_hdr
 

Macros

#define RTE_ETHER_ADDR_LEN   6
 
#define RTE_ETHER_TYPE_LEN   2
 
#define RTE_ETHER_CRC_LEN   4
 
#define RTE_ETHER_HDR_LEN
 
#define RTE_ETHER_MIN_LEN   64
 
#define RTE_ETHER_MAX_LEN   1518
 
#define RTE_ETHER_MTU
 
#define RTE_VLAN_HLEN   4
 
#define RTE_ETHER_MAX_VLAN_FRAME_LEN    (RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
 
#define RTE_ETHER_MAX_JUMBO_FRAME_LEN    0x3F00
 
#define RTE_ETHER_MAX_VLAN_ID   4095
 
#define RTE_ETHER_MIN_MTU   68
 
#define RTE_ETHER_LOCAL_ADMIN_ADDR   0x02
 
#define RTE_ETHER_GROUP_ADDR   0x01
 
#define RTE_ETHER_ADDR_PRT_FMT   "%02X:%02X:%02X:%02X:%02X:%02X"
 
#define RTE_ETHER_ADDR_BYTES(mac_addrs)
 
#define RTE_ETHER_TYPE_IPV4   0x0800
 
#define RTE_ETHER_TYPE_IPV6   0x86DD
 
#define RTE_ETHER_TYPE_ARP   0x0806
 
#define RTE_ETHER_TYPE_RARP   0x8035
 
#define RTE_ETHER_TYPE_VLAN   0x8100
 
#define RTE_ETHER_TYPE_QINQ   0x88A8
 
#define RTE_ETHER_TYPE_QINQ1   0x9100
 
#define RTE_ETHER_TYPE_QINQ2   0x9200
 
#define RTE_ETHER_TYPE_QINQ3   0x9300
 
#define RTE_ETHER_TYPE_PPPOE_DISCOVERY   0x8863
 
#define RTE_ETHER_TYPE_PPPOE_SESSION   0x8864
 
#define RTE_ETHER_TYPE_ETAG   0x893F
 
#define RTE_ETHER_TYPE_1588   0x88F7
 
#define RTE_ETHER_TYPE_SLOW   0x8809
 
#define RTE_ETHER_TYPE_TEB   0x6558
 
#define RTE_ETHER_TYPE_LLDP   0x88CC
 
#define RTE_ETHER_TYPE_MPLS   0x8847
 
#define RTE_ETHER_TYPE_MPLSM   0x8848
 
#define RTE_ETHER_TYPE_ECPRI   0xAEFE
 

Functions

struct __rte_aligned (2) rte_ether_addr
 
static int rte_is_same_ether_addr (const struct rte_ether_addr *ea1, const struct rte_ether_addr *ea2)
 
static int rte_is_zero_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_unicast_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_multicast_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_broadcast_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_universal_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_local_admin_ether_addr (const struct rte_ether_addr *ea)
 
static int rte_is_valid_assigned_ether_addr (const struct rte_ether_addr *ea)
 
void rte_eth_random_addr (uint8_t *addr)
 
static void rte_ether_addr_copy (const struct rte_ether_addr *__restrict ea_from, struct rte_ether_addr *__restrict ea_to)
 
void rte_ether_format_addr (char *buf, uint16_t size, const struct rte_ether_addr *eth_addr)
 
int rte_ether_unformat_addr (const char *str, struct rte_ether_addr *eth_addr)
 
static int rte_vlan_strip (struct rte_mbuf *m)
 
static int rte_vlan_insert (struct rte_mbuf **m)
 
static __rte_experimental int rte_vlan_insert_tpid (struct rte_mbuf **m, uint16_t tpid)
 

Detailed Description

Ethernet Helpers in RTE

Definition in file rte_ether.h.

Macro Definition Documentation

◆ RTE_ETHER_ADDR_LEN

#define RTE_ETHER_ADDR_LEN   6

◆ RTE_ETHER_TYPE_LEN

#define RTE_ETHER_TYPE_LEN   2

Length of Ethernet type field.

Definition at line 28 of file rte_ether.h.

◆ RTE_ETHER_CRC_LEN

#define RTE_ETHER_CRC_LEN   4

◆ RTE_ETHER_HDR_LEN

#define RTE_ETHER_HDR_LEN

◆ RTE_ETHER_MIN_LEN

#define RTE_ETHER_MIN_LEN   64

Minimum frame len, including CRC.

Examples
examples/dma/dmafwd.c.

Definition at line 33 of file rte_ether.h.

◆ RTE_ETHER_MAX_LEN

#define RTE_ETHER_MAX_LEN   1518

Maximum frame len, including CRC.

Definition at line 34 of file rte_ether.h.

◆ RTE_ETHER_MTU

#define RTE_ETHER_MTU
Value:
RTE_ETHER_CRC_LEN)
#define RTE_ETHER_HDR_LEN
Definition: rte_ether.h:30
#define RTE_ETHER_MAX_LEN
Definition: rte_ether.h:34

Ethernet MTU.

Examples
examples/ipsec-secgw/ipsec-secgw.c, examples/l3fwd-graph/main.c, examples/l3fwd-power/main.c, and examples/l3fwd/main.c.

Definition at line 37 of file rte_ether.h.

◆ RTE_VLAN_HLEN

#define RTE_VLAN_HLEN   4

VLAN (IEEE 802.1Q) header length.

Examples
examples/l2fwd-macsec/main.c, and examples/vhost/main.c.

Definition at line 39 of file rte_ether.h.

◆ RTE_ETHER_MAX_VLAN_FRAME_LEN

#define RTE_ETHER_MAX_VLAN_FRAME_LEN    (RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)

Maximum VLAN frame length (excluding QinQ), including CRC.

Definition at line 41 of file rte_ether.h.

◆ RTE_ETHER_MAX_JUMBO_FRAME_LEN

#define RTE_ETHER_MAX_JUMBO_FRAME_LEN    0x3F00

Maximum Jumbo frame length, including CRC.

Examples
examples/dma/dmafwd.c, and examples/ethtool/ethtool-app/ethapp.c.

Definition at line 45 of file rte_ether.h.

◆ RTE_ETHER_MAX_VLAN_ID

#define RTE_ETHER_MAX_VLAN_ID   4095

Maximum VLAN ID.

Definition at line 47 of file rte_ether.h.

◆ RTE_ETHER_MIN_MTU

#define RTE_ETHER_MIN_MTU   68

Minimum MTU for IPv4 packets, see RFC 791.

Examples
examples/ethtool/ethtool-app/ethapp.c.

Definition at line 49 of file rte_ether.h.

◆ RTE_ETHER_LOCAL_ADMIN_ADDR

#define RTE_ETHER_LOCAL_ADMIN_ADDR   0x02

Locally assigned Eth. address.

Examples
examples/l3fwd-graph/main.c, and examples/l3fwd/main.c.

Definition at line 85 of file rte_ether.h.

◆ RTE_ETHER_GROUP_ADDR

#define RTE_ETHER_GROUP_ADDR   0x01

Multicast or broadcast Eth. address.

Definition at line 86 of file rte_ether.h.

◆ RTE_ETHER_ADDR_PRT_FMT

#define RTE_ETHER_ADDR_PRT_FMT   "%02X:%02X:%02X:%02X:%02X:%02X"

◆ RTE_ETHER_ADDR_BYTES

#define RTE_ETHER_ADDR_BYTES (   mac_addrs)

◆ RTE_ETHER_TYPE_IPV4

#define RTE_ETHER_TYPE_IPV4   0x0800

◆ RTE_ETHER_TYPE_IPV6

#define RTE_ETHER_TYPE_IPV6   0x86DD

◆ RTE_ETHER_TYPE_ARP

#define RTE_ETHER_TYPE_ARP   0x0806

Arp Protocol.

Examples
examples/bond/main.c.

Definition at line 331 of file rte_ether.h.

◆ RTE_ETHER_TYPE_RARP

#define RTE_ETHER_TYPE_RARP   0x8035

Reverse Arp Protocol.

Definition at line 332 of file rte_ether.h.

◆ RTE_ETHER_TYPE_VLAN

#define RTE_ETHER_TYPE_VLAN   0x8100

IEEE 802.1Q VLAN tagging.

Examples
examples/bond/main.c, and examples/vhost/main.c.

Definition at line 333 of file rte_ether.h.

◆ RTE_ETHER_TYPE_QINQ

#define RTE_ETHER_TYPE_QINQ   0x88A8

IEEE 802.1ad QinQ tagging.

Definition at line 334 of file rte_ether.h.

◆ RTE_ETHER_TYPE_QINQ1

#define RTE_ETHER_TYPE_QINQ1   0x9100

Deprecated QinQ VLAN.

Definition at line 335 of file rte_ether.h.

◆ RTE_ETHER_TYPE_QINQ2

#define RTE_ETHER_TYPE_QINQ2   0x9200

Deprecated QinQ VLAN.

Definition at line 336 of file rte_ether.h.

◆ RTE_ETHER_TYPE_QINQ3

#define RTE_ETHER_TYPE_QINQ3   0x9300

Deprecated QinQ VLAN.

Definition at line 337 of file rte_ether.h.

◆ RTE_ETHER_TYPE_PPPOE_DISCOVERY

#define RTE_ETHER_TYPE_PPPOE_DISCOVERY   0x8863

PPPoE Discovery Stage.

Definition at line 338 of file rte_ether.h.

◆ RTE_ETHER_TYPE_PPPOE_SESSION

#define RTE_ETHER_TYPE_PPPOE_SESSION   0x8864

PPPoE Session Stage.

Definition at line 339 of file rte_ether.h.

◆ RTE_ETHER_TYPE_ETAG

#define RTE_ETHER_TYPE_ETAG   0x893F

IEEE 802.1BR E-Tag.

Definition at line 340 of file rte_ether.h.

◆ RTE_ETHER_TYPE_1588

#define RTE_ETHER_TYPE_1588   0x88F7

IEEE 802.1AS 1588 Precise Time Protocol.

Examples
examples/ptpclient/ptpclient.c.

Definition at line 342 of file rte_ether.h.

◆ RTE_ETHER_TYPE_SLOW

#define RTE_ETHER_TYPE_SLOW   0x8809

Slow protocols (LACP and Marker).

Definition at line 343 of file rte_ether.h.

◆ RTE_ETHER_TYPE_TEB

#define RTE_ETHER_TYPE_TEB   0x6558

Transparent Ethernet Bridging.

Definition at line 344 of file rte_ether.h.

◆ RTE_ETHER_TYPE_LLDP

#define RTE_ETHER_TYPE_LLDP   0x88CC

LLDP Protocol.

Definition at line 345 of file rte_ether.h.

◆ RTE_ETHER_TYPE_MPLS

#define RTE_ETHER_TYPE_MPLS   0x8847

MPLS ethertype.

Definition at line 346 of file rte_ether.h.

◆ RTE_ETHER_TYPE_MPLSM

#define RTE_ETHER_TYPE_MPLSM   0x8848

MPLS multicast ethertype.

Definition at line 347 of file rte_ether.h.

◆ RTE_ETHER_TYPE_ECPRI

#define RTE_ETHER_TYPE_ECPRI   0xAEFE

eCPRI ethertype (.1Q supported).

Definition at line 348 of file rte_ether.h.

Function Documentation

◆ __rte_aligned()

struct __rte_aligned ( 2  )

Ethernet address: A universally administered address is uniquely assigned to a device by its manufacturer. The first three octets (in transmission order) contain the Organizationally Unique Identifier (OUI). The following three (MAC-48 and EUI-48) octets are assigned by that organization with the only constraint of uniqueness. A locally administered address is assigned to a device by a network administrator and does not contain OUIs. See http://standards.ieee.org/regauth/groupmac/tutorial.html

< Addr bytes in tx order

Definition at line 1 of file rte_ether.h.

◆ rte_is_same_ether_addr()

static int rte_is_same_ether_addr ( const struct rte_ether_addr *  ea1,
const struct rte_ether_addr *  ea2 
)
inlinestatic

Check if two Ethernet addresses are the same.

Parameters
ea1A pointer to the first ether_addr structure containing the ethernet address.
ea2A pointer to the second ether_addr structure containing the ethernet address.
Returns
True (1) if the given two ethernet address are the same; False (0) otherwise.
Examples
examples/vhost/main.c.

Definition at line 102 of file rte_ether.h.

◆ rte_is_zero_ether_addr()

static int rte_is_zero_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is filled with zeros.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is filled with zeros; false (0) otherwise.

Definition at line 121 of file rte_ether.h.

◆ rte_is_unicast_ether_addr()

static int rte_is_unicast_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a unicast address.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is a unicast address; false (0) otherwise.

Definition at line 138 of file rte_ether.h.

◆ rte_is_multicast_ether_addr()

static int rte_is_multicast_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a multicast address.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is a multicast address; false (0) otherwise.

Definition at line 153 of file rte_ether.h.

◆ rte_is_broadcast_ether_addr()

static int rte_is_broadcast_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a broadcast address.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is a broadcast address; false (0) otherwise.
Examples
examples/vhost/main.c.

Definition at line 168 of file rte_ether.h.

◆ rte_is_universal_ether_addr()

static int rte_is_universal_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a universally assigned address.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is a universally assigned address; false (0) otherwise.

Definition at line 185 of file rte_ether.h.

◆ rte_is_local_admin_ether_addr()

static int rte_is_local_admin_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a locally assigned address.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is a locally assigned address; false (0) otherwise.

Definition at line 200 of file rte_ether.h.

◆ rte_is_valid_assigned_ether_addr()

static int rte_is_valid_assigned_ether_addr ( const struct rte_ether_addr *  ea)
inlinestatic

Check if an Ethernet address is a valid address. Checks that the address is a unicast address and is not filled with zeros.

Parameters
eaA pointer to a ether_addr structure containing the ethernet address to check.
Returns
True (1) if the given ethernet address is valid; false (0) otherwise.
Examples
examples/ethtool/lib/rte_ethtool.c.

Definition at line 216 of file rte_ether.h.

◆ rte_eth_random_addr()

void rte_eth_random_addr ( uint8_t *  addr)

Generate a random Ethernet address that is locally administered and not multicast.

Parameters
addrA pointer to Ethernet address.

◆ rte_ether_addr_copy()

static void rte_ether_addr_copy ( const struct rte_ether_addr *__restrict  ea_from,
struct rte_ether_addr *__restrict  ea_to 
)
inlinestatic

◆ rte_ether_format_addr()

void rte_ether_format_addr ( char *  buf,
uint16_t  size,
const struct rte_ether_addr *  eth_addr 
)

Format 48bits Ethernet address in pattern xx:xx:xx:xx:xx:xx.

Parameters
bufA pointer to buffer contains the formatted MAC address.
sizeThe format buffer size.
eth_addrA pointer to a ether_addr structure.
Examples
examples/flow_filtering/main.c, examples/ip_fragmentation/main.c, examples/ip_reassembly/main.c, examples/ipsec-secgw/ipsec-secgw.c, examples/ipv4_multicast/main.c, examples/l3fwd-graph/main.c, examples/l3fwd-power/main.c, examples/l3fwd/l3fwd_event.c, examples/l3fwd/main.c, and examples/multi_process/client_server_mp/mp_server/main.c.

◆ rte_ether_unformat_addr()

int rte_ether_unformat_addr ( const char *  str,
struct rte_ether_addr *  eth_addr 
)

Convert string with Ethernet address to an ether_addr.

Parameters
strA pointer to buffer contains the formatted MAC address. Accepts either byte or word format separated by colon, hyphen or period.

The example formats are: XX:XX:XX:XX:XX:XX - Canonical form XX-XX-XX-XX-XX-XX - Windows and IEEE 802 XXXX.XXXX.XXXX - Cisco where XX is a hex digit: 0-9, a-f, or A-F. In the byte format, leading zeros are optional.

Parameters
eth_addrA pointer to a ether_addr structure.
Returns
0 if successful -1 and sets rte_errno if invalid string
Examples
examples/l2fwd-macsec/main.c.

◆ rte_vlan_strip()

static int rte_vlan_strip ( struct rte_mbuf *  m)
inlinestatic

Extract VLAN tag information into mbuf

Software version of VLAN stripping

Parameters
mThe packet mbuf.
Returns
  • 0: Success
  • 1: not a vlan packet

Definition at line 361 of file rte_ether.h.

◆ rte_vlan_insert()

static int rte_vlan_insert ( struct rte_mbuf **  m)
inlinestatic

Insert VLAN tag into mbuf.

Software version of VLAN unstripping. Always inserts an 802.1Q tag (TPID 0x8100). Use rte_vlan_insert_tpid() when the original TPID may differ (e.g. 802.1ad QinQ outer tags).

Parameters
mThe packet mbuf.
Returns
  • 0: On success
  • -EINVAL: overwriting would be unsafe because mbuf is shared or indirect, or mbuf's first segment is too short
  • -ENOSPC: not enough headroom in mbuf

Definition at line 431 of file rte_ether.h.

◆ rte_vlan_insert_tpid()

static __rte_experimental int rte_vlan_insert_tpid ( struct rte_mbuf **  m,
uint16_t  tpid 
)
inlinestatic
Warning
EXPERIMENTAL: this API may change without prior notice.

Insert VLAN tag with the given TPID into mbuf.

Software version of VLAN unstripping.

Parameters
mThe packet mbuf.
tpidTag Protocol Identifier to insert (host order).
Returns
  • 0: On success -EINVAL: overwriting would be unsafe because mbuf is shared or indirect, or mbuf's first segment is too short -ENOSPC: not enough headroom in mbuf

Definition at line 455 of file rte_ether.h.