Skip to contentSkip to conversation

ether: improvements and optimizations

PATCH Superseded Stephen Hemminger 15 participants 127 messages May 16, 2019 – Jul 22, 2019 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ether: improvements and optimizations

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

This does not include the prefixing of the ether_address which is still under review.

v2 incorporates feedback and Bruce's alignement patch

Bruce Richardson (1):
ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (6):
ether: do not mark ethernet address and header as packed
ether: deinline non-critical functions
ether: add eth_unformat_addr
ethdev: use eth_unformat_addr
ether: use bitops to speedup comparison
cmdline: use ether_unformat_addr

 lib/Makefile                                 |  3 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 69 ++----------------
 lib/librte_cmdline/meson.build               |  3 +
 lib/librte_ethdev/Makefile                   |  2 +-
 lib/librte_ethdev/meson.build                |  2 +-
 lib/librte_ethdev/rte_class_eth.c            |  9 +--
 lib/librte_net/Makefile                      |  1 +
 lib/librte_net/rte_ether.c                   | 76 ++++++++++++++++++++
 lib/librte_net/rte_ether.h                   | 70 +++++++++---------
 lib/librte_net/rte_net_version.map           |  8 +++
 11 files changed, 134 insertions(+), 112 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/7 ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/librte_net/rte_ether.h +3 -2
index 3a87ff184900..ac8897681aca 100644
@@ -55,7 +55,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct ether_addr {
-	uint8_t addr_bytes[ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	/** Addr bytes in tx order */
+	uint8_t addr_bytes[ETHER_ADDR_LEN] __rte_aligned(2);
 } __attribute__((__packed__));
 
 #define ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -146,7 +147,7 @@ static inline int is_multicast_ether_addr(const struct ether_addr *ea)
  */
 static inline int is_broadcast_ether_addr(const struct ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/7 ether: do not mark ethernet address and header as packed

In reply to Stephen Hemminger

Since the Ethernet address and header are naturally aligned correctly on all architectures, there is no need to mark them as packed. This results in faster code, and also gets rid of warnings with gcc-9 about getting address of packed structure.

---
 lib/librte_net/rte_ether.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +5 -5
index ac8897681aca..0954d183cca7 100644
@@ -57,7 +57,7 @@ extern "C" {
 struct ether_addr {
 	/** Addr bytes in tx order */
 	uint8_t addr_bytes[ETHER_ADDR_LEN] __rte_aligned(2);
-} __attribute__((__packed__));
+};
 
 #define ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
 #define ETHER_GROUP_ADDR       0x01 /**< Multicast or broadcast Eth. address. */
@@ -273,7 +273,7 @@ struct ether_hdr {
 	struct ether_addr d_addr; /**< Destination address. */
 	struct ether_addr s_addr; /**< Source address. */
 	uint16_t ether_type;      /**< Frame type. */
-} __attribute__((__packed__));
+};
 
 /**
  * Ethernet VLAN Header.
@@ -283,7 +283,7 @@ struct ether_hdr {
 struct vlan_hdr {
 	uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
 	uint16_t eth_proto;/**< Ethernet type of encapsulated frame. */
-} __attribute__((__packed__));
+};
 
 /**
  * VXLAN protocol header.
@@ -293,7 +293,7 @@ struct vlan_hdr {
 struct vxlan_hdr {
 	uint32_t vx_flags; /**< flag (8) + Reserved (24). */
 	uint32_t vx_vni;   /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 
 /* Ethernet frame types */
 #define ETHER_TYPE_IPv4 0x0800 /**< IPv4 Protocol. */
@@ -325,7 +325,7 @@ struct vxlan_gpe_hdr {
 	uint8_t reserved[2]; /**< Reserved (16). */
 	uint8_t proto;       /**< next-protocol (8). */
 	uint32_t vx_vni;     /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 
 /* VXLAN-GPE next protocol types */
 #define VXLAN_GPE_TYPE_IPV4 1 /**< IPv4 Protocol. */
Signature · 1 line
2.20.1
#3 lore raw

Re: [dpdk-dev] [PATCH v2 2/7] ether: do not mark ethernet address and header as packed

Quoted 52 lines · Stephen Hemminger

Since the Ethernet address and header are naturally aligned correctly on all architectures, there is no need to mark them as packed. This results in faster code, and also gets rid of warnings with gcc-9 about getting address of packed structure.

---
 lib/librte_net/rte_ether.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +4 -4
index ac8897681aca..0954d183cca7 100644
@@ -57,7 +57,7 @@ extern "C" {
 struct ether_addr {
 	/** Addr bytes in tx order */
 	uint8_t addr_bytes[ETHER_ADDR_LEN] __rte_aligned(2);
-} __attribute__((__packed__));
+};
 
 #define ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
 #define ETHER_GROUP_ADDR       0x01 /**< Multicast or broadcast Eth. address. */
@@ -273,7 +273,7 @@ struct ether_hdr {
 	struct ether_addr d_addr; /**< Destination address. */
 	struct ether_addr s_addr; /**< Source address. */
 	uint16_t ether_type;      /**< Frame type. */
-} __attribute__((__packed__));
+};
 
 /**
  * Ethernet VLAN Header.
@@ -283,7 +283,7 @@ struct ether_hdr {
 struct vlan_hdr {
 	uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
 	uint16_t eth_proto;/**< Ethernet type of encapsulated frame. */
-} __attribute__((__packed__));
+};
 
 /**
  * VXLAN protocol header.
@@ -293,7 +293,7 @@ struct vlan_hdr {
 struct vxlan_hdr {
 	uint32_t vx_flags; /**< flag (8) + Reserved (24). */
 	uint32_t vx_vni;   /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 
 /* Ethernet frame types */
 #define ETHER_TYPE_IPv4 0x0800 /**< IPv4 Protocol. */

lib/librte_net/rte_ether.h struct vxlan_gpe_hdr { · line 329

Quoted 6 lines
lib/librte_net/rte_ether.h +1 -1
@@ -325,7 +325,7 @@ struct vxlan_gpe_hdr {
 	uint8_t reserved[2]; /**< Reserved (16). */
 	uint8_t proto;       /**< next-protocol (8). */
 	uint32_t vx_vni;     /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 

Are we sure that these last two structures are always 4-byte aligned in packets?

Quoted 5 lines
lib/librte_net/rte_ether.h +0 -0
 /* VXLAN-GPE next protocol types */
 #define VXLAN_GPE_TYPE_IPV4 1 /**< IPv4 Protocol. */
Signature · 1 line
2.20.1
#4 lore raw

Re: [dpdk-dev] [PATCH v2 2/7] ether: do not mark ethernet address and header as packed

Quoted 50 lines · On Thu, 16 May 2019 21:40:05 +0100 Bruce Richardson…
Quoted 49 lines · Stephen Hemminger

Since the Ethernet address and header are naturally aligned correctly on all architectures, there is no need to mark them as packed. This results in faster code, and also gets rid of warnings with gcc-9 about getting address of packed structure.

---
 lib/librte_net/rte_ether.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +4 -4
index ac8897681aca..0954d183cca7 100644
@@ -57,7 +57,7 @@ extern "C" {
 struct ether_addr {
 	/** Addr bytes in tx order */
 	uint8_t addr_bytes[ETHER_ADDR_LEN] __rte_aligned(2);
-} __attribute__((__packed__));
+};
 
 #define ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
 #define ETHER_GROUP_ADDR       0x01 /**< Multicast or broadcast Eth. address. */
@@ -273,7 +273,7 @@ struct ether_hdr {
 	struct ether_addr d_addr; /**< Destination address. */
 	struct ether_addr s_addr; /**< Source address. */
 	uint16_t ether_type;      /**< Frame type. */
-} __attribute__((__packed__));
+};
 
 /**
  * Ethernet VLAN Header.
@@ -283,7 +283,7 @@ struct ether_hdr {
 struct vlan_hdr {
 	uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
 	uint16_t eth_proto;/**< Ethernet type of encapsulated frame. */
-} __attribute__((__packed__));
+};
 
 /**
  * VXLAN protocol header.
@@ -293,7 +293,7 @@ struct vlan_hdr {
 struct vxlan_hdr {
 	uint32_t vx_flags; /**< flag (8) + Reserved (24). */
 	uint32_t vx_vni;   /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 
Quoted 12 lines

lib/librte_net/rte_ether.h struct vxlan_gpe_hdr { · line 329

Quoted 9 lines
lib/librte_net/rte_ether.h +1 -1
 /* Ethernet frame types */
 #define ETHER_TYPE_IPv4 0x0800 /**< IPv4 Protocol. */
@@ -325,7 +325,7 @@ struct vxlan_gpe_hdr {
 	uint8_t reserved[2]; /**< Reserved (16). */
 	uint8_t proto;       /**< next-protocol (8). */
 	uint32_t vx_vni;     /**< VNI (24) + Reserved (8). */
-} __attribute__((__packed__));
+};
 

Are we sure that these last two structures are always 4-byte aligned in packets?

That is a general issue of unaligned IP header problem. Really we should be doing a combination of packed and 2 byte alignment.

I will drop the Vxlan and NVGre ones

#5 lore raw

PATCH v2 3/7 ether: deinline non-critical functions

In reply to Stephen Hemminger

Formatting ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 24 ++++--------------------
 lib/librte_net/rte_net_version.map |  8 ++++++++
 4 files changed, 42 insertions(+), 20 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
