[3/4] net/nfp: support generic UDP flow item

Message ID 20240528015504.2376070-4-chaoyong.he@corigine.com (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers
Series support generic flow item |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He May 28, 2024, 1:55 a.m. UTC
  Add support of UDP flow item with a NULL 'item->spec' value.

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 | 41 ++++++++++++++++--------
 1 file changed, 28 insertions(+), 13 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c
index 810f55f805..4cbdfd02b8 100644
--- a/drivers/net/nfp/flower/nfp_flower_flow.c
+++ b/drivers/net/nfp/flower/nfp_flower_flow.c
@@ -1522,18 +1522,13 @@  nfp_flow_merge_udp(__rte_unused struct nfp_app_fw_flower *app_fw_flower,
 		bool is_mask,
 		bool is_outer_layer)
 {
-	char *ports_off;
 	struct nfp_flower_tp_ports *ports;
+	struct nfp_flower_ipv4 *ipv4 = NULL;
+	struct nfp_flower_ipv6 *ipv6 = NULL;
 	const struct rte_flow_item_udp *spec;
 	const struct rte_flow_item_udp *mask;
 	struct nfp_flower_meta_tci *meta_tci;
 
-	spec = item->spec;
-	if (spec == NULL) {
-		PMD_DRV_LOG(DEBUG, "nfp flow merge udp: no item->spec!");
-		return 0;
-	}
-
 	/* Don't add L4 info if working on a inner layer pattern */
 	if (!is_outer_layer) {
 		PMD_DRV_LOG(INFO, "Detected inner layer UDP, skipping.");
@@ -1542,13 +1537,33 @@  nfp_flow_merge_udp(__rte_unused struct nfp_app_fw_flower *app_fw_flower,
 
 	meta_tci = (struct nfp_flower_meta_tci *)nfp_flow->payload.unmasked_data;
 	if ((meta_tci->nfp_flow_key_layer & NFP_FLOWER_LAYER_IPV4) != 0) {
-		ports_off = *mbuf_off - sizeof(struct nfp_flower_ipv4) -
-				sizeof(struct nfp_flower_tp_ports);
-	} else {/* IPv6 */
-		ports_off = *mbuf_off - sizeof(struct nfp_flower_ipv6) -
-				sizeof(struct nfp_flower_tp_ports);
+		ipv4 = (struct nfp_flower_ipv4 *)
+				(*mbuf_off - sizeof(struct nfp_flower_ipv4));
+		if (is_mask)
+			ipv4->ip_ext.proto = 0xFF;
+		else
+			ipv4->ip_ext.proto = IPPROTO_UDP;
+		ports = (struct nfp_flower_tp_ports *)
+				((char *)ipv4 - sizeof(struct nfp_flower_tp_ports));
+	} else if ((meta_tci->nfp_flow_key_layer & NFP_FLOWER_LAYER_IPV6) != 0) {
+		ipv6 = (struct nfp_flower_ipv6 *)
+				(*mbuf_off - sizeof(struct nfp_flower_ipv6));
+		if (is_mask)
+			ipv6->ip_ext.proto = 0xFF;
+		else
+			ipv6->ip_ext.proto = IPPROTO_UDP;
+		ports = (struct nfp_flower_tp_ports *)
+				((char *)ipv6 - sizeof(struct nfp_flower_tp_ports));
+	} else {
+		PMD_DRV_LOG(ERR, "nfp flow merge udp: no L3 layer!");
+		return -EINVAL;
+	}
+
+	spec = item->spec;
+	if (spec == NULL) {
+		PMD_DRV_LOG(DEBUG, "nfp flow merge udp: no item->spec!");
+		return 0;
 	}
-	ports = (struct nfp_flower_tp_ports *)ports_off;
 
 	mask = item->mask ? item->mask : proc->mask_default;
 	if (is_mask) {