DPDK patches and discussions
 help / color / mirror / Atom feed
From: Artemii Morozov <artemii.morozov@arknetworks.am>
To: dev@dpdk.org
Cc: Ivan Malov <ivan.malov@arknetworks.am>,
	Viacheslav Galaktionov <viacheslav.galaktionov@arknetworks.am>,
	Andy Moreton <amoreton@xilinx.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
	Ferruh Yigit <ferruh.yigit@amd.com>
Subject: [PATCH v2 2/2] net/sfc: support IPv4 fragment matching in transfer rules
Date: Wed, 28 Jun 2023 11:00:22 +0400	[thread overview]
Message-ID: <20230628070022.410127-3-artemii.morozov@arknetworks.am> (raw)
In-Reply-To: <20230628070022.410127-1-artemii.morozov@arknetworks.am>

This patch adds the support for IPv4 fragmented packets, but with
some limitations: for non-zero fragment offset an exact match is not
allowed, but ranges are allowed.

Signed-off-by: Artemii Morozov <artemii.morozov@arknetworks.am>
Reviewed-by: Viacheslav Galaktionov <viacheslav.galaktionov@arknetworks.am>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc_mae.c | 110 +++++++++++++++++++++++++++++++++++++-
 drivers/net/sfc/sfc_mae.h |   4 ++
 2 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/drivers/net/sfc/sfc_mae.c b/drivers/net/sfc/sfc_mae.c
index a3131c244d..63f6536243 100644
--- a/drivers/net/sfc/sfc_mae.c
+++ b/drivers/net/sfc/sfc_mae.c
@@ -1700,6 +1700,80 @@ sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
 	if (rc != 0)
 		goto fail;
 
+	if (pdata->l3_frag_ofst_mask != 0) {
+		const rte_be16_t hdr_mask = RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK);
+		rte_be16_t value;
+		rte_be16_t last;
+		boolean_t first_frag;
+		boolean_t is_ip_frag;
+		boolean_t any_frag;
+
+		if (pdata->l3_frag_ofst_mask & RTE_BE16(RTE_IPV4_HDR_DF_FLAG)) {
+			sfc_err(ctx->sa, "Don't fragment flag is not supported.");
+			rc = ENOTSUP;
+			goto fail;
+		}
+
+		if ((pdata->l3_frag_ofst_mask & hdr_mask) != hdr_mask) {
+			sfc_err(ctx->sa, "Invalid value for fragment offset mask.");
+			rc = EINVAL;
+			goto fail;
+		}
+
+		value = pdata->l3_frag_ofst_mask & pdata->l3_frag_ofst_value;
+		last = pdata->l3_frag_ofst_mask & pdata->l3_frag_ofst_last;
+
+		/*
+		 *  value:  last:       matches:
+		 *  0       0           Non-fragmented packet
+		 *  1       0x1fff      Non-first fragment
+		 *  1       0x1fff+MF   Any fragment
+		 *  MF      0           First fragment
+		 */
+		if (last == 0 &&
+		    (pdata->l3_frag_ofst_value & hdr_mask) != 0) {
+			sfc_err(ctx->sa,
+				"Exact matching is prohibited for non-zero offsets, but ranges are allowed.");
+			rc = EINVAL;
+			goto fail;
+		}
+
+		if (value == 0 && last == 0) {
+			is_ip_frag = false;
+			any_frag = true;
+		} else if (value == RTE_BE16(1) && (last & hdr_mask) == hdr_mask) {
+			if (last & RTE_BE16(RTE_IPV4_HDR_MF_FLAG)) {
+				is_ip_frag = true;
+				any_frag = true;
+			} else {
+				is_ip_frag = true;
+				any_frag = false;
+				first_frag = false;
+			}
+		} else if (value == RTE_BE16(RTE_IPV4_HDR_MF_FLAG) && last == 0) {
+			is_ip_frag = true;
+			any_frag = false;
+			first_frag = true;
+		} else {
+			sfc_err(ctx->sa, "Invalid value for fragment offset.");
+			rc = EINVAL;
+			goto fail;
+		}
+
+		rc = efx_mae_match_spec_bit_set(ctx->match_spec,
+						fremap[EFX_MAE_FIELD_IS_IP_FRAG], is_ip_frag);
+		if (rc != 0)
+			goto fail;
+
+		if (!any_frag) {
+			rc = efx_mae_match_spec_bit_set(ctx->match_spec,
+							fremap[EFX_MAE_FIELD_IP_FIRST_FRAG],
+							first_frag);
+			if (rc != 0)
+				goto fail;
+		}
+	}
+
 	return 0;
 
 fail:
@@ -2208,6 +2282,15 @@ static const struct sfc_mae_field_locator flocs_ipv4[] = {
 		RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
 		offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
 	},