lib/librte_net/Makefile +1 -0
index c3082069ab50..b4900b44f4d0 100644
@@ -15,6 +15,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 
 # install includes
 SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h rte_esp.h
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..d4b41f122a16
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+ether_format_addr(char *buf, uint16_t size,
+		  const struct ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -20
index 0954d183cca7..ed178a1f1736 100644
@@ -205,15 +205,8 @@ static inline int is_valid_assigned_ether_addr(const struct ether_addr *ea)
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~ETHER_GROUP_ADDR;       /* clear multicast bit */
-	addr[0] |= ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -252,18 +245,9 @@ static inline void ether_addr_copy(const struct ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 ether_format_addr(char *buf, uint16_t size,
-		  const struct ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
+		  const struct ether_addr *eth_addr);
 
 /**
  * Ethernet header: Contains the destination address, source address
lib/librte_net/rte_net_version.map +8 -0
index 26c06e7c7ae7..49d34093781c 100644
@@ -13,6 +13,14 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	eth_random_addr;
+	eth_format_addr;
+} DPDK_17.05;
+
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
#8 lore raw

PATCH v2 4/7 ether: add eth_unformat_addr

In reply to Stephen Hemminger

Make a function that coresponds with eth_aton_r which can be used to convert string to ether_addr.

This also allows rte_ethdev to no longer depend on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  2 +-
 3 files changed, 62 insertions(+), 1 deletion(-)
lib/librte_net/rte_ether.c +47 -0
index d4b41f122a16..12d9af58b5c3 100644
@@ -27,3 +27,50 @@ ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+ether_unformat_addr(const char *s, struct ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index ed178a1f1736..0fa4481d266b 100644
@@ -249,6 +249,20 @@ void
 ether_format_addr(char *buf, uint16_t size,
 		  const struct ether_addr *eth_addr);
 
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+ether_unformat_addr(const char *str, struct ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -1
index 49d34093781c..41d6a5943515 100644
@@ -20,10 +20,10 @@ DPDK_19.08 {
 	eth_format_addr;
 } DPDK_17.05;
 
-
 EXPERIMENTAL {
 	global:
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	eth_unformat_addr;
 };
Signature · 1 line
2.20.1
#9 lore raw

Re: [dpdk-dev] [PATCH v2 4/7] ether: add eth_unformat_addr

Quoted 2 lines · Stephen Hemminger

Make a function that coresponds with eth_aton_r which can

corresponds

be used to convert string to ether_addr.

Quoted 24 lines

This also allows rte_ethdev to no longer depend on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  2 +-
 3 files changed, 62 insertions(+), 1 deletion(-)
lib/librte_net/rte_ether.c +4 -0
index d4b41f122a16..12d9af58b5c3 100644
@@ -27,3 +27,50 @@ ether_format_addr(char *buf, uint16_t size,
                 eth_addr->addr_bytes[4],
                 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX

lib/librte_net/rte_ether.c ether_format_addr(char *buf, uint16_t size, · line 43

Quoted 10 lines
lib/librte_net/rte_ether.c +10 -0
+ */
+int
+ether_unformat_addr(const char *s, struct ether_addr *ea)
+{
+       unsigned int o0, o1, o2, o3, o4, o5;
+       int n;
+
+       n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+                   &o0, &o1, &o2, &o3, &o4, &o5);
+

Still weak to trailing characters.

+ if (n == 6) {

Quoted 7 lines
lib/librte_net/rte_ether.c +6 -0
+               if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+                   o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+                       return -1;
+
+               ea->addr_bytes[0] = o0;
+               ea->addr_bytes[1] = o1;

lib/librte_net/rte_ether.c ether_format_addr(char *buf, uint16_t size, · line 60

Quoted 10 lines
lib/librte_net/rte_ether.c +10 -0
+               ea->addr_bytes[2] = o2;
+               ea->addr_bytes[3] = o3;
+               ea->addr_bytes[4] = o4;
+               ea->addr_bytes[5] = o5;
+
+               return 0;
+       }
+
+       /* Support the format XXXX:XXXX:XXXX */
+       n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);

Idem trailing characters.

+ if (n == 3) {

Quoted 46 lines
lib/librte_net/rte_ether.c +15 -0
+               if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+                       return -1;
+
+               ea->addr_bytes[0] = o0 >> 8;
+               ea->addr_bytes[1] = o0 & 0xff;
+               ea->addr_bytes[2] = o1 >> 8;
+               ea->addr_bytes[3] = o1 & 0xff;
+               ea->addr_bytes[4] = o2 >> 8;
+               ea->addr_bytes[5] = o2 & 0xff;
+               return 0;
+       }
+       /* unknown format */
+
+       return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index ed178a1f1736..0fa4481d266b 100644
@@ -249,6 +249,20 @@ void
 ether_format_addr(char *buf, uint16_t size,
                  const struct ether_addr *eth_addr);
 
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+ether_unformat_addr(const char *str, struct ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +0 -0
index 49d34093781c..41d6a5943515 100644

lib/librte_net/rte_net_version.map DPDK_19.08 { · line 23

Quoted 5 lines
lib/librte_net/rte_net_version.map +0 -1
@@ -20,10 +20,10 @@ DPDK_19.08 {
        eth_format_addr;
 } DPDK_17.05;
 
-
 

And same comment on the function name than in the rfc patch.

EXPERIMENTAL {

Quoted 10 lines
lib/librte_net/rte_net_version.map +1 -1
        global:
 
        rte_net_make_rarp_packet;
        rte_net_skip_ip6_ext;
+       eth_unformat_addr;
 };
--

2.20.1

Signature · 1 line
David Marchand
#10 lore raw

PATCH v2 5/7 ethdev: use eth_unformat_addr

In reply to Stephen Hemminger

Use eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index cb99c92ece93..40ca936230c6 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#11 lore raw

PATCH v2 6/7 ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 0fa4481d266b..799996dc7e1b 100644
@@ -79,11 +79,10 @@ struct ether_addr {
 static inline int is_same_ether_addr(const struct ether_addr *ea1,
 				     const struct ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -98,11 +97,9 @@ static inline int is_same_ether_addr(const struct ether_addr *ea1,
  */
 static inline int is_zero_ether_addr(const struct ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#12 lore raw

PATCH v2 7/7 cmdline: use ether_unformat_addr

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 69 ++------------------
 lib/librte_cmdline/meson.build               |  3 +
 4 files changed, 13 insertions(+), 64 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +7 -62

100 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -0
index 0fa61385fccf..c01033fd796f 100644
@@ -4,6 +4,8 @@
 # This library is processed before EAL
 includes = [global_inc]
 
+cflags  += '-DALLOW_EXPERIMENTAL_API'
+
 version = 2
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
@@ -28,3 +30,4 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+deps += ['net']
Signature · 1 line
2.20.1
#13 lore raw

v3 cover net/ether: improvements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Bruce Richardson (1):
net/ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (5):
net/rte_ether: deinline non-critical functions
net/ether: add rte_eth_unformat_addr
ethdev: use rte_eth_unformat_addr
net/ether: use bitops to speedup comparison
cmdline: use rte_ether_unformat_addr

 lib/Makefile                                 |  3 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++---------------
 lib/librte_cmdline/meson.build               |  3 +
 lib/librte_ethdev/Makefile                   |  2 +-
 lib/librte_ethdev/meson.build                |  2 +-
 lib/librte_ethdev/rte_class_eth.c            |  9 +--
 lib/librte_net/Makefile                      |  1 +
 lib/librte_net/rte_ether.c                   | 76 ++++++++++++++++++++
 lib/librte_net/rte_ether.h                   | 59 +++++++--------
 lib/librte_net/rte_net_version.map           |  8 +++
 11 files changed, 129 insertions(+), 108 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#14 lore raw

PATCH v3 1/6 net/rte_ether: deinline non-critical functions

Formatting ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 4 files changed, 41 insertions(+), 21 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..dae6e420cded 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	eth_random_addr;
+	eth_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
Reviewed-by on v3 1/6
#15 lore raw

Re: [dpdk-dev] [PATCH v3 1/6] net/rte_ether: deinline non-critical functions

Quoted 5 lines · Stephen Hemminger

Formatting ethernet address and getting a random value are not in critical path so they should not be inlined.

Meson build is lost plus one nit below.
Other than that:

[...]

lib/librte_net/rte_net_version.map DPDK_17.05 { · line 20

Quoted 13 lines
lib/librte_net/rte_net_version.map +5 -0
index 26c06e7c7ae7..dae6e420cded 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
  } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	eth_random_addr;
+	eth_format_addr;

rte_ prefix is lost

Quoted 5 lines
lib/librte_net/rte_net_version.map +2 -0
+} DPDK_17.05;
+
  EXPERIMENTAL {
  	global:
 
#16 lore raw

Re: [dpdk-dev] [PATCH v3 1/6] net/rte_ether: deinline non-critical functions

Quoted 30 lines · On Wed, 5 Jun 2019 11:44:42 +0300 Andrew Rybchenko <[email protected]>…
Quoted 5 lines · Stephen Hemminger

Formatting ethernet address and getting a random value are not in critical path so they should not be inlined.

Meson build is lost plus one nit below.
Other than that:

[...]

lib/librte_net/rte_net_version.map DPDK_17.05 { · line 20

Quoted 13 lines
lib/librte_net/rte_net_version.map +5 -0
index 26c06e7c7ae7..dae6e420cded 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
  } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	eth_random_addr;
+	eth_format_addr;  

rte_ prefix is lost

Quoted 6 lines

lib/librte_net/rte_net_version.map DPDK_17.05 { · line 25

Quoted 5 lines
lib/librte_net/rte_net_version.map +2 -0
+} DPDK_17.05;
+
  EXPERIMENTAL {
  	global:
 

Fixing those now for v4

#17 lore raw

PATCH v3 2/6 net/ether: add rte_eth_unformat_addr

In reply to Stephen Hemminger

Make a function that coresponds with eth_aton_r which can be used to convert string to rte_ether_addr.

This also allows rte_ethdev to no longer depend on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index dae6e420cded..8776534b731d 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_eth_unformat_addr;
 };
Signature · 1 line
2.20.1
Reviewed-by on v3 2/6
#18 lore raw

Re: [dpdk-dev] [PATCH v3 2/6] net/ether: add rte_eth_unformat_addr

Quoted 1 line · Stephen Hemminger

Make a function that coresponds with eth_aton_r which can

I guess ether_aton_r

Quoted 23 lines

be used to convert string to rte_ether_addr.

This also allows rte_ethdev to no longer depend on the cmdline library.

---
  lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
  lib/librte_net/rte_ether.h         | 14 +++++++++
  lib/librte_net/rte_net_version.map |  1 +
  3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +3 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
  		 eth_addr->addr_bytes[4],
  		 eth_addr->addr_bytes[5]);
  }
+
+/*
+ * Like ether_aton_r but can handle either

lib/librte_net/rte_ether.c rte_ether_format_addr(char *buf, uint16_t size, · line 42

Quoted 10 lines
lib/librte_net/rte_ether.c +10 -0
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);

Is it intended that the following input will pass? "af:bb:03:65:dc:ddobar" or  "af:bb:03:65:dc:dd foobar"

I guess yes since ether_aton() accepts it. If so,

#19 lore raw

Re: [dpdk-dev] [PATCH v3 2/6] net/ether: add rte_eth_unformat_addr

Quoted 42 lines · On Wed, 5 Jun 2019 11:55:21 +0300 Andrew Rybchenko <[email protected]>…
Quoted 1 line · Stephen Hemminger

Make a function that coresponds with eth_aton_r which can

I guess ether_aton_r

Quoted 23 lines

be used to convert string to rte_ether_addr.

This also allows rte_ethdev to no longer depend on the cmdline library.

---
  lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
  lib/librte_net/rte_ether.h         | 14 +++++++++
  lib/librte_net/rte_net_version.map |  1 +
  3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +3 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
  		 eth_addr->addr_bytes[4],
  		 eth_addr->addr_bytes[5]);
  }
+
+/*
+ * Like ether_aton_r but can handle either

lib/librte_net/rte_ether.c rte_ether_format_addr(char *buf, uint16_t size, · line 42

Quoted 10 lines
lib/librte_net/rte_ether.c +10 -0
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);  

Is it intended that the following input will pass?
 "af:bb:03:65:dc:ddobar" or  "af:bb:03:65:dc:dd foobar"

Quoted 2 lines

I guess yes since ether_aton() accepts it. If so,

you are right ether_aton has same logic.
doing something more complex is possible but not really needed.

#20 lore raw

PATCH v3 3/6 ethdev: use rte_eth_unformat_addr

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#21 lore raw

Re: [dpdk-dev] [PATCH v3 3/6] ethdev: use rte_eth_unformat_addr

Quoted 5 lines · Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

[...]

Quoted 16 lines
lib/librte_ethdev/rte_class_eth.c +0 -1
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
  #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
  #include <rte_class.h>
  #include <rte_compat.h>
  #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
  eth_mac_cmp(const char *key __rte_unused,
  		const char *value, void *opaque)
  {

lib/librte_ethdev/rte_class_eth.c static int · line 55

Quoted 10 lines
lib/librte_ethdev/rte_class_eth.c +0 -4
-	int ret;
  	struct rte_ether_addr mac;
  	const struct rte_eth_dev_data *data = opaque;
  	struct rte_eth_dev_info dev_info;
  	uint32_t index;
 
  	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h

Why not ether_aton_r()? Isn't conflict resolved now after patch series from Olivier? I think it would be nice to explain it in the changeset description.

Quoted 7 lines
lib/librte_ethdev/rte_class_eth.c +1 -3
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
  		return -1; /* invalid devargs value */
 
  	/* Return 0 if devargs MAC is matching one of the device MACs. */
#22 lore raw

Re: [dpdk-dev] [PATCH v3 3/6] ethdev: use rte_eth_unformat_addr

Quoted 31 lines · On Wed, 5 Jun 2019 11:59:52 +0300 Andrew Rybchenko <[email protected]>…
Quoted 5 lines · Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

[...]

Quoted 22 lines
lib/librte_ethdev/rte_class_eth.c +0 -2
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
  #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
  #include <rte_class.h>
  #include <rte_compat.h>
  #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
  eth_mac_cmp(const char *key __rte_unused,
  		const char *value, void *opaque)
  {
-	int ret;
  	struct rte_ether_addr mac;
  	const struct rte_eth_dev_data *data = opaque;
  	struct rte_eth_dev_info dev_info;
  	uint32_t index;
 
Quoted 8 lines

lib/librte_ethdev/rte_class_eth.c static int · line 55

Quoted 4 lines
lib/librte_ethdev/rte_class_eth.c +0 -3
  	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h  

Why not ether_aton_r()? Isn't conflict resolved now after patch series from Olivier?
I think it would be nice to explain it in the changeset description.

ether_aton_r won;t work for 3 three ushorts model.

#23 lore raw

Re: [dpdk-dev] [PATCH v3 3/6] ethdev: use rte_eth_unformat_addr

In reply to Andrew Rybchenko
Quoted 31 lines · On Wed, 5 Jun 2019 11:59:52 +0300 Andrew Rybchenko <[email protected]>…
Quoted 5 lines · Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

[...]

Quoted 22 lines
lib/librte_ethdev/rte_class_eth.c +0 -2
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
  #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
  #include <rte_class.h>
  #include <rte_compat.h>
  #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
  eth_mac_cmp(const char *key __rte_unused,
  		const char *value, void *opaque)
  {
-	int ret;
  	struct rte_ether_addr mac;
  	const struct rte_eth_dev_data *data = opaque;
  	struct rte_eth_dev_info dev_info;
  	uint32_t index;
 
Quoted 8 lines

lib/librte_ethdev/rte_class_eth.c static int · line 55

Quoted 4 lines
lib/librte_ethdev/rte_class_eth.c +0 -3
  	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h  

Why not ether_aton_r()? Isn't conflict resolved now after patch series from Olivier?
I think it would be nice to explain it in the changeset description.

The problem with using ether_aton_r is that it does not accept the same input formats as old code.

#24 lore raw

PATCH v3 4/6 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#26 lore raw

PATCH v3 5/6 net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
Reviewed-by on v3 5/6
#27 lore raw

Re: [dpdk-dev] [PATCH v3 5/6] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 13 lines · Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
     |  ^~~~~
Quoted 6 lines

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

#28 lore raw

PATCH v3 6/6 cmdline: use rte_ether_unformat_addr

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  3 +
 4 files changed, 14 insertions(+), 65 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -0
index 0fa61385fccf..c01033fd796f 100644
@@ -4,6 +4,8 @@
 # This library is processed before EAL
 includes = [global_inc]
 
+cflags  += '-DALLOW_EXPERIMENTAL_API'
+
 version = 2
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
@@ -28,3 +30,4 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+deps += ['net']
Signature · 1 line
2.20.1
#29 lore raw

v4 cover net/ether: enhancements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Bruce Richardson (1):
net/ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (7):
net/rte_ether: deinline non-critical functions net/ether: add rte_eth_unformat_addr
ethdev: use rte_eth_unformat_addr
net/ether: use bitops to speedup comparison
cmdline: use rte_ether_unformat_addr
net/bonding: use rte_ether_unformat_addr rather than cmdline_parse app/testpmd: use rte_ether_unformat_addr

 app/test-pmd/cmdline_flow.c                  |  5 +-
 app/test-pmd/config.c                        | 10 +--
 app/test-pmd/parameters.c                    | 15 +---
 drivers/net/bonding/Makefile                 |  2 +-
 drivers/net/bonding/meson.build              |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c      |  6 +-
 lib/Makefile                                 |  3 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++---------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/librte_ethdev/Makefile                   |  2 +-
 lib/librte_ethdev/meson.build                |  2 +-
 lib/librte_ethdev/rte_class_eth.c            |  9 +--
 lib/librte_net/Makefile                      |  1 +
 lib/librte_net/meson.build                   |  2 +-
 lib/librte_net/rte_ether.c                   | 76 ++++++++++++++++++++
 lib/librte_net/rte_ether.h                   | 59 +++++++--------
 lib/librte_net/rte_net_version.map           |  8 +++
 lib/meson.build                              |  2 +-
 19 files changed, 142 insertions(+), 142 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#30 lore raw

PATCH v4 1/8 net/rte_ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 5 files changed, 42 insertions(+), 22 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
Reviewed-by on v4 1/8
#31 lore raw

Re: [dpdk-dev] [PATCH v4 1/8] net/rte_ether: deinline non-critical functions

Quoted 6 lines · Stephen Hemminger

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

Quoted 9 lines
---
  lib/librte_net/Makefile            |  1 +
  lib/librte_net/meson.build         |  2 +-
  lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
  lib/librte_net/rte_ether.h         | 25 ++++---------------------
  lib/librte_net/rte_net_version.map |  7 +++++++
  5 files changed, 42 insertions(+), 22 deletions(-)

create mode 100644 lib/librte_net/rte_ether.c

#32 lore raw

PATCH v4 2/8 net/ether: add rte_eth_unformat_addr

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#33 lore raw

PATCH v4 3/8 ethdev: use rte_eth_unformat_addr

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#34 lore raw

PATCH v4 4/8 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#35 lore raw

PATCH v4 5/8 net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
#36 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 39 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +0 -0
index feb35a33c94b..d7b76ddf63eb 100644

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 7 lines
lib/librte_net/rte_ether.h +2 -1
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));

Hmm, that would change layout of any struct/union that has struct rte_ether_addr inside. So seems like implicit ABI breakage to me.
Konstantin

Quoted 33 lines
lib/librte_net/rte_ether.h +4 -5
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
--

2.20.1

#37 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 32 lines · Konstantin
Quoted 32 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 16 lines

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 12 lines
lib/librte_net/rte_ether.h +2 -1
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));  

Hmm, that would change layout of any struct/union that has struct rte_ether_addr inside. So seems like implicit ABI breakage to me.
Konstantin

There was no rte_ether_addr in previous releases.

#38 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 66 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, June 7, 2019 7:35 PM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Richardson, Bruce <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 17 lines · Konstantin
Quoted 17 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

Quoted 5 lines
Quoted 5 lines

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t

*)ea;

Quoted 5 lines
Quoted 5 lines
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using

16-bit operations.

Quoted 8 lines
Quoted 8 lines
---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 9 lines

lib/librte_net/rte_ether.h extern "C" { · line 61

Quoted 9 lines
lib/librte_net/rte_ether.h +0 -1
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order

*/

Quoted 5 lines

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 3 lines
lib/librte_net/rte_ether.h +2 -0
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));

Hmm, that would change layout of any struct/union that has struct

Quoted 5 lines

rte_ether_addr inside.

Quoted 2 lines

So seems like implicit ABI breakage to me.
Konstantin

There was no rte_ether_addr in previous releases.

Good point. Thanks for remembering...

#39 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger
Quoted 41 lines
Quoted 24 lines
Quoted 24 lines

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 16 lines

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 12 lines
lib/librte_net/rte_ether.h +2 -1
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));

