ethdev: add generic MAC address rewrite actions
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
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
@@ -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
@@ -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
@@ -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
Quoted 9 lines · Xiaoyu Min
rte_flowactions:
-RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
-RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NICThe
rte_flow_itme_ethmust be present inrte_flowpatternSigned-off-by Xiaoyu Min <[email protected]>---
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@@ -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@@ -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 intlib/librte_ethdev/rte_flow.h +29
-0@@ -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
Quoted 8 lines · Xiaoyu Min
rte_flowactions:
-RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
-RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NICThe
rte_flow_itme_ethmust be present inrte_flowpatternSigned-off-by Xiaoyu Min <[email protected]>
PATCH 2/3 app/testpmd: add commands of modify MAC address
In reply to Xiaoyu Minadd 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
@@ -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
@@ -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
@@ -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
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_DSTSigned-off-by Xiaoyu Min <[email protected]>---
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@@ -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@@ -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@@ -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
PATCH 3/3 net/mlx5: eswitch-modify MAC address actions
In reply to Xiaoyu MinOffload 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
@@ -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
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_ethmust be present inrte_flowpatternOnly support modify outer layer MAC address
Signed-off-by Xiaoyu Min <[email protected]>---
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@@ -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 6drivers/net/mlx5/mlx5_flow_tcf.c +61
-1@@ -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
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.
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
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 actionsSame 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
v2 cover ethdev: add generic MAC address rewrite actions
In reply to Xiaoyu MinThis 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
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
@@ -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
@@ -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
@@ -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
PATCH v2 2/3 app/testpmd: add commands of modify MAC address
In reply to Jack Minadd 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
@@ -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
@@ -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
PATCH v2 3/3 net/mlx5: rewrite MAC address by E-Switch
In reply to Jack MinOffload 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
@@ -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
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_DSTThe corresponding
rte_flow_item_ethmust be present inrte_flowpatternOnly 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 actionsset_mac_dstmac_addrdd:00:aa:11:bb:33 /set_mac_srcmac_addrbb:00:cc:11:aa:22 /port_idid 1 / endSigned-off-by Xiaoyu Min <[email protected]>---
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@@ -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@@ -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
v3 cover ethdev: add generic MAC address rewrite actions
In reply to Jack MinThis 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
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
@@ -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
@@ -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
@@ -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
PATCH v3 2/3 app/testpmd: add commands of modify MAC address
In reply to Jack Minadd 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
@@ -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
@@ -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
PATCH v3 3/3 net/mlx5: rewrite MAC address by E-Switch
In reply to Jack MinOffload 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
@@ -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
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.