Skip to contentSkip to conversation

net/pcap: fix handling of transmit errors

PATCH Superseded Stephen Hemminger 1 participant 3 messages Nov 16 – Nov 22 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/pcap: fix handling of transmit errors

The pcap PMD assumed that every error from pcap_sendpacket() was from back pressure. But in the case of bad mbuf or file system full or other hard errors, the packet needs to be dropped.

Bugzilla ID: 2132

Fixes cf91cce204ea ("net/pcap: fix error accounting and backpressure on Tx")
Reported-by Anthropic OSS scanner (ANT-2026-DLCI8IK6)
---
 drivers/net/pcap/pcap_ethdev.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -11
index fb18f0932b..e7a8f007e0 100644
@@ -607,16 +607,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 /*
  * Send a burst of packets to a pcap device.
- *
- * On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET
- * socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING).
- * The send() call only blocks when the kernel socket send buffer is full,
- * providing limited backpressure.
- *
- * On error, pcap_sendpacket() returns non-zero and the loop breaks,
- * leaving remaining packets unsent.
- *
- * Bottom line: backpressure is not an error.
  */
 static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
@@ -666,10 +656,18 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
 		RTE_ASSERT(data != NULL);
 
+		errno = 0;
 		if (unlikely(pcap_sendpacket(pcap, data, len) != 0)) {
+			/* retry on soft errors */
+			if (errno == EINTR || errno == EAGAIN ||
+			    errno == EWOULDBLOCK)
+				break;
+
 			/* Assume failure is backpressure */
 			PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
-			break;
+			rte_pktmbuf_free(mbuf);
+			tx_queue->tx_stat.err_pkts++;
+			continue;
 		}
 		num_tx++;
 		tx_bytes += len;
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/1 net/pcap: fix handling of transmit errors

The pcap PMD assumed every pcap_sendpacket() failure was back pressure and stopped the burst. A hard error such as EMSGSIZE or ENETDOWN caused the same mbuf to be returned to the caller on every burst, stalling the queue.

Only treat EAGAIN (socket send buffer full) as back pressure. Drop and count the packet on any other error, including ENOBUFS which means the packet was already dropped by the qdisc.

Use PMD_TX_LOG for the error message, as other errors in the Tx burst path do.

Bugzilla ID: 2132

Fixes cf91cce204ea ("net/pcap: fix error accounting and backpressure on Tx")
Reported-by Anthropic OSS scanner (ANT-2026-DLCI8IK6)

---
v2 - fix AI review feedback, use PMD_TX_LOG

 drivers/net/pcap/pcap_ethdev.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/net/pcap/pcap_ethdev.c +12 -13
index fb18f0932b..1b8d6dafa2 100644
@@ -607,16 +607,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 /*
  * Send a burst of packets to a pcap device.
- *
- * On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET
- * socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING).
- * The send() call only blocks when the kernel socket send buffer is full,
- * providing limited backpressure.
- *
- * On error, pcap_sendpacket() returns non-zero and the loop breaks,
- * leaving remaining packets unsent.
- *
- * Bottom line: backpressure is not an error.
  */
 static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
@@ -666,10 +656,19 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
 		RTE_ASSERT(data != NULL);
 
+		/* pcap_sendpacket() does not document errno, but it is the only way
+		 * to tell back pressure from a hard error.
+		 */
+		errno = 0;
 		if (unlikely(pcap_sendpacket(pcap, data, len) != 0)) {
-			/* Assume failure is backpressure */
-			PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
-			break;
+			/* nothing sent, caller should retry */
+			if (errno == EAGAIN || errno == EWOULDBLOCK)
+				break;
+
+			PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+			rte_pktmbuf_free(mbuf);
+			tx_queue->tx_stat.err_pkts++;
+			continue;
 		}
 		num_tx++;
 		tx_bytes += len;
Signature · 1 line
2.53.0
#2 lore raw
Quoted 11 lines · On Tue, 17 Nov 2026 10:32:12 -0800 Stephen Hemminger…

The pcap PMD assumed every pcap_sendpacket() failure was back pressure and stopped the burst. A hard error such as EMSGSIZE or ENETDOWN caused the same mbuf to be returned to the caller on every burst, stalling the queue.

Only treat EAGAIN (socket send buffer full) as back pressure. Drop and count the packet on any other error, including ENOBUFS which means the packet was already dropped by the qdisc.

Use PMD_TX_LOG for the error message, as other errors in the Tx burst path do.

Quoted 7 lines

Bugzilla ID: 2132

Fixes cf91cce204ea ("net/pcap: fix error accounting and backpressure on Tx")
Reported-by Anthropic OSS scanner (ANT-2026-DLCI8IK6)

---

Fixed up complaints about comments from AI and applied to next-net