[PATCH v23 10/24] net/pcap: clean up TX dumper return value and types

Stephen Hemminger
2026-04-15T14:49:24Z

Use uint32_t for packet lengths to match rte_pktmbuf_pkt_len()
return type. Split rte_pktmbuf_read() out of the pcap_dump() call
and add RTE_ASSERT for bogus mbuf detection. Remove incorrect
err_pkts accounting since the dumper loop cannot partially fail,
and return the loop index for consistency with eth_pcap_tx.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/pcap/pcap_ethdev.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index ca08b8e342..8df66ebb96 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -407,7 +407,8 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
* dumper */
for (i = 0; i < nb_pkts; i++) {
struct rte_mbuf *mbuf = bufs[i];
- size_t len, caplen;
+ uint32_t len, caplen;
+ const uint8_t *data;

len = rte_pktmbuf_pkt_len(mbuf);
caplen = RTE_MIN(len, RTE_ETH_PCAP_SNAPSHOT_LEN);
@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
calculate_timestamp(&header.ts);
header.len = len;
header.caplen = caplen;
- /* rte_pktmbuf_read() returns a pointer to the data directly
- * in the mbuf (when the mbuf is contiguous) or, otherwise,
- * a pointer to temp_data after copying into it.
- */
- pcap_dump((u_char *)dumper, &header,
- rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
+
+ data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+
+ /* This could only happen if mbuf is bogus pkt_len > data_len */
+ RTE_ASSERT(data != NULL);
+ pcap_dump((u_char *)dumper, &header, data);

num_tx++;
tx_bytes += caplen;
+
rte_pktmbuf_free(mbuf);
}

@@ -435,9 +437,8 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
pcap_dump_flush(dumper);
dumper_q->tx_stat.pkts += num_tx;
dumper_q->tx_stat.bytes += tx_bytes;
- dumper_q->tx_stat.err_pkts += nb_pkts - num_tx;

- return nb_pkts;
+ return i;
}

/*
--
2.53.0