Hmm, that would change layout of any struct/union that has struct rte_ether_addr inside. So seems like implicit ABI breakage to me.
Konstantin

Quoted 1 line

There was no rte_ether_addr in previous releases.

I suppose you refer to the fact that struct ether_addr was renamed to rte_ether_addr by:
https://git.dpdk.org/dpdk/commit/?id=6d13ea8e8e49ab957deae2bba5ecf4a4bfe747d1
As I understand, Olivier patches in that rework introduce API change only, keeping ABI unchanged. While your patch makes ABI breakage possible.
Konstantin

#40 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Ananyev, Konstantin
Quoted 59 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Friday, June 7, 2019 6:00 PM
To: Stephen Hemminger <[email protected]>; [email protected]
Cc: Richardson, Bruce <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 16 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

Quoted 5 lines

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t

*)ea;

Quoted 5 lines
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit

operations.

Quoted 13 lines
---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +0 -0
index feb35a33c94b..d7b76ddf63eb 100644

lib/librte_net/rte_ether.h extern "C" { · line 61

Quoted 4 lines
lib/librte_net/rte_ether.h +0 -1
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order

*/

Quoted 9 lines

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 3 lines
lib/librte_net/rte_ether.h +2 -0
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));

Hmm, that would change layout of any struct/union that has struct rte_ether_addr inside.
So seems like implicit ABI breakage to me.
Konstantin

I suppose it could, though only if you had the structure starting at an odd byte inside the larger structure. Personally, I'd think it should be ok in just about all cases, as I'd find it hard to imagine when you wouldn't have this, but technically I suppose it's a break. For real packet heads the fields will always be two-byte aligned so there is no issue.

/Bruce

#41 lore raw

Re: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 57 lines
Quoted 47 lines
Quoted 17 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v4 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

Quoted 5 lines

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t

*)ea;

Quoted 5 lines
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit

operations.

Quoted 13 lines
---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +0 -0
index feb35a33c94b..d7b76ddf63eb 100644

lib/librte_net/rte_ether.h extern "C" { · line 61

Quoted 4 lines
lib/librte_net/rte_ether.h +0 -1
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order

*/

Quoted 9 lines

lib/librte_net/rte_ether.h extern "C" { · line 63

Quoted 3 lines
lib/librte_net/rte_ether.h +2 -0
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));

Hmm, that would change layout of any struct/union that has struct rte_ether_addr inside.
So seems like implicit ABI breakage to me.
Konstantin

Quoted 2 lines

I suppose it could, though only if you had the structure starting at an odd byte inside the larger structure.

Yes.

Quoted 3 lines

Personally, I'd think it should be ok in just about
all cases, as I'd find it hard to imagine when you wouldn't have this, but technically I suppose it's a break.

I also don't expect it to be a common case, but it is not totally impossible. So I still think it qualifies as ABI change and we need to follow our own ABI breakage policy here.

Quoted 3 lines

For real packet heads the fields will always be
two-byte aligned so there is no issue.

#42 lore raw

PATCH v4 6/8 cmdline: use rte_ether_unformat_addr

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index e067ce5ea349..fc57fec1908a 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1
#43 lore raw

PATCH v4 7/8 net/bonding: use rte_ether_unformat_addr rather than cmdline_parse

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#44 lore raw

PATCH v4 8/8 app/testpmd: use rte_ether_unformat_addr

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
#45 lore raw

Re: [dpdk-dev] [PATCH v4 8/8] app/testpmd: use rte_ether_unformat_addr

Hi Stephen,

Quoted 134 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v4 8/8] app/testpmd: use rte_ether_unformat_addr

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--
Quoted 1 line

2.20.1

./devtools/check-git-log.sh -1
Wrong headline format:
app/testpmd: use rte_ether_unformat_addr

Does not like the "_" in the commit message. This also affects four of the other patches in the set.

/devtools/checkpatches.sh v4-8-8-app-testpmd-use-rte_ether_unformat_addr.patch

WARNING:LONG_LINE: line over 80 characters
#125: FILE: app/test-pmd/parameters.c:737:
+ &peer_eth_addrs[n]) < 0)

total: 0 errors, 1 warnings, 88 lines checked

Long line should probably be fixed.

Regards,

Bernard

#46 lore raw

Re: [dpdk-dev] [PATCH v4 8/8] app/testpmd: use rte_ether_unformat_addr

Quoted 142 lines · Bernard

Hi Stephen,

Quoted 134 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, June 5, 2019 7:10 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v4 8/8] app/testpmd: use rte_ether_unformat_addr

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--
Quoted 1 line

2.20.1

./devtools/check-git-log.sh -1
Wrong headline format:
app/testpmd: use rte_ether_unformat_addr

Quoted 2 lines

Does not like the "_" in the commit message. This also affects four of the other patches in the set.

The tool is broken, not the patch.
This is not a restriction in other projects.

Quoted 9 lines

/devtools/checkpatches.sh v4-8-8-app-testpmd-use-rte_ether_unformat_addr.patch

WARNING:LONG_LINE: line over 80 characters
#125: FILE: app/test-pmd/parameters.c:737:
+ &peer_eth_addrs[n]) < 0)

total: 0 errors, 1 warnings, 88 lines checked

Long line should probably be fixed.

The pre-existing code had a long line already.

#47 lore raw

v5 cover net/ether: enhancements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Bruce Richardson (1):
net/ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (7):
net/rte_ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser

 app/test-pmd/cmdline_flow.c                  |  5 +-
 app/test-pmd/config.c                        | 10 +--
 app/test-pmd/parameters.c                    | 15 +---
 drivers/net/bonding/Makefile                 |  2 +-
 drivers/net/bonding/meson.build              |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c      |  6 +-
 lib/Makefile                                 |  3 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++---------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/librte_ethdev/Makefile                   |  2 +-
 lib/librte_ethdev/meson.build                |  2 +-
 lib/librte_ethdev/rte_class_eth.c            |  9 +--
 lib/librte_net/Makefile                      |  1 +
 lib/librte_net/meson.build                   |  2 +-
 lib/librte_net/rte_ether.c                   | 76 ++++++++++++++++++++
 lib/librte_net/rte_ether.h                   | 59 +++++++--------
 lib/librte_net/rte_net_version.map           |  8 +++
 lib/meson.build                              |  2 +-
 19 files changed, 142 insertions(+), 142 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#48 lore raw

PATCH v5 1/8 net/rte_ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 5 files changed, 42 insertions(+), 22 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
#49 lore raw

Re: [dpdk-dev] [PATCH v5 1/8] net/rte_ether: deinline non-critical functions

Hi Stephen,

Quoted 138 lines · Stephen Hemminger

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 5 files changed, 42 insertions(+), 22 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1

In drivers/net/memif and drivers/net/axgbe, rte_ether_format_addr() is used, but -lrte_net is not passed to LDLIBS in the Makefile. This was probably ok before because it was an inline function, but I wonder if it shouldn't be added in this patch.

#50 lore raw

PATCH v5 2/8 net/ether: add function to convert string to ethernet address

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#51 lore raw

PATCH v5 3/8 ethdev: use new ethernet parsing function

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#52 lore raw

PATCH v5 4/8 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#53 lore raw

Re: [dpdk-dev] [PATCH v5 4/8] net/ether: use bitops to speedup comparison

Hi,

Quoted 37 lines · Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +4 -6
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;

lib/librte_net/rte_ether.h static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, · line 107

Quoted 10 lines
lib/librte_net/rte_ether.h +3 -4
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**

I wonder if using memcmp() isn't faster with recent compilers (gcc >= 7). I tried it quickly, and it seems the generated code is good (no call):
https://godbolt.org/z/9MOL7g

It would avoid the use of unaligned_uint16_t, and the next patch that adds the alignment constraint.

#54 lore raw

Re: [dpdk-dev] [PATCH v5 4/8] net/ether: use bitops to speedup comparison

Quoted 49 lines · Olivier Matz

Hi,

Quoted 46 lines · Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
Quoted 8 lines

lib/librte_net/rte_ether.h static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, · line 107

