diff mbox series

[RFC,2/2] net/i40e: add IP-in-GRE flow parsing

Message ID 20201020082427.33105-3-chenxux.di@intel.com (mailing list archive)
State Superseded
Delegated to: Qi Zhang
Headers show
Series net/i40e: add VXLAN-GPE and IP-in-GRE flow parsing | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Chenxu Di Oct. 20, 2020, 8:24 a.m. UTC
This patch adds IP in GRE flow parsing function to support
IP in GRE classification.

Signed-off-by: Chenxu Di <chenxux.di@intel.com>
---
 drivers/net/i40e/i40e_flow.c | 237 +++++++++++++++++++++++++++++++++++
 1 file changed, 237 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/i40e/i40e_flow.c b/drivers/net/i40e/i40e_flow.c
index e29ea6da2..364003528 100644
--- a/drivers/net/i40e/i40e_flow.c
+++ b/drivers/net/i40e/i40e_flow.c
@@ -141,6 +141,12 @@  static int i40e_flow_parse_l4_cloud_filter(struct rte_eth_dev *dev,
 					   const struct rte_flow_action actions[],
 					   struct rte_flow_error *error,
 					   union i40e_filter_t *filter);
+static int i40e_flow_parse_ip_in_gre_filter(struct rte_eth_dev *dev,
+					    const struct rte_flow_attr *attr,
+					    const struct rte_flow_item pattern[],
+					    const struct rte_flow_action actions[],
+					    struct rte_flow_error *error,
+					    union i40e_filter_t *filter);
 const struct rte_flow_ops i40e_flow_ops = {
 	.validate = i40e_flow_validate,
 	.create = i40e_flow_create,
@@ -1737,6 +1743,38 @@  static enum rte_flow_item_type pattern_vxlan_gpe_6[] = {
 	RTE_FLOW_ITEM_TYPE_END,
 };
 
+static enum rte_flow_item_type pattern_ip_in_gre_1[] = {
+	RTE_FLOW_ITEM_TYPE_ETH,
+	RTE_FLOW_ITEM_TYPE_IPV4,
+	RTE_FLOW_ITEM_TYPE_GRE,
+	RTE_FLOW_ITEM_TYPE_IPV4,
+	RTE_FLOW_ITEM_TYPE_END,
+};
+
+static enum rte_flow_item_type pattern_ip_in_gre_2[] = {
+	RTE_FLOW_ITEM_TYPE_ETH,
+	RTE_FLOW_ITEM_TYPE_IPV4,
+	RTE_FLOW_ITEM_TYPE_GRE,
+	RTE_FLOW_ITEM_TYPE_IPV6,
+	RTE_FLOW_ITEM_TYPE_END,
+};
+
+static enum rte_flow_item_type pattern_ip_in_gre_3[] = {
+	RTE_FLOW_ITEM_TYPE_ETH,
+	RTE_FLOW_ITEM_TYPE_IPV6,
+	RTE_FLOW_ITEM_TYPE_GRE,
+	RTE_FLOW_ITEM_TYPE_IPV4,
+	RTE_FLOW_ITEM_TYPE_END,
+};
+
+static enum rte_flow_item_type pattern_ip_in_gre_4[] = {
+	RTE_FLOW_ITEM_TYPE_ETH,
+	RTE_FLOW_ITEM_TYPE_IPV6,
+	RTE_FLOW_ITEM_TYPE_GRE,
+	RTE_FLOW_ITEM_TYPE_IPV6,
+	RTE_FLOW_ITEM_TYPE_END,
+};
+
 static struct i40e_valid_pattern i40e_supported_patterns[] = {
 	/* Ethertype */
 	{ pattern_ethertype, i40e_flow_parse_ethertype_filter },
@@ -1938,6 +1976,11 @@  static struct i40e_valid_pattern i40e_supported_patterns[] = {
 	{ pattern_vxlan_gpe_4, i40e_flow_parse_vxlan_gpe_filter },
 	{ pattern_vxlan_gpe_5, i40e_flow_parse_vxlan_gpe_filter },
 	{ pattern_vxlan_gpe_6, i40e_flow_parse_vxlan_gpe_filter },
+	/* IP in GRE */
+	{ pattern_ip_in_gre_1, i40e_flow_parse_ip_in_gre_filter },
+	{ pattern_ip_in_gre_2, i40e_flow_parse_ip_in_gre_filter },
+	{ pattern_ip_in_gre_3, i40e_flow_parse_ip_in_gre_filter },
+	{ pattern_ip_in_gre_4, i40e_flow_parse_ip_in_gre_filter },
 };
 
 #define NEXT_ITEM_OF_ACTION(act, actions, index)                        \
@@ -4348,6 +4391,200 @@  i40e_flow_parse_nvgre_filter(struct rte_eth_dev *dev,
 	if (ret)
 		return ret;
 
+	cons_filter_type = RTE_ETH_FILTER_TUNNEL;
+	return ret;
+}
+
+/* 1. Last in item should be NULL as range is not supported.
+ * 2. Supported filter types: OIP and IIP.
+ * 3. Mask of fields which need to be matched should be
+ *    filled with 1.
+ * 4. Mask of fields which needn't to be matched should be
+ *    filled with 0.
+ */
+static int
+i40e_flow_parse_ip_in_gre_pattern(__rte_unused struct rte_eth_dev *dev,
+			      const struct rte_flow_item *pattern,
+			      struct rte_flow_error *error,
+			      struct i40e_tunnel_filter_conf *filter)
+{
+	const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
+	const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
+	const struct rte_flow_item *item = pattern;
+	uint8_t  ipv6_src_addr_mask[16] = {0x00};
+	uint8_t  ipv6_dst_addr_mask[16] = {
+					0xFF, 0xFF, 0xFF, 0xFF,
+					0xFF, 0xFF, 0xFF, 0xFF,
+					0xFF, 0xFF, 0xFF, 0xFF,
+					0xFF, 0xFF, 0xFF, 0xFF
+	};
+	enum rte_flow_item_type item_type;
+	uint8_t filter_type = 0;
+	bool gre_flag = 0;
+	int ret;
+
+	for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
+		if (item->last) {
+			rte_flow_error_set(error, EINVAL,
+					   RTE_FLOW_ERROR_TYPE_ITEM,
+					   item,
+					   "Not support range");
+			return -rte_errno;
+		}
+		item_type = item->type;
+		switch (item_type) {
+		case RTE_FLOW_ITEM_TYPE_ETH:
+			/* Ether is used to describe protocol,
+			 * spec and mask should be NULL.
+			 */
+			if (item->spec || item->mask) {
+				rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid ether item");
+				return -rte_errno;
+			}
+			break;
+		case RTE_FLOW_ITEM_TYPE_IPV4:
+			ipv4_spec = item->spec;
+			ipv4_mask = item->mask;
+
+			if ((!ipv4_spec && ipv4_mask) ||
+			    (ipv4_spec && !ipv4_mask)) {
+				rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid IPv4 item");
+				return -rte_errno;
+			}
+
+			if (ipv4_spec && ipv4_mask) {
+				/* Check IPv4 mask */
+				if (ipv4_mask->hdr.version_ihl ||
+				    ipv4_mask->hdr.total_length ||
+				    ipv4_mask->hdr.packet_id ||
+				    ipv4_mask->hdr.fragment_offset ||
+				    ipv4_mask->hdr.hdr_checksum ||
+				    ipv4_mask->hdr.type_of_service ||
+				    ipv4_mask->hdr.time_to_live ||
+				    ipv4_mask->hdr.next_proto_id ||
+				    ipv4_mask->hdr.src_addr ||
+				    ipv4_mask->hdr.dst_addr != UINT32_MAX) {
+					rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid IPv4 mask.");
+					return -rte_errno;
+				}
+
+				filter->ip_addr.ipv4_addr = ipv4_spec->hdr.dst_addr;
+				filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
+				if (gre_flag)
+					filter_type |= ETH_TUNNEL_FILTER_IIP;
+				else
+					filter_type |= ETH_TUNNEL_FILTER_OIP;
+			}
+			break;
+		case RTE_FLOW_ITEM_TYPE_IPV6:
+			ipv6_spec = item->spec;
+			ipv6_mask = item->mask;
+
+			if ((!ipv6_spec && ipv6_mask) ||
+			    (ipv6_spec && !ipv6_mask)) {
+				rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid IPv6 item");
+				return -rte_errno;
+			}
+
+			if (ipv6_spec && ipv6_mask) {
+				/* Check IPv6 mask */
+				if (ipv6_mask->hdr.vtc_flow ||
+				    ipv6_mask->hdr.payload_len ||
+				    ipv6_mask->hdr.proto ||
+				    ipv6_mask->hdr.hop_limits ||
+				    memcmp(ipv6_mask->hdr.src_addr,
+					   ipv6_src_addr_mask,
+					   RTE_DIM(ipv6_mask->hdr.src_addr)) ||
+				    memcmp(ipv6_mask->hdr.dst_addr,
+					   ipv6_dst_addr_mask,
+					   RTE_DIM(ipv6_mask->hdr.dst_addr))) {
+					rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid IPv6 item");
+					return -rte_errno;
+				}
+
+				rte_memcpy(filter->ip_addr.ipv6_addr,
+					   ipv6_spec->hdr.dst_addr, 16);
+				filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
+				if (gre_flag)
+					filter_type |= ETH_TUNNEL_FILTER_IIP;
+				else
+					filter_type |= ETH_TUNNEL_FILTER_OIP;
+			}
+			break;
+		case RTE_FLOW_ITEM_TYPE_GRE:
+			/* GRE is used to describe protocol,
+			 * spec and mask should be NULL.
+			 */
+			if (item->spec || item->mask) {
+				rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Invalid GRE item");
+				return -rte_errno;
+			}
+
+			gre_flag = 1;
+			break;
+		default:
+			break;
+		}
+	}
+
+	ret = i40e_check_tunnel_filter_type(filter_type);
+	if (ret < 0) {
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ITEM,
+				   NULL,
+				   "Invalid filter type");
+		return -rte_errno;
+	}
+	filter->filter_type = filter_type;
+
+	filter->tunnel_type = I40E_TUNNEL_TYPE_IP_IN_GRE;
+
+	return 0;
+}
+
+static int
+i40e_flow_parse_ip_in_gre_filter(struct rte_eth_dev *dev,
+			     const struct rte_flow_attr *attr,
+			     const struct rte_flow_item pattern[],
+			     const struct rte_flow_action actions[],
+			     struct rte_flow_error *error,
+			     union i40e_filter_t *filter)
+{
+	struct i40e_tunnel_filter_conf *tunnel_filter =
+		&filter->consistent_tunnel_filter;
+	int ret;
+
+	ret = i40e_flow_parse_ip_in_gre_pattern(dev, pattern,
+					    error, tunnel_filter);
+	if (ret)
+		return ret;
+
+	ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
+	if (ret)
+		return ret;
+
+	ret = i40e_flow_parse_attr(attr, error);
+	if (ret)
+		return ret;
+
 	cons_filter_type = RTE_ETH_FILTER_TUNNEL;
 
 	return ret;