DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
	Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
Subject: [PATCH v2 07/11] net/sfc: add IPV4 in flow API filters support
Date: Thu, 9 Mar 2017 15:26:29 +0000	[thread overview]
Message-ID: <1489073193-2920-8-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1489073193-2920-1-git-send-email-arybchenko@solarflare.com>

From: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>

Exact match of IP protocol, source and destination
addresses is supported by parser.
EtherType match is enforced to IPv4 EtherType.

Signed-off-by: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
---
 doc/guides/nics/sfc_efx.rst |  3 ++
 drivers/net/sfc/sfc_flow.c  | 98 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index 71dc99f..12ac308 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -131,6 +131,9 @@ Supported pattern items:
 
 - VLAN (exact match of VID, double-tagging is supported)
 
+- IPV4 (exact match of source/destination addresses,
+  IP transport protocol)
+
 Supported actions:
 
 - VOID
diff --git a/drivers/net/sfc/sfc_flow.c b/drivers/net/sfc/sfc_flow.c
index 70d926f..05be5a5 100644
--- a/drivers/net/sfc/sfc_flow.c
+++ b/drivers/net/sfc/sfc_flow.c
@@ -55,6 +55,7 @@ enum sfc_flow_item_layers {
 	SFC_FLOW_ITEM_ANY_LAYER,
 	SFC_FLOW_ITEM_START_LAYER,
 	SFC_FLOW_ITEM_L2,
+	SFC_FLOW_ITEM_L3,
 };
 
 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
