All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Zhao <wei.zhao1@intel.com>
To: dev@dpdk.org
Cc: wenzhuo.lu@intel.com, Wei Zhao <wei.zhao1@intel.com>
Subject: [PATCH v2 07/11] net/e1000: parse TCP SYN filter
Date: Fri,  2 Jun 2017 14:36:27 +0800	[thread overview]
Message-ID: <1496385391-12445-8-git-send-email-wei.zhao1@intel.com> (raw)
In-Reply-To: <1496385391-12445-1-git-send-email-wei.zhao1@intel.com>

check if the rule is a TCP SYN rule, and get the SYN info.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/e1000/igb_flow.c | 277 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 277 insertions(+)

diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 87cc851..244fc9e 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -746,6 +746,276 @@ igb_parse_ethertype_filter(struct rte_eth_dev *dev,
 }
 
 /**
+ * Parse the rule to see if it is a TCP SYN rule.
+ * And get the TCP SYN filter info BTW.
+ * pattern:
+ * The first not void item must be ETH.
+ * The second not void item must be IPV4 or IPV6.
+ * The third not void item must be TCP.
+ * The next not void item must be END.
+ * action:
+ * The first not void action should be QUEUE.
+ * The next not void action should be END.
+ * pattern example:
+ * ITEM		Spec			Mask
+ * ETH		NULL			NULL
+ * IPV4/IPV6	NULL			NULL
+ * TCP		tcp_flags	0x02	0xFF
+ * END
+ * other members in mask and spec should set to 0x00.
+ * item->last should be NULL.
+ */
+static int
+cons_parse_syn_filter(const struct rte_flow_attr *attr,
+				const struct rte_flow_item pattern[],
+				const struct rte_flow_action actions[],
+				struct rte_eth_syn_filter *filter,
+				struct rte_flow_error *error)
+{
+	const struct rte_flow_item *item;
+	const struct rte_flow_action *act;
+	const struct rte_flow_item_tcp *tcp_spec;
+	const struct rte_flow_item_tcp *tcp_mask;
+	const struct rte_flow_action_queue *act_q;
+	uint32_t index;
+
+	if (!pattern) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM_NUM,
+				NULL, "NULL pattern.");
+		return -rte_errno;
+	}
+
+	if (!actions) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION_NUM,
+				NULL, "NULL action.");
+		return -rte_errno;
+	}
+
+	if (!attr) {
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR,
+				   NULL, "NULL attribute.");
+		return -rte_errno;
+	}
+
+	/* parse pattern */
+	index = 0;
+
+	/* the first not void item should be MAC or IPv4 or IPv6 or TCP */
+	NEXT_ITEM_OF_PATTERN(item, pattern, index);
+	if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
+	    item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
+	    item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
+	    item->type != RTE_FLOW_ITEM_TYPE_TCP) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Not supported by syn filter");
+		return -rte_errno;
+	}
+		/*Not supported last point for range*/
+	if (item->last) {
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			item, "Not supported last point for range");
+		return -rte_errno;
+	}
+
+	/* Skip Ethernet */
+	if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
+		/* if the item is MAC, the content should be NULL */
+		if (item->spec || item->mask) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Invalid SYN address mask");
+			return -rte_errno;
+		}
+
+		/* check if the next not void item is IPv4 or IPv6 */
+		index++;
+		NEXT_ITEM_OF_PATTERN(item, pattern, index);
+		if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
+		    item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Not supported by syn filter");
+			return -rte_errno;
+		}
+	}
+
+	/* Skip IP */
+	if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
+	    item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
+		/* if the item is IP, the content should be NULL */
+		if (item->spec || item->mask) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Invalid SYN mask");
+			return -rte_errno;
+		}
+
+		/* check if the next not void item is TCP */
+		index++;
+		NEXT_ITEM_OF_PATTERN(item, pattern, index);
+		if (item->type != RTE_FLOW_ITEM_TYPE_TCP) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Not supported by syn filter");
+			return -rte_errno;
+		}
+	}
+
+	/* Get the TCP info. Only support SYN. */
+	if (!item->spec || !item->mask) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Invalid SYN mask");
+		return -rte_errno;
+	}
+	/*Not supported last point for range*/
+	if (item->last) {
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			item, "Not supported last point for range");
+		return -rte_errno;
+	}
+
+	tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
+	tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
+	if (!(tcp_spec->hdr.tcp_flags & TCP_SYN_FLAG) ||
+	    tcp_mask->hdr.src_port ||
+	    tcp_mask->hdr.dst_port ||
+	    tcp_mask->hdr.sent_seq ||
+	    tcp_mask->hdr.recv_ack ||
+	    tcp_mask->hdr.data_off ||
+	    tcp_mask->hdr.tcp_flags != TCP_SYN_FLAG ||
+	    tcp_mask->hdr.rx_win ||
+	    tcp_mask->hdr.cksum ||
+	    tcp_mask->hdr.tcp_urp) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Not supported by syn filter");
+		return -rte_errno;
+	}
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_PATTERN(item, pattern, index);
+	if (item->type != RTE_FLOW_ITEM_TYPE_END) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				item, "Not supported by syn filter");
+		return -rte_errno;
+	}
+
+	/* parse action */
+	index = 0;
+
+	/* check if the first not void action is QUEUE. */
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	act_q = (const struct rte_flow_action_queue *)act->conf;
+	filter->queue = act_q->index;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+			attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+			attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	/* Support 2 priorities, the lowest or highest. */
+	if (!attr->priority) {
+		filter->hig_pri = 0;
+	} else if (attr->priority == (uint32_t)~0U) {
+		filter->hig_pri = 1;
+	} else {
+		memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+			attr, "Not support priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+static int
+igb_parse_syn_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_eth_syn_filter *filter,
+			     struct rte_flow_error *error)
+{
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	int ret;
+
+	MAC_TYPE_FILTER_SUP(hw->mac.type);
+
+	ret = cons_parse_syn_filter(attr, pattern,
+					actions, filter, error);
+
+	if (hw->mac.type == e1000_82576) {
+		if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576) {
+			memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				NULL, "queue number not "
+					"supported by syn filter");
+			return -rte_errno;
+		}
+	} else {
+		if (filter->queue >= IGB_MAX_RX_QUEUE_NUM) {
+			memset(filter, 0, sizeof(struct rte_eth_syn_filter));
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM,
+				NULL, "queue number not "
+					"supported by syn filter");
+			return -rte_errno;
+		}
+	}
+
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+/**
  * Check if the flow rule is supported by igb.
  * It only checkes the format. Don't guarantee the rule can be programmed into
  * the HW. Because there can be no enough room for the rule.
@@ -759,6 +1029,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 {
 	struct rte_eth_ntuple_filter ntuple_filter;
 	struct rte_eth_ethertype_filter ethertype_filter;
+	struct rte_eth_syn_filter syn_filter;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -773,6 +1044,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	if (!ret)
 		return 0;
 
+	memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
+	ret = igb_parse_syn_filter(dev, attr, pattern,
+				actions, &syn_filter, error);
+	if (!ret)
+		return 0;
+
 	return ret;
 }
 
-- 
2.9.3

  parent reply	other threads:[~2017-06-02  6:45 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-23  7:12 [PATCH 00/11] net/e1000: Consistent filter API Wei Zhao
2017-05-23  7:12 ` [PATCH 01/11] net/e1000: store and restore TCP SYN filter Wei Zhao
2017-05-23  7:12 ` [PATCH 02/11] net/e1000: restore n-tuple filter Wei Zhao
2017-05-23  7:12 ` [PATCH 03/11] net/e1000: restore ether type filter Wei Zhao
2017-05-23  7:12 ` [PATCH 04/11] net/e1000: restore flex " Wei Zhao
2017-05-23  7:12 ` [PATCH 05/11] net/e1000: parse n-tuple filter Wei Zhao
2017-05-23  7:12 ` [PATCH 06/11] net/e1000: parse ethertype filter Wei Zhao
2017-05-23  7:12 ` [PATCH 07/11] net/e1000: parse TCP SYN filter Wei Zhao
2017-05-23  7:12 ` [PATCH 08/11] net/e1000: parse flex filter Wei Zhao
2017-05-23  7:12 ` [PATCH 09/11] net/e1000: create consistent filter Wei Zhao
2017-05-23  7:13 ` [PATCH 10/11] net/e1000: destroy " Wei Zhao
2017-05-23  7:13 ` [PATCH 11/11] net/e1000: flush all the filter Wei Zhao
2017-05-29 11:01 ` [PATCH 00/11] net/e1000: Consistent filter API Ferruh Yigit
2017-05-31  3:17   ` Zhao1, Wei
2017-06-02  6:36 ` Wei Zhao
2017-06-02  6:36   ` [PATCH v2 01/11] net/e1000: store and restore TCP SYN filter Wei Zhao
2017-06-02  7:51     ` Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 02/11] net/e1000: restore n-tuple filter Wei Zhao
2017-06-02  7:56     ` Lu, Wenzhuo
2017-06-02  8:00       ` Zhao1, Wei
2017-06-02  6:36   ` [PATCH v2 03/11] net/e1000: restore ether type filter Wei Zhao
2017-06-02  8:08     ` Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 04/11] net/e1000: restore flex " Wei Zhao
2017-06-02  8:17     ` Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 05/11] net/e1000: parse n-tuple filter Wei Zhao
2017-06-05  1:21     ` Lu, Wenzhuo
2017-06-05  1:55       ` Zhao1, Wei
2017-06-05  2:36         ` Lu, Wenzhuo
2017-06-05  2:39           ` Zhao1, Wei
2017-06-02  6:36   ` [PATCH v2 06/11] net/e1000: parse ethertype filter Wei Zhao
2017-06-05  3:13     ` Lu, Wenzhuo
2017-06-05  3:26       ` Zhao1, Wei
2017-06-02  6:36   ` Wei Zhao [this message]
2017-06-05  3:16     ` [PATCH v2 07/11] net/e1000: parse TCP SYN filter Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 08/11] net/e1000: parse flex filter Wei Zhao
2017-06-05  3:38     ` Lu, Wenzhuo
2017-06-05  3:41       ` Zhao1, Wei
2017-06-02  6:36   ` [PATCH v2 09/11] net/e1000: create consistent filter Wei Zhao
2017-06-05  5:14     ` Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 10/11] net/e1000: destroy " Wei Zhao
2017-06-05  5:41     ` Lu, Wenzhuo
2017-06-05  6:00       ` Zhao1, Wei
2017-06-05  6:08         ` Lu, Wenzhuo
2017-06-02  6:36   ` [PATCH v2 11/11] net/e1000: flush all the filter Wei Zhao
2017-06-05  6:09     ` Lu, Wenzhuo
2017-06-09  3:11   ` [PATCH 00/11] net/e1000: Consistent filter API Wei Zhao
2017-06-09  3:11     ` [PATCH v3 01/11] net/e1000: store and restore TCP SYN filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 02/11] net/e1000: restore n-tuple filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 03/11] net/e1000: restore ether type filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 04/11] net/e1000: restore flex " Wei Zhao
2017-06-09  3:11     ` [PATCH v3 05/11] net/e1000: parse n-tuple filter Wei Zhao
2017-06-09 12:29       ` Ferruh Yigit
2017-06-12  7:47         ` Zhao1, Wei
2017-06-09  3:11     ` [PATCH v3 06/11] net/e1000: parse ethertype filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 07/11] net/e1000: parse TCP SYN filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 08/11] net/e1000: parse flex filter Wei Zhao
2017-06-09 12:23       ` Ferruh Yigit
2017-06-12  3:25         ` Zhao1, Wei
2017-06-09  3:11     ` [PATCH v3 09/11] net/e1000: create consistent filter Wei Zhao
2017-06-09  3:11     ` [PATCH v3 10/11] net/e1000: destroy " Wei Zhao
2017-06-09  3:11     ` [PATCH v3 11/11] net/e1000: flush all the filter Wei Zhao
2017-06-12  6:30     ` [PATCH 00/11] net/e1000: Consistent filter API Wei Zhao
2017-06-12  6:30       ` [PATCH v4] net/e1000: parse n-tuple filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 01/11] net/e1000: store and restore TCP SYN filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 02/11] net/e1000: restore n-tuple filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 03/11] net/e1000: restore ether type filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 04/11] net/e1000: restore flex " Wei Zhao
2017-06-12  6:30       ` [PATCH v4 05/11] net/e1000: parse n-tuple filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 06/11] net/e1000: parse ethertype filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 07/11] net/e1000: parse TCP SYN filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 08/11] net/e1000: parse flex filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 09/11] net/e1000: create consistent filter Wei Zhao
2017-06-12  6:30       ` [PATCH v4 10/11] net/e1000: destroy " Wei Zhao
2017-06-12  6:30       ` [PATCH v4 11/11] net/e1000: flush all the filter Wei Zhao
2017-06-12  6:48       ` [PATCH 00/11] net/e1000: Consistent filter API Wei Zhao
2017-06-12  6:48         ` [PATCH v5 01/11] net/e1000: store and restore TCP SYN filter Wei Zhao
2017-06-12 10:45           ` Ferruh Yigit
2017-06-14  8:59             ` Zhao1, Wei
2017-06-12  6:48         ` [PATCH v5 02/11] net/e1000: restore n-tuple filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 03/11] net/e1000: restore ether type filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 04/11] net/e1000: restore flex " Wei Zhao
2017-06-12  6:48         ` [PATCH v5 05/11] net/e1000: parse n-tuple filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 06/11] net/e1000: parse ethertype filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 07/11] net/e1000: parse TCP SYN filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 08/11] net/e1000: parse flex filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 09/11] net/e1000: create consistent filter Wei Zhao
2017-06-12  6:48         ` [PATCH v5 10/11] net/e1000: destroy " Wei Zhao
2017-06-12  6:48         ` [PATCH v5 11/11] net/e1000: flush all the filter Wei Zhao
2017-06-12 10:47         ` [PATCH 00/11] net/e1000: Consistent filter API Ferruh Yigit

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=1496385391-12445-8-git-send-email-wei.zhao1@intel.com \
    --to=wei.zhao1@intel.com \
    --cc=dev@dpdk.org \
    --cc=wenzhuo.lu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.