Quoted 1 line
lib/librte_net/rte_ether.h +0 -0
 /**

I wonder if using memcmp() isn't faster with recent compilers (gcc >= 7). I tried it quickly, and it seems the generated code is good (no call):
https://godbolt.org/z/9MOL7g

It would avoid the use of unaligned_uint16_t, and the next patch that adds the alignment constraint.

As pointed out by Konstantin privately (I guess he wanted to do a reply-all), the size of addr_bytes is wrong in my previous link (8 instead of 6). Thanks for catching it.

With 6, the gcc code is not as good: there is still no call to memcmp(), but there are some jumps. With the latest clang, the generated code is
nice: https://godbolt.org/z/nfptnY

#55 lore raw

Re: [dpdk-dev] [PATCH v5 4/8] net/ether: use bitops to speedup comparison

Quoted 59 lines · On Tue, 2 Jul 2019 11:26:15 +0200 Olivier Matz <[email protected]> wrote:
Quoted 49 lines · Olivier Matz

Hi,

Quoted 46 lines · Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
Quoted 8 lines

lib/librte_net/rte_ether.h static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, · line 107

Quoted 1 line
lib/librte_net/rte_ether.h +0 -0
 /**  

I wonder if using memcmp() isn't faster with recent compilers (gcc >= 7). I tried it quickly, and it seems the generated code is good (no call):
https://godbolt.org/z/9MOL7g

It would avoid the use of unaligned_uint16_t, and the next patch that adds the alignment constraint.

Quoted 7 lines

As pointed out by Konstantin privately (I guess he wanted to do a reply-all), the size of addr_bytes is wrong in my previous link (8 instead of 6). Thanks for catching it.

With 6, the gcc code is not as good: there is still no call to memcmp(), but there are some jumps. With the latest clang, the generated code is
nice: https://godbolt.org/z/nfptnY

gcc matters most for current DPDK users.

#56 lore raw

PATCH v5 5/8 net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
#57 lore raw

PATCH v5 6/8 cmdline: use new ethernet address parser

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index 992091a9407e..5c892404e706 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): 8688172CD5C0B74590FAE19D9579F94B53742875@SHSMSX103.ccr.corp.intel.com

#59 lore raw

Re: [dpdk-dev] [PATCH v5 6/8] cmdline: use new ethernet address parser

Quoted 31 lines · WenjieX A

Hi Stephen,

This DPDK patch makes cmdline_autotest failed. List the details as below.

Could you please help to resolve it?

Thank you!
Test Setup
Steps to reproduce
List the steps to reproduce the issue. ./x86_64-native-linuxapp-gcc/app/test -n 1 -c 0xff testpmd> cmdline_autotest
Show the output from the previous commands.
Testind parsing ethernet addresses...
Error: parsing 01:23:45:67:89:A succeeded!
Test Failed
Expected Result
Explain what is the expected result in text or as an example output:
Testind parsing ethernet addresses...
Testind parsing port lists...
Testind parsing numbers...
Testing parsing IP addresses...
Testing parsing strings...
Testing circular buffer...
Testing library functions...
Test OK

Quoted 4 lines

BR,

Wenjie

There are two possible solutions. Make the ether_unformat_addr function more complex and more restrictive. The new version corresponds to the FreeBSD behavior.

The other possibility is just remove the test case.

I am leaning towards the latter as the least work.

#60 lore raw

Re: [dpdk-dev] [PATCH v5 6/8] cmdline: use new ethernet address parser

Quoted 34 lines · Stephen Hemminger
Quoted 31 lines · WenjieX A

Hi Stephen,

This DPDK patch makes cmdline_autotest failed. List the details as below.

Could you please help to resolve it?

Thank you!
Test Setup
Steps to reproduce
List the steps to reproduce the issue. ./x86_64-native-linuxapp-gcc/app/test -n 1 -c 0xff testpmd> cmdline_autotest
Show the output from the previous commands.
Testind parsing ethernet addresses...
Error: parsing 01:23:45:67:89:A succeeded!
Test Failed
Expected Result
Explain what is the expected result in text or as an example output:
Testind parsing ethernet addresses...
Testind parsing port lists...
Testind parsing numbers...
Testing parsing IP addresses...
Testing parsing strings...
Testing circular buffer...
Testing library functions...
Test OK

Quoted 8 lines
Quoted 4 lines

BR,

Wenjie

There are two possible solutions. Make the ether_unformat_addr function more complex and more restrictive. The new version corresponds to the FreeBSD behavior.

Not exactly. The new code accepts 2 forms (X:X:X:X:X:X which is FreeBSD, as well as X:X:X which is not). Because of this, there is a higher likelihood of ambiguity. I want to submit a patch to fix this ambiguity (but got pulled into a customer bug). Maybe someone else can?

I think it's best to make the code slightly more complex. I originally submitted a change just validating the string length[0], which is probably too restrictive.

Maybe a better version would be something like the original (rewritten to ensure it supports things like XX:X:XX:X:XX:X format, also):

{
unsigned long o[ETHER_ADDR_LEN];
char *end, *input = buf;
size_t i = 0;

   do {
     errno = 0;
     o[i] = strtoul(input, &end, 16);
     if (errno != 0 || end == input || (end && *end != ':' && *end != 0))
        return ERROR;
     input = end+1;
   } while((input - buf < buflen) && ++i < ARRAY_SIZE(o) && *end != 0);

if (*end != 0)

      return ERROR;

if (i == 6) /*x:x:x:x:x:x*/
else if (i == 3) /*x:x:x*/
else return ERROR
}

WDYT?

Quoted 1 line

The other possibility is just remove the test case.

I don't like this approach - right now its possible that a user (doing c/p) can submit an ipv6 address which will be accepted as valid. I prefer to be validating the form. Even if XX:X:X:XX:X:X is okay, XXXX:XXXX:XX::X shouldn't be. There's a limit to how liberal we should be when accepting input.

Quoted 1 line

I am leaning towards the latter as the least work.

Least work isn't always the right thing.

0: http://mails.dpdk.org/archives/dev/2019-July/137827.html

#61 lore raw

Re: [dpdk-dev] [PATCH v5 6/8] cmdline: use new ethernet address parser

Quoted 41 lines · Aaron Conole
Quoted 39 lines · Stephen Hemminger
Quoted 35 lines · WenjieX A

Hi Stephen,

This DPDK patch makes cmdline_autotest failed. List the details as below.

Could you please help to resolve it?

Thank you!
Test Setup
Steps to reproduce
List the steps to reproduce the issue. ./x86_64-native-linuxapp-gcc/app/test -n 1 -c 0xff testpmd> cmdline_autotest
Show the output from the previous commands.
Testind parsing ethernet addresses...
Error: parsing 01:23:45:67:89:A succeeded!
Test Failed
Expected Result
Explain what is the expected result in text or as an example output:
Testind parsing ethernet addresses...
Testind parsing port lists...
Testind parsing numbers...
Testing parsing IP addresses...
Testing parsing strings...
Testing circular buffer...
Testing library functions...
Test OK

BR,

Wenjie

Quoted 8 lines
Quoted 3 lines

There are two possible solutions. Make the ether_unformat_addr function more complex and more restrictive. The new version corresponds to the FreeBSD behavior.

Not exactly. The new code accepts 2 forms (X:X:X:X:X:X which is FreeBSD, as well as X:X:X which is not). Because of this, there is a higher likelihood of ambiguity. I want to submit a patch to fix this ambiguity (but got pulled into a customer bug). Maybe someone else can?

I will have a look at it.

Quoted 43 lines

I think it's best to make the code slightly more complex. I originally submitted a change just validating the string length[0], which is probably too restrictive.

Maybe a better version would be something like the original (rewritten to ensure it supports things like XX:X:XX:X:XX:X format, also):

{
   unsigned long o[ETHER_ADDR_LEN];
   char *end, *input = buf;
   size_t i = 0;

   do {
     errno = 0;
     o[i] = strtoul(input, &end, 16);
     if (errno != 0 || end == input || (end && *end != ':' && *end != 0))
        return ERROR;
     input = end+1;
   } while((input - buf < buflen) && ++i < ARRAY_SIZE(o) && *end != 0);

   if (*end != 0)
      return ERROR;

   if (i == 6) /*x:x:x:x:x:x*/
   else if (i == 3) /*x:x:x*/
   else return ERROR
}

WDYT?

Quoted 1 line

The other possibility is just remove the test case.

I don't like this approach - right now its possible that a user (doing c/p) can submit an ipv6 address which will be accepted as valid. I prefer to be validating the form. Even if XX:X:X:XX:X:X is okay, XXXX:XXXX:XX::X shouldn't be. There's a limit to how liberal we should be when accepting input.

Quoted 1 line

I am leaning towards the latter as the least work.

Least work isn't always the right thing.

0: http://mails.dpdk.org/archives/dev/2019-July/137827.html

#62 lore raw

PATCH v5 7/8 net/bonding: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#63 lore raw

PATCH v5 8/8 app/testpmd: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
#64 lore raw

v6 cover net/ether: enhancements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Bruce Richardson (1):
net/ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (7):
net/rte_ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser

 app/test-pmd/cmdline_flow.c                  |  5 +-
 app/test-pmd/config.c                        | 10 +--
 app/test-pmd/parameters.c                    | 15 +---
 drivers/net/axgbe/Makefile                   |  2 +-
 drivers/net/bonding/Makefile                 |  2 +-
 drivers/net/bonding/meson.build              |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c      |  6 +-
 drivers/net/memif/Makefile                   |  2 +-
 lib/Makefile                                 |  3 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++---------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/librte_ethdev/Makefile                   |  2 +-
 lib/librte_ethdev/meson.build                |  2 +-
 lib/librte_ethdev/rte_class_eth.c            |  9 +--
 lib/librte_net/Makefile                      |  1 +
 lib/librte_net/meson.build                   |  2 +-
 lib/librte_net/rte_ether.c                   | 76 ++++++++++++++++++++
 lib/librte_net/rte_ether.h                   | 59 +++++++--------
 lib/librte_net/rte_net_version.map           |  8 +++
 lib/meson.build                              |  2 +-
 21 files changed, 144 insertions(+), 144 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#65 lore raw

PATCH v6 1/8 net/rte_ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 drivers/net/axgbe/Makefile         |  2 +-
 drivers/net/memif/Makefile         |  2 +-
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 7 files changed, 44 insertions(+), 24 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
drivers/net/axgbe/Makefile +1 -1
index 72215aedaf55..c2d4336800c0 100644
@@ -17,7 +17,7 @@ LIBABIVER := 1
 
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
 LDLIBS += -lrte_pci -lrte_bus_pci
-LDLIBS += -lrte_ethdev
+LDLIBS += -lrte_ethdev -lrte_net
 
 #
 # all source are stored in SRCS-y
drivers/net/memif/Makefile +1 -1
index fdbdf3378019..3d92b08f259b 100644
@@ -21,7 +21,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 # - rte_mp_reply
 # - rte_mp_request_sync
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
-LDLIBS += -lrte_ethdev -lrte_kvargs
+LDLIBS += -lrte_ethdev -lrte_kvargs -lrte_net
 LDLIBS += -lrte_hash
 LDLIBS += -lrte_bus_vdev
 
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
#66 lore raw

PATCH v6 2/8 net/ether: add function to convert string to ethernet address

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#67 lore raw

PATCH v6 3/8 ethdev: use new ethernet parsing function

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#68 lore raw

PATCH v6 4/8 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#69 lore raw

PATCH v6 5/8 net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
#70 lore raw

Re: [dpdk-dev] [PATCH v6 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 23 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, July 2, 2019 5:50 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Stephen Hemminger <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [dpdk-dev] [PATCH v6 5/8] net/ether: mark ethernet addresses as being 2-byte aligned

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~
Quoted 7 lines

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

Seems like you forgot to remove that patch from the seies. Konstantin

Quoted 49 lines
---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -6
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
--

2.20.1

#71 lore raw

PATCH v6 6/8 cmdline: use new ethernet address parser

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index 9398a3ac04e3..c133f2f35ff3 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1
#72 lore raw

PATCH v6 7/8 net/bonding: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#73 lore raw

PATCH v6 8/8 app/testpmd: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
#74 lore raw

Re: [dpdk-dev] [PATCH v6 0/8] net/ether: enhancements and optimizations

In reply to Stephen Hemminger
Quoted 8 lines

Stephen Hemminger (7):
net/rte_ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser

There are other MAC parsing code:
drivers/net/failsafe/failsafe_args.c - fs_get_mac_addr_arg() drivers/net/memif/rte_eth_memif.c - memif_set_mac() drivers/net/vdev_netvsc/vdev_netvsc.c - vdev_netvsc_netvsc_probe() drivers/net/virtio/virtio_user/virtio_user_dev.c - parse_mac()
Should they be replaced?

#75 lore raw

Re: [dpdk-dev] [PATCH v6 0/8] net/ether: enhancements and optimizations

Quoted 9 lines · On Tue, 02 Jul 2019 23:37:29 +0200 Thomas Monjalon <[email protected]> wrote:
Quoted 8 lines

Stephen Hemminger (7):
net/rte_ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser

Quoted 8 lines

There are other MAC parsing code:
drivers/net/failsafe/failsafe_args.c - fs_get_mac_addr_arg() drivers/net/memif/rte_eth_memif.c - memif_set_mac() drivers/net/vdev_netvsc/vdev_netvsc.c - vdev_netvsc_netvsc_probe() drivers/net/virtio/virtio_user/virtio_user_dev.c - parse_mac()
Should they be replaced?

Sure, I can add these to v7

#76 lore raw

v7 cover ether: improvements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v7
use rte_ether_unformat_addr in more drivers
v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Bruce Richardson (1):
net/ether: mark ethernet addresses as being 2-byte aligned

Stephen Hemminger (11):
net/rte_ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser net/virtio: use new ether addr parsing net/failsafe: use common ether address parsing routine net/vdev_netvsc: use common ethernet address parsing net/memif: use common ethernet address parsing routine

 app/test-pmd/cmdline_flow.c                   |  5 +-
 app/test-pmd/config.c                         | 10 +--
 app/test-pmd/parameters.c                     | 15 +---
 drivers/net/axgbe/Makefile                    |  2 +-
 drivers/net/bonding/Makefile                  |  2 +-
 drivers/net/bonding/meson.build               |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c       |  6 +-
 drivers/net/failsafe/failsafe_args.c          |  8 +-
 drivers/net/memif/Makefile                    |  2 +-
 drivers/net/memif/rte_eth_memif.c             |  7 +-
 drivers/net/vdev_netvsc/vdev_netvsc.c         | 10 +--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 10 +--
 lib/Makefile                                  |  3 +-
 lib/librte_cmdline/Makefile                   |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c  | 71 ++---------------
 lib/librte_cmdline/meson.build                |  6 +-
 lib/librte_ethdev/Makefile                    |  2 +-
 lib/librte_ethdev/meson.build                 |  2 +-
 lib/librte_ethdev/rte_class_eth.c             |  9 +--
 lib/librte_net/Makefile                       |  1 +
 lib/librte_net/meson.build                    |  2 +-
 lib/librte_net/rte_ether.c                    | 76 +++++++++++++++++++
 lib/librte_net/rte_ether.h                    | 59 +++++++-------
 lib/librte_net/rte_net_version.map            |  8 ++
 lib/meson.build                               |  2 +-
 25 files changed, 151 insertions(+), 172 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#77 lore raw

PATCH v7 1/12 net/rte_ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 drivers/net/axgbe/Makefile         |  2 +-
 drivers/net/memif/Makefile         |  2 +-
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 7 files changed, 44 insertions(+), 24 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
drivers/net/axgbe/Makefile +1 -1
index 72215aedaf55..c2d4336800c0 100644
@@ -17,7 +17,7 @@ LIBABIVER := 1
 
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
 LDLIBS += -lrte_pci -lrte_bus_pci
-LDLIBS += -lrte_ethdev
+LDLIBS += -lrte_ethdev -lrte_net
 
 #
 # all source are stored in SRCS-y
drivers/net/memif/Makefile +1 -1
index fdbdf3378019..3d92b08f259b 100644
@@ -21,7 +21,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 # - rte_mp_reply
 # - rte_mp_request_sync
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
-LDLIBS += -lrte_ethdev -lrte_kvargs
+LDLIBS += -lrte_ethdev -lrte_kvargs -lrte_net
 LDLIBS += -lrte_hash
 LDLIBS += -lrte_bus_vdev
 
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 7be9b4890af7..3caae0d98f6d 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
Acked-by on v7 1/12
#78 lore raw

Re: [dpdk-dev] [PATCH v7 01/12] net/rte_ether: deinline non-critical functions

Quoted 6 lines · Stephen Hemminger

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

just a nit in the title: net/ether instead of net/rte_ether for consistency with other patches

Thanks

#79 lore raw

PATCH v7 2/12 net/ether: add function to convert string to ethernet address

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +14 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#80 lore raw

Re: [dpdk-dev] [PATCH v7 02/12] net/ether: add function to convert string to ethernet address

Hi,

Quoted 79 lines · Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 62 insertions(+)
lib/librte_net/rte_ether.c +47 -0
index 974fe815b335..acc8a0e938c5 100644
@@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+
+		return 0;
+	}
+
+	/* Support the format XXXX:XXXX:XXXX */
+	n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2);
+	if (n == 3) {
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX)
+			return -1;
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+		return 0;
+	}
+	/* unknown format */
+
+	return -1;
+}
lib/librte_net/rte_ether.h +0 -0
index 3caae0d98f6d..8edc7e217b25 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);

