net/mlx5: fix VLAN VID action validation
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index afa3d0e..4b6a92c 100644 (file)
@@ -1634,17 +1634,16 @@ flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                          NULL,
                                          "pop vlan action is not supported");
-       /*
-        * Check for inconsistencies:
-        *  fail strip_vlan in a flow that matches packets without VLAN tags.
-        *  fail strip_vlan in a flow that matches packets without explicitly a
-        *  matching on VLAN tag ?
-        */
-       if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN)
+       if (attr->egress)
                return rte_flow_error_set(error, ENOTSUP,
-                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
                                          NULL,
-                                         "no support for multiple vlan pop "
+                                         "pop vlan action not supported for "
+                                         "egress");
+       if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "no support for multiple VLAN "
                                          "actions");
        if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
                return rte_flow_error_set(error, ENOTSUP,
@@ -1734,32 +1733,29 @@ flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
  */
 static int
 flow_dv_validate_action_push_vlan(uint64_t action_flags,
-                                 uint64_t item_flags,
+                                 uint64_t item_flags __rte_unused,
                                  const struct rte_flow_action *action,
                                  const struct rte_flow_attr *attr,
                                  struct rte_flow_error *error)
 {
        const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
 
+       if (attr->ingress)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+                                         NULL,
+                                         "push VLAN action not supported for "
+                                         "ingress");
        if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
            push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "invalid vlan ethertype");
-       if (action_flags &
-               (MLX5_FLOW_ACTION_OF_POP_VLAN | MLX5_FLOW_ACTION_OF_PUSH_VLAN))
+       if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "no support for multiple VLAN "
                                          "actions");
-       if (!mlx5_flow_find_action
-                       (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) &&
-           !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
-               return rte_flow_error_set(error, ENOTSUP,
-                               RTE_FLOW_ERROR_TYPE_ACTION, action,
-                               "push VLAN needs to match on VLAN in order to "
-                               "get VLAN VID information because there is "
-                               "no followed set VLAN VID action");
        if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
@@ -1819,10 +1815,10 @@ flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
  *
  * @param[in] item_flags
  *   Holds the items detected in this rule.
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
  * @param[in] actions
  *   Pointer to the list of actions remaining in the flow rule.
- * @param[in] attr
- *   Pointer to flow attributes
  * @param[out] error
  *   Pointer to error structure.
  *
@@ -1842,33 +1838,17 @@ flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "VLAN VID value is too big");
-       /* there is an of_push_vlan action before us */
-       if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
-               if (mlx5_flow_find_action(actions + 1,
-                                         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID))
-                       return rte_flow_error_set(error, ENOTSUP,
-                                       RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                       "Multiple VLAN VID modifications are "
-                                       "not supported");
-               else
-                       return 0;
-       }
-
-       /*
-        * Action is on an existing VLAN header:
-        *    Need to verify this is a single modify CID action.
-        *   Rule mast include a match on outer VLAN.
-        */
+       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
+           !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN VID action must follow push"
+                                         " VLAN action or match on VLAN item");
        if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "Multiple VLAN VID modifications are "
                                          "not supported");
-       if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                         "match on VLAN is required in order "
-                                         "to set VLAN VID");
        if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
@@ -1921,10 +1901,6 @@ flow_dv_validate_action_flag(struct rte_eth_dev *dev,
        if (ret < 0)
                return ret;
        assert(ret > 0);
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and flag in same flow");
        if (action_flags & MLX5_FLOW_ACTION_MARK)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -1994,10 +1970,6 @@ flow_dv_validate_action_mark(struct rte_eth_dev *dev,
                                          RTE_FLOW_ERROR_TYPE_ACTION_CONF,
                                          &mark->id,
                                          "mark id exceeds the limit");
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and mark in same flow");
        if (action_flags & MLX5_FLOW_ACTION_FLAG)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -2182,10 +2154,6 @@ flow_dv_validate_action_l2_encap(uint64_t action_flags,
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "configuration cannot be null");
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and encap in same flow");
        if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -2218,10 +2186,6 @@ flow_dv_validate_action_l2_decap(uint64_t action_flags,
                                 const struct rte_flow_attr *attr,
                                 struct rte_flow_error *error)
 {
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and decap in same flow");
        if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -2268,10 +2232,6 @@ flow_dv_validate_action_raw_encap(uint64_t action_flags,
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "configuration cannot be null");
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and encap in same flow");
        if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -2315,10 +2275,6 @@ flow_dv_validate_action_raw_decap(uint64_t action_flags,
 {
        const struct rte_flow_action_raw_decap *decap   = action->conf;
 
-       if (action_flags & MLX5_FLOW_ACTION_DROP)
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
-                                         "can't drop and decap in same flow");
        if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, NULL,
@@ -5060,6 +5016,18 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                  "action not supported");
                }
        }
+       /*
+        * Validate the drop action mutual exclusion with other actions.
+        * Drop action is mutually-exclusive with any other action, except for
+        * Count action.
+        */
+       if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
+           (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+                                         "Drop action is mutually-exclusive "
+                                         "with any other action, except for "
+                                         "Count action");
        /* Eswitch has few restrictions on using items and actions */
        if (attr->transfer) {
                if (!mlx5_flow_ext_mreg_supported(dev) &&