DPDK 21.11.2
Loading...
Searching...
No Matches
rte_ether.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 */
4
5#ifndef _RTE_ETHER_H_
6#define _RTE_ETHER_H_
7
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stdint.h>
19#include <stdio.h>
20
21#include <rte_memcpy.h>
22#include <rte_random.h>
23#include <rte_mbuf.h>
24#include <rte_byteorder.h>
25
26#define RTE_ETHER_ADDR_LEN 6
27#define RTE_ETHER_TYPE_LEN 2
28#define RTE_ETHER_CRC_LEN 4
29#define RTE_ETHER_HDR_LEN \
30 (RTE_ETHER_ADDR_LEN * 2 + \
31 RTE_ETHER_TYPE_LEN)
32#define RTE_ETHER_MIN_LEN 64
33#define RTE_ETHER_MAX_LEN 1518
34#define RTE_ETHER_MTU \
35 (RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN - \
36 RTE_ETHER_CRC_LEN)
38#define RTE_VLAN_HLEN 4
40#define RTE_ETHER_MAX_VLAN_FRAME_LEN \
41 (RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN)
42
43#define RTE_ETHER_MAX_JUMBO_FRAME_LEN \
44 0x3F00
46#define RTE_ETHER_MAX_VLAN_ID 4095
48#define RTE_ETHER_MIN_MTU 68
63} __rte_aligned(2);
64
65#define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02
66#define RTE_ETHER_GROUP_ADDR 0x01
82static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
83 const struct rte_ether_addr *ea2)
84{
85 const uint16_t *w1 = (const uint16_t *)ea1;
86 const uint16_t *w2 = (const uint16_t *)ea2;
87
88 return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
89}
90
101static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
102{
103 const uint16_t *w = (const uint16_t *)ea;
104
105 return (w[0] | w[1] | w[2]) == 0;
106}
107
118static inline int rte_is_unicast_ether_addr(const struct rte_ether_addr *ea)
119{
120 return (ea->addr_bytes[0] & RTE_ETHER_GROUP_ADDR) == 0;
121}
122
133static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
134{
135 return ea->addr_bytes[0] & RTE_ETHER_GROUP_ADDR;
136}
137
148static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
149{
150 const uint16_t *w = (const uint16_t *)ea;
151
152 return (w[0] & w[1] & w[2]) == 0xFFFF;
153}
154
165static inline int rte_is_universal_ether_addr(const struct rte_ether_addr *ea)
166{
167 return (ea->addr_bytes[0] & RTE_ETHER_LOCAL_ADMIN_ADDR) == 0;
168}
169
180static inline int rte_is_local_admin_ether_addr(const struct rte_ether_addr *ea)
181{
182 return (ea->addr_bytes[0] & RTE_ETHER_LOCAL_ADMIN_ADDR) != 0;
183}
184
196static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *ea)
197{
199}
200
207void
208rte_eth_random_addr(uint8_t *addr);
209
218static inline void
219rte_ether_addr_copy(const struct rte_ether_addr *__restrict ea_from,
220 struct rte_ether_addr *__restrict ea_to)
221{
222 *ea_to = *ea_from;
223}
224
228#define RTE_ETHER_ADDR_PRT_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
232#define RTE_ETHER_ADDR_BYTES(mac_addrs) ((mac_addrs)->addr_bytes[0]), \
233 ((mac_addrs)->addr_bytes[1]), \
234 ((mac_addrs)->addr_bytes[2]), \
235 ((mac_addrs)->addr_bytes[3]), \
236 ((mac_addrs)->addr_bytes[4]), \
237 ((mac_addrs)->addr_bytes[5])
238
239#define RTE_ETHER_ADDR_FMT_SIZE 18
250void
251rte_ether_format_addr(char *buf, uint16_t size,
252 const struct rte_ether_addr *eth_addr);
267int
268rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
269
278} __rte_aligned(2);
279
289
290
291
292/* Ethernet frame types */
293#define RTE_ETHER_TYPE_IPV4 0x0800
294#define RTE_ETHER_TYPE_IPV6 0x86DD
295#define RTE_ETHER_TYPE_ARP 0x0806
296#define RTE_ETHER_TYPE_RARP 0x8035
297#define RTE_ETHER_TYPE_VLAN 0x8100
298#define RTE_ETHER_TYPE_QINQ 0x88A8
299#define RTE_ETHER_TYPE_QINQ1 0x9100
300#define RTE_ETHER_TYPE_QINQ2 0x9200
301#define RTE_ETHER_TYPE_QINQ3 0x9300
302#define RTE_ETHER_TYPE_PPPOE_DISCOVERY 0x8863
303#define RTE_ETHER_TYPE_PPPOE_SESSION 0x8864
304#define RTE_ETHER_TYPE_ETAG 0x893F
305#define RTE_ETHER_TYPE_1588 0x88F7
307#define RTE_ETHER_TYPE_SLOW 0x8809
308#define RTE_ETHER_TYPE_TEB 0x6558
309#define RTE_ETHER_TYPE_LLDP 0x88CC
310#define RTE_ETHER_TYPE_MPLS 0x8847
311#define RTE_ETHER_TYPE_MPLSM 0x8848
312#define RTE_ETHER_TYPE_ECPRI 0xAEFE
325static inline int rte_vlan_strip(struct rte_mbuf *m)
326{
327 struct rte_ether_hdr *eh
328 = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
329 struct rte_vlan_hdr *vh;
330
332 return -1;
333
334 vh = (struct rte_vlan_hdr *)(eh + 1);
337
338 /* Copy ether header over rather than moving whole packet */
339 memmove(rte_pktmbuf_adj(m, sizeof(struct rte_vlan_hdr)),
340 eh, 2 * RTE_ETHER_ADDR_LEN);
341
342 return 0;
343}
344
357static inline int rte_vlan_insert(struct rte_mbuf **m)
358{
359 struct rte_ether_hdr *oh, *nh;
360 struct rte_vlan_hdr *vh;
361
362 /* Can't insert header if mbuf is shared */
363 if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1)
364 return -EINVAL;
365
366 /* Can't insert header if the first segment is too short */
368 return -EINVAL;
369
370 oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *);
371 nh = (struct rte_ether_hdr *)(void *)
372 rte_pktmbuf_prepend(*m, sizeof(struct rte_vlan_hdr));
373 if (nh == NULL)
374 return -ENOSPC;
375
376 memmove(nh, oh, 2 * RTE_ETHER_ADDR_LEN);
378
379 vh = (struct rte_vlan_hdr *) (nh + 1);
380 vh->vlan_tci = rte_cpu_to_be_16((*m)->vlan_tci);
381
382 (*m)->ol_flags &= ~(RTE_MBUF_F_RX_VLAN_STRIPPED | RTE_MBUF_F_TX_VLAN);
383
384 if ((*m)->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
385 (*m)->outer_l2_len += sizeof(struct rte_vlan_hdr);
386 else
387 (*m)->l2_len += sizeof(struct rte_vlan_hdr);
388
389 return 0;
390}
391
392#ifdef __cplusplus
393}
394#endif
395
396#endif /* _RTE_ETHER_H_ */
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
static rte_be16_t rte_cpu_to_be_16(uint16_t x)
uint16_t rte_be16_t
#define __rte_aligned(a)
Definition: rte_common.h:71
#define __rte_packed
Definition: rte_common.h:86
#define RTE_ETHER_TYPE_VLAN
Definition: rte_ether.h:297
#define RTE_ETHER_ADDR_LEN
Definition: rte_ether.h:26
static int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, const struct rte_ether_addr *ea2)
Definition: rte_ether.h:82
static int rte_is_unicast_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:118
#define RTE_ETHER_LOCAL_ADMIN_ADDR
Definition: rte_ether.h:65
static int rte_is_universal_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:165
static int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:101
static int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:196
int rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr)
#define RTE_ETHER_GROUP_ADDR
Definition: rte_ether.h:66
static int rte_vlan_strip(struct rte_mbuf *m)
Definition: rte_ether.h:325
static int rte_is_local_admin_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:180
static int rte_vlan_insert(struct rte_mbuf **m)
Definition: rte_ether.h:357
void rte_ether_format_addr(char *buf, uint16_t size, const struct rte_ether_addr *eth_addr)
static void rte_ether_addr_copy(const struct rte_ether_addr *__restrict ea_from, struct rte_ether_addr *__restrict ea_to)
Definition: rte_ether.h:219
static int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:133
void rte_eth_random_addr(uint8_t *addr)
static int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
Definition: rte_ether.h:148
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:1534
static char * rte_pktmbuf_prepend(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1551
static char * rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
Definition: rte_mbuf.h:1615
static uint16_t rte_mbuf_refcnt_read(const struct rte_mbuf *m)
Definition: rte_mbuf.h:404
#define rte_pktmbuf_mtod(m, t)
#define RTE_MBUF_F_TX_VLAN
#define RTE_MBUF_DIRECT(mb)
#define RTE_MBUF_F_RX_VLAN_STRIPPED
Definition: rte_mbuf_core.h:75
#define RTE_MBUF_F_RX_VLAN
Definition: rte_mbuf_core.h:50
uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]
Definition: rte_ether.h:62
rte_be16_t ether_type
Definition: rte_ether.h:277
struct rte_ether_addr src_addr
Definition: rte_ether.h:276
struct rte_ether_addr dst_addr
Definition: rte_ether.h:275
uint64_t ol_flags
uint16_t vlan_tci
rte_be16_t eth_proto
Definition: rte_ether.h:287
rte_be16_t vlan_tci
Definition: rte_ether.h:286