[PATCH 1/4] app/dumpcap: fix packet count overshoot

Stephen Hemminger stephen at networkplumber.org
Tue Nov 17 17:06:19 CET 2026


When a packet count was given with -c or -a packets:NUM,
the capture could write up to a whole burst (32) of extra
packets because the count was only checked after each burst.
Limit the burst to the number of packets still wanted.

Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")
Cc: stable at dpdk.org

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 app/dumpcap/main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 46a6cb251e..c4790988e5 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -945,12 +945,15 @@ pcap_write_packets(pcap_dumper_t *dumper,
 static int process_ring(dumpcap_out_t out, struct rte_ring *r)
 {
 	struct rte_mbuf *pkts[BURST_SIZE];
-	unsigned int avail, n;
+	unsigned int avail, n, burst = BURST_SIZE;
 	static unsigned int empty_count;
 	ssize_t written;
 
-	n = rte_ring_sc_dequeue_burst(r, (void **) pkts, BURST_SIZE,
-				      &avail);
+	/* don't capture more than the requested number of packets */
+	if (stop.packets != 0 && stop.packets - packets_received < burst)
+		burst = stop.packets - packets_received;
+
+	n = rte_ring_sc_dequeue_burst(r, (void **) pkts, burst, &avail);
 	if (n == 0) {
 		/* don't consume endless amounts of cpu if idle */
 		if (empty_count < SLEEP_THRESHOLD)
-- 
2.53.0



More information about the dev mailing list