net/mlx5: add VXLAN to flow translate routine
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_tcf.c
index 55c77e3..ba17806 100644 (file)
@@ -1115,6 +1115,665 @@ flow_tcf_validate_attributes(const struct rte_flow_attr *attr,
        return 0;
 }
 
+/**
+ * Validate VXLAN_ENCAP action RTE_FLOW_ITEM_TYPE_ETH item for E-Switch.
+ * The routine checks the L2 fields to be used in encapsulation header.
+ *
+ * @param[in] item
+ *   Pointer to the item structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap_eth(const struct rte_flow_item *item,
+                                 struct rte_flow_error *error)
+{
+       const struct rte_flow_item_eth *spec = item->spec;
+       const struct rte_flow_item_eth *mask = item->mask;
+
+       if (!spec) {
+               /*
+                * Specification for L2 addresses can be empty
+                * because these ones are optional and not
+                * required directly by tc rule. Kernel tries
+                * to resolve these ones on its own
+                */
+               return 0;
+       }
+       if (!mask) {
+               /* If mask is not specified use the default one. */
+               mask = &rte_flow_item_eth_mask;
+       }
+       if (memcmp(&mask->dst,
+                  &flow_tcf_mask_empty.eth.dst,
+                  sizeof(flow_tcf_mask_empty.eth.dst))) {
+               if (memcmp(&mask->dst,
+                          &rte_flow_item_eth_mask.dst,
+                          sizeof(rte_flow_item_eth_mask.dst)))
+                       return rte_flow_error_set
+                               (error, ENOTSUP,
+                                RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                "no support for partial mask on"
+                                " \"eth.dst\" field");
+       }
+       if (memcmp(&mask->src,
+                  &flow_tcf_mask_empty.eth.src,
+                  sizeof(flow_tcf_mask_empty.eth.src))) {
+               if (memcmp(&mask->src,
+                          &rte_flow_item_eth_mask.src,
+                          sizeof(rte_flow_item_eth_mask.src)))
+                       return rte_flow_error_set
+                               (error, ENOTSUP,
+                                RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                "no support for partial mask on"
+                                " \"eth.src\" field");
+       }
+       if (mask->type != RTE_BE16(0x0000)) {
+               if (mask->type != RTE_BE16(0xffff))
+                       return rte_flow_error_set
+                               (error, ENOTSUP,
+                                RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                "no support for partial mask on"
+                                " \"eth.type\" field");
+               DRV_LOG(WARNING,
+                       "outer ethernet type field"
+                       " cannot be forced for vxlan"
+                       " encapsulation, parameter ignored");
+       }
+       return 0;
+}
+
+/**
+ * Validate VXLAN_ENCAP action RTE_FLOW_ITEM_TYPE_IPV4 item for E-Switch.
+ * The routine checks the IPv4 fields to be used in encapsulation header.
+ *
+ * @param[in] item
+ *   Pointer to the item structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap_ipv4(const struct rte_flow_item *item,
+                                  struct rte_flow_error *error)
+{
+       const struct rte_flow_item_ipv4 *spec = item->spec;
+       const struct rte_flow_item_ipv4 *mask = item->mask;
+
+       if (!spec) {
+               /*
+                * Specification for IP addresses cannot be empty
+                * because it is required by tunnel_key parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "NULL outer ipv4 address"
+                                         " specification for vxlan"
+                                         " encapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_ipv4_mask;
+       if (mask->hdr.dst_addr != RTE_BE32(0x00000000)) {
+               if (mask->hdr.dst_addr != RTE_BE32(0xffffffff))
+                       return rte_flow_error_set
+                               (error, ENOTSUP,
+                                RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                "no support for partial mask on"
+                                " \"ipv4.hdr.dst_addr\" field"
+                                " for vxlan encapsulation");
+               /* More IPv4 address validations can be put here. */
+       } else {
+               /*
+                * Kernel uses the destination IP address to determine
+                * the routing path and obtain the MAC destination
+                * address, so IP destination address must be
+                * specified in the tc rule.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer ipv4 destination address"
+                                         " must be specified for"
+                                         " vxlan encapsulation");
+       }
+       if (mask->hdr.src_addr != RTE_BE32(0x00000000)) {
+               if (mask->hdr.src_addr != RTE_BE32(0xffffffff))
+                       return rte_flow_error_set
+                               (error, ENOTSUP,
+                                RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                "no support for partial mask on"
+                                " \"ipv4.hdr.src_addr\" field"
+                                " for vxlan encapsulation");
+               /* More IPv4 address validations can be put here. */
+       } else {
+               /*
+                * Kernel uses the source IP address to select the
+                * interface for egress encapsulated traffic, so
+                * it must be specified in the tc rule.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer ipv4 source address"
+                                         " must be specified for"
+                                         " vxlan encapsulation");
+       }
+       return 0;
+}
+
+/**
+ * Validate VXLAN_ENCAP action RTE_FLOW_ITEM_TYPE_IPV6 item for E-Switch.
+ * The routine checks the IPv6 fields to be used in encapsulation header.
+ *
+ * @param[in] item
+ *   Pointer to the item structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap_ipv6(const struct rte_flow_item *item,
+                                  struct rte_flow_error *error)
+{
+       const struct rte_flow_item_ipv6 *spec = item->spec;
+       const struct rte_flow_item_ipv6 *mask = item->mask;
+
+       if (!spec) {
+               /*
+                * Specification for IP addresses cannot be empty
+                * because it is required by tunnel_key parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "NULL outer ipv6 address"
+                                         " specification for"
+                                         " vxlan encapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_ipv6_mask;
+       if (memcmp(&mask->hdr.dst_addr,
+                  &flow_tcf_mask_empty.ipv6.hdr.dst_addr,
+                  IPV6_ADDR_LEN)) {
+               if (memcmp(&mask->hdr.dst_addr,
+                          &rte_flow_item_ipv6_mask.hdr.dst_addr,
+                          IPV6_ADDR_LEN))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"ipv6.hdr.dst_addr\" field"
+                                        " for vxlan encapsulation");
+               /* More IPv6 address validations can be put here. */
+       } else {
+               /*
+                * Kernel uses the destination IP address to determine
+                * the routing path and obtain the MAC destination
+                * address (heigh or gate), so IP destination address
+                * must be specified within the tc rule.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer ipv6 destination address"
+                                         " must be specified for"
+                                         " vxlan encapsulation");
+       }
+       if (memcmp(&mask->hdr.src_addr,
+                  &flow_tcf_mask_empty.ipv6.hdr.src_addr,
+                  IPV6_ADDR_LEN)) {
+               if (memcmp(&mask->hdr.src_addr,
+                          &rte_flow_item_ipv6_mask.hdr.src_addr,
+                          IPV6_ADDR_LEN))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"ipv6.hdr.src_addr\" field"
+                                        " for vxlan encapsulation");
+               /* More L3 address validation can be put here. */
+       } else {
+               /*
+                * Kernel uses the source IP address to select the
+                * interface for egress encapsulated traffic, so
+                * it must be specified in the tc rule.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer L3 source address"
+                                         " must be specified for"
+                                         " vxlan encapsulation");
+       }
+       return 0;
+}
+
+/**
+ * Validate VXLAN_ENCAP action RTE_FLOW_ITEM_TYPE_UDP item for E-Switch.
+ * The routine checks the UDP fields to be used in encapsulation header.
+ *
+ * @param[in] item
+ *   Pointer to the item structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap_udp(const struct rte_flow_item *item,
+                                 struct rte_flow_error *error)
+{
+       const struct rte_flow_item_udp *spec = item->spec;
+       const struct rte_flow_item_udp *mask = item->mask;
+
+       if (!spec) {
+               /*
+                * Specification for UDP ports cannot be empty
+                * because it is required by tunnel_key parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "NULL UDP port specification "
+                                         " for vxlan encapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_udp_mask;
+       if (mask->hdr.dst_port != RTE_BE16(0x0000)) {
+               if (mask->hdr.dst_port != RTE_BE16(0xffff))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"udp.hdr.dst_port\" field"
+                                        " for vxlan encapsulation");
+               if (!spec->hdr.dst_port)
+                       return rte_flow_error_set
+                                       (error, EINVAL,
+                                        RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                        "outer UDP remote port cannot be"
+                                        " 0 for vxlan encapsulation");
+       } else {
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer UDP remote port"
+                                         " must be specified for"
+                                         " vxlan encapsulation");
+       }
+       if (mask->hdr.src_port != RTE_BE16(0x0000)) {
+               if (mask->hdr.src_port != RTE_BE16(0xffff))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"udp.hdr.src_port\" field"
+                                        " for vxlan encapsulation");
+               DRV_LOG(WARNING,
+                       "outer UDP source port cannot be"
+                       " forced for vxlan encapsulation,"
+                       " parameter ignored");
+       }
+       return 0;
+}
+
+/**
+ * Validate VXLAN_ENCAP action RTE_FLOW_ITEM_TYPE_VXLAN item for E-Switch.
+ * The routine checks the VNIP fields to be used in encapsulation header.
+ *
+ * @param[in] item
+ *   Pointer to the item structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap_vni(const struct rte_flow_item *item,
+                                 struct rte_flow_error *error)
+{
+       const struct rte_flow_item_vxlan *spec = item->spec;
+       const struct rte_flow_item_vxlan *mask = item->mask;
+
+       if (!spec) {
+               /* Outer VNI is required by tunnel_key parameter. */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "NULL VNI specification"
+                                         " for vxlan encapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_vxlan_mask;
+       if (!mask->vni[0] && !mask->vni[1] && !mask->vni[2])
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "outer VNI must be specified "
+                                         "for vxlan encapsulation");
+       if (mask->vni[0] != 0xff ||
+           mask->vni[1] != 0xff ||
+           mask->vni[2] != 0xff)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                         "no support for partial mask on"
+                                         " \"vxlan.vni\" field");
+
+       if (!spec->vni[0] && !spec->vni[1] && !spec->vni[2])
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
+                                         "vxlan vni cannot be 0");
+       return 0;
+}
+
+/**
+ * Validate VXLAN_ENCAP action item list for E-Switch.
+ * The routine checks items to be used in encapsulation header.
+ *
+ * @param[in] action
+ *   Pointer to the VXLAN_ENCAP action structure.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_encap(const struct rte_flow_action *action,
+                             struct rte_flow_error *error)
+{
+       const struct rte_flow_item *items;
+       int ret;
+       uint32_t item_flags = 0;
+
+       if (!action->conf)
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "Missing vxlan tunnel"
+                                         " action configuration");
+       items = ((const struct rte_flow_action_vxlan_encap *)
+                                       action->conf)->definition;
+       if (!items)
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "Missing vxlan tunnel"
+                                         " encapsulation parameters");
+       for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
+               switch (items->type) {
+               case RTE_FLOW_ITEM_TYPE_VOID:
+                       break;
+               case RTE_FLOW_ITEM_TYPE_ETH:
+                       ret = mlx5_flow_validate_item_eth(items, item_flags,
+                                                         error);
+                       if (ret < 0)
+                               return ret;
+                       ret = flow_tcf_validate_vxlan_encap_eth(items, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_OUTER_L2;
+                       break;
+               break;
+               case RTE_FLOW_ITEM_TYPE_IPV4:
+                       ret = mlx5_flow_validate_item_ipv4(items, item_flags,
+                                                          error);
+                       if (ret < 0)
+                               return ret;
+                       ret = flow_tcf_validate_vxlan_encap_ipv4(items, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_IPV6:
+                       ret = mlx5_flow_validate_item_ipv6(items, item_flags,
+                                                          error);
+                       if (ret < 0)
+                               return ret;
+                       ret = flow_tcf_validate_vxlan_encap_ipv6(items, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_UDP:
+                       ret = mlx5_flow_validate_item_udp(items, item_flags,
+                                                          0xFF, error);
+                       if (ret < 0)
+                               return ret;
+                       ret = flow_tcf_validate_vxlan_encap_udp(items, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       ret = mlx5_flow_validate_item_vxlan(items,
+                                                           item_flags, error);
+                       if (ret < 0)
+                               return ret;
+                       ret = flow_tcf_validate_vxlan_encap_vni(items, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_VXLAN;
+                       break;
+               default:
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM, items,
+                                        "vxlan encap item not supported");
+               }
+       }
+       if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "no outer IP layer found"
+                                         " for vxlan encapsulation");
+       if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "no outer UDP layer found"
+                                         " for vxlan encapsulation");
+       if (!(item_flags & MLX5_FLOW_LAYER_VXLAN))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "no VXLAN VNI found"
+                                         " for vxlan encapsulation");
+       return 0;
+}
+
+/**
+ * Validate RTE_FLOW_ITEM_TYPE_IPV4 item if VXLAN_DECAP action
+ * is present in actions list.
+ *
+ * @param[in] ipv4
+ *   Outer IPv4 address item (if any, NULL otherwise).
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_decap_ipv4(const struct rte_flow_item *ipv4,
+                                  struct rte_flow_error *error)
+{
+       const struct rte_flow_item_ipv4 *spec = ipv4->spec;
+       const struct rte_flow_item_ipv4 *mask = ipv4->mask;
+
+       if (!spec) {
+               /*
+                * Specification for IP addresses cannot be empty
+                * because it is required as decap parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, ipv4,
+                                         "NULL outer ipv4 address"
+                                         " specification for vxlan"
+                                         " for vxlan decapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_ipv4_mask;
+       if (mask->hdr.dst_addr != RTE_BE32(0x00000000)) {
+               if (mask->hdr.dst_addr != RTE_BE32(0xffffffff))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"ipv4.hdr.dst_addr\" field");
+               /* More IP address validations can be put here. */
+       } else {
+               /*
+                * Kernel uses the destination IP address
+                * to determine the ingress network interface
+                * for traffic being decapsulated.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, ipv4,
+                                         "outer ipv4 destination address"
+                                         " must be specified for"
+                                         " vxlan decapsulation");
+       }
+       /* Source IP address is optional for decap. */
+       if (mask->hdr.src_addr != RTE_BE32(0x00000000) &&
+           mask->hdr.src_addr != RTE_BE32(0xffffffff))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                         "no support for partial mask on"
+                                         " \"ipv4.hdr.src_addr\" field");
+       return 0;
+}
+
+/**
+ * Validate RTE_FLOW_ITEM_TYPE_IPV6 item if VXLAN_DECAP action
+ * is present in actions list.
+ *
+ * @param[in] ipv6
+ *   Outer IPv6 address item (if any, NULL otherwise).
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_decap_ipv6(const struct rte_flow_item *ipv6,
+                                  struct rte_flow_error *error)
+{
+       const struct rte_flow_item_ipv6 *spec = ipv6->spec;
+       const struct rte_flow_item_ipv6 *mask = ipv6->mask;
+
+       if (!spec) {
+               /*
+                * Specification for IP addresses cannot be empty
+                * because it is required as decap parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, ipv6,
+                                         "NULL outer ipv6 address"
+                                         " specification for vxlan"
+                                         " decapsulation");
+       }
+       if (!mask)
+               mask = &rte_flow_item_ipv6_mask;
+       if (memcmp(&mask->hdr.dst_addr,
+                  &flow_tcf_mask_empty.ipv6.hdr.dst_addr,
+                  IPV6_ADDR_LEN)) {
+               if (memcmp(&mask->hdr.dst_addr,
+                       &rte_flow_item_ipv6_mask.hdr.dst_addr,
+                       IPV6_ADDR_LEN))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"ipv6.hdr.dst_addr\" field");
+               /* More IP address validations can be put here. */
+       } else {
+               /*
+                * Kernel uses the destination IP address
+                * to determine the ingress network interface
+                * for traffic being decapsulated.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, ipv6,
+                                         "outer ipv6 destination address must be "
+                                         "specified for vxlan decapsulation");
+       }
+       /* Source IP address is optional for decap. */
+       if (memcmp(&mask->hdr.src_addr,
+                  &flow_tcf_mask_empty.ipv6.hdr.src_addr,
+                  IPV6_ADDR_LEN)) {
+               if (memcmp(&mask->hdr.src_addr,
+                          &rte_flow_item_ipv6_mask.hdr.src_addr,
+                          IPV6_ADDR_LEN))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"ipv6.hdr.src_addr\" field");
+       }
+       return 0;
+}
+
+/**
+ * Validate RTE_FLOW_ITEM_TYPE_UDP item if VXLAN_DECAP action
+ * is present in actions list.
+ *
+ * @param[in] udp
+ *   Outer UDP layer item (if any, NULL otherwise).
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_ernno is set.
+ **/
+static int
+flow_tcf_validate_vxlan_decap_udp(const struct rte_flow_item *udp,
+                                 struct rte_flow_error *error)
+{
+       const struct rte_flow_item_udp *spec = udp->spec;
+       const struct rte_flow_item_udp *mask = udp->mask;
+
+       if (!spec)
+               /*
+                * Specification for UDP ports cannot be empty
+                * because it is required as decap parameter.
+                */
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, udp,
+                                         "NULL UDP port specification"
+                                         " for VXLAN decapsulation");
+       if (!mask)
+               mask = &rte_flow_item_udp_mask;
+       if (mask->hdr.dst_port != RTE_BE16(0x0000)) {
+               if (mask->hdr.dst_port != RTE_BE16(0xffff))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"udp.hdr.dst_port\" field");
+               if (!spec->hdr.dst_port)
+                       return rte_flow_error_set
+                                       (error, EINVAL,
+                                        RTE_FLOW_ERROR_TYPE_ITEM, udp,
+                                        "zero decap local UDP port");
+       } else {
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ITEM, udp,
+                                         "outer UDP destination port must be "
+                                         "specified for vxlan decapsulation");
+       }
+       if (mask->hdr.src_port != RTE_BE16(0x0000)) {
+               if (mask->hdr.src_port != RTE_BE16(0xffff))
+                       return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
+                                        "no support for partial mask on"
+                                        " \"udp.hdr.src_port\" field");
+               DRV_LOG(WARNING,
+                       "outer UDP local port cannot be "
+                       "forced for VXLAN encapsulation, "
+                       "parameter ignored");
+       }
+       return 0;
+}
+
 /**
  * Validate flow for E-Switch.
  *
@@ -1147,6 +1806,7 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                const struct rte_flow_item_ipv6 *ipv6;
                const struct rte_flow_item_tcp *tcp;
                const struct rte_flow_item_udp *udp;
+               const struct rte_flow_item_vxlan *vxlan;
        } spec, mask;
        union {
                const struct rte_flow_action_port_id *port_id;
@@ -1156,6 +1816,7 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                        of_set_vlan_vid;
                const struct rte_flow_action_of_set_vlan_pcp *
                        of_set_vlan_pcp;
+               const struct rte_flow_action_vxlan_encap *vxlan_encap;
                const struct rte_flow_action_set_ipv4 *set_ipv4;
                const struct rte_flow_action_set_ipv6 *set_ipv6;
        } conf;
@@ -1174,9 +1835,170 @@ flow_tcf_validate(struct rte_eth_dev *dev,
        ret = flow_tcf_validate_attributes(attr, error);
        if (ret < 0)
                return ret;
+       for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
+               unsigned int i;
+               uint64_t current_action_flag = 0;
+
+               switch (actions->type) {
+               case RTE_FLOW_ACTION_TYPE_VOID:
+                       break;
+               case RTE_FLOW_ACTION_TYPE_PORT_ID:
+                       current_action_flag = MLX5_FLOW_ACTION_PORT_ID;
+                       if (!actions->conf)
+                               break;
+                       conf.port_id = actions->conf;
+                       if (conf.port_id->original)
+                               i = 0;
+                       else
+                               for (i = 0; ptoi[i].ifindex; ++i)
+                                       if (ptoi[i].port_id == conf.port_id->id)
+                                               break;
+                       if (!ptoi[i].ifindex)
+                               return rte_flow_error_set
+                                       (error, ENODEV,
+                                        RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+                                        conf.port_id,
+                                        "missing data to convert port ID to"
+                                        " ifindex");
+                       port_id_dev = &rte_eth_devices[conf.port_id->id];
+                       break;
+               case RTE_FLOW_ACTION_TYPE_JUMP:
+                       current_action_flag = MLX5_FLOW_ACTION_JUMP;
+                       if (!actions->conf)
+                               break;
+                       conf.jump = actions->conf;
+                       if (attr->group >= conf.jump->group)
+                               return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ACTION,
+                                        actions,
+                                        "can jump only to a group forward");
+                       break;
+               case RTE_FLOW_ACTION_TYPE_DROP:
+                       current_action_flag = MLX5_FLOW_ACTION_DROP;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_COUNT:
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
+                       current_action_flag = MLX5_FLOW_ACTION_OF_POP_VLAN;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
+                       current_action_flag = MLX5_FLOW_ACTION_OF_PUSH_VLAN;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+                       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
+                               return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ACTION, actions,
+                                        "vlan modify is not supported,"
+                                        " set action must follow push action");
+                       current_action_flag = MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
+                       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
+                               return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ACTION, actions,
+                                        "vlan modify is not supported,"
+                                        " set action must follow push action");
+                       current_action_flag = MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
+                       current_action_flag = MLX5_FLOW_ACTION_VXLAN_DECAP;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+                       ret = flow_tcf_validate_vxlan_encap(actions, error);
+                       if (ret < 0)
+                               return ret;
+                       current_action_flag = MLX5_FLOW_ACTION_VXLAN_ENCAP;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV4_SRC;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV4_DST;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV6_SRC;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV6_DST;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_TP_SRC;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_SET_TTL:
+                       current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+                       break;
+               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,
+                                                 actions,
+                                                 "action not supported");
+               }
+               if (current_action_flag & MLX5_TCF_CONFIG_ACTIONS) {
+                       if (!actions->conf)
+                               return rte_flow_error_set
+                                       (error, EINVAL,
+                                        RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+                                        actions,
+                                        "action configuration not set");
+               }
+               if ((current_action_flag & MLX5_TCF_PEDIT_ACTIONS) &&
+                   pedit_validated)
+                       return rte_flow_error_set(error, ENOTSUP,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 actions,
+                                                 "set actions should be "
+                                                 "listed successively");
+               if ((current_action_flag & ~MLX5_TCF_PEDIT_ACTIONS) &&
+                   (action_flags & MLX5_TCF_PEDIT_ACTIONS))
+                       pedit_validated = 1;
+               if ((current_action_flag & MLX5_TCF_FATE_ACTIONS) &&
+                   (action_flags & MLX5_TCF_FATE_ACTIONS))
+                       return rte_flow_error_set(error, EINVAL,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 actions,
+                                                 "can't have multiple fate"
+                                                 " actions");
+               if ((current_action_flag & MLX5_TCF_VXLAN_ACTIONS) &&
+                   (action_flags & MLX5_TCF_VXLAN_ACTIONS))
+                       return rte_flow_error_set(error, EINVAL,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 actions,
+                                                 "can't have multiple vxlan"
+                                                 " actions");
+               if ((current_action_flag & MLX5_TCF_VXLAN_ACTIONS) &&
+                   (action_flags & MLX5_TCF_VLAN_ACTIONS))
+                       return rte_flow_error_set(error, ENOTSUP,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 actions,
+                                                 "can't have vxlan and vlan"
+                                                 " actions in the same rule");
+               action_flags |= current_action_flag;
+       }
        for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
                unsigned int i;
 
+               if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
+                   items->type != RTE_FLOW_ITEM_TYPE_ETH)
+                       return rte_flow_error_set(error, ENOTSUP,
+                                                 RTE_FLOW_ERROR_TYPE_ITEM,
+                                                 items,
+                                                 "only L2 inner item"
+                                                 " is supported");
                switch (items->type) {
                case RTE_FLOW_ITEM_TYPE_VOID:
                        break;
@@ -1230,7 +2052,9 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                                          error);
                        if (ret < 0)
                                return ret;
-                       item_flags |= MLX5_FLOW_LAYER_OUTER_L2;
+                       item_flags |= (item_flags & MLX5_FLOW_LAYER_TUNNEL) ?
+                                       MLX5_FLOW_LAYER_INNER_L2 :
+                                       MLX5_FLOW_LAYER_OUTER_L2;
                        /* TODO:
                         * Redundant check due to different supported mask.
                         * Same for the rest of items.
@@ -1308,6 +2132,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                next_protocol =
                                        ((const struct rte_flow_item_ipv4 *)
                                         (items->spec))->hdr.next_proto_id;
+                       if (action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP) {
+                               ret = flow_tcf_validate_vxlan_decap_ipv4
+                                                               (items, error);
+                               if (ret < 0)
+                                       return ret;
+                       }
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV6:
                        ret = mlx5_flow_validate_item_ipv6(items, item_flags,
@@ -1335,6 +2165,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                next_protocol =
                                        ((const struct rte_flow_item_ipv6 *)
                                         (items->spec))->hdr.proto;
+                       if (action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP) {
+                               ret = flow_tcf_validate_vxlan_decap_ipv6
+                                                               (items, error);
+                               if (ret < 0)
+                                       return ret;
+                       }
                        break;
                case RTE_FLOW_ITEM_TYPE_UDP:
                        ret = mlx5_flow_validate_item_udp(items, item_flags,
@@ -1350,6 +2186,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                 error);
                        if (!mask.udp)
                                return -rte_errno;
+                       if (action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP) {
+                               ret = flow_tcf_validate_vxlan_decap_udp
+                                                               (items, error);
+                               if (ret < 0)
+                                       return ret;
+                       }
                        break;
                case RTE_FLOW_ITEM_TYPE_TCP:
                        ret = mlx5_flow_validate_item_tcp
@@ -1364,146 +2206,46 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                (items, &rte_flow_item_tcp_mask,
                                 &flow_tcf_mask_supported.tcp,
                                 &flow_tcf_mask_empty.tcp,
-                                sizeof(flow_tcf_mask_supported.tcp),
-                                error);
-                       if (!mask.tcp)
-                               return -rte_errno;
-                       break;
-               default:
-                       return rte_flow_error_set(error, ENOTSUP,
-                                                 RTE_FLOW_ERROR_TYPE_ITEM,
-                                                 NULL, "item not supported");
-               }
-       }
-       for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
-               unsigned int i;
-               uint64_t current_action_flag = 0;
-
-               switch (actions->type) {
-               case RTE_FLOW_ACTION_TYPE_VOID:
-                       break;
-               case RTE_FLOW_ACTION_TYPE_PORT_ID:
-                       current_action_flag = MLX5_FLOW_ACTION_PORT_ID;
-                       if (!actions->conf)
-                               break;
-                       conf.port_id = actions->conf;
-                       if (conf.port_id->original)
-                               i = 0;
-                       else
-                               for (i = 0; ptoi[i].ifindex; ++i)
-                                       if (ptoi[i].port_id == conf.port_id->id)
-                                               break;
-                       if (!ptoi[i].ifindex)
-                               return rte_flow_error_set
-                                       (error, ENODEV,
-                                        RTE_FLOW_ERROR_TYPE_ACTION_CONF,
-                                        conf.port_id,
-                                        "missing data to convert port ID to"
-                                        " ifindex");
-                       port_id_dev = &rte_eth_devices[conf.port_id->id];
-                       break;
-               case RTE_FLOW_ACTION_TYPE_JUMP:
-                       current_action_flag = MLX5_FLOW_ACTION_JUMP;
-                       if (!actions->conf)
-                               break;
-                       conf.jump = actions->conf;
-                       if (attr->group >= conf.jump->group)
-                               return rte_flow_error_set
-                                       (error, ENOTSUP,
-                                        RTE_FLOW_ERROR_TYPE_ACTION,
-                                        actions,
-                                        "can jump only to a group forward");
-                       break;
-               case RTE_FLOW_ACTION_TYPE_DROP:
-                       current_action_flag = MLX5_FLOW_ACTION_DROP;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_COUNT:
-                       break;
-               case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
-                       current_action_flag = MLX5_FLOW_ACTION_OF_POP_VLAN;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
-                       current_action_flag = MLX5_FLOW_ACTION_OF_PUSH_VLAN;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
-                       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
-                               return rte_flow_error_set
-                                       (error, ENOTSUP,
-                                        RTE_FLOW_ERROR_TYPE_ACTION, actions,
-                                        "vlan modify is not supported,"
-                                        " set action must follow push action");
-                       current_action_flag = MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
-                       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
-                               return rte_flow_error_set
-                                       (error, ENOTSUP,
-                                        RTE_FLOW_ERROR_TYPE_ACTION, actions,
-                                        "vlan modify is not supported,"
-                                        " set action must follow push action");
-                       current_action_flag = MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV4_SRC;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV4_DST;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV6_SRC;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_IPV6_DST;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_TP_SRC;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
-                       break;
-               case RTE_FLOW_ACTION_TYPE_SET_TTL:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
-                       break;
-               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;
+                                sizeof(flow_tcf_mask_supported.tcp),
+                                error);
+                       if (!mask.tcp)
+                               return -rte_errno;
                        break;
-               case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
-                       current_action_flag = MLX5_FLOW_ACTION_SET_MAC_DST;
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       if (!(action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP))
+                               return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM,
+                                        items,
+                                        "vni pattern should be followed by"
+                                        " vxlan decapsulation action");
+                       ret = mlx5_flow_validate_item_vxlan(items,
+                                                           item_flags, error);
+                       if (ret < 0)
+                               return ret;
+                       item_flags |= MLX5_FLOW_LAYER_VXLAN;
+                       mask.vxlan = flow_tcf_item_mask
+                               (items, &rte_flow_item_vxlan_mask,
+                                &flow_tcf_mask_supported.vxlan,
+                                &flow_tcf_mask_empty.vxlan,
+                                sizeof(flow_tcf_mask_supported.vxlan), error);
+                       if (!mask.vxlan)
+                               return -rte_errno;
+                       if (mask.vxlan->vni[0] != 0xff ||
+                           mask.vxlan->vni[1] != 0xff ||
+                           mask.vxlan->vni[2] != 0xff)
+                               return rte_flow_error_set
+                                       (error, ENOTSUP,
+                                        RTE_FLOW_ERROR_TYPE_ITEM_MASK,
+                                        mask.vxlan,
+                                        "no support for partial or "
+                                        "empty mask on \"vxlan.vni\" field");
                        break;
                default:
                        return rte_flow_error_set(error, ENOTSUP,
-                                                 RTE_FLOW_ERROR_TYPE_ACTION,
-                                                 actions,
-                                                 "action not supported");
-               }
-               if (current_action_flag & MLX5_TCF_CONFIG_ACTIONS) {
-                       if (!actions->conf)
-                               return rte_flow_error_set(error, EINVAL,
-                                               RTE_FLOW_ERROR_TYPE_ACTION_CONF,
-                                               actions,
-                                               "action configuration not set");
+                                                 RTE_FLOW_ERROR_TYPE_ITEM,
+                                                 items, "item not supported");
                }
-               if ((current_action_flag & MLX5_TCF_PEDIT_ACTIONS) &&
-                   pedit_validated)
-                       return rte_flow_error_set(error, ENOTSUP,
-                                                 RTE_FLOW_ERROR_TYPE_ACTION,
-                                                 actions,
-                                                 "set actions should be "
-                                                 "listed successively");
-               if ((current_action_flag & ~MLX5_TCF_PEDIT_ACTIONS) &&
-                   (action_flags & MLX5_TCF_PEDIT_ACTIONS))
-                       pedit_validated = 1;
-               if ((current_action_flag & MLX5_TCF_FATE_ACTIONS) &&
-                   (action_flags & MLX5_TCF_FATE_ACTIONS))
-                       return rte_flow_error_set(error, EINVAL,
-                                                 RTE_FLOW_ERROR_TYPE_ACTION,
-                                                 actions,
-                                                 "can't have multiple fate"
-                                                 " actions");
-               action_flags |= current_action_flag;
        }
        if ((action_flags & MLX5_TCF_PEDIT_ACTIONS) &&
            (action_flags & MLX5_FLOW_ACTION_DROP))
@@ -1571,6 +2313,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                          RTE_FLOW_ERROR_TYPE_ACTION, actions,
                                          "vlan actions are supported"
                                          " only with port_id action");
+       if ((action_flags & MLX5_TCF_VXLAN_ACTIONS) &&
+           !(action_flags & MLX5_FLOW_ACTION_PORT_ID))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+                                         "vxlan actions are supported"
+                                         " only with port_id action");
        if (!(action_flags & MLX5_TCF_FATE_ACTIONS))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, actions,
@@ -1594,6 +2342,28 @@ flow_tcf_validate(struct rte_eth_dev *dev,
                                                  "no ethernet found in"
                                                  " pattern");
        }
+       if (action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP) {
+               if (!(item_flags &
+                    (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+                     MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+                       return rte_flow_error_set(error, EINVAL,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 NULL,
+                                                 "no outer IP pattern found"
+                                                 " for vxlan decap action");
+               if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
+                       return rte_flow_error_set(error, EINVAL,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 NULL,
+                                                 "no outer UDP pattern found"
+                                                 " for vxlan decap action");
+               if (!(item_flags & MLX5_FLOW_LAYER_VXLAN))
+                       return rte_flow_error_set(error, EINVAL,
+                                                 RTE_FLOW_ERROR_TYPE_ACTION,
+                                                 NULL,
+                                                 "no VNI pattern found"
+                                                 " for vxlan decap action");
+       }
        return 0;
 }
 
@@ -1652,7 +2422,7 @@ flow_tcf_get_items_and_size(const struct rte_flow_attr *attr,
                case RTE_FLOW_ITEM_TYPE_IPV6:
                        size += SZ_NLATTR_TYPE_OF(uint16_t) + /* Ether type. */
                                SZ_NLATTR_TYPE_OF(uint8_t) + /* IP proto. */
