[PATCH v21 09/25] net/pcap: fix error accounting and backpressure on transmit

Stephen Hemminger
2026-03-25T02:41:16Z

Fix two problems in eth_pcap_tx():

Oversized multi-segment packets that exceed the bounce buffer are
dropped but were not counted as errors. Add err_pkts accounting
for these drops.

When pcap_sendpacket() fails due to kernel socket backpressure,
the remaining unsent packets were counted as TX errors. Since
backpressure is transient (EAGAIN/EBUSY/EINTR), break the loop
and return the number of packets attempted so the caller retains
ownership of the unsent mbufs per tx_burst semantics.

Fixes: fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
Cc: stable@dpdk.org

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

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index 02d5cb591f..ca08b8e342 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -462,7 +462,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
}

/*
- * Callback to handle sending packets through a real NIC.
+ * 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)
@@ -484,26 +494,27 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)

for (i = 0; i < nb_pkts; i++) {
struct rte_mbuf *mbuf = bufs[i];
- size_t len = rte_pktmbuf_pkt_len(mbuf);
- int ret;
+ uint32_t len = rte_pktmbuf_pkt_len(mbuf);
+ const uint8_t *data;

if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
PMD_LOG(ERR,
- "Dropping multi segment PCAP packet. Size (%zd) > max size (%u).",
+ "Dropping multi segment PCAP packet. Size (%u) > max size (%u).",
len, RTE_ETH_PCAP_SNAPSHOT_LEN);
+ tx_queue->tx_stat.err_pkts++;
rte_pktmbuf_free(mbuf);
continue;
}

- /* 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.
- */
- ret = pcap_sendpacket(pcap,
- rte_pktmbuf_read(mbuf, 0, len, temp_data), len);
- if (unlikely(ret != 0))
+ data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+ RTE_ASSERT(data != NULL);
+
+ if (unlikely(pcap_sendpacket(pcap, data, len) != 0)) {
+ /* Assume failure is backpressure */
+ PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
break;
+ }
num_tx++;
tx_bytes += len;
rte_pktmbuf_free(mbuf);
@@ -511,7 +522,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)

tx_queue->tx_stat.pkts += num_tx;
tx_queue->tx_stat.bytes += tx_bytes;
- tx_queue->tx_stat.err_pkts += i - num_tx;

return i;
}
--
2.53.0