From: Rahul Lakkireddy Date: Sat, 6 Oct 2018 15:45:34 +0000 (+0530) Subject: ethdev: add flow action to swap MAC addresses X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=8287597059ad374925a21349302ed1b1e71dd194;p=dpdk.git ethdev: add flow action to swap MAC addresses 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 Acked-by: Andrew Rybchenko --- diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index a9888cacf0..4a27642702 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 1c81a824d8..a5ec441c9b 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 ec0ee9702e..436b20e2ba 100644 --- a/doc/guides/rel_notes/release_18_11.rst +++ b/doc/guides/rel_notes/release_18_11.rst @@ -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: diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 11a80cada3..d0f984f484 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 4eeb392b68..bc9e719dc5 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 0805906aeb..68bbf57d05 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, }; /**