[dpdk-dev] [PATCH v2] ethdev: add action to swap source and destination MAC to flow API

Rahul Lakkireddy rahul.lakkireddy at chelsio.com
Sat Oct 6 17:45:34 CEST 2018


This action is useful for offloading loopback mode, where the hardware
will swap source and destination MAC addresses in the outermost Ethernet
header before looping back the packet. This action can be used in
conjunction with other rewrite actions to achieve MAC layer transparent
NAT where the MAC addresses are swapped before either the source or
destination MAC address is rewritten and NAT is performed.

Must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error should be returned by the
PMDs.

Original work by Shagun Agrawal

Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy at chelsio.com>
Acked-by: Andrew Rybchenko <arybchenko at solarflare.com>
---
RFC v1: http://mails.dpdk.org/archives/dev/2018-August/110232.html
RFC v2: http://mails.dpdk.org/archives/dev/2018-August/110355.html

v2:
- Rebased to tip.
- Removed adding action to app/test-pmd/config.c, to sync with
  rte_flow_conv() changes.

v1 changes since RFC v2:
- Updated release notes.

 app/test-pmd/cmdline_flow.c                 | 10 ++++++++++
 doc/guides/prog_guide/rte_flow.rst          | 19 +++++++++++++++++++
 doc/guides/rel_notes/release_18_11.rst      |  5 +++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  3 +++
 lib/librte_ethdev/rte_flow.c                |  1 +
 lib/librte_ethdev/rte_flow.h                | 11 +++++++++++
 6 files changed, 49 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index a9888cacf..4a2764270 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -255,6 +255,7 @@ enum index {
 	ACTION_SET_TP_SRC_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
+	ACTION_MAC_SWAP,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -834,6 +835,7 @@ static const enum index next_action[] = {
 	ACTION_SET_IPV6_DST,
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
+	ACTION_MAC_SWAP,
 	ZERO,
 };
 
@@ -2626,6 +2628,14 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_tp, port)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_MAC_SWAP] = {
+		.name = "mac_swap",
+		.help = "Swap the source and destination MAC addresses"
+			" in the outermost Ethernet header",
+		.priv = PRIV_ACTION(MAC_SWAP, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 1c81a824d..a5ec441c9 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2184,6 +2184,25 @@ flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
    | ``port`` | new TCP/UDP destination port |
    +---------------+-------------------------+
 
+Action: ``MAC_SWAP``
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Swap the source and destination MAC addresses in the outermost Ethernet
+header.
+
+It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
+Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
+
+.. _table_rte_flow_action_mac_swap:
+
+.. table:: MAC_SWAP
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/release_18_11.rst
index 9a135c89c..96e09b7b0 100644
--- a/doc/guides/rel_notes/release_18_11.rst
+++ b/doc/guides/rel_notes/release_18_11.rst
@@ -141,6 +141,11 @@ New Features
   * Modify source and destination port numbers in the outermost TCP/UDP
     headers.
 
+* **Added new Flow API action to swap MAC addresses in Ethernet header.**
+
+  Added new Flow API action to swap the source and destination MAC
+  addresses in the outermost Ethernet header.
+
 API Changes
 -----------
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index ffec7013b..ed8aa861b 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3732,6 +3732,9 @@ This section lists supported actions and their attributes, if any.
 
   - ``port``: New TCP/UDP destination port number.
 
+- ``mac_swap``: Swap the source and destination MAC addresses in the outermost
+  Ethernet header.
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 4eeb392b6..bc9e719dc 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -135,6 +135,7 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(MAC_SWAP, 0),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index ce2021641..02c34917f 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1568,6 +1568,17 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_tp.
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
+
+	/**
+	 * Swap the source and destination MAC addresses in the outermost
+	 * Ethernet header.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * No associated configuration structure.
+	 */
+	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
 };
 
 /**
-- 
2.18.0



More information about the dev mailing list