Skip to contentSkip to conversation

ethdev: add generic MAC address rewrite actions

PATCH In review Xiaoyu Min 4 participants 20 messages Sep 25, 2018 – Oct 16, 2018 Network drivers

lore
Share & tools
lore

Xiaoyu Min

author
#0 lore raw

cover ethdev: add generic MAC address rewrite actions

This series is for RFC[1]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

[1]: https://patches.dpdk.org/patch/44005/

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: eswitch-modify MAC address actions

 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++
 app/test-pmd/config.c                       |  4 ++
 doc/guides/prog_guide/rte_flow.rst          | 30 ++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 +++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 62 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 29 ++++++++++
 8 files changed, 186 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 ethdev: add generic MAC address rewrite actions

rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC

The rte_flow_itme_eth must be present in rte_flow pattern

---
 doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 29 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
doc/guides/prog_guide/rte_flow.rst +30 -0
index 3aec0834b..5ecf154b6 100644
@@ -2196,6 +2196,36 @@ Assigns a new TTL value.
    | ``ttl_value`` | new TTL value      |
    +---------------+--------------------+
 
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +2 -0
index 631f80efd..1f4b67603 100644
@@ -123,6 +123,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
 };
 
 static int
lib/librte_ethdev/rte_flow.h +29 -0
index b41e37a31..19552902a 100644
@@ -1567,6 +1567,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_ttl
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+	/**
+	 * Set source MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+	/**
+	 * Set destination MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
 };
 
 /**
@@ -1986,6 +2006,15 @@ struct rte_flow_action_set_ttl {
 	uint8_t ttl_value;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+	uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
 /*
  * Definition of a single action.
  *
Signature · 1 line
2.17.1
Acked-by on v1 1/3
#2 lore raw
Quoted 9 lines · Xiaoyu Min

rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC

The rte_flow_itme_eth must be present in rte_flow pattern

---

Thanks

Quoted 109 lines
 doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 29 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
doc/guides/prog_guide/rte_flow.rst +30 -0
index 3aec0834b..5ecf154b6 100644
@@ -2196,6 +2196,36 @@ Assigns a new TTL value.
    | ``ttl_value`` | new TTL value      |
    +---------------+--------------------+
 
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +2 -0
index 631f80efd..1f4b67603 100644
@@ -123,6 +123,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
 };
 
 static int
lib/librte_ethdev/rte_flow.h +29 -0
index b41e37a31..19552902a 100644
@@ -1567,6 +1567,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_ttl
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+	/**
+	 * Set source MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+	/**
+	 * Set destination MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
 };
 
 /**
@@ -1986,6 +2006,15 @@ struct rte_flow_action_set_ttl {
 	uint8_t ttl_value;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+	uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
 /*
  * Definition of a single action.
  *
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 2/3 app/testpmd: add commands of modify MAC address

In reply to Xiaoyu Min

add commands to support following actions:

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

---
 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++++++
 app/test-pmd/config.c                       |  4 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 ++++
 3 files changed, 62 insertions(+)
app/test-pmd/cmdline_flow.c +50 -0
index fae825462..d06e75799 100644
@@ -258,6 +258,10 @@ enum index {
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
 	ACTION_SET_TTL_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_SET_MAC_DST,
+	ACTION_SET_MAC_DST_MAC_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -839,6 +843,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_DST,
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_DST,
 	ZERO,
 };
 
@@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_src[] = {
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_set_ipv4_dst[] = {
 	ACTION_SET_IPV4_DST_IPV4_DST,
 	ACTION_NEXT,
@@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_dst[] = {
+	ACTION_SET_MAC_DST_MAC_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_ttl, ttl_value)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SET_MAC_SRC] = {
+		.name = "set_mac_src",
+		.help = "set source mac address",
+		.priv = PRIV_ACTION(SET_MAC_SRC,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_src),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_SRC_MAC_SRC] = {
+		.name = "mac_addr",
+		.help = "new source mac address",
+		.next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_SET_MAC_DST] = {
+		.name = "set_mac_dst",
+		.help = "set destination mac address",
+		.priv = PRIV_ACTION(SET_MAC_DST,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_dst),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_DST_MAC_DST] = {
+		.name = "mac_addr",
+		.help = "new destination mac address to set",
+		.next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
app/test-pmd/config.c +4 -0
index d28b6ed14..c2cbf5ce8 100644
@@ -1177,6 +1177,10 @@ static const struct {
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL,
 		       sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC,
+		       sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST,
+		       sizeof(struct rte_flow_action_set_mac)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
doc/guides/testpmd_app_ug/testpmd_funcs.rst +8 -0
index db68c4346..0a8cc73a3 100644
@@ -3726,6 +3726,14 @@ This section lists supported actions and their attributes, if any.
 - ``set_ttl``: Set TTL value with specificed value
   - ``ttl_value {unsigned}``: The new TTL value to be set
 
+- ``set_mac_src``: set source MAC address
+
+  - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+  - ``mac_addr {MAC-48}``: new destination MAC address
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.17.1
Acked-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] app/testpmd: add commands of modify MAC address

Quoted 7 lines · Xiaoyu Min

add commands to support following actions:

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

---

Thanks

Quoted 131 lines
 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++++++
 app/test-pmd/config.c                       |  4 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 ++++
 3 files changed, 62 insertions(+)
app/test-pmd/cmdline_flow.c +50 -0
index fae825462..d06e75799 100644
@@ -258,6 +258,10 @@ enum index {
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
 	ACTION_SET_TTL_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_SET_MAC_DST,
+	ACTION_SET_MAC_DST_MAC_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -839,6 +843,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_DST,
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_DST,
 	ZERO,
 };
 
@@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_src[] = {
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_set_ipv4_dst[] = {
 	ACTION_SET_IPV4_DST_IPV4_DST,
 	ACTION_NEXT,
@@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_dst[] = {
+	ACTION_SET_MAC_DST_MAC_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_ttl, ttl_value)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SET_MAC_SRC] = {
+		.name = "set_mac_src",
+		.help = "set source mac address",
+		.priv = PRIV_ACTION(SET_MAC_SRC,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_src),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_SRC_MAC_SRC] = {
+		.name = "mac_addr",
+		.help = "new source mac address",
+		.next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_SET_MAC_DST] = {
+		.name = "set_mac_dst",
+		.help = "set destination mac address",
+		.priv = PRIV_ACTION(SET_MAC_DST,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_dst),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_DST_MAC_DST] = {
+		.name = "mac_addr",
+		.help = "new destination mac address to set",
+		.next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
app/test-pmd/config.c +4 -0
index d28b6ed14..c2cbf5ce8 100644
@@ -1177,6 +1177,10 @@ static const struct {
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL,
 		       sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC,
+		       sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST,
+		       sizeof(struct rte_flow_action_set_mac)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
doc/guides/testpmd_app_ug/testpmd_funcs.rst +8 -0
index db68c4346..0a8cc73a3 100644
@@ -3726,6 +3726,14 @@ This section lists supported actions and their attributes, if any.
 - ``set_ttl``: Set TTL value with specificed value
   - ``ttl_value {unsigned}``: The new TTL value to be set
 
+- ``set_mac_src``: set source MAC address
+
+  - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+  - ``mac_addr {MAC-48}``: new destination MAC address
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH 3/3 net/mlx5: eswitch-modify MAC address actions

In reply to Xiaoyu Min

Offload following modify MAC address actions to E-Switch via TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

The corresponding rte_flow_item_eth must be present in rte_flow pattern

Only support modify outer layer MAC address

---
 drivers/net/mlx5/mlx5_flow.h     |  2 ++
 drivers/net/mlx5/mlx5_flow_tcf.c | 62 +++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.h +2 -0
index 5237e31dd..76c4e8398 100644
@@ -95,6 +95,8 @@
 #define MLX5_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_ACTION_SET_TTL (1u << 17)
 #define MLX5_ACTION_DEC_TTL (1u << 18)
+#define MLX5_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_ACTION_SET_MAC_DST (1u << 20)
 
 /* possible L3 layers protocols filtering. */
 #define MLX5_IP_PROTOCOL_TCP 6
