Allow only actions that are currently supported.
Fixes: f8c8a6d8440d ("net/mlx5/hws: add action object") Reviewed-by: Alex Vesker <va...@nvidia.com> Signed-off-by: Erez Shitrit <ere...@nvidia.com> --- drivers/common/mlx5/mlx5_prm.h | 1 + drivers/net/mlx5/hws/mlx5dr_action.c | 6 ++++++ drivers/net/mlx5/hws/mlx5dr_pat_arg.c | 16 ++++++++++++++++ drivers/net/mlx5/hws/mlx5dr_pat_arg.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index 4b0a56f4e5..0b6dc43752 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -715,6 +715,7 @@ enum { MLX5_MODIFICATION_TYPE_REMOVE = 0x5, MLX5_MODIFICATION_TYPE_NOP = 0x6, MLX5_MODIFICATION_TYPE_REMOVE_WORDS = 0x7, + MLX5_MODIFICATION_TYPE_MAX, }; /* The field of packet to be modified. */ diff --git a/drivers/net/mlx5/hws/mlx5dr_action.c b/drivers/net/mlx5/hws/mlx5dr_action.c index 77cf1f5132..2d93be717f 100644 --- a/drivers/net/mlx5/hws/mlx5dr_action.c +++ b/drivers/net/mlx5/hws/mlx5dr_action.c @@ -1603,6 +1603,12 @@ mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx, goto free_action; } + if (!mlx5dr_pat_arg_verify_actions(pattern, pattern_sz / MLX5DR_MODIFY_ACTION_SIZE)) { + DR_LOG(ERR, "One of the actions is not supported\n"); + rte_errno = EINVAL; + goto free_action; + } + if (pattern_sz / MLX5DR_MODIFY_ACTION_SIZE == 1) { /* Optimize single modiy action to be used inline */ action->modify_header.single_action = pattern[0]; diff --git a/drivers/net/mlx5/hws/mlx5dr_pat_arg.c b/drivers/net/mlx5/hws/mlx5dr_pat_arg.c index 6ed04dac6d..830bc08678 100644 --- a/drivers/net/mlx5/hws/mlx5dr_pat_arg.c +++ b/drivers/net/mlx5/hws/mlx5dr_pat_arg.c @@ -441,6 +441,22 @@ mlx5dr_arg_create_modify_header_arg(struct mlx5dr_context *ctx, return 0; } +bool mlx5dr_pat_arg_verify_actions(__be64 pattern[], uint16_t num_of_actions) +{ + int i; + + for (i = 0; i < num_of_actions; i++) { + u8 action_id = + MLX5_GET(set_action_in, &pattern[i], action_type); + if (action_id >= MLX5_MODIFICATION_TYPE_MAX) { + DR_LOG(ERR, "Invalid action %u\n", action_id); + return false; + } + } + + return true; +} + int mlx5dr_pat_arg_create_modify_header(struct mlx5dr_context *ctx, struct mlx5dr_action *action, size_t pattern_sz, diff --git a/drivers/net/mlx5/hws/mlx5dr_pat_arg.h b/drivers/net/mlx5/hws/mlx5dr_pat_arg.h index 92db6d6aee..ec467dbb4b 100644 --- a/drivers/net/mlx5/hws/mlx5dr_pat_arg.h +++ b/drivers/net/mlx5/hws/mlx5dr_pat_arg.h @@ -53,6 +53,8 @@ int mlx5dr_pat_init_pattern_cache(struct mlx5dr_pattern_cache **cache); void mlx5dr_pat_uninit_pattern_cache(struct mlx5dr_pattern_cache *cache); +bool mlx5dr_pat_arg_verify_actions(__be64 pattern[], uint16_t num_of_actions); + int mlx5dr_pat_arg_create_modify_header(struct mlx5dr_context *ctx, struct mlx5dr_action *action, size_t pattern_sz, -- 2.18.2