-                               SZ_NLATTR_TYPE_OF(IPV6_ADDR_LEN) * 4;
+                               SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) * 4;
                                /* dst/src IP addr and mask. */
                        flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
                        break;
@@ -1668,6 +2438,10 @@ flow_tcf_get_items_and_size(const struct rte_flow_attr *attr,
                                /* dst/src port and mask. */
                        flags |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
                        break;
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       size += SZ_NLATTR_TYPE_OF(uint32_t);
+                       flags |= MLX5_FLOW_LAYER_VXLAN;
+                       break;
                default:
                        DRV_LOG(WARNING,
                                "unsupported item %p type %d,"
@@ -1680,6 +2454,69 @@ flow_tcf_get_items_and_size(const struct rte_flow_attr *attr,
        return size;
 }
 
+/**
+ * Calculate size of memory to store the VXLAN encapsultion
+ * related items in the Netlink message buffer. Items list
+ * is specified by RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP action.
+ * The item list should be validated.
+ *
+ * @param[in] action
+ *   RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP action object.
+ *   List of pattern items to scan data from.
+ *
+ * @return
+ *   The size the part of Netlink message buffer to store the
+ *   VXLAN encapsulation item attributes.
+ */
+static int
+flow_tcf_vxlan_encap_size(const struct rte_flow_action *action)
+{
+       const struct rte_flow_item *items;
+       int size = 0;
+
+       assert(action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP);
+       assert(action->conf);
+
+       items = ((const struct rte_flow_action_vxlan_encap *)
+                                       action->conf)->definition;
+       assert(items);
+       for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
+               switch (items->type) {
+               case RTE_FLOW_ITEM_TYPE_VOID:
+                       break;
+               case RTE_FLOW_ITEM_TYPE_ETH:
+                       /* This item does not require message buffer. */
+                       break;
+               case RTE_FLOW_ITEM_TYPE_IPV4:
+                       size += SZ_NLATTR_DATA_OF(IPV4_ADDR_LEN) * 2;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_IPV6:
+                       size += SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) * 2;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_UDP: {
+                       const struct rte_flow_item_udp *udp = items->mask;
+
+                       size += SZ_NLATTR_TYPE_OF(uint16_t);
+                       if (!udp || udp->hdr.src_port != RTE_BE16(0x0000))
+                               size += SZ_NLATTR_TYPE_OF(uint16_t);
+                       break;
+               }
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       size += SZ_NLATTR_TYPE_OF(uint32_t);
+                       break;
+               default:
+                       assert(false);
+                       DRV_LOG(WARNING,
+                               "unsupported item %p type %d,"
+                               " items must be validated"
+                               " before flow creation",
+                               (const void *)items, items->type);
+                       return 0;
+               }
+       }
+       return size;
+}
+
 /**
  * Calculate maximum size of memory for flow actions of Linux TC flower and
  * extract specified actions.
@@ -1749,6 +2586,29 @@ action_of_vlan:
                                SZ_NLATTR_TYPE_OF(uint16_t) + /* VLAN ID. */
                                SZ_NLATTR_TYPE_OF(uint8_t); /* VLAN prio. */
                        break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+                       size += SZ_NLATTR_NEST + /* na_act_index. */