drivers/net/mlx5/mlx5_flow_tcf.c +61 -1

110 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions

Quoted 6 lines · Xiaoyu Min

Offload following modify MAC address actions to E-Switch via TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

Quoted 7 lines

The corresponding rte_flow_item_eth must be present in rte_flow pattern

Only support modify outer layer MAC address

---

Same comments as before.

Thanks,
Yongseok

Quoted 142 lines
 drivers/net/mlx5/mlx5_flow.h     |  2 ++
 drivers/net/mlx5/mlx5_flow_tcf.c | 62 +++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.h +2 -0
index 5237e31dd..76c4e8398 100644
@@ -95,6 +95,8 @@
 #define MLX5_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_ACTION_SET_TTL (1u << 17)
 #define MLX5_ACTION_DEC_TTL (1u << 18)
+#define MLX5_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_ACTION_SET_MAC_DST (1u << 20)
 
 /* possible L3 layers protocols filtering. */
 #define MLX5_IP_PROTOCOL_TCP 6
drivers/net/mlx5/mlx5_flow_tcf.c +61 -1
index af88c4a0d..cb60c3e05 100644
@@ -303,7 +303,9 @@ struct flow_tcf_ptoi {
 		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC    || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST    || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_TTL       || \
-		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ?       \
+		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL       || \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC   || \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_MAC_DST) ?   \
 		1 : 0; })
 #define MAX_PEDIT_KEYS (128)
 #define SZ_PEDIT_KEY_VAL (4)