lib/librte_net/rte_ether.h static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from, · line 262

Quoted 10 lines
lib/librte_net/rte_ether.h +10 -0
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string

Is rte_errno really set?

Quoted 20 lines
lib/librte_net/rte_ether.h +4 -0
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#81 lore raw

PATCH v7 3/12 ethdev: use new ethernet parsing function

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#82 lore raw

PATCH v7 4/12 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 8edc7e217b25..feb35a33c94b 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
Acked-by on v7 4/12
#83 lore raw

Re: [dpdk-dev] [PATCH v7 04/12] net/ether: use bitops to speedup comparison

Quoted 8 lines · Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

#84 lore raw

PATCH v7 5/12 net/ether: mark ethernet addresses as being 2-byte aligned

In reply to Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1
#85 lore raw

Re: [dpdk-dev] [PATCH v7 05/12] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 70 lines · Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]

149 |  const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations.

---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +6 -5
index feb35a33c94b..d7b76ddf63eb 100644
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
@@ -81,8 +82,8 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
@@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea)
  */
 static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea)
 {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
Signature · 1 line
2.20.1

Following this discussion:
https://mails.dpdk.org/archives/dev/2019-July/136590.html

I still think that changing the ABI without deprecation notice is not a good idea.

The warning issued by the compiler makes me think that the definition of unaligned_uint16_t is wrong on intel arch. I made a quick test, and it seems that in this particular case, the generated code is the same with or without __attribute__((aligned(1))). See: https://godbolt.org/z/NjBNQk

But changing the definition of unaligned_uint16_t without a deprecation notice is not an option either.

What do you think about using a specific typedef similar to unaligned_uint16_t in rte_ether, that has the __attribute__((aligned(1))) ? It would avoid to change the alignment of struct rte_ether_addr.

In parallel, we can talk about changing unaligned_uint16_t for intel in another patchset.

Olivier

#86 lore raw

Re: [dpdk-dev] [PATCH v7 05/12] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 89 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Friday, July 5, 2019 3:34 PM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; Richardson, Bruce <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v7 05/12] net/ether: mark ethernet addresses as being 2-byte aligned

Quoted 11 lines · Stephen Hemminger

From: Bruce Richardson <[email protected]>

When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them.

.../include/rte_ether.h:149:2: warning: converting a packed ‘const
struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t

*)ea;

Quoted 5 lines
    |  ^~~~~

Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit

operations.

Quoted 13 lines
---
 lib/librte_net/rte_ether.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_net/rte_ether.h +0 -0
index feb35a33c94b..d7b76ddf63eb 100644

lib/librte_net/rte_ether.h extern "C" { · line 61

Quoted 4 lines
lib/librte_net/rte_ether.h +0 -1
@@ -58,7 +58,8 @@ extern "C" {
  * See http://standards.ieee.org/regauth/groupmac/tutorial.html
  */
 struct rte_ether_addr {
-	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order

*/

lib/librte_net/rte_ether.h static inline int rte_is_multicast_ether_addr(const

Quoted 25 lines
lib/librte_net/rte_ether.h +2 -0
+	uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2);
+	/**< Addr bytes in tx order */
 } __attribute__((__packed__));
 
 #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth.

address. */ @@ -81,8 +82,8 @@ struct rte_ether_addr { static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,

lib/librte_net/rte_ether.h +2 -2
 				     const struct rte_ether_addr *ea2)  {
-	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
-	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+	const uint16_t *w1 = (const uint16_t *)ea1;
+	const uint16_t *w2 = (const uint16_t *)ea2;
 
 	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;

} @@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
*/
static inline int rte_is_zero_ether_addr(const struct rte_ether_addr
*ea) {

lib/librte_net/rte_ether.h +1 -1
-	const unaligned_uint16_t *w = (const uint16_t *)ea;
+	const uint16_t *w = (const uint16_t *)ea;
 
 	return (w[0] | w[1] | w[2]) == 0;
 }
@@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const

struct rte_ether_addr *ea)

Quoted 11 lines
lib/librte_net/rte_ether.h +1 -2
  */
 static inline int rte_is_broadcast_ether_addr(const struct
 rte_ether_addr *ea)  {
-	const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea;
+	const uint16_t *ea_words = (const uint16_t *)ea;
 
 	return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF &&
 		ea_words[2] == 0xFFFF);
--

2.20.1

Following this discussion:
https://mails.dpdk.org/archives/dev/2019-July/136590.html

Quoted 3 lines

I still think that changing the ABI without deprecation notice is not a good idea.

I'm ok with that. Let's put in a deprecation notice and take this patch in 19.11.

Quoted 5 lines

The warning issued by the compiler makes me think that the definition of unaligned_uint16_t is wrong on intel arch. I made a quick test, and it seems that in this particular case, the generated code is the same with or without __attribute__((aligned(1))). See: https://godbolt.org/z/NjBNQk

Quoted 8 lines

But changing the definition of unaligned_uint16_t without a deprecation notice is not an option either.

What do you think about using a specific typedef similar to unaligned_uint16_t in rte_ether, that has the __attribute__((aligned(1))) ?
It would avoid to change the alignment of struct rte_ether_addr.

I'd like the alignment changed. Since the existing warnings about alignment don’t seem to be causing anyone any real problems, I suggest we just leave them for now and fix them by changing the alignment setting for 19.11.

Quoted 3 lines

In parallel, we can talk about changing unaligned_uint16_t for intel in another patchset.

Yes, let's fix the broken unaligned definition as a separate issue.

/Bruce

#87 lore raw

PATCH v7 6/12 cmdline: use new ethernet address parser

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index 9398a3ac04e3..c133f2f35ff3 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1
Acked-by on v7 6/12
#88 lore raw

Re: [dpdk-dev] [PATCH v7 06/12] cmdline: use new ethernet address parser

Quoted 8 lines · Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

Thanks!

BTW, I noticed that it also fixes a more serious bug: the previous commandline parser was using a static buffer, making it thread-unsafe. I didn't see any places that could have been impacted.

#89 lore raw

PATCH v7 7/12 net/bonding: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#90 lore raw

PATCH v7 8/12 app/testpmd: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
Acked-by on v7 8/12
#91 lore raw

Re: [dpdk-dev] [PATCH v7 08/12] app/testpmd: use new ethernet address parser

Hi Stephen,

Quoted 134 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, July 2, 2019 11:13 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v7 08/12] app/testpmd: use new ethernet address parser

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--
Quoted 1 line

2.20.1

./devtools/checkpatches.sh v7-08-12-app-testpmd-use-new-ethernet-address-parser.patch

WARNING:LONG_LINE: line over 80 characters
#126: FILE: app/test-pmd/parameters.c:737:
+ &peer_eth_addrs[n]) < 0)

No harm to fix this, otherwise

#92 lore raw

Re: [dpdk-dev] [PATCH v7 08/12] app/testpmd: use new ethernet address parser

Quoted 140 lines · Bernard

Hi Stephen,

Quoted 134 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, July 2, 2019 11:13 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH v7 08/12] app/testpmd: use new ethernet address parser

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--
Quoted 1 line

2.20.1

./devtools/checkpatches.sh v7-08-12-app-testpmd-use-new-ethernet-address-parser.patch

Quoted 5 lines

WARNING:LONG_LINE: line over 80 characters
#126: FILE: app/test-pmd/parameters.c:737:
+ &peer_eth_addrs[n]) < 0)

No harm to fix this, otherwise

Fixing the long lines (the right way) would require refactoring testpmd here. Not something I want to do.

Quoted 2 lines
#93 lore raw

