DPDK patches and discussions
 help / color / mirror / Atom feed
From: wenjing.qiao@intel.com
To: jingjing.wu@intel.com, beilei.xing@intel.com, qi.z.zhang@intel.com
Cc: dev@dpdk.org, yuying.zhang@intel.com,
	Wenjing Qiao <wenjing.qiao@intel.com>
Subject: [PATCH] net/cpfl: refine vxlan encap content
Date: Thu,  2 Nov 2023 09:39:50 +0000	[thread overview]
Message-ID: <20231102093949.484647-1-wenjing.qiao@intel.com> (raw)

From: Wenjing Qiao <wenjing.qiao@intel.com>

Refine vxlan encap content of all protocol headers with default
configuration.

Fixes: 6cc97c9971d7 ("net/cpfl: build action mapping rules from JSON")

Signed-off-by: Wenjing Qiao <wenjing.qiao@intel.com>
---
 drivers/net/cpfl/cpfl_flow_parser.c | 63 ++++++++++++++++++++++++++++-
 drivers/net/cpfl/cpfl_flow_parser.h | 11 +++++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/drivers/net/cpfl/cpfl_flow_parser.c b/drivers/net/cpfl/cpfl_flow_parser.c
index 412f7feed0..9b2d6df150 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.c
+++ b/drivers/net/cpfl/cpfl_flow_parser.c
@@ -1609,6 +1609,60 @@ cpfl_parse_mr_key_action(struct cpfl_flow_js_mr_key_action *key_acts, int size,
 	return 0;
 }
 
+static int
+cpfl_translate_definition(struct rte_flow_item *definition, int def_length,
+			  struct cpfl_action_vxlan_encap_data *encap_data)
+{
+	int i;
+	struct rte_flow_item *item;
+
+	for (i = 0; i < def_length; i++) {
+		item = &encap_data->items[i];
+		item->type = definition[i].type;
+		switch (item->type) {
+		case RTE_FLOW_ITEM_TYPE_ETH:
+			item->spec = &encap_data->item_eth;
+			memcpy(&encap_data->item_eth, definition[i].spec,
+			       sizeof(struct rte_flow_item_eth));
+			break;
+		case RTE_FLOW_ITEM_TYPE_VOID:
+		case RTE_FLOW_ITEM_TYPE_VLAN:
+			item->spec = &encap_data->item_vlan;
+			memcpy(&encap_data->item_vlan, definition[i].spec,
+			       sizeof(struct rte_flow_item_vlan));
+			break;
+		case RTE_FLOW_ITEM_TYPE_IPV4:
+			item->spec = &encap_data->item_ipv4;
+			memcpy(&encap_data->item_ipv4, definition[i].spec,
+			       sizeof(struct rte_flow_item_ipv4));
+			break;
+		case RTE_FLOW_ITEM_TYPE_UDP:
+			item->spec = &encap_data->item_udp;
+			memcpy(&encap_data->item_udp, definition[i].spec,
+			       sizeof(struct rte_flow_item_udp));
+			break;
+		case RTE_FLOW_ITEM_TYPE_VXLAN:
+			item->spec = &encap_data->item_vxlan;
+			memcpy(&encap_data->item_vxlan, definition[i].spec,
+			       sizeof(struct rte_flow_item_vxlan));
+			break;
+		case RTE_FLOW_ITEM_TYPE_END:
+			break;
+		default:
+			return -EINVAL;
+		}
+		encap_data->item_eth.hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
+		encap_data->item_ipv4.hdr.version_ihl = RTE_IPV4_VHL_DEF;
+		encap_data->item_ipv4.hdr.next_proto_id = IPPROTO_UDP;
+		encap_data->item_ipv4.hdr.time_to_live = IPDEFTTL;
+		encap_data->item_ipv4.hdr.hdr_checksum = rte_cpu_to_be_16(1);
+		encap_data->item_udp.hdr.dgram_cksum = RTE_BE16(0x01);
+		encap_data->item_vxlan.flags = 0x08;
+	}
+
+	return 0;
+}
+
 /* output: uint8_t *buffer, uint16_t *byte_len */
 static int
 cpfl_parse_layout(struct cpfl_flow_js_mr_layout *layouts, int layout_size,
@@ -1640,12 +1694,19 @@ cpfl_parse_layout(struct cpfl_flow_js_mr_layout *layouts, int layout_size,
 		if (temp->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP) {
 			const struct rte_flow_action_vxlan_encap *action_vxlan_encap;
 			struct rte_flow_item *definition;
-			int def_length, k;
+			int def_length, k, ret;
+			struct cpfl_action_vxlan_encap_data vxlan_encap_data = {0};
 
 			action_vxlan_encap =
 			    (const struct rte_flow_action_vxlan_encap *)temp->encap.action->conf;
 			definition = action_vxlan_encap->definition;
 			def_length = cpfl_get_items_length(definition);
+			ret = cpfl_translate_definition(definition, def_length, &vxlan_encap_data);
+			if (ret < 0) {
+				PMD_DRV_LOG(ERR, "vxlan_encap: can't translate definition items.");
+				return -EINVAL;
+			}
+			definition = vxlan_encap_data.items;
 			for (k = 0; k < def_length - 1; k++) {
 				if ((strcmp(hint, "eth") == 0 &&
 				     definition[k].type == RTE_FLOW_ITEM_TYPE_ETH) ||
diff --git a/drivers/net/cpfl/cpfl_flow_parser.h b/drivers/net/cpfl/cpfl_flow_parser.h
index 962667adc2..99b4b87d90 100644
--- a/drivers/net/cpfl/cpfl_flow_parser.h
+++ b/drivers/net/cpfl/cpfl_flow_parser.h
@@ -13,6 +13,7 @@
 #define CPFL_MAX_SEM_FV_KEY_SIZE 64
 #define CPFL_FLOW_JS_PROTO_SIZE 16
 #define CPFL_MOD_KEY_NUM_MAX 8
+#define CPFL_VXLAN_ENCAP_ITEMS_NUM_MAX 6
 
 /* Pattern Rules Storage */
 enum cpfl_flow_pr_action_type {
@@ -203,6 +204,16 @@ struct cpfl_flow_mr_key_action_vxlan_encap {
 	const struct rte_flow_action *action;
 };
 
+/* Storage for struct rte_flow_action_vxlan_encap including external data. */
+struct cpfl_action_vxlan_encap_data {
+	struct rte_flow_item items[CPFL_VXLAN_ENCAP_ITEMS_NUM_MAX];
+	struct rte_flow_item_eth item_eth;
+	struct rte_flow_item_vlan item_vlan;
+	struct rte_flow_item_ipv4 item_ipv4;
+	struct rte_flow_item_udp item_udp;
+	struct rte_flow_item_vxlan item_vxlan;
+};
+
 struct cpfl_flow_mr_key_action {
 	enum rte_flow_action_type type;
 	union {
-- 
2.34.1


                 reply	other threads:[~2023-11-02  9:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231102093949.484647-1-wenjing.qiao@intel.com \
    --to=wenjing.qiao@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=yuying.zhang@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).