@@ -71,6 +72,7 @@ struct sfc_flow_item {
 static sfc_flow_item_parse sfc_flow_parse_void;
 static sfc_flow_item_parse sfc_flow_parse_eth;
 static sfc_flow_item_parse sfc_flow_parse_vlan;
+static sfc_flow_item_parse sfc_flow_parse_ipv4;
 
 static boolean_t
 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
@@ -337,6 +339,96 @@ sfc_flow_parse_vlan(const struct rte_flow_item *item,
 	return 0;
 }
 
+/**
+ * Convert IPv4 item to EFX filter specification.
+ *
+ * @param item[in]
+ *   Item specification. Only source and destination addresses and
+ *   protocol fields are supported. If the mask is NULL, default
+ *   mask will be used. Ranging is not supported.
+ * @param efx_spec[in, out]
+ *   EFX filter specification to update.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ */
+static int
+sfc_flow_parse_ipv4(const struct rte_flow_item *item,
+		    efx_filter_spec_t *efx_spec,
+		    struct rte_flow_error *error)
+{
+	int rc;
+	const struct rte_flow_item_ipv4 *spec = NULL;
+	const struct rte_flow_item_ipv4 *mask = NULL;
+	const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
+	const struct rte_flow_item_ipv4 supp_mask = {
+		.hdr = {
+			.src_addr = 0xffffffff,
+			.dst_addr = 0xffffffff,
+			.next_proto_id = 0xff,
+		}
+	};
+
+	rc = sfc_flow_parse_init(item,
+				 (const void **)&spec,
+				 (const void **)&mask,
+				 &supp_mask,
+				 &rte_flow_item_ipv4_mask,
+				 sizeof(struct rte_flow_item_ipv4),
+				 error);
+	if (rc != 0)
+		return rc;
+
+	/*
+	 * Filtering by IPv4 source and destination addresses requires
+	 * the appropriate ETHER_TYPE in hardware filters
+	 */
+	if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
+		efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
+		efx_spec->efs_ether_type = ether_type_ipv4;
+	} else if (efx_spec->efs_ether_type != ether_type_ipv4) {
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ITEM, item,
+			"Ethertype in pattern with IPV4 item should be appropriate");
+		return -rte_errno;
+	}
+
+	if (spec == NULL)
+		return 0;
+
+	/*
+	 * IPv4 addresses are in big-endian byte order in item and in
+	 * efx_spec
+	 */
+	if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
+		efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
+		efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
+	} else if (mask->hdr.src_addr != 0) {
+		goto fail_bad_mask;
+	}
+
+	if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
+		efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
+		efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
+	} else if (mask->hdr.dst_addr != 0) {
+		goto fail_bad_mask;
+	}
+
+	if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
+		efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
+		efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
+	} else if (mask->hdr.next_proto_id != 0) {
+		goto fail_bad_mask;
+	}
+
+	return 0;
+
+fail_bad_mask:
+	rte_flow_error_set(error, EINVAL,
+			   RTE_FLOW_ERROR_TYPE_ITEM, item,
+			   "Bad mask in the IPV4 pattern item");
+	return -rte_errno;
+}
+
 static const struct sfc_flow_item sfc_flow_items[] = {
 	{
 		.type = RTE_FLOW_ITEM_TYPE_VOID,
@@ -356,6 +448,12 @@ static const struct sfc_flow_item sfc_flow_items[] = {
 		.layer = SFC_FLOW_ITEM_L2,
 		.parse = sfc_flow_parse_vlan,
 	},
+	{
+		.type = RTE_FLOW_ITEM_TYPE_IPV4,
+		.prev_layer = SFC_FLOW_ITEM_L2,
+		.layer = SFC_FLOW_ITEM_L3,
+		.parse = sfc_flow_parse_ipv4,
+	},
 };
 
 /*
-- 
2.9.3

  parent reply	other threads:[~2017-03-09 15:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02 16:03 [PATCH 00/11] Support flow API in Solarflare PMD Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 01/11] net/sfc/base: split local MAC I/G back into separate flags Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 02/11] net/sfc/base: improve API to get supported filter matches Andrew Rybchenko
2017-03-07 13:25   ` Ferruh Yigit
2017-03-07 14:47     ` Andrew Rybchenko
2017-03-07 14:56       ` Ferruh Yigit
2017-03-02 16:03 ` [PATCH 03/11] net/sfc: implement dummy filter control callback Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 04/11] net/sfc: provide a way to check if filter is supported Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 05/11] net/sfc: add flow API filters support Andrew Rybchenko
2017-03-07 13:21   ` Ferruh Yigit
2017-03-09 15:29     ` Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 06/11] net/sfc: add VLAN in " Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 07/11] net/sfc: add IPV4 " Andrew Rybchenko
2017-03-07 13:21   ` Ferruh Yigit
2017-03-02 16:03 ` [PATCH 08/11] net/sfc: add IPV6 " Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 09/11] net/sfc: add TCP " Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 10/11] net/sfc: add UDP " Andrew Rybchenko
2017-03-02 16:03 ` [PATCH 11/11] net/sfc: add unknown unicast/multicast match in flow API Andrew Rybchenko
2017-03-07 13:27 ` [PATCH 00/11] Support flow API in Solarflare PMD Ferruh Yigit
2017-03-07 14:56   ` Andrew Rybchenko
2017-03-09 15:26 ` [PATCH v2 " Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 01/11] net/sfc/base: split local MAC I/G back into separate flags Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 02/11] net/sfc/base: improve API to get supported filter matches Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 03/11] net/sfc: implement dummy filter control callback Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 04/11] net/sfc: provide a way to check if filter is supported Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 05/11] net/sfc: add flow API filters support Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 06/11] net/sfc: add VLAN in " Andrew Rybchenko
2017-03-09 15:26   ` Andrew Rybchenko [this message]
2017-03-09 15:26   ` [PATCH v2 08/11] net/sfc: add IPV6 " Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 09/11] net/sfc: add TCP " Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 10/11] net/sfc: add UDP " Andrew Rybchenko
2017-03-09 15:26   ` [PATCH v2 11/11] net/sfc: add unknown unicast/multicast match in flow API Andrew Rybchenko
2017-03-09 17:28   ` [PATCH v2 00/11] Support flow API in Solarflare PMD 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=1489073193-2920-8-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=Roman.Zhukov@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@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