+                               SZ_NLATTR_STRZ_OF("tunnel_key") +
+                               SZ_NLATTR_NEST + /* TCA_ACT_OPTIONS. */
+                               SZ_NLATTR_TYPE_OF(uint8_t);
+                       size += SZ_NLATTR_TYPE_OF(struct tc_tunnel_key);
+                       size += flow_tcf_vxlan_encap_size(actions) +
+                               RTE_ALIGN_CEIL /* preceding encap params. */
+                               (sizeof(struct flow_tcf_vxlan_encap),
+                               MNL_ALIGNTO);
+                       flags |= MLX5_FLOW_ACTION_VXLAN_ENCAP;
+                       break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
+                       size += SZ_NLATTR_NEST + /* na_act_index. */
+                               SZ_NLATTR_STRZ_OF("tunnel_key") +
+                               SZ_NLATTR_NEST + /* TCA_ACT_OPTIONS. */
+                               SZ_NLATTR_TYPE_OF(uint8_t);
+                       size += SZ_NLATTR_TYPE_OF(struct tc_tunnel_key);
+                       size += RTE_ALIGN_CEIL /* preceding decap params. */
+                               (sizeof(struct flow_tcf_vxlan_decap),
+                               MNL_ALIGNTO);
+                       flags |= MLX5_FLOW_ACTION_VXLAN_DECAP;
+                       break;
                case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
                case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
                case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