+	{
+		/*
+		 * This locator is used only for building supported fields mask.
+		 * The field is handled by sfc_mae_rule_process_pattern_data().
+		 */
+		SFC_MAE_FIELD_HANDLING_DEFERRED,
+		RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.fragment_offset),
+		offsetof(struct rte_flow_item_ipv4, hdr.fragment_offset),
+	},
 	{
 		EFX_MAE_FIELD_IP_TOS,
 		RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
@@ -2230,14 +2313,30 @@ sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
 	struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
 	struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
 	struct rte_flow_item_ipv4 supp_mask;
+	struct rte_flow_item item_dup;
 	const uint8_t *spec = NULL;
 	const uint8_t *mask = NULL;
+	const uint8_t *last = NULL;
 	int rc;
 
+	item_dup.spec = item->spec;
+	item_dup.mask = item->mask;
+	item_dup.last = item->last;
+	item_dup.type = item->type;
+
 	sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
 				     &supp_mask, sizeof(supp_mask));
 
-	rc = sfc_flow_parse_init(item,
+	/* We don't support IPv4 fragmentation in the outer frames. */
+	if (ctx_mae->match_spec != ctx_mae->match_spec_action)
+		supp_mask.hdr.fragment_offset = 0;
+
+	if (item != NULL && item->last != NULL) {
+		last = item->last;
+		item_dup.last = NULL;
+	}
+
+	rc = sfc_flow_parse_init(&item_dup,
 				 (const void **)&spec, (const void **)&mask,
 				 (const void *)&supp_mask,
 				 &rte_flow_item_ipv4_mask,
@@ -2251,12 +2350,19 @@ sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
 	if (spec != NULL) {
 		const struct rte_flow_item_ipv4 *item_spec;
 		const struct rte_flow_item_ipv4 *item_mask;
+		const struct rte_flow_item_ipv4 *item_last;
 
 		item_spec = (const struct rte_flow_item_ipv4 *)spec;
 		item_mask = (const struct rte_flow_item_ipv4 *)mask;
+		if (last != NULL)
+			item_last = (const struct rte_flow_item_ipv4 *)last;
 
 		pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
 		pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
+		pdata->l3_frag_ofst_mask = item_mask->hdr.fragment_offset;
+		pdata->l3_frag_ofst_value = item_spec->hdr.fragment_offset;
+		if (last != NULL)
+			pdata->l3_frag_ofst_last = item_last->hdr.fragment_offset;
 	} else {
 		return 0;
 	}
@@ -2518,6 +2624,8 @@ static const efx_mae_field_id_t field_ids_no_remap[] = {
 	FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
 	FIELD_ID_NO_REMAP(HAS_OVLAN),
 	FIELD_ID_NO_REMAP(HAS_IVLAN),
+	FIELD_ID_NO_REMAP(IS_IP_FRAG),
+	FIELD_ID_NO_REMAP(IP_FIRST_FRAG),
 
 #undef FIELD_ID_NO_REMAP
 };
diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h
index 80585c0e93..059718e383 100644
--- a/drivers/net/sfc/sfc_mae.h
+++ b/drivers/net/sfc/sfc_mae.h
@@ -334,6 +334,10 @@ struct sfc_mae_pattern_data {
 	uint8_t				l3_next_proto_restriction_value;
 	uint8_t				l3_next_proto_restriction_mask;
 
+	rte_be16_t			l3_frag_ofst_value;
+	rte_be16_t			l3_frag_ofst_mask;
+	rte_be16_t			l3_frag_ofst_last;
+
 	/* Projected state of EFX_MAE_FIELD_HAS_OVLAN match bit */
 	bool				has_ovlan_value;
 	bool				has_ovlan_mask;
-- 
2.34.1


  parent reply	other threads:[~2023-06-28  7:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 16:58 [PATCH 0/2] " Artemii Morozov
2023-06-23 16:58 ` [PATCH 1/2] common/sfc_efx/base: add MAE IP fragmentation match bits Artemii Morozov
2023-06-23 16:58 ` [PATCH 2/2] net/sfc: support IPv4 fragment matching in transfer rules Artemii Morozov
2023-06-27 14:02 ` [PATCH 0/2] " Ferruh Yigit
2023-06-28  7:00 ` [PATCH v2 " Artemii Morozov
2023-06-28  7:00   ` [PATCH v2 1/2] common/sfc_efx/base: add MAE IP fragmentation match bits Artemii Morozov
2023-06-28  7:00   ` Artemii Morozov [this message]
2023-06-28 10:53   ` [PATCH v2 0/2] support IPv4 fragment matching in transfer rules 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=20230628070022.410127-3-artemii.morozov@arknetworks.am \
    --to=artemii.morozov@arknetworks.am \
    --cc=amoreton@xilinx.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=ivan.malov@arknetworks.am \
    --cc=viacheslav.galaktionov@arknetworks.am \
    /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).