DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chenxu Di <chenxux.di@intel.com>
To: dev@dpdk.org
Cc: beilei.xing@intel.com, jia.guo@intel.com, junyux.jiang@intel.com,
	Chenxu Di <chenxux.di@intel.com>
Subject: [dpdk-dev] [RFC 2/2] net/i40e: add IP-in-GRE flow parsing
Date: Tue, 20 Oct 2020 08:24:27 +0000	[thread overview]
Message-ID: <20201020082427.33105-3-chenxux.di@intel.com> (raw)
In-Reply-To: <20201020082427.33105-1-chenxux.di@intel.com>

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 --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;
-- 
2.17.1


      parent reply	other threads:[~2020-10-20  8:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20  8:24 [dpdk-dev] [RFC 0/2] net/i40e: add VXLAN-GPE and " Chenxu Di
2020-10-20  8:24 ` [dpdk-dev] [RFC 1/2] net/i40e: add VXLAN-GPE " Chenxu Di
2020-10-20  8:24 ` Chenxu Di [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201020082427.33105-3-chenxux.di@intel.com \
    --to=chenxux.di@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jia.guo@intel.com \
    --cc=junyux.jiang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).