@@ -1824,12 +2684,15 @@ flow_tcf_prepare(const struct rte_flow_attr *attr,
                 uint64_t *item_flags, uint64_t *action_flags,
                 struct rte_flow_error *error)
 {
-       size_t size = sizeof(struct mlx5_flow) +
+       size_t size = RTE_ALIGN_CEIL
+                       (sizeof(struct mlx5_flow),
+                        alignof(struct flow_tcf_tunnel_hdr)) +
                      MNL_ALIGN(sizeof(struct nlmsghdr)) +
                      MNL_ALIGN(sizeof(struct tcmsg));
        struct mlx5_flow *dev_flow;
        struct nlmsghdr *nlh;
        struct tcmsg *tcm;
+       uint8_t *sp, *tun = NULL;
 
        size += flow_tcf_get_items_and_size(attr, items, item_flags);
        size += flow_tcf_get_actions_and_size(actions, action_flags);
@@ -1840,14 +2703,52 @@ flow_tcf_prepare(const struct rte_flow_attr *attr,
                                   "not enough memory to create E-Switch flow");
                return NULL;
        }
-       nlh = mnl_nlmsg_put_header((void *)(dev_flow + 1));
+       sp = (uint8_t *)(dev_flow + 1);
+       if (*action_flags & MLX5_FLOW_ACTION_VXLAN_ENCAP) {
+               sp = RTE_PTR_ALIGN
+                       (sp, alignof(struct flow_tcf_tunnel_hdr));
+               tun = sp;
+               sp += RTE_ALIGN_CEIL
+                       (sizeof(struct flow_tcf_vxlan_encap),
+                       MNL_ALIGNTO);
+#ifndef NDEBUG
+               size -= RTE_ALIGN_CEIL
+                       (sizeof(struct flow_tcf_vxlan_encap),
+                       MNL_ALIGNTO);
+#endif
+       } else if (*action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP) {
+               sp = RTE_PTR_ALIGN
+                       (sp, alignof(struct flow_tcf_tunnel_hdr));
+               tun = sp;
+               sp += RTE_ALIGN_CEIL
+                       (sizeof(struct flow_tcf_vxlan_decap),
+                       MNL_ALIGNTO);
+#ifndef NDEBUG
+               size -= RTE_ALIGN_CEIL
+                       (sizeof(struct flow_tcf_vxlan_decap),
+                       MNL_ALIGNTO);
+#endif
+       } else {
+               sp = RTE_PTR_ALIGN(sp, MNL_ALIGNTO);
+       }
+       nlh = mnl_nlmsg_put_header(sp);
        tcm = mnl_nlmsg_put_extra_header(nlh, sizeof(*tcm));
        *dev_flow = (struct mlx5_flow){
                .tcf = (struct mlx5_flow_tcf){
+#ifndef NDEBUG
+                       .nlsize = size - RTE_ALIGN_CEIL
+                               (sizeof(struct mlx5_flow),
+                                alignof(struct flow_tcf_tunnel_hdr)),
+#endif
+                       .tunnel = (struct flow_tcf_tunnel_hdr *)tun,
                        .nlh = nlh,
                        .tcm = tcm,
                },
        };
