Commit 218d05ce authored by Tonghao Zhang's avatar Tonghao Zhang Committed by David S. Miller

net/mlx5e: Don't overwrite pedit action when multiple pedit used

In some case, we may use multiple pedit actions to modify packets.
The command shown as below: the last pedit action is effective.

$ tc filter add dev netdev_rep parent ffff: protocol ip prio 1    \
	flower skip_sw ip_proto icmp dst_ip 3.3.3.3        \
	action pedit ex munge ip dst set 192.168.1.100 pipe    \
	action pedit ex munge eth src set 00:00:00:00:00:01 pipe    \
	action pedit ex munge eth dst set 00:00:00:00:00:02 pipe    \
	action csum ip pipe    \
	action tunnel_key set src_ip 1.1.1.100 dst_ip 1.1.1.200 dst_port 4789 id 100 \
	action mirred egress redirect dev vxlan0

To fix it, we add max_mod_hdr_actions to mlx5e_tc_flow_parse_attr struction,
max_mod_hdr_actions will store the max pedit action number we support and
num_mod_hdr_actions indicates how many pedit action we used, and store all
pedit action to mod_hdr_actions.

Fixes: d79b6df6 ("net/mlx5e: Add parsing of TC pedit actions to HW format")
Cc: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarTonghao Zhang <xiangxia.m.yue@gmail.com>
Reviewed-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Acked-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6707f74b
...@@ -128,6 +128,7 @@ struct mlx5e_tc_flow_parse_attr { ...@@ -128,6 +128,7 @@ struct mlx5e_tc_flow_parse_attr {
struct net_device *filter_dev; struct net_device *filter_dev;
struct mlx5_flow_spec spec; struct mlx5_flow_spec spec;
int num_mod_hdr_actions; int num_mod_hdr_actions;
int max_mod_hdr_actions;
void *mod_hdr_actions; void *mod_hdr_actions;
int mirred_ifindex[MLX5_MAX_FLOW_FWD_VPORTS]; int mirred_ifindex[MLX5_MAX_FLOW_FWD_VPORTS];
}; };
...@@ -1936,9 +1937,9 @@ static struct mlx5_fields fields[] = { ...@@ -1936,9 +1937,9 @@ static struct mlx5_fields fields[] = {
OFFLOAD(UDP_DPORT, 2, udp.dest, 0), OFFLOAD(UDP_DPORT, 2, udp.dest, 0),
}; };
/* On input attr->num_mod_hdr_actions tells how many HW actions can be parsed at /* On input attr->max_mod_hdr_actions tells how many HW actions can be parsed at
* max from the SW pedit action. On success, it says how many HW actions were * max from the SW pedit action. On success, attr->num_mod_hdr_actions
* actually parsed. * says how many HW actions were actually parsed.
*/ */
static int offload_pedit_fields(struct pedit_headers *masks, static int offload_pedit_fields(struct pedit_headers *masks,
struct pedit_headers *vals, struct pedit_headers *vals,
...@@ -1962,9 +1963,11 @@ static int offload_pedit_fields(struct pedit_headers *masks, ...@@ -1962,9 +1963,11 @@ static int offload_pedit_fields(struct pedit_headers *masks,
add_vals = &vals[TCA_PEDIT_KEY_EX_CMD_ADD]; add_vals = &vals[TCA_PEDIT_KEY_EX_CMD_ADD];
action_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto); action_size = MLX5_UN_SZ_BYTES(set_action_in_add_action_in_auto);
action = parse_attr->mod_hdr_actions; action = parse_attr->mod_hdr_actions +
max_actions = parse_attr->num_mod_hdr_actions; parse_attr->num_mod_hdr_actions * action_size;
nactions = 0;
max_actions = parse_attr->max_mod_hdr_actions;
nactions = parse_attr->num_mod_hdr_actions;
for (i = 0; i < ARRAY_SIZE(fields); i++) { for (i = 0; i < ARRAY_SIZE(fields); i++) {
f = &fields[i]; f = &fields[i];
...@@ -2075,7 +2078,7 @@ static int alloc_mod_hdr_actions(struct mlx5e_priv *priv, ...@@ -2075,7 +2078,7 @@ static int alloc_mod_hdr_actions(struct mlx5e_priv *priv,
if (!parse_attr->mod_hdr_actions) if (!parse_attr->mod_hdr_actions)
return -ENOMEM; return -ENOMEM;
parse_attr->num_mod_hdr_actions = max_actions; parse_attr->max_mod_hdr_actions = max_actions;
return 0; return 0;
} }
...@@ -2121,9 +2124,11 @@ static int parse_tc_pedit_action(struct mlx5e_priv *priv, ...@@ -2121,9 +2124,11 @@ static int parse_tc_pedit_action(struct mlx5e_priv *priv,
goto out_err; goto out_err;
} }
if (!parse_attr->mod_hdr_actions) {
err = alloc_mod_hdr_actions(priv, a, namespace, parse_attr); err = alloc_mod_hdr_actions(priv, a, namespace, parse_attr);
if (err) if (err)
goto out_err; goto out_err;
}
err = offload_pedit_fields(masks, vals, parse_attr, extack); err = offload_pedit_fields(masks, vals, parse_attr, extack);
if (err < 0) if (err < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment