[6/8] ethdev: use ARP protocol struct for flow matching

Message ID 20221025214410.715864-7-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series start cleanup of rte_flow_item_* |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Thomas Monjalon Oct. 25, 2022, 9:44 p.m. UTC
  As announced in the deprecation notice, flow item structures
should re-use the protocol header definitions from the directory lib/net/.

The protocol struct is added in an unnamed union, keeping old field names.

The ARP header struct members are used in testpmd
instead of the redundant fields in the flow items.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/cmdline_flow.c          |  8 +++---
 doc/guides/prog_guide/rte_flow.rst   | 10 +-------
 doc/guides/rel_notes/deprecation.rst |  1 -
 lib/ethdev/rte_flow.h                | 37 ++++++++++++++++++----------
 4 files changed, 29 insertions(+), 27 deletions(-)
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 90da247eaf..84e1ed039f 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -4192,7 +4192,7 @@  static const struct token token_list[] = {
 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_MAC_ADDR),
 			     item_param),
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
-					     sha)),
+					     hdr.arp_data.arp_sha)),
 	},
 	[ITEM_ARP_ETH_IPV4_SPA] = {
 		.name = "spa",
@@ -4200,7 +4200,7 @@  static const struct token token_list[] = {
 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
 			     item_param),
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
-					     spa)),
+					     hdr.arp_data.arp_sip)),
 	},
 	[ITEM_ARP_ETH_IPV4_THA] = {
 		.name = "tha",
@@ -4208,7 +4208,7 @@  static const struct token token_list[] = {
 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_MAC_ADDR),
 			     item_param),
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
-					     tha)),
+					     hdr.arp_data.arp_tha)),
 	},
 	[ITEM_ARP_ETH_IPV4_TPA] = {
 		.name = "tpa",
@@ -4216,7 +4216,7 @@  static const struct token token_list[] = {
 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
 			     item_param),
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
-					     tpa)),
+					     hdr.arp_data.arp_tip)),
 	},
 	[ITEM_IPV6_EXT] = {
 		.name = "ipv6_ext",
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index e8512e0a03..421c6407a9 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1100,15 +1100,7 @@  Item: ``ARP_ETH_IPV4``
 
 Matches an ARP header for Ethernet/IPv4.
 
-- ``hdr``: hardware type, normally 1.
-- ``pro``: protocol type, normally 0x0800.
-- ``hln``: hardware address length, normally 6.
-- ``pln``: protocol address length, normally 4.
-- ``op``: opcode (1 for request, 2 for reply).
-- ``sha``: sender hardware address.
-- ``spa``: sender IPv4 address.
-- ``tha``: target hardware address.
-- ``tpa``: target IPv4 address.
+- ``hdr``:  header definition (``rte_arp.h``).
 - Default ``mask`` matches SHA, SPA, THA and TPA.
 
 Item: ``IPV6_EXT``
diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index b4b97d3165..af266cf9f4 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -66,7 +66,6 @@  Deprecation Notices
 
   These items are not compliant (not including struct from lib/net/):
   - ``rte_flow_item_ah``
-  - ``rte_flow_item_arp_eth_ipv4``
   - ``rte_flow_item_e_tag``
   - ``rte_flow_item_geneve``
   - ``rte_flow_item_geneve_opt``
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 02c6cc9981..d890c253b4 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -19,6 +19,7 @@ 
 
 #include <rte_common.h>
 #include <rte_ether.h>
+#include <rte_arp.h>
 #include <rte_icmp.h>
 #include <rte_ip.h>
 #include <rte_sctp.h>
@@ -1254,26 +1255,36 @@  static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
  *
  * Matches an ARP header for Ethernet/IPv4.
  */
+RTE_STD_C11
 struct rte_flow_item_arp_eth_ipv4 {
-	rte_be16_t hrd; /**< Hardware type, normally 1. */
-	rte_be16_t pro; /**< Protocol type, normally 0x0800. */
-	uint8_t hln; /**< Hardware address length, normally 6. */
-	uint8_t pln; /**< Protocol address length, normally 4. */
-	rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
-	struct rte_ether_addr sha; /**< Sender hardware address. */
-	rte_be32_t spa; /**< Sender IPv4 address. */
-	struct rte_ether_addr tha; /**< Target hardware address. */
-	rte_be32_t tpa; /**< Target IPv4 address. */
+	union {
+		struct {
+			/*
+			 * These are old fields kept for compatibility.
+			 * Please prefer hdr field below.
+			 */
+			rte_be16_t hrd; /**< Hardware type, normally 1. */
+			rte_be16_t pro; /**< Protocol type, normally 0x0800. */
+			uint8_t hln; /**< Hardware address length, normally 6. */
+			uint8_t pln; /**< Protocol address length, normally 4. */
+			rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
+			struct rte_ether_addr sha; /**< Sender hardware address. */
+			rte_be32_t spa; /**< Sender IPv4 address. */
+			struct rte_ether_addr tha; /**< Target hardware address. */
+			rte_be32_t tpa; /**< Target IPv4 address. */
+		};
+		struct rte_arp_hdr hdr; /**< ARP header definition. */
+	};
 };
 
 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
 #ifndef __cplusplus
 static const struct rte_flow_item_arp_eth_ipv4
 rte_flow_item_arp_eth_ipv4_mask = {
-	.sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
-	.spa = RTE_BE32(0xffffffff),
-	.tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
-	.tpa = RTE_BE32(0xffffffff),
+	.hdr.arp_data.arp_sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	.hdr.arp_data.arp_sip = RTE_BE32(UINT32_MAX),
+	.hdr.arp_data.arp_tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
+	.hdr.arp_data.arp_tip = RTE_BE32(UINT32_MAX),
 };
 #endif