+       if (*action_flags & MLX5_FLOW_ACTION_VXLAN_DECAP)
+               dev_flow->tcf.tunnel->type = FLOW_TCF_TUNACT_VXLAN_DECAP;
+       else if (*action_flags & MLX5_FLOW_ACTION_VXLAN_ENCAP)
+               dev_flow->tcf.tunnel->type = FLOW_TCF_TUNACT_VXLAN_ENCAP;
        /*
         * Generate a reasonably unique handle based on the address of the
         * target buffer.
@@ -1897,6 +2798,241 @@ flow_tcf_translate_action_count(struct rte_eth_dev *dev __rte_unused,
        return 0;
 }
 
+/**
+ * Convert VXLAN VNI to 32-bit integer.
+ *
+ * @param[in] vni
+ *   VXLAN VNI in 24-bit wire format.
+ *
+ * @return
+ *   VXLAN VNI as a 32-bit integer value in network endian.
+ */
+static inline rte_be32_t
+vxlan_vni_as_be32(const uint8_t vni[3])
+{
+       union {
+               uint8_t vni[4];
+               rte_be32_t dword;
+       } ret = {
+               .vni = { 0, vni[0], vni[1], vni[2] },
+       };
+       return ret.dword;
+}
+
+/**
+ * Helper function to process RTE_FLOW_ITEM_TYPE_ETH entry in configuration
+ * of action RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. Fills the MAC address fields
+ * in the encapsulation parameters structure. The item must be prevalidated,
+ * no any validation checks performed by function.
+ *
+ * @param[in] spec
+ *   RTE_FLOW_ITEM_TYPE_ETH entry specification.
+ * @param[in] mask
+ *   RTE_FLOW_ITEM_TYPE_ETH entry mask.
+ * @param[out] encap
+ *   Structure to fill the gathered MAC address data.
+ */
+static void
+flow_tcf_parse_vxlan_encap_eth(const struct rte_flow_item_eth *spec,
+                              const struct rte_flow_item_eth *mask,
+                              struct flow_tcf_vxlan_encap *encap)
+{
+       /* Item must be validated before. No redundant checks. */
+       assert(spec);
+       if (!mask || !memcmp(&mask->dst,
+                            &rte_flow_item_eth_mask.dst,
+                            sizeof(rte_flow_item_eth_mask.dst))) {
+               /*
+                * Ethernet addresses are not supported by
+                * tc as tunnel_key parameters. Destination
+                * address is needed to form encap packet
+                * header and retrieved by kernel from
+                * implicit sources (ARP table, etc),
+                * address masks are not supported at all.
+                */
+               encap->eth.dst = spec->dst;
+               encap->mask |= FLOW_TCF_ENCAP_ETH_DST;
+       }
+       if (!mask || !memcmp(&mask->src,
+                            &rte_flow_item_eth_mask.src,
+                            sizeof(rte_flow_item_eth_mask.src))) {
+               /*
+                * Ethernet addresses are not supported by
+                * tc as tunnel_key parameters. Source ethernet
+                * address is ignored anyway.
+                */
+               encap->eth.src = spec->src;
+               encap->mask |= FLOW_TCF_ENCAP_ETH_SRC;
+       }
+}
+
+/**
+ * Helper function to process RTE_FLOW_ITEM_TYPE_IPV4 entry in configuration
+ * of action RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. Fills the IPV4 address fields
+ * in the encapsulation parameters structure. The item must be prevalidated,
+ * no any validation checks performed by function.
+ *
+ * @param[in] spec
+ *   RTE_FLOW_ITEM_TYPE_IPV4 entry specification.
+ * @param[out] encap
+ *   Structure to fill the gathered IPV4 address data.
+ */
+static void
+flow_tcf_parse_vxlan_encap_ipv4(const struct rte_flow_item_ipv4 *spec,
+                               struct flow_tcf_vxlan_encap *encap)
+{
+       /* Item must be validated before. No redundant checks. */
+       assert(spec);
+       encap->ipv4.dst = spec->hdr.dst_addr;
+       encap->ipv4.src = spec->hdr.src_addr;
+       encap->mask |= FLOW_TCF_ENCAP_IPV4_SRC |
+                      FLOW_TCF_ENCAP_IPV4_DST;
+}
+
+/**
+ * Helper function to process RTE_FLOW_ITEM_TYPE_IPV6 entry in configuration
+ * of action RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. Fills the IPV6 address fields
+ * in the encapsulation parameters structure. The item must be prevalidated,
+ * no any validation checks performed by function.
+ *
+ * @param[in] spec
+ *   RTE_FLOW_ITEM_TYPE_IPV6 entry specification.
+ * @param[out] encap
+ *   Structure to fill the gathered IPV6 address data.
+ */
+static void
+flow_tcf_parse_vxlan_encap_ipv6(const struct rte_flow_item_ipv6 *spec,
+                               struct flow_tcf_vxlan_encap *encap)
+{
+       /* Item must be validated before. No redundant checks. */
+       assert(spec);
+       memcpy(encap->ipv6.dst, spec->hdr.dst_addr, IPV6_ADDR_LEN);
+       memcpy(encap->ipv6.src, spec->hdr.src_addr, IPV6_ADDR_LEN);
+       encap->mask |= FLOW_TCF_ENCAP_IPV6_SRC |
+                      FLOW_TCF_ENCAP_IPV6_DST;
+}
+
+/**
+ * Helper function to process RTE_FLOW_ITEM_TYPE_UDP entry in configuration
+ * of action RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. Fills the UDP port fields
+ * in the encapsulation parameters structure. The item must be prevalidated,
+ * no any validation checks performed by function.
+ *
+ * @param[in] spec
+ *   RTE_FLOW_ITEM_TYPE_UDP entry specification.
+ * @param[in] mask
+ *   RTE_FLOW_ITEM_TYPE_UDP entry mask.
+ * @param[out] encap
+ *   Structure to fill the gathered UDP port data.
+ */
+static void
+flow_tcf_parse_vxlan_encap_udp(const struct rte_flow_item_udp *spec,
+                              const struct rte_flow_item_udp *mask,
+                              struct flow_tcf_vxlan_encap *encap)
+{
+       assert(spec);
+       encap->udp.dst = spec->hdr.dst_port;
+       encap->mask |= FLOW_TCF_ENCAP_UDP_DST;
+       if (!mask || mask->hdr.src_port != RTE_BE16(0x0000)) {
+               encap->udp.src = spec->hdr.src_port;
+               encap->mask |= FLOW_TCF_ENCAP_IPV4_SRC;
+       }
+}
+
+/**
+ * Helper function to process RTE_FLOW_ITEM_TYPE_VXLAN entry in configuration
+ * of action RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. Fills the VNI fields
+ * in the encapsulation parameters structure. The item must be prevalidated,
+ * no any validation checks performed by function.
+ *
+ * @param[in] spec
+ *   RTE_FLOW_ITEM_TYPE_VXLAN entry specification.
+ * @param[out] encap
+ *   Structure to fill the gathered VNI address data.
+ */
+static void
+flow_tcf_parse_vxlan_encap_vni(const struct rte_flow_item_vxlan *spec,
+                              struct flow_tcf_vxlan_encap *encap)
+{
+       /* Item must be validated before. Do not redundant checks. */
+       assert(spec);
+       memcpy(encap->vxlan.vni, spec->vni, sizeof(encap->vxlan.vni));
+       encap->mask |= FLOW_TCF_ENCAP_VXLAN_VNI;
+}
+
+/**
+ * Populate consolidated encapsulation object from list of pattern items.
+ *
+ * Helper function to process configuration of action such as
+ * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP. The item list should be
+ * validated, there is no way to return an meaningful error.
+ *
+ * @param[in] action
+ *   RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP action object.
+ *   List of pattern items to gather data from.
+ * @param[out] src
+ *   Structure to fill gathered data.
+ */
+static void
+flow_tcf_vxlan_encap_parse(const struct rte_flow_action *action,
+                          struct flow_tcf_vxlan_encap *encap)
+{
+       union {
+               const struct rte_flow_item_eth *eth;
+               const struct rte_flow_item_ipv4 *ipv4;
+               const struct rte_flow_item_ipv6 *ipv6;
+               const struct rte_flow_item_udp *udp;
+               const struct rte_flow_item_vxlan *vxlan;
+       } spec, mask;
+       const struct rte_flow_item *items;
+
+       assert(action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP);
+       assert(action->conf);
+
+       items = ((const struct rte_flow_action_vxlan_encap *)
+                                       action->conf)->definition;
+       assert(items);
+       for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
+               switch (items->type) {
+               case RTE_FLOW_ITEM_TYPE_VOID:
+                       break;
+               case RTE_FLOW_ITEM_TYPE_ETH:
+                       mask.eth = items->mask;
+                       spec.eth = items->spec;
+                       flow_tcf_parse_vxlan_encap_eth(spec.eth, mask.eth,
+                                                      encap);
+                       break;
+               case RTE_FLOW_ITEM_TYPE_IPV4:
+                       spec.ipv4 = items->spec;
+                       flow_tcf_parse_vxlan_encap_ipv4(spec.ipv4, encap);
+                       break;
+               case RTE_FLOW_ITEM_TYPE_IPV6:
+                       spec.ipv6 = items->spec;
+                       flow_tcf_parse_vxlan_encap_ipv6(spec.ipv6, encap);
+                       break;
+               case RTE_FLOW_ITEM_TYPE_UDP:
+                       mask.udp = items->mask;
+                       spec.udp = items->spec;
+                       flow_tcf_parse_vxlan_encap_udp(spec.udp, mask.udp,
+                                                      encap);
+                       break;
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       spec.vxlan = items->spec;
+                       flow_tcf_parse_vxlan_encap_vni(spec.vxlan, encap);
+                       break;
+               default:
+                       assert(false);
+                       DRV_LOG(WARNING,
+                               "unsupported item %p type %d,"
+                               " items must be validated"
+                               " before flow creation",
+                               (const void *)items, items->type);
+                       encap->mask = 0;
+                       return;
+               }
+       }
+}
+
 /**
  * Translate flow for Linux TC flower and construct Netlink message.
  *
@@ -1931,6 +3067,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                const struct rte_flow_item_ipv6 *ipv6;
                const struct rte_flow_item_tcp *tcp;
                const struct rte_flow_item_udp *udp;
+               const struct rte_flow_item_vxlan *vxlan;
        } spec, mask;
        union {
                const struct rte_flow_action_port_id *port_id;
@@ -1941,6 +3078,18 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                const struct rte_flow_action_of_set_vlan_pcp *
                        of_set_vlan_pcp;
        } conf;
+       union {
+               struct flow_tcf_tunnel_hdr *hdr;
+               struct flow_tcf_vxlan_decap *vxlan;
+       } decap = {
+               .hdr = NULL,
+       };
+       union {
+               struct flow_tcf_tunnel_hdr *hdr;
+               struct flow_tcf_vxlan_encap *vxlan;
+       } encap = {
+               .hdr = NULL,
+       };
        struct flow_tcf_ptoi ptoi[PTOI_TABLE_SZ_MAX(dev)];
        struct nlmsghdr *nlh = dev_flow->tcf.nlh;
        struct tcmsg *tcm = dev_flow->tcf.tcm;
@@ -1958,6 +3107,20 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 
        claim_nonzero(flow_tcf_build_ptoi_table(dev, ptoi,
                                                PTOI_TABLE_SZ_MAX(dev)));
+       if (dev_flow->tcf.tunnel) {
+               switch (dev_flow->tcf.tunnel->type) {
+               case FLOW_TCF_TUNACT_VXLAN_DECAP:
+                       decap.vxlan = dev_flow->tcf.vxlan_decap;
+                       break;
+               case FLOW_TCF_TUNACT_VXLAN_ENCAP:
+                       encap.vxlan = dev_flow->tcf.vxlan_encap;
+                       break;
+               /* New tunnel actions can be added here. */
+               default:
+                       assert(false);
+                       break;
+               }
+       }
        nlh = dev_flow->tcf.nlh;
        tcm = dev_flow->tcf.tcm;
        /* Prepare API must have been called beforehand. */