@@ -327,6 +329,33 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
 	return keys;
 }
 
+static void
+flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
+			   struct pedit_parser *p_parser)
+{
+	int idx = p_parser->sel.nkeys;
+	uint32_t off =
+		actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ? 6 : 0;
+	const struct rte_flow_action_set_mac *conf =
+		(const struct rte_flow_action_set_mac *)actions->conf;
+
+	p_parser->keys[idx].off = off;
+	p_parser->keys[idx].mask = ~UINT32_MAX;
+	p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+	p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+	memcpy(&p_parser->keys[idx].val,
+		conf->mac_addr, SZ_PEDIT_KEY_VAL);
+	idx++;
+	p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
+	p_parser->keys[idx].mask = 0xFFFF0000;
+	p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+	p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+	memcpy(&p_parser->keys[idx].val,
+		conf->mac_addr + SZ_PEDIT_KEY_VAL,
+		ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
+	p_parser->sel.nkeys = (++idx);
+}
+
 static void
 flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
 				struct pedit_parser *p_parser,
@@ -447,6 +476,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_dec_ttl(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			flow_tcf_pedit_key_set_mac(*actions, &p_parser);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -535,6 +568,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
 			flags |= MLX5_ACTION_DEC_TTL;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+			keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+			flags |= MLX5_ACTION_SET_MAC_SRC;
+			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+			flags |= MLX5_ACTION_SET_MAC_DST;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1041,6 +1082,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			action_flags |= MLX5_ACTION_DEC_TTL;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+			action_flags |= MLX5_ACTION_SET_MAC_SRC;
+			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			action_flags |= MLX5_ACTION_SET_MAC_DST;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1093,6 +1140,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 						  actions,
 						  "no IP found in pattern");
 	}
+	if (action_flags &
+	    (MLX5_ACTION_SET_MAC_SRC | MLX5_ACTION_SET_MAC_DST)) {
+		if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no ethernet found in"
+						  " pattern");
+	}
 	return 0;
 }
 
