CNDP  22.08.0
cne_ether.h File Reference
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <net/ethernet.h>
#include <linux/if_ether.h>
#include <stdbool.h>
#include <string.h>
#include <cne_common.h>

Go to the source code of this file.

Data Structures

struct  ether_addr
 
struct  cne_ether_hdr
 
struct  cne_vlan_hdr
 

Macros

#define CNE_ETHER_MAX_VLAN_FRAME_LEN   (ETHER_MAX_LEN + 4)
 
#define CNE_ETHER_MAX_JUMBO_FRAME_LEN   0x3F00
 
#define CNE_ETHER_MAX_VLAN_ID   4095
 
#define CNE_ETHER_MIN_MTU   68
 
#define ETHER_LOCAL_ADMIN_ADDR   0x02
 
#define ETHER_GROUP_ADDR   0x01
 
#define CNE_ETHER_TYPE_IPV4   0x0800
 
#define CNE_ETHER_TYPE_IPV6   0x86DD
 
#define CNE_ETHER_TYPE_ARP   0x0806
 
#define CNE_ETHER_TYPE_RARP   0x8035
 
#define CNE_ETHER_TYPE_VLAN   0x8100
 
#define CNE_ETHER_TYPE_QINQ   0x88A8
 
#define CNE_ETHER_TYPE_PPPOE_DISCOVERY   0x8863
 
#define CNE_ETHER_TYPE_PPPOE_SESSION   0x8864
 
#define CNE_ETHER_TYPE_ETAG   0x893F
 
#define CNE_ETHER_TYPE_1588   0x88F7
 
#define CNE_ETHER_TYPE_SLOW   0x8809
 
#define CNE_ETHER_TYPE_TEB   0x6558
 
#define CNE_ETHER_TYPE_LLDP   0x88CC
 
#define CNE_ETHER_TYPE_MPLS   0x8847
 
#define CNE_ETHER_TYPE_MPLSM   0x8848
 
#define __ETHER_TYPE_IPV4   0x0008
 
#define __ETHER_TYPE_IPV6   0xDD86
 
#define __ETHER_TYPE_ARP   0x0608
 
#define __ETHER_TYPE_RARP   0x3580
 
#define __ETHER_TYPE_VLAN   0x0081
 
#define __ETHER_TYPE_QINQ   0xA888
 
#define __ETHER_TYPE_PPPOE_DISCOVERY   0x6388
 
#define __ETHER_TYPE_PPPOE_SESSION   0x6488
 
#define __ETHER_TYPE_ETAG   0x3F89
 
#define __ETHER_TYPE_1588   0xF788
 
#define __ETHER_TYPE_SLOW   0x0988
 
#define __ETHER_TYPE_TEB   0x5865
 
#define __ETHER_TYPE_LLDP   0xCC88
 
#define __ETHER_TYPE_MPLS   0x4788
 
#define __ETHER_TYPE_MPLSM   0x4888
 

Functions

CNDP_API __cne_always_inline int ether_addr_is_same (const struct ether_addr *ea1, const struct ether_addr *ea2)
 