@@ -1975,7 +3138,6 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                mnl_attr_put_u32(nlh, TCA_CHAIN, attr->group);
        mnl_attr_put_strz(nlh, TCA_KIND, "flower");
        na_flower = mnl_attr_nest_start(nlh, TCA_OPTIONS);
-       mnl_attr_put_u32(nlh, TCA_FLOWER_FLAGS, TCA_CLS_FLAGS_SKIP_SW);
        for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
                unsigned int i;
 
@@ -2003,7 +3165,9 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                        tcm->tcm_ifindex = ptoi[i].ifindex;
                        break;
                case RTE_FLOW_ITEM_TYPE_ETH:
-                       item_flags |= MLX5_FLOW_LAYER_OUTER_L2;
+                       item_flags |= (item_flags & MLX5_FLOW_LAYER_VXLAN) ?
+                                     MLX5_FLOW_LAYER_INNER_L2 :
+                                     MLX5_FLOW_LAYER_OUTER_L2;
                        mask.eth = flow_tcf_item_mask
                                (items, &rte_flow_item_eth_mask,
                                 &flow_tcf_mask_supported.eth,
@@ -2014,6 +3178,14 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                        if (mask.eth == &flow_tcf_mask_empty.eth)
                                break;
                        spec.eth = items->spec;
+                       if (decap.vxlan &&
+                           !(item_flags & MLX5_FLOW_LAYER_VXLAN)) {
+                               DRV_LOG(WARNING,
+                                       "outer L2 addresses cannot be forced"
+                                       " for vxlan decapsulation, parameter"
+                                       " ignored");
+                               break;
+                       }
                        if (mask.eth->type) {
                                mnl_attr_put_u16(nlh, TCA_FLOWER_KEY_ETH_TYPE,
                                                 spec.eth->type);
@@ -2035,8 +3207,11 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                             ETHER_ADDR_LEN,
                                             mask.eth->src.addr_bytes);
                        }
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                case RTE_FLOW_ITEM_TYPE_VLAN:
+                       assert(!encap.hdr);
+                       assert(!decap.hdr);
                        item_flags |= MLX5_FLOW_LAYER_OUTER_VLAN;
                        mask.vlan = flow_tcf_item_mask
                                (items, &rte_flow_item_vlan_mask,
@@ -2068,6 +3243,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                                 rte_be_to_cpu_16
                                                 (spec.vlan->tci &
                                                  RTE_BE16(0x0fff)));
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV4:
                        item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