PATCH v7 9/12 net/virtio: use new ether addr parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -7
index e743695e4510..0bac725e7cdd 100644
@@ -225,17 +225,13 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 static inline void
 parse_mac(struct virtio_user_dev *dev, const char *mac)
 {
-	int i, r;
-	uint32_t tmp[RTE_ETHER_ADDR_LEN];
+	struct rte_ether_addr tmp;
 
 	if (!mac)
 		return;
 
-	r = sscanf(mac, "%x:%x:%x:%x:%x:%x", &tmp[0],
-			&tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
-	if (r == RTE_ETHER_ADDR_LEN) {
-		for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
-			dev->mac_addr[i] = (uint8_t)tmp[i];
+	if (rte_ether_unformat_addr(mac, &tmp) == 0) {
+		memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN);
 		dev->mac_specified = 1;
 	} else {
 		/* ignore the wrong mac, use random mac */
Signature · 1 line
2.20.1
#94 lore raw

PATCH v7 10/12 net/failsafe: use common ether address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/failsafe/failsafe_args.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/failsafe/failsafe_args.c +2 -6
index d2e725bcea13..707490b94c4e 100644
@@ -368,15 +368,11 @@ fs_get_mac_addr_arg(const char *key __rte_unused,
 		const char *value, void *out)
 {
 	struct rte_ether_addr *ea = out;
-	int ret;
 
 	if ((value == NULL) || (out == NULL))
 		return -EINVAL;
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-		&ea->addr_bytes[0], &ea->addr_bytes[1],
-		&ea->addr_bytes[2], &ea->addr_bytes[3],
-		&ea->addr_bytes[4], &ea->addr_bytes[5]);
-	return ret != RTE_ETHER_ADDR_LEN;
+
+	return rte_ether_unformat_addr(value, ea);
 }
 
 int
Signature · 1 line
2.20.1
#96 lore raw

PATCH v7 11/12 net/vdev_netvsc: use common ethernet address parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/vdev_netvsc/vdev_netvsc.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/net/vdev_netvsc/vdev_netvsc.c +1 -9
index 1fcf90d7bc02..be8f19c0c63e 100644
@@ -529,15 +529,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
 			} else if (!strcmp(pair->key, VDEV_NETVSC_ARG_MAC)) {
 				struct rte_ether_addr tmp;
 
-				if (sscanf(pair->value,
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":"
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8,
-					   &tmp.addr_bytes[0],
-					   &tmp.addr_bytes[1],
-					   &tmp.addr_bytes[2],
-					   &tmp.addr_bytes[3],
-					   &tmp.addr_bytes[4],
-					   &tmp.addr_bytes[5]) != 6) {
+				if (rte_ether_unformat_addr(pair->value, &tmp) != 0) {
 					DRV_LOG(ERR,
 						"invalid MAC address format"
 						" \"%s\"",
Signature · 1 line
2.20.1
#98 lore raw

PATCH v7 12/12 net/memif: use common ethernet address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/memif/rte_eth_memif.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/net/memif/rte_eth_memif.c +1 -6
index e9ddf6413597..00c9b396ab85 100644
@@ -1224,13 +1224,8 @@ static int
 memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args)
 {
 	struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args;
-	int ret = 0;
 
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-	       &ether_addr->addr_bytes[0], &ether_addr->addr_bytes[1],
-	       &ether_addr->addr_bytes[2], &ether_addr->addr_bytes[3],
-	       &ether_addr->addr_bytes[4], &ether_addr->addr_bytes[5]);
-	if (ret != 6)
+	if (rte_ether_unformat_addr(value, ether_addr) < 0)
 		MIF_LOG(WARNING, "Failed to parse mac '%s'.", value);
 	return 0;
 }
Signature · 1 line
2.20.1
#99 lore raw

v8 cover ether: improvements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v8
set rte_errno in rte_eth_unformat_addr
drop ether_address alignment patch. Bruce can handle deprecation and sending the patches later
v7
use rte_ether_unformat_addr in more drivers
v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Stephen Hemminger (11):
net/ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser net/virtio: use new ether addr parsing net/failsafe: use common ether address parsing routine net/vdev_netvsc: use common ethernet address parsing net/memif: use common ethernet address parsing routine

 app/test-pmd/cmdline_flow.c                   |  5 +-
 app/test-pmd/config.c                         | 10 +--
 app/test-pmd/parameters.c                     | 15 +---
 drivers/net/axgbe/Makefile                    |  2 +-
 drivers/net/bonding/Makefile                  |  2 +-
 drivers/net/bonding/meson.build               |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c       |  6 +-
 drivers/net/failsafe/failsafe_args.c          |  8 +-
 drivers/net/memif/Makefile                    |  2 +-
 drivers/net/memif/rte_eth_memif.c             |  7 +-
 drivers/net/vdev_netvsc/vdev_netvsc.c         | 10 +--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 10 +--
 lib/Makefile                                  |  3 +-
 lib/librte_cmdline/Makefile                   |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c  | 71 ++---------------
 lib/librte_cmdline/meson.build                |  6 +-
 lib/librte_ethdev/Makefile                    |  2 +-
 lib/librte_ethdev/meson.build                 |  2 +-
 lib/librte_ethdev/rte_class_eth.c             |  9 +--
 lib/librte_net/Makefile                       |  1 +
 lib/librte_net/meson.build                    |  2 +-
 lib/librte_net/rte_ether.c                    | 78 +++++++++++++++++++
 lib/librte_net/rte_ether.h                    | 54 ++++++-------
 lib/librte_net/rte_net_version.map            |  8 ++
 lib/meson.build                               |  2 +-
 25 files changed, 150 insertions(+), 170 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#100 lore raw

PATCH v8 1/11 net/ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 drivers/net/axgbe/Makefile         |  2 +-
 drivers/net/memif/Makefile         |  2 +-
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 7 files changed, 44 insertions(+), 24 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
drivers/net/axgbe/Makefile +1 -1
index 72215aedaf55..c2d4336800c0 100644
@@ -17,7 +17,7 @@ LIBABIVER := 1
 
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
 LDLIBS += -lrte_pci -lrte_bus_pci
-LDLIBS += -lrte_ethdev
+LDLIBS += -lrte_ethdev -lrte_net
 
 #
 # all source are stored in SRCS-y
drivers/net/memif/Makefile +1 -1
index fdbdf3378019..3d92b08f259b 100644
@@ -21,7 +21,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 # - rte_mp_reply
 # - rte_mp_request_sync
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
-LDLIBS += -lrte_ethdev -lrte_kvargs
+LDLIBS += -lrte_ethdev -lrte_kvargs -lrte_net
 LDLIBS += -lrte_hash
 LDLIBS += -lrte_bus_vdev
 
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 1868cb7077d2..df1a51462a37 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
#101 lore raw

PATCH v8 2/11 net/ether: add function to convert string to ethernet address

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 49 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 64 insertions(+)
lib/librte_net/rte_ether.c +49 -0
index 974fe815b335..8d040173cfc6 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_ether.h>
+#include <rte_errno.h>
 
 void
 rte_eth_random_addr(uint8_t *addr)
@@ -27,3 +28,51 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		/* Standard format XX:XX:XX:XX:XX:XX */
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX) {
+			rte_errno = ERANGE;
+			return -1;
+		}
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+	} else if (n == 3) {
+		/* Support the format XXXX:XXXX:XXXX */
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX) {
+			rte_errno = ERANGE;
+			return -1;
+		}
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+	} else {
+		/* unknown format */
+		rte_errno = EINVAL;
+		return -1;
+	}
+	return 0;
+}
lib/librte_net/rte_ether.h +14 -0
index df1a51462a37..77b4569b1ad4 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#102 lore raw

PATCH v8 3/11 ethdev: use new ethernet parsing function

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 791e0d9911d6..82b2c4bfa8ea 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#103 lore raw

PATCH v8 4/11 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 77b4569b1ad4..6c07f4696a95 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#104 lore raw

PATCH v8 5/11 cmdline: use new ethernet address parser

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 82b2c4bfa8ea..cc36fe7591f0 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index 5ddf1ca116e5..38e6ccf13947 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1
#105 lore raw

PATCH v8 6/11 net/bonding: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#106 lore raw

PATCH v8 7/11 app/testpmd: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index 201bd9de56e0..2b02ca29b7ac 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
#107 lore raw

PATCH v8 8/11 net/virtio: use new ether addr parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -7
index e743695e4510..0bac725e7cdd 100644
@@ -225,17 +225,13 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 static inline void
 parse_mac(struct virtio_user_dev *dev, const char *mac)
 {
-	int i, r;
-	uint32_t tmp[RTE_ETHER_ADDR_LEN];
+	struct rte_ether_addr tmp;
 
 	if (!mac)
 		return;
 
-	r = sscanf(mac, "%x:%x:%x:%x:%x:%x", &tmp[0],
-			&tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
-	if (r == RTE_ETHER_ADDR_LEN) {
-		for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
-			dev->mac_addr[i] = (uint8_t)tmp[i];
+	if (rte_ether_unformat_addr(mac, &tmp) == 0) {
+		memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN);
 		dev->mac_specified = 1;
 	} else {
 		/* ignore the wrong mac, use random mac */
Signature · 1 line
2.20.1
#108 lore raw

PATCH v8 9/11 net/failsafe: use common ether address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/failsafe/failsafe_args.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/failsafe/failsafe_args.c +2 -6
index d2e725bcea13..707490b94c4e 100644
@@ -368,15 +368,11 @@ fs_get_mac_addr_arg(const char *key __rte_unused,
 		const char *value, void *out)
 {
 	struct rte_ether_addr *ea = out;
-	int ret;
 
 	if ((value == NULL) || (out == NULL))
 		return -EINVAL;
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-		&ea->addr_bytes[0], &ea->addr_bytes[1],
-		&ea->addr_bytes[2], &ea->addr_bytes[3],
-		&ea->addr_bytes[4], &ea->addr_bytes[5]);
-	return ret != RTE_ETHER_ADDR_LEN;
+
+	return rte_ether_unformat_addr(value, ea);
 }
 
 int
Signature · 1 line
2.20.1
#109 lore raw

PATCH v8 10/11 net/vdev_netvsc: use common ethernet address parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/vdev_netvsc/vdev_netvsc.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/net/vdev_netvsc/vdev_netvsc.c +1 -9
index 1fcf90d7bc02..be8f19c0c63e 100644
@@ -529,15 +529,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
 			} else if (!strcmp(pair->key, VDEV_NETVSC_ARG_MAC)) {
 				struct rte_ether_addr tmp;
 
-				if (sscanf(pair->value,
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":"
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8,
-					   &tmp.addr_bytes[0],
-					   &tmp.addr_bytes[1],
-					   &tmp.addr_bytes[2],
-					   &tmp.addr_bytes[3],
-					   &tmp.addr_bytes[4],
-					   &tmp.addr_bytes[5]) != 6) {
+				if (rte_ether_unformat_addr(pair->value, &tmp) != 0) {
 					DRV_LOG(ERR,
 						"invalid MAC address format"
 						" \"%s\"",
Signature · 1 line
2.20.1
#110 lore raw

PATCH v8 11/11 net/memif: use common ethernet address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/memif/rte_eth_memif.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/net/memif/rte_eth_memif.c +1 -6
index e9ddf6413597..00c9b396ab85 100644
@@ -1224,13 +1224,8 @@ static int
 memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args)
 {
 	struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args;
-	int ret = 0;
 
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-	       &ether_addr->addr_bytes[0], &ether_addr->addr_bytes[1],
-	       &ether_addr->addr_bytes[2], &ether_addr->addr_bytes[3],
-	       &ether_addr->addr_bytes[4], &ether_addr->addr_bytes[5]);
-	if (ret != 6)
+	if (rte_ether_unformat_addr(value, ether_addr) < 0)
 		MIF_LOG(WARNING, "Failed to parse mac '%s'.", value);
 	return 0;
 }
Signature · 1 line
2.20.1
#111 lore raw

v9 cover ether: improvements and optimizations

In reply to Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v9
add missing librte_net for new octoeonx2
v8
set rte_errno in rte_eth_unformat_addr
drop ether_address alignment patch. Bruce can handle deprecation and sending the patches later
v7
use rte_ether_unformat_addr in more drivers
v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Stephen Hemminger (11):
net/ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser net/virtio: use new ether addr parsing net/failsafe: use common ether address parsing routine net/vdev_netvsc: use common ethernet address parsing net/memif: use common ethernet address parsing routine

 app/test-pmd/cmdline_flow.c                   |  5 +-
 app/test-pmd/config.c                         | 10 +--
 app/test-pmd/parameters.c                     | 15 +---
 drivers/net/axgbe/Makefile                    |  2 +-
 drivers/net/bonding/Makefile                  |  2 +-
 drivers/net/bonding/meson.build               |  2 +-
 drivers/net/bonding/rte_eth_bond_args.c       |  6 +-
 drivers/net/failsafe/failsafe_args.c          |  8 +-
 drivers/net/memif/Makefile                    |  2 +-
 drivers/net/memif/rte_eth_memif.c             |  7 +-
 drivers/net/octeontx2/Makefile                |  2 +-
 drivers/net/vdev_netvsc/vdev_netvsc.c         | 10 +--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 10 +--
 lib/Makefile                                  |  3 +-
 lib/librte_cmdline/Makefile                   |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c  | 71 ++---------------
 lib/librte_cmdline/meson.build                |  6 +-
 lib/librte_ethdev/Makefile                    |  2 +-
 lib/librte_ethdev/meson.build                 |  2 +-
 lib/librte_ethdev/rte_class_eth.c             |  9 +--
 lib/librte_net/Makefile                       |  1 +
 lib/librte_net/meson.build                    |  2 +-
 lib/librte_net/rte_ether.c                    | 78 +++++++++++++++++++
 lib/librte_net/rte_ether.h                    | 54 ++++++-------
 lib/librte_net/rte_net_version.map            |  8 ++
 lib/meson.build                               |  2 +-
 26 files changed, 151 insertions(+), 171 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
Signature · 1 line
2.20.1
#112 lore raw

PATCH v9 1/11 net/ether: deinline non-critical functions

Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined.

---
 drivers/net/axgbe/Makefile         |  2 +-
 drivers/net/memif/Makefile         |  2 +-
 drivers/net/octeontx2/Makefile     |  2 +-
 lib/librte_net/Makefile            |  1 +
 lib/librte_net/meson.build         |  2 +-
 lib/librte_net/rte_ether.c         | 29 +++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 25 ++++---------------------
 lib/librte_net/rte_net_version.map |  7 +++++++
 8 files changed, 45 insertions(+), 25 deletions(-)
 create mode 100644 lib/librte_net/rte_ether.c
drivers/net/axgbe/Makefile +1 -1
index 72215aedaf55..c2d4336800c0 100644
@@ -17,7 +17,7 @@ LIBABIVER := 1
 
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
 LDLIBS += -lrte_pci -lrte_bus_pci
-LDLIBS += -lrte_ethdev
+LDLIBS += -lrte_ethdev -lrte_net
 
 #
 # all source are stored in SRCS-y
drivers/net/memif/Makefile +1 -1
index fdbdf3378019..3d92b08f259b 100644
@@ -21,7 +21,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 # - rte_mp_reply
 # - rte_mp_request_sync
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
-LDLIBS += -lrte_ethdev -lrte_kvargs
+LDLIBS += -lrte_ethdev -lrte_kvargs -lrte_net
 LDLIBS += -lrte_hash
 LDLIBS += -lrte_bus_vdev
 
drivers/net/octeontx2/Makefile +1 -1
index d08d3d854b46..66cb5f25bb2b 100644
@@ -54,7 +54,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX2_PMD) += \
 	otx2_ethdev_debug.c \
 	otx2_ethdev_devargs.c
 
-LDLIBS += -lrte_common_octeontx2 -lrte_mempool_octeontx2 -lrte_eal
+LDLIBS += -lrte_common_octeontx2 -lrte_mempool_octeontx2 -lrte_eal -lrte_net
 LDLIBS += -lrte_ethdev -lrte_bus_pci -lrte_kvargs -lrte_mbuf  -lrte_mempool -lm
 
 include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_net/Makefile +1 -0
index c3082069ab50..1244c9fd54c9 100644
@@ -14,6 +14,7 @@ LIBABIVER := 1
 
 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c
+SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c
 SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c
 
 # install includes
lib/librte_net/meson.build +1 -1
index 7d66f693cbf3..868a93fd6b6b 100644
@@ -16,5 +16,5 @@ headers = files('rte_ip.h',
 	'rte_net_crc.h',
 	'rte_mpls.h')
 
-sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c')
+sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c')
 deps += ['mbuf']
lib/librte_net/rte_ether.c new file +29 -0
new file mode 100644
index 000000000000..974fe815b335
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#include <rte_ether.h>
+
+void
+rte_eth_random_addr(uint8_t *addr)
+{
+	uint64_t rand = rte_rand();
+	uint8_t *p = (uint8_t *)&rand;
+
+	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
+	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;	/* clear multicast bit */
+	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;	/* set local assignment bit */
+}
+
+void
+rte_ether_format_addr(char *buf, uint16_t size,
+		      const struct rte_ether_addr *eth_addr)
+{
+	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
+		 eth_addr->addr_bytes[0],
+		 eth_addr->addr_bytes[1],
+		 eth_addr->addr_bytes[2],
+		 eth_addr->addr_bytes[3],
+		 eth_addr->addr_bytes[4],
+		 eth_addr->addr_bytes[5]);
+}
lib/librte_net/rte_ether.h +4 -21
index 1868cb7077d2..df1a51462a37 100644
@@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr *
  * @param addr
  *   A pointer to Ethernet address.
  */
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
-	uint64_t rand = rte_rand();
-	uint8_t *p = (uint8_t *)&rand;
-
-	rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
-	addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR;  /* clear multicast bit */
-	addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;  /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
 
 /**
  * Fast copy an Ethernet address.
@@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
  * @param eth_addr
  *   A pointer to a ether_addr structure.
  */
-static inline void
+void
 rte_ether_format_addr(char *buf, uint16_t size,
-		  const struct rte_ether_addr *eth_addr)
-{
-	snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
-		 eth_addr->addr_bytes[0],
-		 eth_addr->addr_bytes[1],
-		 eth_addr->addr_bytes[2],
-		 eth_addr->addr_bytes[3],
-		 eth_addr->addr_bytes[4],
-		 eth_addr->addr_bytes[5]);
-}
-
+		      const struct rte_ether_addr *eth_addr);
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +7 -0
index 26c06e7c7ae7..f1e1b84ab491 100644
@@ -13,6 +13,13 @@ DPDK_17.05 {
 
 } DPDK_16.11;
 