CNDP_API __cne_always_inline int ether_addr_is_zero (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_unicast (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_multicast (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_broadcast (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_universal (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_local_admin (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline int ether_addr_is_valid_assigned (const struct ether_addr *ea)
 
CNDP_API __cne_always_inline void ether_random_addr (uint8_t *addr)
 
CNDP_API __cne_always_inline void ether_addr_copy (const struct ether_addr *ea_from, struct ether_addr *ea_to)
 
CNDP_API __cne_always_inline void ether_format_addr (char *buf, uint16_t size, const struct ether_addr *eth_addr)
 
CNDP_API __cne_always_inline int ether_unformat_addr (const char *s, struct ether_addr *ea)
 
CNDP_API __cne_always_inline struct ether_addrcne_ether_aton (const char *a, struct ether_addr *e)
 

Detailed Description

Ethernet Helpers in CNE

Definition in file cne_ether.h.

Macro Definition Documentation

◆ CNE_ETHER_MAX_VLAN_FRAME_LEN

#define CNE_ETHER_MAX_VLAN_FRAME_LEN   (ETHER_MAX_LEN + 4)

Maximum VLAN frame length, including CRC.

Definition at line 30 of file cne_ether.h.

◆ CNE_ETHER_MAX_JUMBO_FRAME_LEN

#define CNE_ETHER_MAX_JUMBO_FRAME_LEN   0x3F00

Maximum Jumbo frame length, including CRC.

Definition at line 32 of file cne_ether.h.

◆ CNE_ETHER_MAX_VLAN_ID

#define CNE_ETHER_MAX_VLAN_ID   4095

Maximum VLAN ID.

Definition at line 34 of file cne_ether.h.

◆ CNE_ETHER_MIN_MTU

#define CNE_ETHER_MIN_MTU   68

Minimum MTU for IPv4 packets, see RFC 791.

Definition at line 36 of file cne_ether.h.

◆ ETHER_LOCAL_ADMIN_ADDR

#define ETHER_LOCAL_ADMIN_ADDR   0x02

Locally assigned Eth. address.

Examples
examples/l3fwd-graph/fwd.c.

Definition at line 57 of file cne_ether.h.

◆ ETHER_GROUP_ADDR

#define ETHER_GROUP_ADDR   0x01

Multicast or broadcast Eth. address.

Definition at line 58 of file cne_ether.h.

◆ CNE_ETHER_TYPE_IPV4

#define CNE_ETHER_TYPE_IPV4   0x0800

IPv4 Protocol.

Definition at line 81 of file cne_ether.h.

◆ CNE_ETHER_TYPE_IPV6

#define CNE_ETHER_TYPE_IPV6   0x86DD

IPv6 Protocol.

Definition at line 82 of file cne_ether.h.

◆ CNE_ETHER_TYPE_ARP

#define CNE_ETHER_TYPE_ARP   0x0806

Arp Protocol.

Definition at line 83 of file cne_ether.h.

◆ CNE_ETHER_TYPE_RARP

#define CNE_ETHER_TYPE_RARP   0x8035

Reverse Arp Protocol.

Definition at line 84 of file cne_ether.h.

◆ CNE_ETHER_TYPE_VLAN

#define CNE_ETHER_TYPE_VLAN   0x8100

IEEE 802.1Q VLAN tagging.

Definition at line 85 of file cne_ether.h.

◆ CNE_ETHER_TYPE_QINQ

#define CNE_ETHER_TYPE_QINQ   0x88A8

IEEE 802.1ad QinQ tagging.

Definition at line 86 of file cne_ether.h.

◆ CNE_ETHER_TYPE_PPPOE_DISCOVERY

#define CNE_ETHER_TYPE_PPPOE_DISCOVERY   0x8863

PPPoE Discovery Stage.

Definition at line 87 of file cne_ether.h.

◆ CNE_ETHER_TYPE_PPPOE_SESSION

#define CNE_ETHER_TYPE_PPPOE_SESSION   0x8864

PPPoE Session Stage.

Definition at line 88 of file cne_ether.h.

◆ CNE_ETHER_TYPE_ETAG

#define CNE_ETHER_TYPE_ETAG   0x893F

IEEE 802.1BR E-Tag.

Definition at line 89 of file cne_ether.h.

◆ CNE_ETHER_TYPE_1588

#define CNE_ETHER_TYPE_1588   0x88F7

IEEE 802.1AS 1588 Precise Time Protocol.

Definition at line 91 of file cne_ether.h.

◆ CNE_ETHER_TYPE_SLOW

#define CNE_ETHER_TYPE_SLOW   0x8809

Slow protocols (LACP and Marker).

Definition at line 92 of file cne_ether.h.

◆ CNE_ETHER_TYPE_TEB

#define CNE_ETHER_TYPE_TEB   0x6558

Transparent Ethernet Bridging.

Definition at line 93 of file cne_ether.h.

◆ CNE_ETHER_TYPE_LLDP

#define CNE_ETHER_TYPE_LLDP   0x88CC

LLDP Protocol.

Definition at line 94 of file cne_ether.h.

◆ CNE_ETHER_TYPE_MPLS

#define CNE_ETHER_TYPE_MPLS   0x8847

MPLS ethertype.

Definition at line 95 of file cne_ether.h.

◆ CNE_ETHER_TYPE_MPLSM

#define CNE_ETHER_TYPE_MPLSM   0x8848

MPLS multicast ethertype.

Definition at line 96 of file cne_ether.h.

◆ __ETHER_TYPE_IPV4

#define __ETHER_TYPE_IPV4   0x0008

IPv4 Protocol.

Definition at line 99 of file cne_ether.h.

◆ __ETHER_TYPE_IPV6

#define __ETHER_TYPE_IPV6   0xDD86

IPv6 Protocol.

Definition at line 100 of file cne_ether.h.

◆ __ETHER_TYPE_ARP

#define __ETHER_TYPE_ARP   0x0608

Arp Protocol.

Definition at line 101 of file cne_ether.h.

◆ __ETHER_TYPE_RARP

#define __ETHER_TYPE_RARP   0x3580

Reverse Arp Protocol.

Definition at line 102 of file cne_ether.h.

◆ __ETHER_TYPE_VLAN

#define __ETHER_TYPE_VLAN   0x0081

IEEE 802.1Q VLAN tagging.

Definition at line 103 of file cne_ether.h.

◆ __ETHER_TYPE_QINQ

#define __ETHER_TYPE_QINQ   0xA888

IEEE 802.1ad QinQ tagging.

Definition at line 104 of file cne_ether.h.

◆ __ETHER_TYPE_PPPOE_DISCOVERY

#define __ETHER_TYPE_PPPOE_DISCOVERY   0x6388

PPPoE Discovery Stage.

Definition at line 105 of file cne_ether.h.

◆ __ETHER_TYPE_PPPOE_SESSION

#define __ETHER_TYPE_PPPOE_SESSION   0x6488

PPPoE Session Stage.

Definition at line 106 of file cne_ether.h.

◆ __ETHER_TYPE_ETAG

#define __ETHER_TYPE_ETAG   0x3F89

IEEE 802.1BR E-Tag.

Definition at line 107 of file cne_ether.h.

◆ __ETHER_TYPE_1588

#define __ETHER_TYPE_1588   0xF788

IEEE 802.1AS 1588 Precise Time Protocol.

Definition at line 109 of file cne_ether.h.

◆ __ETHER_TYPE_SLOW

#define __ETHER_TYPE_SLOW   0x0988

Slow protocols (LACP and Marker).

Definition at line 110 of file cne_ether.h.

◆ __ETHER_TYPE_TEB

#define __ETHER_TYPE_TEB   0x5865

Transparent Ethernet Bridging.

Definition at line 111 of file cne_ether.h.

◆ __ETHER_TYPE_LLDP

#define __ETHER_TYPE_LLDP   0xCC88

LLDP Protocol.

Definition at line 112 of file cne_ether.h.

◆ __ETHER_TYPE_MPLS

#define __ETHER_TYPE_MPLS   0x4788

MPLS ethertype.

Definition at line 113 of file cne_ether.h.

◆ __ETHER_TYPE_MPLSM

#define __ETHER_TYPE_MPLSM   0x4888

MPLS multicast ethertype.

Definition at line 114 of file cne_ether.h.

Function Documentation

◆ ether_addr_is_same()

CNDP_API __cne_always_inline int ether_addr_is_same ( const struct ether_addr ea1,
const struct ether_addr ea2 
)

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.

Definition at line 131 of file cne_ether.h.

◆ ether_addr_is_zero()

CNDP_API __cne_always_inline int ether_addr_is_zero ( const struct ether_addr ea)

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 150 of file cne_ether.h.

◆ ether_addr_is_unicast()

CNDP_API __cne_always_inline int ether_addr_is_unicast ( const struct ether_addr ea)

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 168 of file cne_ether.h.

◆ ether_addr_is_multicast()

CNDP_API __cne_always_inline int ether_addr_is_multicast ( const struct ether_addr ea)

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 184 of file cne_ether.h.

◆ ether_addr_is_broadcast()

CNDP_API __cne_always_inline int ether_addr_is_broadcast ( const struct ether_addr ea)

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.

Definition at line 200 of file cne_ether.h.

◆ ether_addr_is_universal()

CNDP_API __cne_always_inline int ether_addr_is_universal ( const struct ether_addr ea)

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 218 of file cne_ether.h.

◆ ether_addr_is_local_admin()

CNDP_API __cne_always_inline int ether_addr_is_local_admin ( const struct ether_addr ea)

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 234 of file cne_ether.h.

◆ ether_addr_is_valid_assigned()

CNDP_API __cne_always_inline int ether_addr_is_valid_assigned ( const struct ether_addr ea)

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.

Definition at line 251 of file cne_ether.h.

◆ ether_random_addr()

CNDP_API __cne_always_inline void ether_random_addr ( uint8_t *  addr)

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

Parameters
addrA pointer to Ethernet address.

Definition at line 263 of file cne_ether.h.

◆ ether_addr_copy()

CNDP_API __cne_always_inline void ether_addr_copy ( const struct ether_addr ea_from,
struct ether_addr ea_to 
)

Fast copy an Ethernet address.

Parameters
ea_fromA pointer to a ether_addr structure holding the Ethernet address to copy.
ea_toA pointer to a ether_addr structure where to copy the Ethernet address.
Examples
examples/l3fwd-graph/fwd.c.

Definition at line 282 of file cne_ether.h.

◆ ether_format_addr()

CNDP_API __cne_always_inline void ether_format_addr ( char *  buf,
uint16_t  size,
const struct 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.

Definition at line 334 of file cne_ether.h.

◆ ether_unformat_addr()

CNDP_API __cne_always_inline int ether_unformat_addr ( const char *  s,
struct ether_addr ea 
)

Convert string with Ethernet address to an ether_addr.

Parameters
sA pointer to buffer contains the formatted MAC address. The supported formats are: XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX where XX is a hex digit: 0-9, a-f, or A-F.
eaA pointer to a ether_addr structure.
Returns
0 if successful -1 and sets errno if invalid string

Definition at line 426 of file cne_ether.h.

◆ cne_ether_aton()

CNDP_API __cne_always_inline struct ether_addr* cne_ether_aton ( const char *  a,
struct ether_addr e 
)

Convert a string Ethernet MAC address to the binary form

Parameters
aString containing the MAC address in two forms XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXX
epointer to a struct ether_addr to place the return value.
Returns
Pointer to the struct ether_addr structure;

Definition at line 449 of file cne_ether.h.