@@ -2078,36 +3254,53 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                 sizeof(flow_tcf_mask_supported.ipv4),
                                 error);
                        assert(mask.ipv4);
-                       if (!eth_type_set || !vlan_eth_type_set)
-                               mnl_attr_put_u16(nlh,
+                       spec.ipv4 = items->spec;
+                       if (!decap.vxlan) {
+                               if (!eth_type_set && !vlan_eth_type_set)
+                                       mnl_attr_put_u16
+                                               (nlh,
                                                 vlan_present ?
                                                 TCA_FLOWER_KEY_VLAN_ETH_TYPE :
                                                 TCA_FLOWER_KEY_ETH_TYPE,
                                                 RTE_BE16(ETH_P_IP));
-                       eth_type_set = 1;
-                       vlan_eth_type_set = 1;
-                       if (mask.ipv4 == &flow_tcf_mask_empty.ipv4)
-                               break;
-                       spec.ipv4 = items->spec;
-                       if (mask.ipv4->hdr.next_proto_id) {
-                               mnl_attr_put_u8(nlh, TCA_FLOWER_KEY_IP_PROTO,
-                                               spec.ipv4->hdr.next_proto_id);
-                               ip_proto_set = 1;
+                               eth_type_set = 1;
+                               vlan_eth_type_set = 1;
+                               if (mask.ipv4 == &flow_tcf_mask_empty.ipv4)
+                                       break;
+                               if (mask.ipv4->hdr.next_proto_id) {
+                                       mnl_attr_put_u8
+                                               (nlh, TCA_FLOWER_KEY_IP_PROTO,
+                                                spec.ipv4->hdr.next_proto_id);
+                                       ip_proto_set = 1;
+                               }
+                       } else {
+                               assert(mask.ipv4 != &flow_tcf_mask_empty.ipv4);
                        }
                        if (mask.ipv4->hdr.src_addr) {
-                               mnl_attr_put_u32(nlh, TCA_FLOWER_KEY_IPV4_SRC,
-                                                spec.ipv4->hdr.src_addr);
-                               mnl_attr_put_u32(nlh,
-                                                TCA_FLOWER_KEY_IPV4_SRC_MASK,
-                                                mask.ipv4->hdr.src_addr);
+                               mnl_attr_put_u32
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_IPV4_SRC :
+                                        TCA_FLOWER_KEY_IPV4_SRC,
+                                        spec.ipv4->hdr.src_addr);
+                               mnl_attr_put_u32
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK :
+                                        TCA_FLOWER_KEY_IPV4_SRC_MASK,
+                                        mask.ipv4->hdr.src_addr);
                        }
                        if (mask.ipv4->hdr.dst_addr) {
-                               mnl_attr_put_u32(nlh, TCA_FLOWER_KEY_IPV4_DST,
-                                                spec.ipv4->hdr.dst_addr);
-                               mnl_attr_put_u32(nlh,
-                                                TCA_FLOWER_KEY_IPV4_DST_MASK,
-                                                mask.ipv4->hdr.dst_addr);
+                               mnl_attr_put_u32
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_IPV4_DST :
+                                        TCA_FLOWER_KEY_IPV4_DST,
+                                        spec.ipv4->hdr.dst_addr);
+                               mnl_attr_put_u32
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_IPV4_DST_MASK :
+                                        TCA_FLOWER_KEY_IPV4_DST_MASK,
+                                        mask.ipv4->hdr.dst_addr);
                        }
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV6:
                        item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
@@ -2118,38 +3311,54 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                 sizeof(flow_tcf_mask_supported.ipv6),
                                 error);
                        assert(mask.ipv6);