@@ -1244,6 +1300,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TTL:
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1788,6 +1846,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TTL:
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
Signature · 1 line
2.17.1
#8 lore raw
In reply to Xiaoyu Min
Quoted 6 lines · Xiaoyu Min

This series is for RFC[1]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

Quoted 6 lines

[1]: https://patches.dpdk.org/patch/44005/

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: eswitch-modify MAC address actions

Same here, can you please rebase and send new version? And it looks like there are change requests to mlx5 patch.

author
#9 lore raw
Quoted 9 lines · Ferruh Yigit
Quoted 8 lines · Xiaoyu Min

This series is for RFC[1]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

[1]: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatches.dpdk.org%2Fpatch%2F44005%2F&amp;data=02%7C01%7Cjackmin%40mellanox.com%7C47ee836f61fc48f0d5fa08d62ac1b9b4%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636743408874175728&amp;sdata=8KZfEwLk4zC0%2BBIWhRtFVcSKQ%2Fmqe6StiU79eseNARs%3D&amp;reserved=0

Quoted 7 lines
Quoted 4 lines

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: eswitch-modify MAC address actions

Same here, can you please rebase and send new version? And it looks like there are change requests to mlx5 patch.

Sure, I will do that

-Jack

author
#10 lore raw

v2 cover ethdev: add generic MAC address rewrite actions

In reply to Xiaoyu Min

This series is for RFC[1] and depends on patch[2]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

[1]: https://patches.dpdk.org/patch/44005/
[2]: https://patches.dpdk.org/patch/46495/

v2:
* rebased
* changed commit message title
* added example testpmd command in commit log
* changes in validation

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: rewrite MAC address by E-Switch

 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++
 doc/guides/prog_guide/rte_flow.rst          | 30 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 +++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 71 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 29 +++++++++
 7 files changed, 191 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH v2 1/3 ethdev: add generic MAC address rewrite actions

rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC

The rte_flow_itme_eth must be present in rte_flow pattern

---
 doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 29 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
doc/guides/prog_guide/rte_flow.rst +30 -0
index e8df1e488..d0f2d8b54 100644
@@ -2196,6 +2196,36 @@ Assigns a new TTL value.
    | ``ttl_value`` | new TTL value      |
    +---------------+--------------------+
 
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +2 -0
index 458a05994..810069935 100644
@@ -137,6 +137,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
 };
 
 static int
