]> git.droids-corp.org - dpdk.git/commitdiff
ethdev: add flow action to swap MAC addresses
authorRahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Sat, 6 Oct 2018 15:45:34 +0000 (21:15 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 11 Oct 2018 16:53:49 +0000 (18:53 +0200)
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@chelsio.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
app/test-pmd/cmdline_flow.c
doc/guides/prog_guide/rte_flow.rst
doc/guides/rel_notes/release_18_11.rst
doc/guides/testpmd_app_ug/testpmd_funcs.rst
lib/librte_ethdev/rte_flow.c
lib/librte_ethdev/rte_flow.h

index a9888cacf031e7f2862ee50a06ce2a43238d7eaa..4a276427029cca5af5f7deb5f64221bdd8dadfb2 100644 (file)
@@ -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. */
index 1c81a824d8e71109f77dfec527041cfe98cbe76d..a5ec441c9bc528cf5f0d8cea9321fea29ffc9919 100644 (file)
@@ -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
 ~~~~~~~~~~~~~~
 
index ec0ee9702ecd5d676f9268fca1f56c2339e9cb9b..436b20e2bacac14637259f0222db26edc43e6b62 100644 (file)
@@ -69,6 +69,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.
+
 * **Add support to offload more flow match and actions for CXGBE PMD**
 
   Flow API support has been enhanced for CXGBE Poll Mode Driver to offload:
index 11a80cada3ce759504c2c26a50b7a8fd66e85eea..d0f984f48475cd8e6c440bed81b00691b862ffc4 100644 (file)
@@ -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
 ~~~~~~~~~~~~~~~~~~~~~
 
index 4eeb392b68bdbf3e9875b2329ae7384fbd6ad444..bc9e719dc50077d1e217fc2c7975ee40654dd941 100644 (file)
@@ -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
index 0805906aeb02213c12a7fe13f30b7a11691b06ab..68bbf57d0585cb411c5f420ec1a713d61c74a775 100644 (file)
@@ -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,
 };
 
 /**