+DPDK_19.08 {
+	global:
+
+	rte_eth_random_addr;
+	rte_ether_format_addr;
+} DPDK_17.05;
+
 EXPERIMENTAL {
 	global:
 
Signature · 1 line
2.20.1
#113 lore raw

PATCH v9 2/11 net/ether: add function to convert string to ethernet address

In reply to Stephen Hemminger

Make a function that can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original.

This also allows ethdev to no longer have a hard dependency on the cmdline library.

---
 lib/librte_net/rte_ether.c         | 49 ++++++++++++++++++++++++++++++
 lib/librte_net/rte_ether.h         | 14 +++++++++
 lib/librte_net/rte_net_version.map |  1 +
 3 files changed, 64 insertions(+)
lib/librte_net/rte_ether.c +49 -0
index 974fe815b335..8d040173cfc6 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_ether.h>
+#include <rte_errno.h>
 
 void
 rte_eth_random_addr(uint8_t *addr)
@@ -27,3 +28,51 @@ rte_ether_format_addr(char *buf, uint16_t size,
 		 eth_addr->addr_bytes[4],
 		 eth_addr->addr_bytes[5]);
 }
+
+/*
+ * Like ether_aton_r but can handle either
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ */
+int
+rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
+{
+	unsigned int o0, o1, o2, o3, o4, o5;
+	int n;
+
+	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
+		    &o0, &o1, &o2, &o3, &o4, &o5);
+
+	if (n == 6) {
+		/* Standard format XX:XX:XX:XX:XX:XX */
+		if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX ||
+		    o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX) {
+			rte_errno = ERANGE;
+			return -1;
+		}
+
+		ea->addr_bytes[0] = o0;
+		ea->addr_bytes[1] = o1;
+		ea->addr_bytes[2] = o2;
+		ea->addr_bytes[3] = o3;
+		ea->addr_bytes[4] = o4;
+		ea->addr_bytes[5] = o5;
+	} else if (n == 3) {
+		/* Support the format XXXX:XXXX:XXXX */
+		if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX) {
+			rte_errno = ERANGE;
+			return -1;
+		}
+
+		ea->addr_bytes[0] = o0 >> 8;
+		ea->addr_bytes[1] = o0 & 0xff;
+		ea->addr_bytes[2] = o1 >> 8;
+		ea->addr_bytes[3] = o1 & 0xff;
+		ea->addr_bytes[4] = o2 >> 8;
+		ea->addr_bytes[5] = o2 & 0xff;
+	} else {
+		/* unknown format */
+		rte_errno = EINVAL;
+		return -1;
+	}
+	return 0;
+}
lib/librte_net/rte_ether.h +14 -0
index df1a51462a37..77b4569b1ad4 100644
@@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from,
 void
 rte_ether_format_addr(char *buf, uint16_t size,
 		      const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ *   A pointer to buffer contains the formatted MAC address.
+ * @param eth_addr
+ *   A pointer to a ether_addr structure.
+ * @return
+ *   0 if successful
+ *   -1 and sets rte_errno if invalid string
+ */
+int __rte_experimental
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
lib/librte_net/rte_net_version.map +1 -0
index f1e1b84ab491..f4c915069d57 100644
@@ -25,4 +25,5 @@ EXPERIMENTAL {
 
 	rte_net_make_rarp_packet;
 	rte_net_skip_ip6_ext;
+	rte_ether_unformat_addr;
 };
Signature · 1 line
2.20.1
#114 lore raw

PATCH v9 3/11 ethdev: use new ethernet parsing function

In reply to Stephen Hemminger

Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway.

---
 lib/Makefile                      | 1 -
 lib/librte_ethdev/Makefile        | 2 +-
 lib/librte_ethdev/meson.build     | 2 +-
 lib/librte_ethdev/rte_class_eth.c | 9 +--------
 4 files changed, 3 insertions(+), 11 deletions(-)
lib/Makefile +0 -1
index 3ad579f68254..493aeab7572e 100644
@@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
 DEPDIRS-librte_ethdev += librte_kvargs
-DEPDIRS-librte_ethdev += librte_cmdline
 DEPDIRS-librte_ethdev += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev
 DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf
lib/librte_ethdev/Makefile +1 -1
index 8d4a02630c4f..60bcc2227878 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter
 
 EXPORT_MAP := rte_ethdev_version.map
 
lib/librte_ethdev/meson.build +1 -1
index 8d6165b2a7dd..f75d428c96d0 100644
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
 	'rte_tm.h',
 	'rte_tm_driver.h')
 
-deps += ['net', 'kvargs', 'cmdline', 'meter']
+deps += ['net', 'kvargs', 'meter']
lib/librte_ethdev/rte_class_eth.c +1 -8
index 873a653532ad..6338355e2557 100644
@@ -4,7 +4,6 @@
 
 #include <string.h>
 
-#include <cmdline_parse_etheraddr.h>
 #include <rte_class.h>
 #include <rte_compat.h>
 #include <rte_errno.h>
@@ -43,19 +42,13 @@ static int
 eth_mac_cmp(const char *key __rte_unused,
 		const char *value, void *opaque)
 {
-	int ret;
 	struct rte_ether_addr mac;
 	const struct rte_eth_dev_data *data = opaque;
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
 	/* Parse devargs MAC address. */
-	/*
-	 * cannot use ether_aton_r(value, &mac)
-	 * because of include conflict with rte_ether.h
-	 */
-	ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
-	if (ret < 0)
+	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
 
 	/* Return 0 if devargs MAC is matching one of the device MACs. */
Signature · 1 line
2.20.1
#115 lore raw

PATCH v9 4/11 net/ether: use bitops to speedup comparison

In reply to Stephen Hemminger

Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling.

Similar cast to uint16 unaligned is already done in other functions here.

---
 lib/librte_net/rte_ether.h | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
lib/librte_net/rte_ether.h +7 -10
index 77b4569b1ad4..6c07f4696a95 100644
@@ -81,11 +81,10 @@ struct rte_ether_addr {
 static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
 				     const struct rte_ether_addr *ea2)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+	const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+	return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
 }
 
 /**
@@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
  */
 static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
 {
-	int i;
-	for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
-		if (ea->addr_bytes[i] != 0x00)
-			return 0;
-	return 1;
+	const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+	return (w[0] | w[1] | w[2]) == 0;
 }
 
 /**
Signature · 1 line
2.20.1
#116 lore raw

PATCH v9 5/11 cmdline: use new ethernet address parser

In reply to Stephen Hemminger

Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser.

Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity.

---
 lib/Makefile                                 |  2 +-
 lib/librte_cmdline/Makefile                  |  3 +-
 lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++-----------------
 lib/librte_cmdline/meson.build               |  6 +-
 lib/meson.build                              |  2 +-
 5 files changed, 15 insertions(+), 69 deletions(-)
lib/Makefile +1 -1
index 493aeab7572e..bdb8a67e2d9d 100644
@@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
-DEPDIRS-librte_cmdline := librte_eal
+DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
 DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring
 DEPDIRS-librte_ethdev += librte_mbuf
lib/librte_cmdline/Makefile +2 -1
index c64142b8d5a0..04057d7c671f 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_cmdline.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 EXPORT_MAP := rte_cmdline_version.map
 
@@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_net -lrte_eal
 
 # install includes
 INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
lib/librte_cmdline/cmdline_parse_etheraddr.c +8 -63

103 lines not on this page · raw message

lib/librte_cmdline/meson.build +3 -3
index 0fa61385fccf..07334c1b0956 100644
@@ -1,10 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-# This library is processed before EAL
-includes = [global_inc]
-
 version = 2
+allow_experimental_apis = true
 sources = files('cmdline.c',
 	'cmdline_cirbuf.c',
 	'cmdline_parse.c',
@@ -28,3 +26,5 @@ headers = files('cmdline.h',
 	'cmdline_socket.h',
 	'cmdline_cirbuf.h',
 	'cmdline_parse_portlist.h')
+
+deps += ['net']
lib/meson.build +1 -1
index 3d77b1f9014a..e5ff83893489 100644
@@ -11,8 +11,8 @@
 libraries = [
 	'kvargs', # eal depends on kvargs
 	'eal', # everything depends on eal
-	'cmdline', # ethdev depends on cmdline for parsing functions
 	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
+	'cmdline',
 	'metrics', # bitrate/latency stats depends on this
 	'hash',    # efd depends on this
 	'timer',   # eventdev depends on this
Signature · 1 line
2.20.1
#117 lore raw

PATCH v9 6/11 net/bonding: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr.

---
 drivers/net/bonding/Makefile            | 2 +-
 drivers/net/bonding/meson.build         | 2 +-
 drivers/net/bonding/rte_eth_bond_args.c | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/Makefile +1 -1
index 1893e3cad313..26c1782554cd 100644
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline
+LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs
 LDLIBS += -lrte_pci -lrte_bus_pci
 LDLIBS += -lrte_bus_vdev
 
drivers/net/bonding/meson.build +1 -1
index 00374edb2a9d..6267210adf5f 100644
@@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c
 	'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c')
 
 deps += 'sched' # needed for rte_bitmap.h
-deps += ['ip_frag', 'cmdline']
+deps += ['ip_frag']
 
 install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
drivers/net/bonding/rte_eth_bond_args.c +1 -5
index 01bbb06c1a84..936440fb8491 100644
@@ -7,9 +7,6 @@
 #include <rte_bus_pci.h>
 #include <rte_kvargs.h>
 
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
 
@@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
 		return -1;
 
 	/* Parse MAC */
-	return cmdline_parse_etheraddr(NULL, value, extra_args,
-		sizeof(struct rte_ether_addr));
+	return rte_ether_unformat_addr(value, extra_args);
 }
 
 int
Signature · 1 line
2.20.1
#118 lore raw

PATCH v9 7/11 app/testpmd: use new ethernet address parser

In reply to Stephen Hemminger

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index e3e8448c9421..c92c748b18eb 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4734,8 +4733,8 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
 		return len;
app/test-pmd/config.c +3 -7
index ab458c8d2837..1d804705d96c 100644
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void
 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
 {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c +3 -12
index 245b610641ee..975a97807009 100644
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10);
@@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
 						 "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n",
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL, port_end,
-						&peer_addr, sizeof(peer_addr)) < 0)
+				if (rte_ether_unformat_addr(port_end,
+							    &peer_eth_addrs[n]) < 0)
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address: %s\n",
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
Signature · 1 line
2.20.1
#119 lore raw

Re: [dpdk-dev] [PATCH v9 07/11] app/testpmd: use new ethernet address parser

Hi Guys,

We have a failure in testpmd commands when parsing rte_flow commands as following which were interduce by this patch:

