DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>,
	Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH 4/7] net/nfp: split out the flow item check logic
Date: Wed, 19 Jun 2024 17:19:38 +0800	[thread overview]
Message-ID: <20240619091941.3479371-5-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240619091941.3479371-1-chaoyong.he@corigine.com>

Split out the flow item check logic.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower_flow.c | 109 +++++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c
index b533f4e3f2..f73be3c9a2 100644
--- a/drivers/net/nfp/flower/nfp_flower_flow.c
+++ b/drivers/net/nfp/flower/nfp_flower_flow.c
@@ -820,8 +820,111 @@ struct nfp_item_calculate_param {
 	struct nfp_item_flag *flag;
 };
 
+typedef int (*nfp_flow_key_check_item_fn)(struct nfp_item_calculate_param *param);
 typedef int (*nfp_flow_key_calculate_item_fn)(struct nfp_item_calculate_param *param);
 
+static int
+nfp_flow_item_check_port(struct nfp_item_calculate_param *param)
+{
+	const struct rte_flow_item_port_id *port_id;
+
+	port_id = param->item->spec;
+	if (port_id == NULL || port_id->id >= RTE_MAX_ETHPORTS)
+		return -ERANGE;
+
+	return 0;
+}
+
+static int
+nfp_flow_item_check_ipv4(struct nfp_item_calculate_param *param)
+{
+	if (!param->flag->outer_ip4_flag)
+		param->flag->outer_ip4_flag = true;
+
+	return 0;
+}
+
+static int
+nfp_flow_item_check_ipv6(struct nfp_item_calculate_param *param)
+{
+	if (!param->flag->outer_ip6_flag)
+		param->flag->outer_ip6_flag = true;
+
+	return 0;
+}
+
+static int
+nfp_flow_item_check_vxlan(struct nfp_item_calculate_param *param)
+{
+	if (!param->flag->outer_ip4_flag && !param->flag->outer_ip6_flag) {
+		PMD_DRV_LOG(ERR, "No outer IP layer for VXLAN tunnel.");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+nfp_flow_item_check_geneve(struct nfp_item_calculate_param *param)
+{
+	if (!param->flag->outer_ip4_flag && !param->flag->outer_ip6_flag) {
+		PMD_DRV_LOG(ERR, "No outer IP layer for GENEVE tunnel.");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+nfp_flow_item_check_gre(struct nfp_item_calculate_param *param)
+{
+	if (!param->flag->outer_ip4_flag && !param->flag->outer_ip6_flag) {
+		PMD_DRV_LOG(ERR, "No outer IP layer for GRE tunnel.");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static nfp_flow_key_check_item_fn check_item_fns[] = {
+	[RTE_FLOW_ITEM_TYPE_PORT_ID]         = nfp_flow_item_check_port,
+	[RTE_FLOW_ITEM_TYPE_IPV4]            = nfp_flow_item_check_ipv4,
+	[RTE_FLOW_ITEM_TYPE_IPV6]            = nfp_flow_item_check_ipv6,
+	[RTE_FLOW_ITEM_TYPE_VXLAN]           = nfp_flow_item_check_vxlan,
+	[RTE_FLOW_ITEM_TYPE_GENEVE]          = nfp_flow_item_check_geneve,
+	[RTE_FLOW_ITEM_TYPE_GRE]             = nfp_flow_item_check_gre,
+};
+
+static int
+nfp_flow_key_layers_check_items(const struct rte_flow_item items[])
+{
+	int ret;
+	struct nfp_item_flag flag = {};
+	const struct rte_flow_item *item;
+	struct nfp_item_calculate_param param = {
+		.flag = &flag,
+	};
+
+	for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) {
+		if (item->type >= RTE_DIM(check_item_fns)) {
+			PMD_DRV_LOG(ERR, "Flow item %d unsupported", item->type);
+			return -ERANGE;
+		}
+
+		if (check_item_fns[item->type] == NULL)
+			continue;
+
+		param.item = item;
+		ret = check_item_fns[item->type](&param);
+		if (ret != 0) {
+			PMD_DRV_LOG(ERR, "Flow item %d check fail", item->type);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int
 nfp_flow_item_calculate_stub(struct nfp_item_calculate_param *param __rte_unused)
 {
@@ -1490,6 +1593,12 @@ nfp_flow_key_layers_calculate(const struct rte_flow_item items[],
 	key_ls->vlan = 0;
 	key_ls->tun_type = NFP_FL_TUN_NONE;
 
+	ret = nfp_flow_key_layers_check_items(items);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "flow items check failed");
+		return ret;
+	}
+
 	ret = nfp_flow_key_layers_calculate_items(items, key_ls);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "flow items calculate failed");
-- 
2.39.1


  parent reply	other threads:[~2024-06-19  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  9:19 [PATCH 0/7] refactor flow validate and create interface Chaoyong He
2024-06-19  9:19 ` [PATCH 1/7] net/nfp: remove the unused parameter Chaoyong He
2024-06-19  9:19 ` [PATCH 2/7] net/nfp: exit as soon as possible Chaoyong He
2024-06-19  9:19 ` [PATCH 3/7] net/nfp: remove the duplicate logic of output action Chaoyong He
2024-06-19  9:19 ` Chaoyong He [this message]
2024-06-19  9:19 ` [PATCH 5/7] net/nfp: simplify the flow item calculate logic Chaoyong He
2024-06-19  9:19 ` [PATCH 6/7] net/nfp: split out the flow action check logic Chaoyong He
2024-06-19  9:19 ` [PATCH 7/7] net/nfp: simplify the flow action calculate logic Chaoyong He

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=20240619091941.3479371-5-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=peng.zhang@corigine.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).