net/cpfl: refine vxlan encap content

Message ID 20231102093949.484647-1-wenjing.qiao@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series net/cpfl: refine vxlan encap content |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Wenjing Qiao Nov. 2, 2023, 9:39 a.m. UTC
  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(-)
  

Patch

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 {