DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: liujie5@linkdatatechnology.com
To: stephen@networkplumber.org
Cc: dev@dpdk.org, Jie Liu <liujie5@linkdatatechnology.com>
Subject: [PATCH v10 19/23] net/sxe2: add mbuf validation in Tx debug mode
Date: Sat, 27 Jun 2026 12:14:49 +0800	[thread overview]
Message-ID: <20260627041449.846832-1-liujie5@linkdatatechnology.com> (raw)
In-Reply-To: <20260626064954.361771-1-liujie5@linkdatatechnology.com>

From: Jie Liu <liujie5@linkdatatechnology.com>

Introduce the 'sxe2_txrx_check_mbuf' helper function to validate
outgoing mbuf tunnel type flags when RTE_ETHDEV_DEBUG_TX is enabled.
The function checks that the RTE_MBUF_F_TX_TUNNEL_x flag in mbuf
ol_flags matches the actual tunnel protocol detected in the packet
(GTP, VXLAN, VXLAN-GPE, Geneve, GRE, or IPIP).

The validation uses only UDP port matching and L4 protocol detection;
it does NOT re-derive header lengths or checksum fields already
verified by rte_validate_tx_offload() and rte_net_intel_cksum_prepare().

All code is wrapped inside RTE_ETHDEV_DEBUG_TX conditional compilation
to ensure zero overhead in production builds.

Signed-off-by: Jie Liu <liujie5@linkdatatechnology.com>
---
 drivers/net/sxe2/sxe2_txrx.c | 156 +++++++++++++++++++++++++++++++++++
 1 file changed, 156 insertions(+)

diff --git a/drivers/net/sxe2/sxe2_txrx.c b/drivers/net/sxe2/sxe2_txrx.c
index 82b2e4fb7c..79870866d1 100644
--- a/drivers/net/sxe2/sxe2_txrx.c
+++ b/drivers/net/sxe2/sxe2_txrx.c
@@ -8,6 +8,9 @@
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <ethdev_driver.h>
+#include <rte_geneve.h>
+#include <rte_gtp.h>
+#include <rte_vxlan.h>
 #include <unistd.h>
 #include "sxe2_txrx.h"
 #include "sxe2_txrx_common.h"
@@ -89,6 +92,152 @@ static inline int32_t sxe2_tx_mbuf_empty_check(struct rte_mbuf *mbuf)
 	return 0;
 }
 