lib/librte_ethdev/rte_flow.h +29 -0
index bb07eba9d..4193f4e05 100644
@@ -1568,6 +1568,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_ttl
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+	/**
+	 * Set source MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+	/**
+	 * Set destination MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
 };
 
 /**
@@ -1987,6 +2007,15 @@ struct rte_flow_action_set_ttl {
 	uint8_t ttl_value;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+	uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
 /*
  * Definition of a single action.
  *
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH v2 2/3 app/testpmd: add commands of modify MAC address

In reply to Jack Min

add commands to support following actions:

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

---
 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 ++++
 2 files changed, 58 insertions(+)
app/test-pmd/cmdline_flow.c +50 -0
index fae825462..d06e75799 100644
@@ -258,6 +258,10 @@ enum index {
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
 	ACTION_SET_TTL_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_SET_MAC_DST,
+	ACTION_SET_MAC_DST_MAC_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -839,6 +843,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_DST,
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_DST,
 	ZERO,
 };
 
@@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_src[] = {
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_set_ipv4_dst[] = {
 	ACTION_SET_IPV4_DST_IPV4_DST,
 	ACTION_NEXT,
@@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_dst[] = {
+	ACTION_SET_MAC_DST_MAC_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_ttl, ttl_value)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SET_MAC_SRC] = {
+		.name = "set_mac_src",
+		.help = "set source mac address",
+		.priv = PRIV_ACTION(SET_MAC_SRC,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_src),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_SRC_MAC_SRC] = {
+		.name = "mac_addr",
+		.help = "new source mac address",
+		.next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_SET_MAC_DST] = {
+		.name = "set_mac_dst",
+		.help = "set destination mac address",
+		.priv = PRIV_ACTION(SET_MAC_DST,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_dst),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_DST_MAC_DST] = {
+		.name = "mac_addr",
+		.help = "new destination mac address to set",
+		.next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
doc/guides/testpmd_app_ug/testpmd_funcs.rst +8 -0
index 16cd4468e..ab478fa96 100644
@@ -3733,6 +3733,14 @@ This section lists supported actions and their attributes, if any.
 - ``set_ttl``: Set TTL value with specificed value
   - ``ttl_value {unsigned}``: The new TTL value to be set
 
+- ``set_mac_src``: set source MAC address
+
+  - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+  - ``mac_addr {MAC-48}``: new destination MAC address
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.17.1
author
#13 lore raw

PATCH v2 3/3 net/mlx5: rewrite MAC address by E-Switch

In reply to Jack Min

Offload following modify MAC address actions to E-Switch via TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

The corresponding rte_flow_item_eth must be present in rte_flow pattern

Only support modify outer layer MAC address

The example testpmd command is:

flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end actions set_mac_dst mac_addr dd:00:aa:11:bb:33 / set_mac_src mac_addr bb:00:cc:11:aa:22 / port_id id 1 / end

---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 71 +++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.h +2 -0
index 0ad8c12ea..22e648b36 100644
@@ -86,6 +86,8 @@
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
+#define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 20)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
drivers/net/mlx5/mlx5_flow_tcf.c +70 -1

119 lines not on this page · raw message

Signature · 1 line
2.17.1
Acked-by on v2 3/3
#14 lore raw

Re: [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch

Quoted 13 lines · Jack Min

Offload following modify MAC address actions to E-Switch via TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

The corresponding rte_flow_item_eth must be present in rte_flow pattern

Only support modify outer layer MAC address

The example testpmd command is:

Quoted 8 lines

flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end actions set_mac_dst mac_addr dd:00:aa:11:bb:33 / set_mac_src mac_addr bb:00:cc:11:aa:22 / port_id id 1 / end

---

But you'll also need to rebase it on your other patchsets.

Thanks

Quoted 151 lines
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 71 +++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.h +2 -0
index 0ad8c12ea..22e648b36 100644
@@ -86,6 +86,8 @@
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
+#define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 20)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
drivers/net/mlx5/mlx5_flow_tcf.c +70 -1
index af8a68529..c10fdd3fb 100644
@@ -305,7 +305,9 @@ struct flow_tcf_ptoi {
 				MLX5_FLOW_ACTION_SET_TP_SRC   | \
 				MLX5_FLOW_ACTION_SET_TP_DST   | \
 				MLX5_FLOW_ACTION_SET_TTL      | \
-				MLX5_FLOW_ACTION_DEC_TTL)
+				MLX5_FLOW_ACTION_DEC_TTL      | \
+				MLX5_FLOW_ACTION_SET_MAC_SRC  | \
+				MLX5_FLOW_ACTION_SET_MAC_DST)
 
 #define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \
 				 MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
@@ -345,6 +347,42 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
 	return keys;
 }
 
+/**
+ * Set pedit key of MAC address
+ *
+ * @param[in] actions
+ *   pointer to action specification
+ * @param[in,out] p_parser
+ *   pointer to pedit_parser
+ */
+static void
+flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
+			   struct pedit_parser *p_parser)
+{
+	int idx = p_parser->sel.nkeys;
+	uint32_t off = actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
+					offsetof(struct ether_hdr, s_addr) :
+					offsetof(struct ether_hdr, d_addr);
+	const struct rte_flow_action_set_mac *conf =
+		(const struct rte_flow_action_set_mac *)actions->conf;
+
+	p_parser->keys[idx].off = off;
+	p_parser->keys[idx].mask = ~UINT32_MAX;
+	p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+	p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+	memcpy(&p_parser->keys[idx].val,
+		conf->mac_addr, SZ_PEDIT_KEY_VAL);
+	idx++;
+	p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
+	p_parser->keys[idx].mask = 0xFFFF0000;
+	p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+	p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+	memcpy(&p_parser->keys[idx].val,
+		conf->mac_addr + SZ_PEDIT_KEY_VAL,
+		ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
+	p_parser->sel.nkeys = (++idx);
+}
+
 /**
  * Set pedit key of decrease/set ttl
  *
@@ -529,6 +567,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_dec_ttl(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			flow_tcf_pedit_key_set_mac(*actions, &p_parser);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -617,6 +659,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
 			flags |= MLX5_FLOW_ACTION_DEC_TTL;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+			keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_MAC_SRC;
+			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_MAC_DST;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1141,6 +1191,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+			current_action_flag = MLX5_FLOW_ACTION_SET_MAC_SRC;
+			break;
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+			current_action_flag = MLX5_FLOW_ACTION_SET_MAC_DST;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1245,6 +1301,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 						  actions,
 						  "no IP found in pattern");
 	}
+	if (action_flags &
+	    (MLX5_FLOW_ACTION_SET_MAC_SRC | MLX5_FLOW_ACTION_SET_MAC_DST)) {
+		if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no ethernet found in"
+						  " pattern");
+	}
 	return 0;
 }
 
@@ -1396,6 +1461,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TTL:
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1942,6 +2009,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TTL:
 		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+		case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
Signature · 1 line
2.17.1
author
#15 lore raw

v3 cover ethdev: add generic MAC address rewrite actions

In reply to Jack Min

This series is for RFC[1] and depends on patch[2]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

[1]: https://patches.dpdk.org/patch/44005/
[2]: http://patches.dpdk.org/patch/46625/

v2:
* rebased
* changed commit message title
* added example testpmd command in commit log
* changes in validation
v3:
* fix some coding style issues
* use macro of calc pedit keys
* rebased

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: rewrite MAC address by E-Switch

 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++
 doc/guides/prog_guide/rte_flow.rst          | 30 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 +++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 70 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 29 +++++++++
 7 files changed, 190 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
author
#16 lore raw

PATCH v3 1/3 ethdev: add generic MAC address rewrite actions

rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC

The rte_flow_itme_eth must be present in rte_flow pattern

---
 doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 29 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
doc/guides/prog_guide/rte_flow.rst +30 -0
index 9fc5b88f2..0f7d89555 100644
@@ -2227,6 +2227,36 @@ Assigns a new TTL value.
    | ``ttl_value`` | new TTL value      |
    +---------------+--------------------+
 
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+   +--------------+---------------+
+   | Field        | Value         |
+   +==============+===============+
+   | ``mac_addr`` | MAC address   |
+   +--------------+---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +2 -0
index 5040c7667..1752ed5eb 100644
@@ -138,6 +138,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	MK_FLOW_ACTION(MAC_SWAP, 0),
 	MK_FLOW_ACTION(DEC_TTL, 0),
 	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+	MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+	MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
 };
 
 static int
lib/librte_ethdev/rte_flow.h +29 -0
index f102e6939..844ee3b25 100644
@@ -1599,6 +1599,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_ttl
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+	/**
+	 * Set source MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+	/**
+	 * Set destination MAC address from matched flow.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+	 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_mac.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
 };
 
 /**
@@ -2018,6 +2038,15 @@ struct rte_flow_action_set_ttl {
 	uint8_t ttl_value;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+	uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
 /*
  * Definition of a single action.
  *
Signature · 1 line
2.17.1
author
#17 lore raw

PATCH v3 2/3 app/testpmd: add commands of modify MAC address

In reply to Jack Min

add commands to support following actions:

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

---
 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 ++++
 2 files changed, 58 insertions(+)
app/test-pmd/cmdline_flow.c +50 -0
index 3efc2d86e..a527b6bb4 100644
@@ -259,6 +259,10 @@ enum index {
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
 	ACTION_SET_TTL_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_SET_MAC_DST,
+	ACTION_SET_MAC_DST_MAC_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -841,6 +845,8 @@ static const enum index next_action[] = {
 	ACTION_MAC_SWAP,
 	ACTION_DEC_TTL,
 	ACTION_SET_TTL,
+	ACTION_SET_MAC_SRC,
+	ACTION_SET_MAC_DST,
 	ZERO,
 };
 
@@ -949,6 +955,12 @@ static const enum index action_set_ipv4_src[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_src[] = {
+	ACTION_SET_MAC_SRC_MAC_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_set_ipv4_dst[] = {
 	ACTION_SET_IPV4_DST_IPV4_DST,
 	ACTION_NEXT,
@@ -991,6 +1003,12 @@ static const enum index action_jump[] = {
 	ZERO,
 };
 
+static const enum index action_set_mac_dst[] = {
+	ACTION_SET_MAC_DST_MAC_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2670,6 +2688,38 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_ttl, ttl_value)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SET_MAC_SRC] = {
+		.name = "set_mac_src",
+		.help = "set source mac address",
+		.priv = PRIV_ACTION(SET_MAC_SRC,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_src),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_SRC_MAC_SRC] = {
+		.name = "mac_addr",
+		.help = "new source mac address",
+		.next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_SET_MAC_DST] = {
+		.name = "set_mac_dst",
+		.help = "set destination mac address",
+		.priv = PRIV_ACTION(SET_MAC_DST,
+			sizeof(struct rte_flow_action_set_mac)),
+		.next = NEXT(action_set_mac_dst),
+		.call = parse_vc,
+	},
+	[ACTION_SET_MAC_DST_MAC_DST] = {
+		.name = "mac_addr",
+		.help = "new destination mac address to set",
+		.next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_mac, mac_addr)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
doc/guides/testpmd_app_ug/testpmd_funcs.rst +8 -0
index 77233987b..1ca3e8c20 100644
@@ -3744,6 +3744,14 @@ This section lists supported actions and their attributes, if any.
 - ``set_ttl``: Set TTL value with specificed value
   - ``ttl_value {unsigned}``: The new TTL value to be set
 
+- ``set_mac_src``: set source MAC address
+
+  - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+  - ``mac_addr {MAC-48}``: new destination MAC address
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.17.1
author
#18 lore raw

PATCH v3 3/3 net/mlx5: rewrite MAC address by E-Switch

In reply to Jack Min

Offload following modify MAC address actions to E-Switch via TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST

The corresponding rte_flow_item_eth must be present in rte_flow pattern

Only support modify outer layer MAC address

The example testpmd command is:

flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end actions set_mac_dst mac_addr dd:00:aa:11:bb:33 / set_mac_src mac_addr bb:00:cc:11:aa:22 / port_id id 1 / end

---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 70 +++++++++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow.h +2 -0
index cb07cf652..8ac24ebd5 100644
@@ -86,6 +86,8 @@
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
+#define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 20)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
drivers/net/mlx5/mlx5_flow_tcf.c +69 -1

118 lines not on this page · raw message

Signature · 1 line
2.17.1
#19 lore raw
In reply to Jack Min
Quoted 19 lines · Jack Min

This series is for RFC[1] and depends on patch[2]

Patch 1 adds generic MAC address rewrite actions to flow API Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule

[1]: https://patches.dpdk.org/patch/44005/
[2]: http://patches.dpdk.org/patch/46625/

v2:
* rebased
* changed commit message title
* added example testpmd command in commit log
* changes in validation
v3:
* fix some coding style issues
* use macro of calc pedit keys
* rebased

Quoted 4 lines

Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: rewrite MAC address by E-Switch

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