-                       if (!eth_type_set || !vlan_eth_type_set)
-                               mnl_attr_put_u16(nlh,
+                       spec.ipv6 = items->spec;
+                       if (!decap.vxlan) {
+                               if (!eth_type_set || !vlan_eth_type_set) {
+                                       mnl_attr_put_u16
+                                               (nlh,
                                                 vlan_present ?
                                                 TCA_FLOWER_KEY_VLAN_ETH_TYPE :
                                                 TCA_FLOWER_KEY_ETH_TYPE,
                                                 RTE_BE16(ETH_P_IPV6));
-                       eth_type_set = 1;
-                       vlan_eth_type_set = 1;
-                       if (mask.ipv6 == &flow_tcf_mask_empty.ipv6)
-                               break;
-                       spec.ipv6 = items->spec;
-                       if (mask.ipv6->hdr.proto) {
-                               mnl_attr_put_u8(nlh, TCA_FLOWER_KEY_IP_PROTO,
-                                               spec.ipv6->hdr.proto);
-                               ip_proto_set = 1;
+                               }
+                               eth_type_set = 1;
+                               vlan_eth_type_set = 1;
+                               if (mask.ipv6 == &flow_tcf_mask_empty.ipv6)
+                                       break;
+                               if (mask.ipv6->hdr.proto) {
+                                       mnl_attr_put_u8
+                                               (nlh, TCA_FLOWER_KEY_IP_PROTO,
+                                                spec.ipv6->hdr.proto);
+                                       ip_proto_set = 1;
+                               }
+                       } else {
+                               assert(mask.ipv6 != &flow_tcf_mask_empty.ipv6);
                        }
                        if (!IN6_IS_ADDR_UNSPECIFIED(mask.ipv6->hdr.src_addr)) {
-                               mnl_attr_put(nlh, TCA_FLOWER_KEY_IPV6_SRC,
-                                            sizeof(spec.ipv6->hdr.src_addr),
+                               mnl_attr_put(nlh, decap.vxlan ?
+                                            TCA_FLOWER_KEY_ENC_IPV6_SRC :
+                                            TCA_FLOWER_KEY_IPV6_SRC,
+                                            IPV6_ADDR_LEN,
                                             spec.ipv6->hdr.src_addr);
-                               mnl_attr_put(nlh, TCA_FLOWER_KEY_IPV6_SRC_MASK,
-                                            sizeof(mask.ipv6->hdr.src_addr),
+                               mnl_attr_put(nlh, decap.vxlan ?
+                                            TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK :
+                                            TCA_FLOWER_KEY_IPV6_SRC_MASK,
+                                            IPV6_ADDR_LEN,
                                             mask.ipv6->hdr.src_addr);
                        }
                        if (!IN6_IS_ADDR_UNSPECIFIED(mask.ipv6->hdr.dst_addr)) {
-                               mnl_attr_put(nlh, TCA_FLOWER_KEY_IPV6_DST,
-                                            sizeof(spec.ipv6->hdr.dst_addr),
+                               mnl_attr_put(nlh, decap.vxlan ?
+                                            TCA_FLOWER_KEY_ENC_IPV6_DST :
+                                            TCA_FLOWER_KEY_IPV6_DST,
+                                            IPV6_ADDR_LEN,
                                             spec.ipv6->hdr.dst_addr);
-                               mnl_attr_put(nlh, TCA_FLOWER_KEY_IPV6_DST_MASK,
-                                            sizeof(mask.ipv6->hdr.dst_addr),
+                               mnl_attr_put(nlh, decap.vxlan ?
+                                            TCA_FLOWER_KEY_ENC_IPV6_DST_MASK :
+                                            TCA_FLOWER_KEY_IPV6_DST_MASK,
+                                            IPV6_ADDR_LEN,
                                             mask.ipv6->hdr.dst_addr);
                        }
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                case RTE_FLOW_ITEM_TYPE_UDP:
                        item_flags |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
@@ -2160,26 +3369,45 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                 sizeof(flow_tcf_mask_supported.udp),
                                 error);
                        assert(mask.udp);
-                       if (!ip_proto_set)
-                               mnl_attr_put_u8(nlh, TCA_FLOWER_KEY_IP_PROTO,
-                                               IPPROTO_UDP);
-                       if (mask.udp == &flow_tcf_mask_empty.udp)
-                               break;
                        spec.udp = items->spec;
+                       if (!decap.vxlan) {
+                               if (!ip_proto_set)
+                                       mnl_attr_put_u8
+                                               (nlh, TCA_FLOWER_KEY_IP_PROTO,
+                                               IPPROTO_UDP);
+                               if (mask.udp == &flow_tcf_mask_empty.udp)
+                                       break;
+                       } else {
+                               assert(mask.udp != &flow_tcf_mask_empty.udp);
+                               decap.vxlan->udp_port =
+                                       rte_be_to_cpu_16
+                                               (spec.udp->hdr.dst_port);
+                       }
                        if (mask.udp->hdr.src_port) {
-                               mnl_attr_put_u16(nlh, TCA_FLOWER_KEY_UDP_SRC,
-                                                spec.udp->hdr.src_port);
-                               mnl_attr_put_u16(nlh,
-                                                TCA_FLOWER_KEY_UDP_SRC_MASK,
-                                                mask.udp->hdr.src_port);
+                               mnl_attr_put_u16
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_UDP_SRC_PORT :
+                                        TCA_FLOWER_KEY_UDP_SRC,
+                                        spec.udp->hdr.src_port);
+                               mnl_attr_put_u16
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK :
+                                        TCA_FLOWER_KEY_UDP_SRC_MASK,
+                                        mask.udp->hdr.src_port);
                        }
                        if (mask.udp->hdr.dst_port) {
-                               mnl_attr_put_u16(nlh, TCA_FLOWER_KEY_UDP_DST,
-                                                spec.udp->hdr.dst_port);
-                               mnl_attr_put_u16(nlh,
-                                                TCA_FLOWER_KEY_UDP_DST_MASK,
-                                                mask.udp->hdr.dst_port);
+                               mnl_attr_put_u16
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_UDP_DST_PORT :
+                                        TCA_FLOWER_KEY_UDP_DST,
+                                        spec.udp->hdr.dst_port);
+                               mnl_attr_put_u16
+                                       (nlh, decap.vxlan ?
+                                        TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK :
+                                        TCA_FLOWER_KEY_UDP_DST_MASK,
+                                        mask.udp->hdr.dst_port);
                        }
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                case RTE_FLOW_ITEM_TYPE_TCP:
                        item_flags |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
@@ -2222,6 +3450,16 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                                         rte_cpu_to_be_16
                                                (mask.tcp->hdr.tcp_flags));
                        }
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
+                       break;
+               case RTE_FLOW_ITEM_TYPE_VXLAN:
+                       assert(decap.vxlan);
+                       item_flags |= MLX5_FLOW_LAYER_VXLAN;
+                       spec.vxlan = items->spec;
+                       mnl_attr_put_u32(nlh,
+                                        TCA_FLOWER_KEY_ENC_KEY_ID,
+                                        vxlan_vni_as_be32(spec.vxlan->vni));
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
                        break;
                default:
                        return rte_flow_error_set(error, ENOTSUP,
@@ -2255,6 +3493,14 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
                        mnl_attr_put_strz(nlh, TCA_ACT_KIND, "mirred");
                        na_act = mnl_attr_nest_start(nlh, TCA_ACT_OPTIONS);
                        assert(na_act);
+                       if (encap.hdr) {
+                               assert(dev_flow->tcf.tunnel);
+                               dev_flow->tcf.tunnel->ifindex_ptr =
+                                       &((struct tc_mirred *)
+                                       mnl_attr_get_payload
+                                       (mnl_nlmsg_get_payload_tail
+                                               (nlh)))->ifindex;
+                       }
                        mnl_attr_put(nlh, TCA_MIRRED_PARMS,
                                     sizeof(struct tc_mirred),
                                     &(struct tc_mirred){
@@ -2372,6 +3618,74 @@ override_na_vlan_priority:
                                        conf.of_set_vlan_pcp->vlan_pcp;
                        }
                        break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
+                       assert(decap.vxlan);
+                       assert(dev_flow->tcf.tunnel);
+                       dev_flow->tcf.tunnel->ifindex_ptr =
+                               (unsigned int *)&tcm->tcm_ifindex;
+                       na_act_index =
+                               mnl_attr_nest_start(nlh, na_act_index_cur++);
+                       assert(na_act_index);
+                       mnl_attr_put_strz(nlh, TCA_ACT_KIND, "tunnel_key");
+                       na_act = mnl_attr_nest_start(nlh, TCA_ACT_OPTIONS);
+                       assert(na_act);
+                       mnl_attr_put(nlh, TCA_TUNNEL_KEY_PARMS,
+                               sizeof(struct tc_tunnel_key),
+                               &(struct tc_tunnel_key){
+                                       .action = TC_ACT_PIPE,
+                                       .t_action = TCA_TUNNEL_KEY_ACT_RELEASE,
+                                       });
+                       mnl_attr_nest_end(nlh, na_act);
+                       mnl_attr_nest_end(nlh, na_act_index);
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
+                       break;
+               case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+                       assert(encap.vxlan);
+                       flow_tcf_vxlan_encap_parse(actions, encap.vxlan);
+                       na_act_index =
+                               mnl_attr_nest_start(nlh, na_act_index_cur++);
+                       assert(na_act_index);
+                       mnl_attr_put_strz(nlh, TCA_ACT_KIND, "tunnel_key");
+                       na_act = mnl_attr_nest_start(nlh, TCA_ACT_OPTIONS);
+                       assert(na_act);
+                       mnl_attr_put(nlh, TCA_TUNNEL_KEY_PARMS,
+                               sizeof(struct tc_tunnel_key),
+                               &(struct tc_tunnel_key){
+                                       .action = TC_ACT_PIPE,
+                                       .t_action = TCA_TUNNEL_KEY_ACT_SET,
+                                       });
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_UDP_DST)
+                               mnl_attr_put_u16(nlh,
+                                        TCA_TUNNEL_KEY_ENC_DST_PORT,
+                                        encap.vxlan->udp.dst);
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_IPV4_SRC)
+                               mnl_attr_put_u32(nlh,
+                                        TCA_TUNNEL_KEY_ENC_IPV4_SRC,
+                                        encap.vxlan->ipv4.src);
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_IPV4_DST)
+                               mnl_attr_put_u32(nlh,
+                                        TCA_TUNNEL_KEY_ENC_IPV4_DST,
+                                        encap.vxlan->ipv4.dst);
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_IPV6_SRC)
+                               mnl_attr_put(nlh,
+                                        TCA_TUNNEL_KEY_ENC_IPV6_SRC,
+                                        sizeof(encap.vxlan->ipv6.src),
+                                        &encap.vxlan->ipv6.src);
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_IPV6_DST)
+                               mnl_attr_put(nlh,
+                                        TCA_TUNNEL_KEY_ENC_IPV6_DST,
+                                        sizeof(encap.vxlan->ipv6.dst),
+                                        &encap.vxlan->ipv6.dst);
+                       if (encap.vxlan->mask & FLOW_TCF_ENCAP_VXLAN_VNI)
+                               mnl_attr_put_u32(nlh,
+                                        TCA_TUNNEL_KEY_ENC_KEY_ID,
+                                        vxlan_vni_as_be32
+                                               (encap.vxlan->vxlan.vni));
+                       mnl_attr_put_u8(nlh, TCA_TUNNEL_KEY_NO_CSUM, 0);
+                       mnl_attr_nest_end(nlh, na_act);
+                       mnl_attr_nest_end(nlh, na_act_index);
+                       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
+                       break;
                case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
                case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
                case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
@@ -2398,7 +3712,13 @@ override_na_vlan_priority:
        assert(na_flower);
        assert(na_flower_act);
        mnl_attr_nest_end(nlh, na_flower_act);
+       mnl_attr_put_u32(nlh, TCA_FLOWER_FLAGS, decap.vxlan ?
+                                               0 : TCA_CLS_FLAGS_SKIP_SW);
        mnl_attr_nest_end(nlh, na_flower);
+       if (dev_flow->tcf.tunnel && dev_flow->tcf.tunnel->ifindex_ptr)
+               dev_flow->tcf.tunnel->ifindex_org =
+                       *dev_flow->tcf.tunnel->ifindex_ptr;
+       assert(dev_flow->tcf.nlsize >= nlh->nlmsg_len);
        return 0;
 }