+#ifdef RTE_ETHDEV_DEBUG_TX
+static int32_t
+sxe2_txrx_check_mbuf(struct rte_mbuf *m)
+{
+	struct rte_ether_hdr *eth_hdr;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	struct rte_ipv6_hdr *ipv6_hdr;
+	struct rte_vlan_hdr *vlan_hdr;
+	void *l3_hdr;
+	uint64_t ol_flags = m->ol_flags;
+	uint64_t tunnel_type = ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK;
+	uint16_t l2_len;
+	uint16_t l3_len;
+	uint8_t l4_proto;
+	uint16_t ethertype;
+
+	eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
+
+	/* Parse Ethernet + VLAN headers */
+	l2_len = sizeof(struct rte_ether_hdr);
+	ethertype = eth_hdr->ether_type;
+	while (ethertype == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ||
+	       ethertype == rte_cpu_to_be_16(RTE_ETHER_TYPE_QINQ)) {
+		vlan_hdr = (struct rte_vlan_hdr *)((char *)eth_hdr + l2_len);
+		l2_len += sizeof(struct rte_vlan_hdr);
+		ethertype = vlan_hdr->eth_proto;
+	}
+
+	/* Parse L3 to get L3 length and L4 protocol */
+	if (ethertype == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4)) {
+		ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + l2_len);
+		l3_len = rte_ipv4_hdr_len(ipv4_hdr);
+		l4_proto = ipv4_hdr->next_proto_id;
+	} else if (ethertype == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6)) {
+		ipv6_hdr = (struct rte_ipv6_hdr *)((char *)eth_hdr + l2_len);
+		l3_len = sizeof(struct rte_ipv6_hdr);
+		l4_proto = ipv6_hdr->proto;
+	} else {
+		return 0;
+	}
+
+	l3_hdr = (char *)eth_hdr + l2_len;
+
+	/* Detect tunnel type and validate flag consistency */
+	if (l4_proto == IPPROTO_UDP) {
+		struct rte_udp_hdr *udp_hdr;
+		uint16_t dst_port;
+
+		udp_hdr = (struct rte_udp_hdr *)((char *)l3_hdr + l3_len);
+		dst_port = udp_hdr->dst_port;
+
+		/* GTP */
+		if (dst_port == rte_cpu_to_be_16(RTE_GTPC_UDP_PORT) ||
+		    dst_port == rte_cpu_to_be_16(RTE_GTPU_UDP_PORT)) {
+			if (!tunnel_type) {
+				PMD_LOG_ERR(TX, "GTP tunnel packet missing "
+					"RTE_MBUF_F_TX_TUNNEL_GTP flag");
+				return -1;
+			}
+			if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_GTP) {
+				PMD_LOG_ERR(TX, "GTP tunnel packet has wrong "
+					"tx offload flag %s, expected GTP",
+					rte_get_tx_ol_flag_name(tunnel_type));
+				return -1;
+			}
+			return 0;
+		}
+		/* VXLAN-GPE */
+		if (dst_port == rte_cpu_to_be_16(RTE_VXLAN_GPE_DEFAULT_PORT)) {
+			if (!tunnel_type) {
+				PMD_LOG_ERR(TX, "VXLAN-GPE tunnel packet missing "
+					"RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE flag");
+				return -1;
+			}
+			if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE) {
+				PMD_LOG_ERR(TX, "VXLAN-GPE tunnel packet has wrong "
+					"tx offload flag %s, expected VXLAN-GPE",
+					rte_get_tx_ol_flag_name(tunnel_type));
+				return -1;
+			}
+			return 0;
+		}
+		/* VXLAN */
+		if (dst_port == rte_cpu_to_be_16(RTE_VXLAN_DEFAULT_PORT)) {
+			if (!tunnel_type) {
+				PMD_LOG_ERR(TX, "VXLAN tunnel packet missing "
+					"RTE_MBUF_F_TX_TUNNEL_VXLAN flag");
+				return -1;
+			}
+			if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_VXLAN) {
+				PMD_LOG_ERR(TX, "VXLAN tunnel packet has wrong "
+					"tx offload flag %s, expected VXLAN",
+					rte_get_tx_ol_flag_name(tunnel_type));
+				return -1;
+			}
+			return 0;
+		}
+		/* Geneve */
+		if (dst_port == rte_cpu_to_be_16(RTE_GENEVE_DEFAULT_PORT)) {
+			if (!tunnel_type) {
+				PMD_LOG_ERR(TX, "Geneve tunnel packet missing "
+					"RTE_MBUF_F_TX_TUNNEL_GENEVE flag");
+				return -1;
+			}
+			if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_GENEVE) {
+				PMD_LOG_ERR(TX, "Geneve tunnel packet has wrong "
+					"tx offload flag %s, expected Geneve",
+					rte_get_tx_ol_flag_name(tunnel_type));
+				return -1;
+			}
+			return 0;
+		}
+	} else if (l4_proto == IPPROTO_GRE) {
+		/* GRE */
+		if (!tunnel_type) {
+			PMD_LOG_ERR(TX, "GRE tunnel packet missing "
+				"RTE_MBUF_F_TX_TUNNEL_GRE flag");
+			return -1;
+		}
+		if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_GRE) {
+			PMD_LOG_ERR(TX, "GRE tunnel packet has wrong "
+				"tx offload flag %s, expected GRE",
+				rte_get_tx_ol_flag_name(tunnel_type));
+			return -1;
+		}
+		return 0;
+	} else if (l4_proto == IPPROTO_IPIP) {
+		/* IP-in-IP */
+		if (!tunnel_type) {
+			PMD_LOG_ERR(TX, "IPIP tunnel packet missing "
+				"RTE_MBUF_F_TX_TUNNEL_IPIP flag");
+			return -1;
+		}
+		if (tunnel_type != RTE_MBUF_F_TX_TUNNEL_IPIP) {
+			PMD_LOG_ERR(TX, "IPIP tunnel packet has wrong "
+				"tx offload flag %s, expected IPIP",
+				rte_get_tx_ol_flag_name(tunnel_type));
+			return -1;
+		}
+		return 0;
+	}
+
+	return 0;
+}
+#endif
+
 uint16_t sxe2_tx_pkts_prepare(void *tx_queue,
 		struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 {
@@ -137,6 +286,13 @@ uint16_t sxe2_tx_pkts_prepare(void *tx_queue,
 			rte_errno = -ret;
 			goto l_end;
 		}
+#ifdef RTE_ETHDEV_DEBUG_TX
+		ret = sxe2_txrx_check_mbuf(mbuf);
+		if (ret != 0) {
+			rte_errno = -ret;
+			goto l_end;
+		}
+#endif
 	}
 l_end:
 	return i;
-- 
2.52.0


  parent reply	other threads:[~2026-06-27  4:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <220260625133139.207632-1-liujie5@linkdatatechnology.com>
2026-06-26  6:38 ` [PATCH v9 00/23] net/sxe2: added Linkdata sxe2 ethernet driver liujie5
2026-06-26 18:18   ` Stephen Hemminger
2026-06-26  6:38 ` [PATCH v9 01/23] net/sxe2: remove software statistics devargs liujie5
2026-06-26  6:39 ` [PATCH v9 02/23] net/sxe2: add Rx framework and packet types callback liujie5
2026-06-26  6:39 ` [PATCH v9 03/23] net/sxe2: support AVX512 vectorized path for Rx and Tx liujie5
2026-06-26  6:40 ` [PATCH v9 04/23] net/sxe2: add AVX2 vector data " liujie5
2026-06-26  6:40 ` [PATCH v9 05/23] net/sxe2: add link update callback liujie5
2026-06-26  6:41 ` [PATCH v9 06/23] net/sxe2: support L2 filtering and MAC config liujie5
2026-06-26  6:41 ` [PATCH v9 07/23] drivers: support RSS feature liujie5
2026-06-26  6:42 ` [PATCH v9 08/23] net/sxe2: support TM hierarchy and shaping liujie5
2026-06-26  6:42 ` [PATCH v9 09/23] net/sxe2: support IPsec inline protocol offload liujie5
2026-06-26  6:43 ` [PATCH v9 10/23] net/sxe2: support statistics and multi-process liujie5
2026-06-26  6:43 ` [PATCH v9 11/23] drivers: interrupt handling liujie5
2026-06-26  6:44 ` [PATCH v9 12/23] net/sxe2: add NEON vec Rx/Tx burst functions liujie5
2026-06-26  6:44 ` [PATCH v9 13/23] drivers: add support for VF representors liujie5
2026-06-26  6:45 ` [PATCH v9 14/23] net/sxe2: add support for custom UDP tunnel ports liujie5
2026-06-26  6:45 ` [PATCH v9 15/23] net/sxe2: support firmware version reading liujie5
2026-06-26  6:46 ` [PATCH v9 16/23] net/sxe2: implement get monitor address liujie5
2026-06-26  6:46 ` [PATCH v9 17/23] common/sxe2: add shared SFP module definitions liujie5
2026-06-26  6:47 ` [PATCH v9 18/23] net/sxe2: support SFP module info and EEPROM access liujie5
2026-06-26  6:47 ` [PATCH v9 19/23] net/sxe2: add mbuf validation in Tx debug mode liujie5
2026-06-26 18:21   ` Stephen Hemminger
2026-06-27  4:00     ` liujie5
2026-06-26  6:48 ` [PATCH v9 20/23] common/sxe2: add callback for memory event handling liujie5
2026-06-26  6:48 ` [PATCH v9 21/23] net/sxe2: add private devargs parsing liujie5
2026-06-26  6:49 ` [PATCH v9 22/23] net/sxe2: implement private dump info liujie5
2026-06-26  6:49 ` [PATCH v9 23/23] net/sxe2: update sxe2 feature matrix docs liujie5
2026-06-27  4:04   ` [PATCH v10 00/23] et/sxe2: added Linkdata sxe2 ethernet driver liujie5
2026-06-27  4:05   ` [PATCH v10 01/23] net/sxe2: remove software statistics devargs liujie5
2026-06-27  4:06   ` [PATCH v10 02/23] net/sxe2: add Rx framework and packet types callback liujie5
2026-06-27  4:06   ` [PATCH v10 03/23] net/sxe2: support AVX512 vectorized path for Rx and Tx liujie5
2026-06-27  4:07   ` [PATCH v10 04/23] net/sxe2: add AVX2 vector data " liujie5
2026-06-27  4:07   ` [PATCH v10 05/23] net/sxe2: add link update callback liujie5
2026-06-27  4:08   ` [PATCH v10 06/23] net/sxe2: support L2 filtering and MAC config liujie5
2026-06-27  4:08   ` [PATCH v10 07/23] drivers: support RSS feature liujie5
2026-06-27  4:09   ` [PATCH v10 08/23] net/sxe2: support TM hierarchy and shaping liujie5
2026-06-27  4:09   ` [PATCH v10 09/23] net/sxe2: support IPsec inline protocol offload liujie5
2026-06-27  4:10   ` [PATCH v10 10/23] net/sxe2: support statistics and multi-process liujie5
2026-06-27  4:10   ` [PATCH v10 11/23] drivers: interrupt handling liujie5
2026-06-27  4:11   ` [PATCH v10 12/23] net/sxe2: add NEON vec Rx/Tx burst functions liujie5
2026-06-27  4:11   ` [PATCH v10 13/23] drivers: add support for VF representors liujie5
2026-06-27  4:12   ` [PATCH v10 14/23] net/sxe2: add support for custom UDP tunnel ports liujie5
2026-06-27  4:12   ` [PATCH v10 15/23] net/sxe2: support firmware version reading liujie5
2026-06-27  4:13   ` [PATCH v10 16/23] net/sxe2: implement get monitor address liujie5
2026-06-27  4:13   ` [PATCH v10 17/23] common/sxe2: add shared SFP module definitions liujie5
2026-06-27  4:14   ` [PATCH v10 18/23] net/sxe2: support SFP module info and EEPROM access liujie5
2026-06-27  4:14   ` liujie5 [this message]
2026-06-27  4:15   ` [PATCH v10 20/23] common/sxe2: add callback for memory event handling liujie5
2026-06-27  4:15   ` [PATCH v10 21/23] net/sxe2: add private devargs parsing liujie5
2026-06-27  4:16   ` [PATCH v10 22/23] net/sxe2: implement private dump info liujie5
2026-06-27  4:16   ` [PATCH v10 23/23] net/sxe2: update sxe2 feature matrix docs liujie5

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=20260627041449.846832-1-liujie5@linkdatatechnology.com \
    --to=liujie5@linkdatatechnology.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /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