net/mlx5/hws: add check for modify-header actions
Checks
Commit Message
Allow only actions that are currently supported.
Fixes: f8c8a6d8440d ("net/mlx5/hws: add action object")
Reviewed-by: Alex Vesker <valex@nvidia.com>
Signed-off-by: Erez Shitrit <erezsh@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(+)
@@ -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. */
@@ -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];
@@ -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,
@@ -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,