This rule is a valid rule to be added to testpmd:
flow validate 0 priority 2 ingress group 0 pattern eth dst is 98:03:9B:5C:D9:00 / end actions queue index 0 / end

but, currently with latest master it will fail with Bad arguments

the check for get_ether_addr6/3 is expecting that you reach the end of string when it parse a MAC address but for rte_flow commands it's not the case, since we provide the full string:
gdb) p s
$3 = 0x28225fa "98:03:9B:5C:D9:00 / end actions queue index 0 / end\n"

Kindest regards,
Raslan Darawsheh

Quoted 136 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Monday, July 8, 2019 9:26 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Bernard Iremonger <[email protected]>
Subject: [dpdk-dev] [PATCH v9 07/11] app/testpmd: use new ethernet address parser

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index e3e8448c9421..c92c748b18eb 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4734,8 +4733,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--

2.20.1

#120 lore raw

Re: [dpdk-dev] [PATCH v9 07/11] app/testpmd: use new ethernet address parser

21/07/2019 15:42, Raslan Darawsheh:

Quoted 7 lines

Hi Guys,

We have a failure in testpmd commands when parsing rte_flow commands as following which were interduce by this patch:

This rule is a valid rule to be added to testpmd:
flow validate 0 priority 2 ingress group 0 pattern eth dst is 98:03:9B:5C:D9:00 / end actions queue index 0 / end

Quoted 6 lines

but, currently with latest master it will fail with Bad arguments

the check for get_ether_addr6/3 is expecting that you reach the end of string when it parse a MAC address but for rte_flow commands it's not the case, since we provide the full string:
gdb) p s
$3 = 0x28225fa "98:03:9B:5C:D9:00 / end actions queue index 0 / end\n"

Ferruh, it seems this patch must be reverted.

We probably need to adapt testpmd to the new function and properly test it. Let's target it for -rc3 or 19.11.

#121 lore raw

Re: [dpdk-dev] [PATCH v9 07/11] app/testpmd: use new ethernet address parser

In reply to Raslan Darawsheh
Quoted 7 lines · Raslan Darawsheh

Hi Guys,

We have a failure in testpmd commands when parsing rte_flow commands as following which were interduce by this patch:

This rule is a valid rule to be added to testpmd:
flow validate 0 priority 2 ingress group 0 pattern eth dst is 98:03:9B:5C:D9:00 / end actions queue index 0 / end

Quoted 6 lines

but, currently with latest master it will fail with Bad arguments

the check for get_ether_addr6/3 is expecting that you reach the end of string when it parse a MAC address but for rte_flow commands it's not the case, since we provide the full string:
gdb) p s
$3 = 0x28225fa "98:03:9B:5C:D9:00 / end actions queue index 0 / end\n"

Hi Raslan,

Will it work if only 'cmdline_flow.c' change reverted?

If so I suggest revert only 'cmdline_flow.c' change for rc2, and we can work on the proper fix later.

Quoted 142 lines

Kindest regards,
Raslan Darawsheh

Quoted 136 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Monday, July 8, 2019 9:26 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Bernard Iremonger <[email protected]>
Subject: [dpdk-dev] [PATCH v9 07/11] app/testpmd: use new ethernet address parser

The cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead.
As an added bonus it eliminates some code for copying.

---
 app/test-pmd/cmdline_flow.c |  5 ++---
 app/test-pmd/config.c       | 10 +++-------
 app/test-pmd/parameters.c   | 15 +++------------
 3 files changed, 8 insertions(+), 22 deletions(-)
app/test-pmd/cmdline_flow.c +2 -3
index e3e8448c9421..c92c748b18eb 100644
@@ -18,7 +18,6 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -4734,8 +4733,8 @@ parse_mac_addr(struct context *ctx, const struct
 token *token,
 	/* Only network endian is supported. */
 	if (!arg->hton)
 		goto error;
-	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
-	if (ret < 0 || (unsigned int)ret != len)
+	ret = rte_ether_unformat_addr(str, &tmp);
+	if (ret < 0)
 		goto error;
 	if (!ctx->object)
app/test-pmd/cmdline_flow.c +0 -0
 		return len;
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

ab458c8d2837..1d804705d96c 100644

app/test-pmd/config.c +3 -7
@@ -49,7 +49,6 @@
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <cmdline_parse_etheraddr.h>
 #include <rte_config.h>
 
 #include "testpmd.h"
@@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg)
 void  set_fwd_eth_peer(portid_t port_id, char *peer_addr)  {
-	uint8_t c, new_peer_addr[6];
+	struct rte_ether_addr new_peer_addr;
 	if (!rte_eth_dev_is_valid_port(port_id)) {
 		printf("Error: Invalid port number %i\n", port_id);
 		return;
 	}
-	if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr,
-					sizeof(new_peer_addr)) < 0) {
+	if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
 		printf("Error: Invalid ethernet address: %s\n", peer_addr);
 		return;
 	}
-	for (c = 0; c < 6; c++)
-		peer_eth_addrs[port_id].addr_bytes[c] =
-			new_peer_addr[c];
+	peer_eth_addrs[port_id] = new_peer_addr;
 }
 
 int
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

245b610641ee..975a97807009 100644

app/test-pmd/parameters.c +1 -6
@@ -39,10 +39,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_CMDLINE
-#include <cmdline_parse.h>
-#include <cmdline_parse_etheraddr.h>
-#endif
 #ifdef RTE_LIBRTE_PMD_BOND
 #include <rte_eth_bond.h>
 #endif
@@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename)
 		if (fgets(buf, sizeof(buf), config_file) == NULL)
 			break;
 
-		if (cmdline_parse_etheraddr(NULL, buf,
 &peer_eth_addrs[i],
-				sizeof(peer_eth_addrs[i])) < 0) {
+		if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) {
 			printf("Bad MAC address format on line %d\n", i+1);
 			fclose(config_file);
app/test-pmd/parameters.c +0 -1
 			return -1;
@@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv)
 			}
 			if (!strcmp(lgopts[opt_idx].name, "eth-peer")) {
 				char *port_end;
-				uint8_t c, peer_addr[6];
 
 				errno = 0;
 				n = strtoul(optarg, &port_end, 10); @@ -

739,14 +733,11 @@ launch_args_parse(int argc, char** argv)
"eth-peer: port %d >=
RTE_MAX_ETHPORTS(%d)\n",

app/test-pmd/parameters.c +0 -1
 						 n, RTE_MAX_ETHPORTS);
 
-				if (cmdline_parse_etheraddr(NULL,

port_end,

app/test-pmd/parameters.c +0 -1
-						&peer_addr,

sizeof(peer_addr)) < 0)

app/test-pmd/parameters.c +2 -0
+				if (rte_ether_unformat_addr(port_end,
+

&peer_eth_addrs[n]) < 0)

app/test-pmd/parameters.c +0 -0
 					rte_exit(EXIT_FAILURE,
 						 "Invalid ethernet address:

%s\n",

app/test-pmd/parameters.c +0 -4
 						 port_end);
-				for (c = 0; c < 6; c++)
-					peer_eth_addrs[n].addr_bytes[c] =
-						peer_addr[c];
 				nb_peer_eth_addrs++;
 			}
 #endif
--

2.20.1

#122 lore raw

PATCH v9 8/11 net/virtio: use new ether addr parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -7
index c3ab9a21d107..fab87eb5b60f 100644
@@ -224,17 +224,13 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 static inline void
 parse_mac(struct virtio_user_dev *dev, const char *mac)
 {
-	int i, r;
-	uint32_t tmp[RTE_ETHER_ADDR_LEN];
+	struct rte_ether_addr tmp;
 
 	if (!mac)
 		return;
 
-	r = sscanf(mac, "%x:%x:%x:%x:%x:%x", &tmp[0],
-			&tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
-	if (r == RTE_ETHER_ADDR_LEN) {
-		for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
-			dev->mac_addr[i] = (uint8_t)tmp[i];
+	if (rte_ether_unformat_addr(mac, &tmp) == 0) {
+		memcpy(dev->mac_addr, &tmp, RTE_ETHER_ADDR_LEN);
 		dev->mac_specified = 1;
 	} else {
 		/* ignore the wrong mac, use random mac */
Signature · 1 line
2.20.1
#123 lore raw

PATCH v9 9/11 net/failsafe: use common ether address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/failsafe/failsafe_args.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/failsafe/failsafe_args.c +2 -6
index d2e725bcea13..707490b94c4e 100644
@@ -368,15 +368,11 @@ fs_get_mac_addr_arg(const char *key __rte_unused,
 		const char *value, void *out)
 {
 	struct rte_ether_addr *ea = out;
-	int ret;
 
 	if ((value == NULL) || (out == NULL))
 		return -EINVAL;
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-		&ea->addr_bytes[0], &ea->addr_bytes[1],
-		&ea->addr_bytes[2], &ea->addr_bytes[3],
-		&ea->addr_bytes[4], &ea->addr_bytes[5]);
-	return ret != RTE_ETHER_ADDR_LEN;
+
+	return rte_ether_unformat_addr(value, ea);
 }
 
 int
Signature · 1 line
2.20.1
#124 lore raw

PATCH v9 10/11 net/vdev_netvsc: use common ethernet address parsing

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/vdev_netvsc/vdev_netvsc.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/net/vdev_netvsc/vdev_netvsc.c +1 -9
index 1fcf90d7bc02..be8f19c0c63e 100644
@@ -529,15 +529,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface,
 			} else if (!strcmp(pair->key, VDEV_NETVSC_ARG_MAC)) {
 				struct rte_ether_addr tmp;
 
-				if (sscanf(pair->value,
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":"
-					   "%" SCNx8 ":%" SCNx8 ":%" SCNx8,
-					   &tmp.addr_bytes[0],
-					   &tmp.addr_bytes[1],
-					   &tmp.addr_bytes[2],
-					   &tmp.addr_bytes[3],
-					   &tmp.addr_bytes[4],
-					   &tmp.addr_bytes[5]) != 6) {
+				if (rte_ether_unformat_addr(pair->value, &tmp) != 0) {
 					DRV_LOG(ERR,
 						"invalid MAC address format"
 						" \"%s\"",
Signature · 1 line
2.20.1
#125 lore raw

PATCH v9 11/11 net/memif: use common ethernet address parsing routine

In reply to Stephen Hemminger

Use rte_ether_unformat_addr rather than sscanf.

---
 drivers/net/memif/rte_eth_memif.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/net/memif/rte_eth_memif.c +1 -6
index e9ddf6413597..00c9b396ab85 100644
@@ -1224,13 +1224,8 @@ static int
 memif_set_mac(const char *key __rte_unused, const char *value, void *extra_args)
 {
 	struct rte_ether_addr *ether_addr = (struct rte_ether_addr *)extra_args;
-	int ret = 0;
 
-	ret = sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-	       &ether_addr->addr_bytes[0], &ether_addr->addr_bytes[1],
-	       &ether_addr->addr_bytes[2], &ether_addr->addr_bytes[3],
-	       &ether_addr->addr_bytes[4], &ether_addr->addr_bytes[5]);
-	if (ret != 6)
+	if (rte_ether_unformat_addr(value, ether_addr) < 0)
 		MIF_LOG(WARNING, "Failed to parse mac '%s'.", value);
 	return 0;
 }
Signature · 1 line
2.20.1
Reviewed-by on the v9 series
#126 lore raw
In reply to Stephen Hemminger
Quoted 23 lines · Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v9
add missing librte_net for new octoeonx2
v8
set rte_errno in rte_eth_unformat_addr
drop ether_address alignment patch. Bruce can handle deprecation and sending the patches later
v7
use rte_ether_unformat_addr in more drivers
v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Quoted 12 lines

Stephen Hemminger (11):
net/ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser net/virtio: use new ether addr parsing net/failsafe: use common ether address parsing routine net/vdev_netvsc: use common ethernet address parsing net/memif: use common ethernet address parsing routine

For series,

Series applied to dpdk-next-net/master, thanks.

#127 lore raw
Quoted 37 lines · Ferruh Yigit
Quoted 23 lines · Stephen Hemminger

This is a collection of patches around the ethernet address manipulation routines in librte_net/rte_ether.

v9
add missing librte_net for new octoeonx2
v8
set rte_errno in rte_eth_unformat_addr
drop ether_address alignment patch. Bruce can handle deprecation and sending the patches later
v7
use rte_ether_unformat_addr in more drivers
v6
add librte_net to axgbe and memif Makefile
v5
reword commit messages to workaround check-log complaints
v4
fix meson build
reword commit messages
add bonding and tespmd patches
v3
rebase to use rte_ether prefix
drop aligning ethernet headers for now.

Quoted 12 lines

Stephen Hemminger (11):
net/ether: deinline non-critical functions net/ether: add function to convert string to ethernet address
ethdev: use new ethernet parsing function net/ether: use bitops to speedup comparison
cmdline: use new ethernet address parser net/bonding: use new ethernet address parser app/testpmd: use new ethernet address parser net/virtio: use new ether addr parsing net/failsafe: use common ether address parsing routine net/vdev_netvsc: use common ethernet address parsing net/memif: use common ethernet address parsing routine

Quoted 4 lines

For series,

Series applied to dpdk-next-net/master, thanks.

Deprecation notice for dropped patch:

http://patches.dpdk.org/patch/56271/