Skip to contentSkip to conversation

net/pcap: cleanups and test

PATCH Superseded Stephen Hemminger 6 participants 543 messages Jan 6 – Apr 30 Page 2 of 4

Subsystems (2)
lore
Share & tools
lore
#140 lore raw

PATCH v10 17/19 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index 5e72a985e4..415de46e22 100644
@@ -820,10 +820,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#141 lore raw

PATCH v10 18/19 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap_ring.rst          |  13 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 205 +++++++++++++++----------
 3 files changed, 137 insertions(+), 82 deletions(-)
doc/guides/nics/pcap_ring.rst +13 -0
index 5b9ca71b18..3a3946e4f1 100644
@@ -132,6 +132,19 @@ Runtime Config Options
 
 In this case, one dummy rx queue is created for each tx queue argument passed
 
+- Set the snapshot length for packet capture
+
+ The snapshot length controls the maximum number of bytes captured per packet.
+ This affects both interface capture and pcap file output.
+ The default value is 65535 bytes, which captures complete packets up to the maximum Ethernet jumbo frame size.
+ Reducing this value can improve performance when only packet headers are needed.
+ This can be done with a ``devarg`` ``snaplen``, for example::
+
+   --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+   --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+ The snapshot length also determines the reported ``max_rx_pktlen`` and ``max_mtu`` in device info.
+
 Examples of Usage
 ^^^^^^^^^^^^^^^^^
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 50ba8bf109..3ad3531800 100644
@@ -61,6 +61,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +123 -82

439 lines not on this page · raw message

Signature · 1 line
2.51.0
#142 lore raw

PATCH v10 19/19 test: add test for pcap PMD

In reply to Stephen Hemminger

This test was generated by Claude AI with some prompting and pointing at existing ring PMD test. It tests basic operations, timestamps, jumbo frame, vlan handling and multiple queues

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 2622 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 2625 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index f4d04a6e42..90e3afaecf 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +2622 -0

2,622 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 3ad3531800..f242ba978c 100644
@@ -62,6 +62,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added unit test suite.
 
 
 Removed Items
Signature · 1 line
2.51.0
#143 lore raw

v11 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snapshot_len devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows

v11:
- Fix build on FreeBsd

v10:
- Split transmit handling into separate patches for bulk free, bounce buffer allocation, and cleanup for easier review
- Add patch to reject non-Ethernet interfaces (fixes loopback issues on FreeBSD/macOS where DLT_NULL is used)
- Test uses pcap_findalldevs() for portable interface discovery instead of hardcoded interface names

v9:
- Add configurable snapshot length parameter (snapshot_len devarg)
- Defer opening of pcap files and interfaces until eth_dev_start() instead of during probe, passing configured snapshot length

Stephen Hemminger (19):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: use bulk free
net/pcap: allocate Tx bounce buffer net/pcap: cleanup transmit buffer handling net/pcap: report multi-segment transmit capability net/pcap: consolidate boolean flag handling net/pcap: support VLAN insert and strip net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet net/pcap: add snapshot length devarg
test: add test for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 2622 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    8 +
 doc/guides/nics/pcap_ring.rst          |   27 +
 doc/guides/rel_notes/release_26_03.rst |    9 +
 drivers/net/pcap/pcap_ethdev.c         |  655 ++++--
 drivers/net/pcap/pcap_osdep.h          |   23 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  115 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 3417 insertions(+), 238 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#144 lore raw

PATCH v11 1/19 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 5683b87e4a..28a3269568 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap_ring.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#145 lore raw

PATCH v11 2/19 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#146 lore raw

PATCH v11 3/19 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#147 lore raw

PATCH v11 4/19 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#148 lore raw

PATCH v11 5/19 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#149 lore raw

PATCH v11 6/19 net/pcap: use bulk free

In reply to Stephen Hemminger

Using function rte_pktmbuf_free_bulk is marginally faster here.

---
 drivers/net/pcap/pcap_ethdev.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +6 -9
index 806451dc99..61ba50e356 100644
@@ -423,8 +423,8 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		num_tx++;
 		tx_bytes += caplen;
-		rte_pktmbuf_free(mbuf);
 	}
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	/*
 	 * Since there's no place to hook a callback when the forwarding
@@ -449,13 +449,10 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
-	for (i = 0; i < nb_pkts; i++) {
+	for (i = 0; i < nb_pkts; i++)
 		tx_bytes += bufs[i]->pkt_len;
-		rte_pktmbuf_free(bufs[i]);
-	}
+
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
@@ -494,7 +491,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			PMD_LOG(ERR,
 				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
 				len, sizeof(temp_data));
-			rte_pktmbuf_free(mbuf);
 			continue;
 		}
 
@@ -508,9 +504,10 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			break;
 		num_tx++;
 		tx_bytes += len;
-		rte_pktmbuf_free(mbuf);
 	}
 
+	rte_pktmbuf_free_bulk(bufs, 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;
Signature · 1 line
2.51.0
#150 lore raw

PATCH v11 7/19 net/pcap: allocate Tx bounce buffer

In reply to Stephen Hemminger

To handle possible multi segment mbufs, the driver would allocate a worst case 64k buffer on the stack. Since each Tx queue is single threaded, better to allocate the buffer from hugepage with rte_malloc when queue is setup.

---
 drivers/net/pcap/pcap_ethdev.c | 41 +++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 15 deletions(-)
drivers/net/pcap/pcap_ethdev.c +26 -15
index 61ba50e356..1a186142d3 100644
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
@@ -91,6 +92,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used to for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -392,11 +396,12 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
+	unsigned char *temp_data;
 	size_t len, caplen;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -406,10 +411,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		calculate_timestamp(&header.ts);
 		header.len = len;
@@ -419,7 +420,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		 * a pointer to temp_data after copying into it.
 		 */
 		pcap_dump((u_char *)dumper, &header,
-			rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
+			  rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
 
 		num_tx++;
 		tx_bytes += caplen;
@@ -474,11 +475,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
+	unsigned char *temp_data;
 	size_t len;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
@@ -486,13 +488,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
-			continue;
-		}
 
 		/* rte_pktmbuf_read() returns a pointer to the data directly
 		 * in the mbuf (when the mbuf is contiguous) or, otherwise,
@@ -962,7 +957,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -970,11 +965,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1015,6 +1025,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
Signature · 1 line
2.51.0
#151 lore raw

PATCH v11 8/19 net/pcap: cleanup transmit buffer handling

In reply to Stephen Hemminger

The transmit loops should handle the possible failure of rte_pktmbuf_read(). If a pcap_sendpacket fails, then the packet with error should be freed.

---
 drivers/net/pcap/pcap_ethdev.c | 50 ++++++++++++++--------------------
 1 file changed, 21 insertions(+), 29 deletions(-)
drivers/net/pcap/pcap_ethdev.c +21 -29
index 1a186142d3..394fd0b6b2 100644
@@ -389,7 +389,6 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
@@ -397,7 +396,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
 	unsigned char *temp_data;
-	size_t len, caplen;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
@@ -409,21 +407,22 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len, caplen;
+		const uint8_t *data;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (likely(data != NULL)) {
+			pcap_dump((u_char *)dumper, &header, data);
+			num_tx++;
+			tx_bytes += caplen;
+		}
 	}
 	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
@@ -458,7 +457,7 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
@@ -468,15 +467,12 @@ static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
 	unsigned char *temp_data;
-	size_t len;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
@@ -486,19 +482,15 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
-
-		/* 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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len = rte_pktmbuf_pkt_len(mbuf);
+		const uint8_t *data;
+
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (likely(data != NULL && pcap_sendpacket(pcap, data, len) == 0)) {
+			num_tx++;
+			tx_bytes += len;
+		}
 	}
 
 	rte_pktmbuf_free_bulk(bufs, nb_pkts);
@@ -507,7 +499,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.bytes += tx_bytes;
 	tx_queue->tx_stat.err_pkts += i - num_tx;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
Signature · 1 line
2.51.0
#152 lore raw

PATCH v11 9/19 net/pcap: report multi-segment transmit capability

In reply to Stephen Hemminger

The driver has always handled multi-segment transmit but the flag was never set in the offload capabilities.

---
 drivers/net/pcap/pcap_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
index 394fd0b6b2..bd33e72a02 100644
@@ -737,6 +737,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
Signature · 1 line
2.51.0
#153 lore raw

PATCH v11 10/19 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index bd33e72a02..201eb97745 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -103,9 +104,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -115,25 +116,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -856,7 +857,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1181,29 +1182,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1479,7 +1470,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1518,9 +1509,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1670,5 +1661,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#154 lore raw

PATCH v11 11/19 net/pcap: support VLAN insert and strip

In reply to Stephen Hemminger

Driver can easily insert VLAN tag strip and insertion similar to how it is handled in virtio and af_packet.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/nics/pcap_ring.rst          | 11 +++++++++
 doc/guides/rel_notes/release_26_03.rst |  4 ++++
 drivers/net/pcap/pcap_ethdev.c         | 31 ++++++++++++++++++++++++--
 4 files changed, 45 insertions(+), 2 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap_ring.rst +11 -0
index 6955e91130..c005786ce3 100644
@@ -213,6 +213,17 @@ Otherwise, the first 512 packets from the input pcap file will be discarded by t
    an error if interface is down, and the PMD itself won't change the status
    of the external network interface.
 
+Features and Limitations
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +4 -0
index 15dabee7a1..7993ce2ee0 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
 
 Removed Items
 -------------
drivers/net/pcap/pcap_ethdev.c +29 -2
index 201eb97745..b19e837b97 100644
@@ -77,6 +77,7 @@ struct queue_missed_stat {
 struct pcap_rx_queue {
 	uint16_t port_id;
 	uint16_t queue_id;
+	bool vlan_strip;
 	struct rte_mempool *mb_pool;
 	struct queue_stat rx_stat;
 	struct queue_missed_stat missed_stat;
@@ -107,6 +108,7 @@ struct pmd_internals {
 	bool single_iface;
 	bool phy_mac;
 	bool infinite_rx;
+	bool vlan_strip;
 };
 
 struct pmd_process_private {
@@ -337,6 +339,10 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 
 		mbuf->pkt_len = len;
+
+		if (pcap_q->vlan_strip)
+			rte_vlan_strip(mbuf);
+
 		uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec;
 
 		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us;
@@ -412,9 +418,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		uint32_t len, caplen;
 		const uint8_t *data;
 
+		if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
+			/* if vlan insert fails treat it as error */
+			if (unlikely(rte_vlan_insert(&mbuf) != 0))
+				continue;
+		}
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
 
 		calculate_timestamp(&header.ts);
+
 		header.len = len;
 		header.caplen = caplen;
 
@@ -487,6 +500,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		uint32_t len = rte_pktmbuf_pkt_len(mbuf);
 		const uint8_t *data;
 
+		if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
+			/* if vlan insert fails treat it as error */
+			if (unlikely(rte_vlan_insert(&mbuf) != 0))
+				continue;
+		}
+
 		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
 		if (likely(data != NULL && pcap_sendpacket(pcap, data, len) == 0)) {
 			num_tx++;
@@ -721,8 +740,13 @@ eth_dev_stop(struct rte_eth_dev *dev)
 }
 
 static int
-eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
+eth_dev_configure(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
+	const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
+
+	internals->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
 	return 0;
 }
 
@@ -738,7 +762,9 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
+		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
+	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
 
 	return 0;
 }
@@ -885,6 +911,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 	pcap_q->mb_pool = mb_pool;
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = rx_queue_id;
+	pcap_q->vlan_strip = internals->vlan_strip;
 	dev->data->rx_queues[rx_queue_id] = pcap_q;
 
 	if (internals->infinite_rx) {
Signature · 1 line
2.51.0
#155 lore raw

PATCH v11 12/19 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  22 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 +++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 109 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 ++++++++++++++++++---
 6 files changed, 383 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index 7993ce2ee0..0264968567 100644
@@ -58,6 +58,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +22 -0
index a0e2b5ace9..732813c028 100644
@@ -13,7 +13,29 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +109 -0

118 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#156 lore raw

PATCH v11 13/19 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Defer timestamp dynfield registration from probe to device start, and only when timestamp offloading is enabled
* Add read_clock dev_op returning current UTC time
for timestamp correlation
* Move per-burst timestamp calculation outside the packet loop in tx_dumper
* Enable immediate mode and improve error reporting
in live capture setup

---
 doc/guides/nics/pcap_ring.rst          |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 145 +++++++++++++++++++------
 3 files changed, 114 insertions(+), 36 deletions(-)
doc/guides/nics/pcap_ring.rst +3 -0
index c005786ce3..5b9ca71b18 100644
@@ -224,6 +224,9 @@ Features and Limitations
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
 
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +2 -0
index 0264968567..50ba8bf109 100644
@@ -59,6 +59,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +109 -36

250 lines not on this page · raw message

Signature · 1 line
2.51.0
#157 lore raw

PATCH v11 14/19 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index 90bedb6286..f1965449eb 100644
@@ -578,6 +578,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#158 lore raw

PATCH v11 15/19 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index f1965449eb..e7c4f3be5f 100644
@@ -47,11 +47,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -536,6 +534,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -647,6 +646,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1416,6 +1417,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#159 lore raw

PATCH v11 16/19 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index e7c4f3be5f..5e72a985e4 100644
@@ -55,10 +55,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -837,11 +837,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#160 lore raw

PATCH v11 17/19 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index 5e72a985e4..415de46e22 100644
@@ -820,10 +820,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#161 lore raw

PATCH v11 18/19 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap_ring.rst          |  13 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 205 +++++++++++++++----------
 3 files changed, 137 insertions(+), 82 deletions(-)
doc/guides/nics/pcap_ring.rst +13 -0
index 5b9ca71b18..3a3946e4f1 100644
@@ -132,6 +132,19 @@ Runtime Config Options
 
 In this case, one dummy rx queue is created for each tx queue argument passed
 
+- Set the snapshot length for packet capture
+
+ The snapshot length controls the maximum number of bytes captured per packet.
+ This affects both interface capture and pcap file output.
+ The default value is 65535 bytes, which captures complete packets up to the maximum Ethernet jumbo frame size.
+ Reducing this value can improve performance when only packet headers are needed.
+ This can be done with a ``devarg`` ``snaplen``, for example::
+
+   --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+   --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+ The snapshot length also determines the reported ``max_rx_pktlen`` and ``max_mtu`` in device info.
+
 Examples of Usage
 ^^^^^^^^^^^^^^^^^
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 50ba8bf109..3ad3531800 100644
@@ -61,6 +61,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +123 -82

439 lines not on this page · raw message

Signature · 1 line
2.51.0
#162 lore raw

PATCH v11 19/19 test: add test for pcap PMD

In reply to Stephen Hemminger

This test was generated by Claude AI with some prompting and pointing at existing ring PMD test. It tests basic operations, timestamps, jumbo frame, vlan handling and multiple queues

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 2622 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 2625 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index f4d04a6e42..90e3afaecf 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +2622 -0

2,622 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 3ad3531800..f242ba978c 100644
@@ -62,6 +62,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added unit test suite.
 
 
 Removed Items
Signature · 1 line
2.51.0
#163 lore raw

v12 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snapshot_len devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v12:
- Add vlan_offload_set callback to support runtime VLAN strip configuration via rte_eth_dev_set_vlan_offload()
- Fix bugs in vlan strip and infinite rx mode
- Rebase to main

v11:
- Fix build on FreeBsd

v10:
- Split transmit handling into separate patches for bulk free, bounce buffer allocation, and cleanup for easier review
- Add patch to reject non-Ethernet interfaces (fixes loopback issues on FreeBSD/macOS where DLT_NULL is used)
- Test uses pcap_findalldevs() for portable interface discovery instead of hardcoded interface names

v9:
- Add configurable snapshot length parameter (snapshot_len devarg)
- Defer opening of pcap files and interfaces until eth_dev_start() instead of during probe, passing configured snapshot length

Stephen Hemminger (19):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: use bulk free
net/pcap: allocate Tx bounce buffer net/pcap: cleanup transmit buffer handling net/pcap: report multi-segment transmit capability net/pcap: consolidate boolean flag handling net/pcap: support VLAN insert and strip net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet net/pcap: add snapshot length devarg
test: add test for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c              | 2962 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    8 +
 doc/guides/nics/pcap_ring.rst          |   27 +
 doc/guides/rel_notes/release_26_03.rst |    9 +
 drivers/net/pcap/pcap_ethdev.c         |  670 ++++--
 drivers/net/pcap/pcap_osdep.h          |   23 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  115 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 3772 insertions(+), 238 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 39 lines
2.51.0

Stephen Hemminger (19):
  maintainers: update for pcap driver
  doc: update features for PCAP PMD
  net/pcap: include used headers
  net/pcap: remove unnecessary casts
  net/pcap: avoid using rte_malloc and rte_memcpy
  net/pcap: use bulk free
  net/pcap: allocate Tx bounce buffer
  net/pcap: cleanup transmit buffer handling
  net/pcap: report multi-segment transmit capability
  net/pcap: consolidate boolean flag handling
  net/pcap: support VLAN insert and strip
  net/pcap: add link state and speed for interface mode
  net/pcap: support nanosecond timestamp precision
  net/pcap: reject non-Ethernet interfaces
  net/pcap: reduce scope of file-level variables
  net/pcap: avoid use of volatile
  net/pcap: clarify maximum received packet
  net/pcap: add snapshot length devarg
  test: add test for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 2962 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    8 +
 doc/guides/nics/pcap_ring.rst          |   27 +
 doc/guides/rel_notes/release_26_03.rst |    9 +
 drivers/net/pcap/pcap_ethdev.c         |  709 ++++--
 drivers/net/pcap/pcap_osdep.h          |   23 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 3819 insertions(+), 239 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c

-- 
2.51.0
#164 lore raw

PATCH v12 1/19 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 5683b87e4a..28a3269568 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap_ring.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#165 lore raw

PATCH v12 2/19 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#166 lore raw

PATCH v12 3/19 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#167 lore raw

PATCH v12 4/19 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#168 lore raw

PATCH v12 5/19 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#169 lore raw

PATCH v12 6/19 net/pcap: use bulk free

In reply to Stephen Hemminger

Using function rte_pktmbuf_free_bulk is marginally faster here.

---
 drivers/net/pcap/pcap_ethdev.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +6 -9
index 806451dc99..61ba50e356 100644
@@ -423,8 +423,8 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		num_tx++;
 		tx_bytes += caplen;
-		rte_pktmbuf_free(mbuf);
 	}
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	/*
 	 * Since there's no place to hook a callback when the forwarding
@@ -449,13 +449,10 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
-	for (i = 0; i < nb_pkts; i++) {
+	for (i = 0; i < nb_pkts; i++)
 		tx_bytes += bufs[i]->pkt_len;
-		rte_pktmbuf_free(bufs[i]);
-	}
+
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
@@ -494,7 +491,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			PMD_LOG(ERR,
 				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
 				len, sizeof(temp_data));
-			rte_pktmbuf_free(mbuf);
 			continue;
 		}
 
@@ -508,9 +504,10 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			break;
 		num_tx++;
 		tx_bytes += len;
-		rte_pktmbuf_free(mbuf);
 	}
 
+	rte_pktmbuf_free_bulk(bufs, 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;
Signature · 1 line
2.51.0
#170 lore raw

PATCH v12 7/19 net/pcap: allocate Tx bounce buffer

In reply to Stephen Hemminger

To handle possible multi segment mbufs, the driver would allocate a worst case 64k buffer on the stack. Since each Tx queue is single threaded, better to allocate the buffer from hugepage with rte_malloc when queue is setup.

The buffer needs to be come from huge pages because the primary process may start the device but the bounce buffer could be used in transmit path by secondary process.

---
 drivers/net/pcap/pcap_ethdev.c | 41 +++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 15 deletions(-)
drivers/net/pcap/pcap_ethdev.c +26 -15
index 61ba50e356..a89379ea9c 100644
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
@@ -91,6 +92,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -392,11 +396,12 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
+	unsigned char *temp_data;
 	size_t len, caplen;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -406,10 +411,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		calculate_timestamp(&header.ts);
 		header.len = len;
@@ -419,7 +420,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		 * a pointer to temp_data after copying into it.
 		 */
 		pcap_dump((u_char *)dumper, &header,
-			rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
+			  rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
 
 		num_tx++;
 		tx_bytes += caplen;
@@ -474,11 +475,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
+	unsigned char *temp_data;
 	size_t len;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
@@ -486,13 +488,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	for (i = 0; i < nb_pkts; i++) {
 		mbuf = bufs[i];
 		len = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
-			continue;
-		}
 
 		/* rte_pktmbuf_read() returns a pointer to the data directly
 		 * in the mbuf (when the mbuf is contiguous) or, otherwise,
@@ -962,7 +957,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -970,11 +965,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1015,6 +1025,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
Signature · 1 line
2.51.0
#171 lore raw

PATCH v12 8/19 net/pcap: cleanup transmit buffer handling

In reply to Stephen Hemminger

The transmit loops should handle the possible failure of rte_pktmbuf_read(). If a pcap_sendpacket fails, then the packet with error should be freed.

---
 drivers/net/pcap/pcap_ethdev.c | 60 ++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 28 deletions(-)
drivers/net/pcap/pcap_ethdev.c +32 -28
index a89379ea9c..0aa3d67e4d 100644
@@ -389,7 +389,6 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
@@ -397,7 +396,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
 	unsigned char *temp_data;
-	size_t len, caplen;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
@@ -409,21 +407,22 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len, caplen;
+		const uint8_t *data;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (likely(data != NULL)) {
+			pcap_dump((u_char *)dumper, &header, data);
+			num_tx++;
+			tx_bytes += caplen;
+		}
 	}
 	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
@@ -458,7 +457,7 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
@@ -468,15 +467,12 @@ static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
 	unsigned char *temp_data;
-	size_t len;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
@@ -486,19 +482,27 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len = rte_pktmbuf_pkt_len(mbuf);
+		const uint8_t *data;
 
-		/* 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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
+			static int warned;
+
+			if (!warned) {
+				PMD_LOG(ERR,
+					"Multi segment PCAP packet. Size (%u) > max size (%u).",
+					len, RTE_ETH_PCAP_SNAPSHOT_LEN);
+				warned = 1;
+			}
+			continue;
+		}
+
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (likely(data != NULL && pcap_sendpacket(pcap, data, len) == 0)) {
+			num_tx++;
+			tx_bytes += len;
+		}
 	}
 
 	rte_pktmbuf_free_bulk(bufs, nb_pkts);
@@ -507,7 +511,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.bytes += tx_bytes;
 	tx_queue->tx_stat.err_pkts += i - num_tx;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
Signature · 1 line
2.51.0
#172 lore raw

PATCH v12 9/19 net/pcap: report multi-segment transmit capability

In reply to Stephen Hemminger

The driver has always handled multi-segment transmit but the flag was never set in the offload capabilities.

---
 drivers/net/pcap/pcap_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
index 0aa3d67e4d..d983135a4a 100644
@@ -749,6 +749,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
Signature · 1 line
2.51.0
#173 lore raw

PATCH v12 10/19 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index d983135a4a..dcfd636fa0 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -103,9 +104,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -115,25 +116,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -868,7 +869,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1193,29 +1194,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1491,7 +1482,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1530,9 +1521,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1682,5 +1673,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#174 lore raw

PATCH v12 11/19 net/pcap: support VLAN insert and strip

In reply to Stephen Hemminger

Driver can easily insert VLAN tag strip and insertion similar to how it is handled in virtio and af_packet.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/nics/pcap_ring.rst          | 11 ++++
 doc/guides/rel_notes/release_26_03.rst |  4 ++
 drivers/net/pcap/pcap_ethdev.c         | 71 ++++++++++++++++++++++++--
 4 files changed, 84 insertions(+), 3 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap_ring.rst +11 -0
index 6955e91130..c005786ce3 100644
@@ -213,6 +213,17 @@ Otherwise, the first 512 packets from the input pcap file will be discarded by t
    an error if interface is down, and the PMD itself won't change the status
    of the external network interface.
 
+Features and Limitations
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +4 -0
index a837bdb600..9d4bdfc985 100644
@@ -59,6 +59,10 @@ New Features
 
   * Added support for V4000 Krackan2e.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
 
 Removed Items
 -------------
drivers/net/pcap/pcap_ethdev.c +68 -3

164 lines not on this page · raw message

Signature · 1 line
2.51.0
#175 lore raw

PATCH v12 12/19 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  22 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 392 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index 9d4bdfc985..3836870961 100644
@@ -62,6 +62,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +22 -0
index a0e2b5ace9..732813c028 100644
@@ -13,7 +13,29 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#176 lore raw

PATCH v12 13/19 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Defer timestamp dynfield registration from probe to device start, and only when timestamp offloading is enabled
* Add read_clock dev_op returning current UTC time
for timestamp correlation
* Move per-burst timestamp calculation outside the packet loop in tx_dumper
* Enable immediate mode and improve error reporting
in live capture setup

---
 doc/guides/nics/pcap_ring.rst          |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 154 +++++++++++++++++++------
 3 files changed, 123 insertions(+), 36 deletions(-)
doc/guides/nics/pcap_ring.rst +3 -0
index c005786ce3..5b9ca71b18 100644
@@ -224,6 +224,9 @@ Features and Limitations
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
 
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +2 -0
index 3836870961..8590dc861b 100644
@@ -63,6 +63,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +118 -36

265 lines not on this page · raw message

Signature · 1 line
2.51.0
#177 lore raw

PATCH v12 14/19 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index a17c2a3986..fdec637988 100644
@@ -603,6 +603,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#178 lore raw

PATCH v12 15/19 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index fdec637988..b1dbf91acc 100644
@@ -47,11 +47,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -561,6 +559,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -672,6 +671,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1475,6 +1476,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#179 lore raw

PATCH v12 16/19 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index b1dbf91acc..f3220cea92 100644
@@ -55,10 +55,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -862,11 +862,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#180 lore raw

PATCH v12 17/19 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index f3220cea92..35d4f28d50 100644
@@ -845,10 +845,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#181 lore raw

PATCH v12 18/19 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap_ring.rst          |  13 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 202 +++++++++++++++----------
 3 files changed, 132 insertions(+), 84 deletions(-)
doc/guides/nics/pcap_ring.rst +13 -0
index 5b9ca71b18..7993fc5e09 100644
@@ -132,6 +132,19 @@ Runtime Config Options
 
 In this case, one dummy rx queue is created for each tx queue argument passed
 
+- Set the snapshot length for packet capture
+
+ The snapshot length controls the maximum number of bytes captured per packet.
+ This affects both interface capture and pcap file output.  The default value is
+ 65535 bytes, which captures complete packets up to the maximum Ethernet jumbo frame size.
+ Reducing this value can improve performance when only packet headers are needed.
+ This can be done with a ``devarg`` ``snaplen``, for example::
+
+   --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+   --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+ The snapshot length also determines the reported ``max_rx_pktlen`` and ``max_mtu`` in device info.
+
 Examples of Usage
 ^^^^^^^^^^^^^^^^^
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 8590dc861b..069bbed807 100644
@@ -65,6 +65,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +118 -84

446 lines not on this page · raw message

Signature · 1 line
2.51.0
#182 lore raw

PATCH v12 19/19 test: add test for pcap PMD

In reply to Stephen Hemminger

This test was generated by Claude AI with some prompting and pointing at existing ring PMD test. It tests basic operations, timestamps, jumbo frame, vlan handling and multiple queues

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 2962 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 2965 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index f4d04a6e42..90e3afaecf 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +2962 -0

2,962 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 069bbed807..604f2c1f23 100644
@@ -66,6 +66,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added unit test suite.
 
 
 Removed Items
Signature · 1 line
2.51.0
#183 lore raw

v13 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snapshot_len devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v13:
- Fix VLAN insert to pass mbuf by reference so caller sees updated pointer after indirect mbuf handling
- Fix VLAN insert error path to not free mbuf (let bulk free handle it, avoiding double-free)
- Fix handling of pcap_sendpacket() errors
- Fix theoretical format string overflows in test suite

Stephen Hemminger (16):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: cleanup transmit burst logic net/pcap: consolidate boolean flag handling net/pcap: support VLAN insert and strip net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet net/pcap: add snapshot length devarg
test: add test for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3023 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    8 +
 doc/guides/nics/pcap_ring.rst          |   27 +
 doc/guides/rel_notes/release_26_03.rst |    9 +
 drivers/net/pcap/pcap_ethdev.c         |  794 +++++--
 drivers/net/pcap/pcap_osdep.h          |   39 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 3979 insertions(+), 241 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#184 lore raw

PATCH v13 1/16 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 5683b87e4a..28a3269568 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap_ring.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#185 lore raw

PATCH v13 2/16 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#186 lore raw

PATCH v13 3/16 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#187 lore raw

PATCH v13 4/16 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#188 lore raw

PATCH v13 5/16 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#189 lore raw

PATCH v13 6/16 net/pcap: cleanup transmit burst logic

In reply to Stephen Hemminger

To handle possible multi segment mbufs, the driver would allocate a worst case 64k buffer on the stack. Since each Tx queue is single threaded, better to allocate the buffer from hugepage with rte_malloc when queue is setup.

The buffer needs to be come from huge pages because the primary process may start the device but the bounce buffer could be used in transmit path by secondary process.

Using function rte_pktmbuf_free_bulk is marginally faster here.

Do proper handling of pcap_sendpacket() errors.
The function can return -1 in case of device queue being full. This should not be counted as an error.

The driver has always handled multi-segment transmit but the flag was never set in the offload capabilities.

---
 drivers/net/pcap/pcap_ethdev.c | 114 +++++++++++++++++++--------------
 drivers/net/pcap/pcap_osdep.h  |  14 ++++
 2 files changed, 81 insertions(+), 47 deletions(-)
drivers/net/pcap/pcap_ethdev.c +67 -47
index 806451dc99..84da41542b 100644
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
@@ -91,6 +92,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -385,18 +389,17 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len, caplen;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -404,27 +407,24 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len, caplen;
+		const uint8_t *data;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
-		rte_pktmbuf_free(mbuf);
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (likely(data != NULL)) {
+			pcap_dump((u_char *)dumper, &header, data);
+			num_tx++;
+			tx_bytes += caplen;
+		}
 	}
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	/*
 	 * Since there's no place to hook a callback when the forwarding
@@ -449,71 +449,74 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
-	for (i = 0; i < nb_pkts; i++) {
+	for (i = 0; i < nb_pkts; i++)
 		tx_bytes += bufs[i]->pkt_len;
-		rte_pktmbuf_free(bufs[i]);
-	}
+
+	rte_pktmbuf_free_bulk(bufs, nb_pkts);
 
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return 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)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
-			rte_pktmbuf_free(mbuf);
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len = rte_pktmbuf_pkt_len(mbuf);
+
+		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
+			PMD_TX_LOG(ERR,
+				"Dropping multi segment PCAP packet. Size (%u) > max size (%u).",
+				len, RTE_ETH_PCAP_SNAPSHOT_LEN);
+			tx_queue->tx_stat.err_pkts++;
 			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))
+		if (pcap_sendpacket(pcap, rte_pktmbuf_read(mbuf, 0, len, temp_data), len) != 0) {
+			/* Unfortunately, libpcap collapses transient and hard errors. */
+			PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
 			break;
+		}
+
 		num_tx++;
 		tx_bytes += len;
-		rte_pktmbuf_free(mbuf);
 	}
 
+	rte_pktmbuf_free_bulk(bufs, i);
+
 	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;
 }
@@ -753,6 +756,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
@@ -965,7 +969,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -973,11 +977,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1018,6 +1037,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
drivers/net/pcap/pcap_osdep.h +14 -0
index a0e2b5ace9..fe7399ff9f 100644
@@ -13,6 +13,20 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+#ifdef RTE_ETHDEV_DEBUG_RX
+#define PMD_RX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() rx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+#define PMD_TX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() tx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(...) do { } while (0)
+#endif
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
Signature · 1 line
2.51.0
#190 lore raw

PATCH v13 7/16 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index 84da41542b..b77fa85dd4 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -103,9 +104,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -115,25 +116,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -875,7 +876,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1200,29 +1201,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1498,7 +1489,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1537,9 +1528,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1689,5 +1680,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#191 lore raw

PATCH v13 8/16 net/pcap: support VLAN insert and strip

In reply to Stephen Hemminger

Driver can easily insert VLAN tag strip and insertion similar to how it is handled in virtio and af_packet.

---
 doc/guides/nics/features/pcap.ini      |   1 +
 doc/guides/nics/pcap_ring.rst          |  11 +++
 doc/guides/rel_notes/release_26_03.rst |   4 +
 drivers/net/pcap/pcap_ethdev.c         | 117 ++++++++++++++++++++++++-
 4 files changed, 129 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap_ring.rst +11 -0
index 6955e91130..c005786ce3 100644
@@ -213,6 +213,17 @@ Otherwise, the first 512 packets from the input pcap file will be discarded by t
    an error if interface is down, and the PMD itself won't change the status
    of the external network interface.
 
+Features and Limitations
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +4 -0
index 031eaa657e..c97ab7c3ca 100644
@@ -63,6 +63,10 @@ New Features
 
   * Added support for pre and post VF reset callbacks.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
 
 Removed Items
 -------------
drivers/net/pcap/pcap_ethdev.c +113 -4

219 lines not on this page · raw message

Signature · 1 line
2.51.0
#192 lore raw

Re: [PATCH v13 08/16] net/pcap: support VLAN insert and strip

Quoted 5 lines · Stephen Hemminger

Driver can easily insert VLAN tag strip and insertion similar to how it is handled in virtio and af_packet.

[snip]

drivers/net/pcap/pcap_ethdev.c calculate_timestamp(struct timeval *ts) { · line 396

Quoted 5 lines
drivers/net/pcap/pcap_ethdev.c +1 -0
@@ -383,6 +393,56 @@ calculate_timestamp(struct timeval *ts) {
        }
 }
 
+

Unneeded empty line.

Quoted 27 lines
drivers/net/pcap/pcap_ethdev.c +27 -0
+/*
+ * If Vlan offload flag is present, insert the vlan.
+ * Returns the mbuf to send, or NULL on error.
+ */
+static inline int
+eth_pcap_tx_vlan(struct pcap_tx_queue *tx_queue, struct rte_mbuf **mbuf)
+{
+       struct rte_mbuf *mb = *mbuf;
+
+       if ((mb->ol_flags & RTE_MBUF_F_TX_VLAN) == 0)
+               return 0;
+
+       if (unlikely(mb->data_len < RTE_ETHER_HDR_LEN)) {
+               PMD_TX_LOG(ERR, "mbuf missing ether header");
+               goto error;
+       }
+
+       /* Need at another buffer to hold VLAN header? */
+       if (!RTE_MBUF_DIRECT(mb) || rte_mbuf_refcnt_read(mb) > 1) {
+               struct rte_mbuf *mh = rte_pktmbuf_alloc(mb->pool);
+               if (unlikely(mh == NULL)) {
+                       PMD_TX_LOG(ERR, "mbuf pool exhausted on transmit vlan");
+                       goto error;
+               }
+
+               /* Extract original ethernet header into new mbuf */
+               memcpy(rte_pktmbuf_mtod(mh, void *), rte_pktmbuf_mtod(mb, void *), RTE_ETHER_HDR_LEN);

drivers/net/pcap/pcap_ethdev.c calculate_timestamp(struct timeval *ts) { · line 433

Quoted 10 lines
drivers/net/pcap/pcap_ethdev.c +10 -0
+               mh->nb_segs = mb->nb_segs + 1;
+               mh->data_len = RTE_ETHER_HDR_LEN;
+               mh->pkt_len = mb->pkt_len;
+               mh->ol_flags = mb->ol_flags;
+
+               mb->data_len -= RTE_ETHER_HDR_LEN;
+               mh->next = mb;
+
+               *mbuf = mh;
+       }

Could this segment allocation+chaining be moved in rte_vlan_insert?

This would help solve this issue in other sw drivers that currently just drop (indirect) mbufs.
We might need an additional input param for driver that don't want multiseg / existing users... ?

Signature · 1 line
David Marchand
#193 lore raw

PATCH v13 9/16 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  24 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 394 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index c97ab7c3ca..1ccf17d1e7 100644
@@ -66,6 +66,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +24 -0
index fe7399ff9f..b72dd0d74c 100644
@@ -10,6 +10,7 @@
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
+
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
@@ -27,7 +28,30 @@ extern int eth_pcap_logtype;
 #define PMD_TX_LOG(...) do { } while (0)
 #endif
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#194 lore raw

PATCH v13 10/16 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Defer timestamp dynfield registration from probe to device start, and only when timestamp offloading is enabled
* Add read_clock dev_op returning current UTC time
for timestamp correlation
* Move per-burst timestamp calculation outside the packet loop in tx_dumper
* Enable immediate mode and improve error reporting
in live capture setup

---
 doc/guides/nics/pcap_ring.rst          |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 157 +++++++++++++++++++------
 3 files changed, 127 insertions(+), 35 deletions(-)
doc/guides/nics/pcap_ring.rst +3 -0
index c005786ce3..5b9ca71b18 100644
@@ -224,6 +224,9 @@ Features and Limitations
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
 
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
+
 
 Rings-based PMD
 ~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_03.rst +2 -0
index 1ccf17d1e7..04968a2c40 100644
@@ -67,6 +67,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -35

269 lines not on this page · raw message

Signature · 1 line
2.51.0
#195 lore raw

PATCH v13 11/16 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index 29030544b8..cde9744766 100644
@@ -654,6 +654,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#196 lore raw

PATCH v13 12/16 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index cde9744766..fde1f9fef2 100644
@@ -47,11 +47,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -612,6 +610,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -723,6 +722,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1526,6 +1527,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#197 lore raw

PATCH v13 13/16 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index fde1f9fef2..acfee68711 100644
@@ -55,10 +55,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -913,11 +913,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#198 lore raw

PATCH v13 14/16 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index acfee68711..2413e44377 100644
@@ -896,10 +896,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#199 lore raw

PATCH v13 15/16 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap_ring.rst          |  13 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 231 ++++++++++++++++---------
 3 files changed, 159 insertions(+), 86 deletions(-)
doc/guides/nics/pcap_ring.rst +13 -0
index 5b9ca71b18..7993fc5e09 100644
@@ -132,6 +132,19 @@ Runtime Config Options
 
 In this case, one dummy rx queue is created for each tx queue argument passed
 
+- Set the snapshot length for packet capture
+
+ The snapshot length controls the maximum number of bytes captured per packet.
+ This affects both interface capture and pcap file output.  The default value is
+ 65535 bytes, which captures complete packets up to the maximum Ethernet jumbo frame size.
+ Reducing this value can improve performance when only packet headers are needed.
+ This can be done with a ``devarg`` ``snaplen``, for example::
+
+   --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+   --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+ The snapshot length also determines the reported ``max_rx_pktlen`` and ``max_mtu`` in device info.
+
 Examples of Usage
 ^^^^^^^^^^^^^^^^^
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 04968a2c40..1022a27486 100644
@@ -69,6 +69,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +145 -86

485 lines not on this page · raw message

Signature · 1 line
2.51.0
#200 lore raw

PATCH v13 16/16 test: add test for pcap PMD

In reply to Stephen Hemminger

This test was generated by Claude AI with some prompting and pointing at existing ring PMD test. It tests basic operations, timestamps, jumbo frame, vlan handling and multiple queues

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3023 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 3026 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index 48874037eb..a83292cf49 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +3023 -0

2,986 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 1022a27486..b68735a64b 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#201 lore raw

Re: [PATCH v13 16/16] test: add test for pcap PMD

Quoted 6 lines · Stephen Hemminger

This test was generated by Claude AI with some prompting and pointing at existing ring PMD test. It tests basic operations, timestamps, jumbo frame, vlan handling and multiple queues

[...]

Quoted 63 lines
app/test/test_pmd_pcap.c new file +63 -0
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+
+/*
+ * Helper: Create a unique temporary file path (Windows version)
+ */
+static int
+create_temp_path(char *buf, size_t buflen, const char *prefix)
+{
+       char temp_dir[MAX_PATH];
+       char temp_file[MAX_PATH];
+       DWORD ret;
+
+       ret = GetTempPathA(sizeof(temp_dir), temp_dir);
+       if (ret == 0 || ret > sizeof(temp_dir))
+               return -1;
+
+       if (GetTempFileNameA(temp_dir, prefix, 0, temp_file) == 0)
+               return -1;
+
+       ret = snprintf(buf, buflen, "%s.pcap", temp_file);
+       if (ret >= buflen) {
+               DeleteFileA(temp_file);
+               return -1;
+       }
+
+       if (MoveFileA(temp_file, buf) == 0) {
+               DeleteFileA(temp_file);
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+ * Helper: Remove temporary file (Windows version)
+ */
+static inline void
+remove_temp_file(const char *path)
+{
+       if (path[0] != '\0')
+               DeleteFileA(path);
+}
+
+#else /* POSIX */
+
+/*
+ * Helper: Create a unique temporary file path (POSIX version)
+ */
+static int
+create_temp_path(char *buf, size_t buflen, const char *prefix)
+{
+       int fd;
+
+       snprintf(buf, buflen, "/tmp/%s_XXXXXX.pcap", prefix);
+       fd = mkstemps(buf, 5);  /* 5 = strlen(".pcap") */
+       if (fd < 0)
+               return -1;
+       close(fd);
+       return 0;
+}
+
+/*

app/test/test_pmd_pcap.c line 211

Quoted 10 lines
app/test/test_pmd_pcap.c new file +10 -0
+ * Helper: Remove temporary file (POSIX version)
+ */
+static inline void
+remove_temp_file(const char *path)
+{
+       if (path[0] != '\0')
+               unlink(path);
+}
+
+#endif /* RTE_EXEC_ENV_WINDOWS */

At a quick glance, that would make it the 3rd unit test having such temp file manipulation helpers.
Could we put it in some app/test/ common file?

Signature · 1 line
David Marchand
#202 lore raw

v14 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Link status change (LSC) interrupt support in interface mode
- EOF notification via link status change for rx_pcap mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snapshot_len devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v14:
- Add LSC interrupt support for iface mode using alarm-based polling
- Add EOF devarg for rx_pcap mode: signals end-of-file via link down and LSC event (mutually exclusive with infinite_rx)
- Fix mbuf leak in eth_pcap_tx() when dropping oversized multi-segment packets (missing rte_pktmbuf_free before continue)
- Fix rte_pktmbuf_read() NULL path falling through to success counters (num_tx/tx_bytes now inside else branch only)
- Fix VLAN insert for indirect/shared mbufs: use rte_pktmbuf_adj() to advance data_off, preventing duplicated Ethernet header in the mbuf chain

v13:
- Fix VLAN insert to pass mbuf by reference so caller sees updated pointer after indirect mbuf handling
- Fix VLAN insert error path to not free mbuf (let bulk free handle it, avoiding double-free)
- Fix handling of pcap_sendpacket() errors
- Fix theoretical format string overflows in test suite

Stephen Hemminger (18):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: rework transmit burst handling net/pcap: consolidate boolean flag handling net/pcap: support VLAN strip and insert offloads net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet net/pcap: add snapshot length devarg
net/pcap: add link status change support for iface mode net/pcap: add EOF notification via link status change
test: add comprehensive test suite for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    9 +
 doc/guides/nics/pcap.rst               |   41 +
 doc/guides/rel_notes/release_26_03.rst |   12 +
 drivers/net/pcap/pcap_ethdev.c         |  920 +++++--
 drivers/net/pcap/pcap_osdep.h          |   39 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 4524 insertions(+), 239 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#203 lore raw

PATCH v14 1/18 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 5683b87e4a..28a3269568 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap_ring.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#204 lore raw

PATCH v14 2/18 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#205 lore raw

PATCH v14 3/18 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#206 lore raw

PATCH v14 4/18 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#207 lore raw

PATCH v14 5/18 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#208 lore raw

PATCH v14 6/18 net/pcap: rework transmit burst handling

In reply to Stephen Hemminger

Replace the 64K stack-allocated bounce buffer with a per-queue buffer allocated from hugepages via rte_malloc at queue setup. This is necessary because the buffer may be used in a secondary process transmit path where the primary process allocated it.

Fix error accounting: backpressure from pcap_sendpacket() (kernel socket buffer full) was incorrectly counted as errors. Malformed multi-segment mbufs where pkt_len exceeds actual data were silently accepted; they are now detected via rte_pktmbuf_read() failure and counted as errors.

Add datapath debug logging macros (PMD_RX_LOG, PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS in device capabilities since the driver has always supported multi-segment transmit. Add tx_queue_release to free the bounce buffer.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 122 +++++++++++++++++++++------------
 drivers/net/pcap/pcap_osdep.h  |  14 ++++
 2 files changed, 92 insertions(+), 44 deletions(-)
drivers/net/pcap/pcap_ethdev.c +78 -44
index 806451dc99..4761741edd 100644
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
@@ -91,6 +92,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -385,18 +389,17 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len, caplen;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -404,25 +407,28 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len, caplen;
+		const uint8_t *data;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
+			dumper_q->tx_stat.err_pkts++;
+		} else {
+			pcap_dump((u_char *)dumper, &header, data);
+
+			num_tx++;
+			tx_bytes += caplen;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
@@ -449,9 +455,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
 	for (i = 0; i < nb_pkts; i++) {
 		tx_bytes += bufs[i]->pkt_len;
 		rte_pktmbuf_free(bufs[i]);
@@ -460,60 +463,74 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return 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)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
+		struct rte_mbuf *mbuf = bufs[i];
+		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_TX_LOG(ERR,
+				"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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
+			tx_queue->tx_stat.err_pkts++;
+		} else {
+			/* Unfortunately, libpcap collapses transient (-EBUSY) and hard errors. */
+			if (pcap_sendpacket(pcap, data, len) != 0) {
+				PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				break;
+			}
+			num_tx++;
+			tx_bytes += len;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
 	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;
 }
@@ -753,6 +770,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
@@ -965,7 +983,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -973,11 +991,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1018,6 +1051,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
drivers/net/pcap/pcap_osdep.h +14 -0
index a0e2b5ace9..fe7399ff9f 100644
@@ -13,6 +13,20 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+#ifdef RTE_ETHDEV_DEBUG_RX
+#define PMD_RX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() rx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+#define PMD_TX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() tx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(...) do { } while (0)
+#endif
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
Signature · 1 line
2.51.0
#209 lore raw

PATCH v14 7/18 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index 4761741edd..f6adc23463 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -103,9 +104,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -115,25 +116,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -889,7 +890,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1214,29 +1215,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1512,7 +1503,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1551,9 +1542,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1703,5 +1694,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#210 lore raw

PATCH v14 8/18 net/pcap: support VLAN strip and insert offloads

In reply to Stephen Hemminger

Add VLAN tag handling to the pcap PMD, consistent with how virtio and af_packet drivers implement it.

RX strip: when RTE_ETH_RX_OFFLOAD_VLAN_STRIP is enabled, the driver calls rte_vlan_strip() on received packets in both normal and infinite_rx modes. For infinite_rx, offloads are deferred to packet delivery rather than applied during ring fill, so the stored template packets remain unmodified.

TX insert: when RTE_MBUF_F_TX_VLAN is set on an mbuf, the driver inserts the VLAN tag via rte_vlan_insert() before writing to pcap or sending to the interface. Indirect or shared mbufs get a new header mbuf to avoid modifying the original.

Runtime reconfiguration is supported through vlan_offload_set, which propagates the strip setting to all active RX queues.

---
 doc/guides/nics/features/pcap.ini      |   1 +
 doc/guides/nics/pcap.rst               |  11 +++
 doc/guides/rel_notes/release_26_03.rst |   4 +
 drivers/net/pcap/pcap_ethdev.c         | 118 ++++++++++++++++++++++++-
 4 files changed, 130 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap.rst +11 -0
index fbfe854bb1..bed5006a42 100644
@@ -247,3 +247,14 @@ will be discarded by the Rx flushing operation.
    The network interface provided to the PMD should be up.
    The PMD will return an error if the interface is down,
    and the PMD itself won't change the status of the external network interface.
+
+Features and Limitations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
doc/guides/rel_notes/release_26_03.rst +4 -0
index 5c2a4bb32e..eb80c8a785 100644
@@ -82,6 +82,10 @@ New Features
   * NEA5, NIA5, NCA5: AES 256 confidentiality, integrity and AEAD modes.
   * NEA6, NIA6, NCA6: ZUC 256 confidentiality, integrity and AEAD modes.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
 
 Removed Items
 -------------
drivers/net/pcap/pcap_ethdev.c +114 -4

220 lines not on this page · raw message

Signature · 1 line
2.51.0
#211 lore raw

PATCH v14 9/18 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  24 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 394 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index eb80c8a785..42ecba925e 100644
@@ -85,6 +85,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +24 -0
index fe7399ff9f..b72dd0d74c 100644
@@ -10,6 +10,7 @@
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
+
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
@@ -27,7 +28,30 @@ extern int eth_pcap_logtype;
 #define PMD_TX_LOG(...) do { } while (0)
 #endif
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#212 lore raw

PATCH v14 10/18 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Add read_clock dev_op returning current UTC time for timestamp correlation.
* Move per-burst timestamp calculation outside the packet loop in tx_dumper.
* Enable immediate mode and improve error reporting
in live capture setup.

---
 doc/guides/nics/pcap.rst               |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 157 +++++++++++++++++++------
 3 files changed, 127 insertions(+), 35 deletions(-)
doc/guides/nics/pcap.rst +3 -0
index bed5006a42..2709c6d017 100644
@@ -258,3 +258,6 @@ Features and Limitations
 *  The PMD will transparently insert a VLAN tag to transmitted packets if
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
+
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
doc/guides/rel_notes/release_26_03.rst +2 -0
index 42ecba925e..5953995b77 100644
@@ -86,6 +86,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -35

269 lines not on this page · raw message

Signature · 1 line
2.51.0
#213 lore raw

PATCH v14 11/18 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index 8e12f7cd0e..3522401b5e 100644
@@ -669,6 +669,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#214 lore raw

PATCH v14 12/18 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index 3522401b5e..89c1eac8d2 100644
@@ -47,11 +47,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -627,6 +625,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -738,6 +737,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1541,6 +1542,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#215 lore raw

PATCH v14 13/18 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index 89c1eac8d2..d4f8811572 100644
@@ -55,10 +55,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -928,11 +928,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#216 lore raw

PATCH v14 14/18 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index d4f8811572..6562f0ecc5 100644
@@ -911,10 +911,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#217 lore raw

PATCH v14 15/18 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap.rst               |  15 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 235 ++++++++++++++++---------
 3 files changed, 165 insertions(+), 86 deletions(-)
doc/guides/nics/pcap.rst +15 -0
index 2709c6d017..f241069ebb 100644
@@ -162,6 +162,21 @@ Runtime Config Options
 
   In this case, one dummy Rx queue is created for each Tx queue argument passed.
 
+* Set the snapshot length for packet capture
+
+  The snapshot length controls the maximum number of bytes captured per packet.
+  This affects both interface capture and pcap file output.  The default value is
+  65535 bytes, which captures complete packets up to the maximum Ethernet jumbo
+  frame size.  Reducing this value can improve performance when only packet headers
+  are needed.  This can be done with the ``snaplen`` devarg, for example::
+
+     --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+     --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+  The snapshot length also determines the reported ``max_rx_pktlen``
+  and ``max_mtu`` in device info.
+
+
 Examples of Usage
 ~~~~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 5953995b77..4d9303ca3a 100644
@@ -88,6 +88,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +149 -86

489 lines not on this page · raw message

Signature · 1 line
2.51.0
#218 lore raw

PATCH v14 16/18 net/pcap: add link status change support for iface mode

In reply to Stephen Hemminger

Add LSC interrupt support for pass-through (iface=) mode so applications can receive link state change notifications via the standard ethdev callback mechanism.

Uses alarm-based polling to periodically check the underlying interface state via osdep_iface_link_get(). The LSC flag is advertised only for iface mode devices, and polling is gated on the application enabling intr_conf.lsc in port configuration.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/rel_notes/release_26_03.rst |  1 +
 drivers/net/pcap/pcap_ethdev.c         | 44 +++++++++++++++++++++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)
doc/guides/nics/features/pcap.ini +1 -0
index 814bc2119f..084fefbbbb 100644
@@ -5,6 +5,7 @@
 ;
 [Features]
 Link status          = Y
+Link status event    = Y
 Queue start/stop     = Y
 Scattered Rx         = Y
 Timestamp offload    = Y
doc/guides/rel_notes/release_26_03.rst +1 -0
index 4d9303ca3a..e614d8a8ac 100644
@@ -89,6 +89,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added support for Link State interrupt in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +43 -1

94 lines not on this page · raw message

Signature · 1 line
2.51.0
#219 lore raw

PATCH v14 17/18 net/pcap: add EOF notification via link status change

In reply to Stephen Hemminger

Add an "eof" devarg for rx_pcap mode that signals end-of-file by setting link down and generating an LSC event. This allows applications to detect when a pcap file has been fully consumed using the standard ethdev callback mechanism.

The eof and infinite_rx options are mutually exclusive. On device restart, the EOF state is reset so the file can be replayed.

---
 doc/guides/nics/pcap.rst               | 12 +++++
 doc/guides/rel_notes/release_26_03.rst |  2 +
 drivers/net/pcap/pcap_ethdev.c         | 75 ++++++++++++++++++++++++--
 3 files changed, 86 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
index f241069ebb..6f3a4fc887 100644
@@ -144,6 +144,18 @@ Runtime Config Options
   so all queues on a device will either have this enabled or disabled.
   This option should only be provided once per device.
 
+* Signal end-of-file via link status change
+
+  In case ``rx_pcap=`` configuration is set, the user may want to be notified when
+  all packets in the pcap file have been read.  This can be done with the ``eof``
+  devarg, for example::
+
+     --vdev 'net_pcap0,rx_pcap=file_rx.pcap,eof=1'
+
+  When enabled, the driver sets link down and generates an LSC event at end of file.
+  If the device is stopped and restarted, the EOF state is reset.
+  This option cannot be combined with ``infinite_rx``.
+
 * Drop all packets on transmit
 
   To drop all packets on transmit for a device,
doc/guides/rel_notes/release_26_03.rst +2 -0
index e614d8a8ac..acd6450a59 100644
@@ -90,6 +90,8 @@ New Features
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
   * Added support for Link State interrupt in ``iface`` mode.
+  * Added ``eof`` devarg to use link state to signal end of receive
+    file input.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +72 -3

156 lines not on this page · raw message

Signature · 1 line
2.51.0
#220 lore raw

PATCH v14 18/18 test: add comprehensive test suite for pcap PMD

In reply to Stephen Hemminger

Add unit tests for the pcap PMD covering file and interface modes.

Tests include:
- basic TX to file and RX from file
- varied packet sizes and jumbo frames
- infinite RX mode
- TX drop mode
- statistics
- interface (iface=) pass-through mode
- link status reporting for file and iface modes
- link status change (LSC) with interface toggle
- EOF notification via LSC
- RX timestamps and timestamp with infinite RX
- multiple TX/RX queues
- VLAN strip, insert, and runtime offload configuration
- snapshot length (snaplen) and truncation

Cross-platform helpers handle temp file creation, interface discovery, and VLAN packet generation.

The LSC link toggle test requires a pre-created dummy interface (Linux: dummy0, FreeBSD: disc0) and is skipped if unavailable.

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 3425 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index 48874037eb..a83292cf49 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +3422 -0

2,986 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index acd6450a59..c48af82868 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#221 lore raw

v15 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Link status change (LSC) interrupt support in interface mode
- EOF notification via link status change for rx_pcap mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snaplen devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v15:
- Fix "Perodic" typo in LSC alarm comment
- Fix missing space after comma in rte_eal_alarm_set() call
- Use eth_link_update() instead of direct dev_link.link_status write in EOF rx path for proper atomic link status update
- Add detailed comment block to eth_pcap_tx() documenting PF_PACKET backpressure semantics and tx_burst return convention
- Add PMD_TX_LOG/PMD_RX_LOG conditional debug logging macros gated by RTE_ETHDEV_DEBUG_TX/RTE_ETHDEV_DEBUG_RX

v14:
- Add LSC interrupt support for iface mode using alarm-based polling
- Add EOF devarg for rx_pcap mode: signals end-of-file via link down and LSC event (mutually exclusive with infinite_rx)
- Fix mbuf leak in eth_pcap_tx() when dropping oversized multi-segment packets (missing rte_pktmbuf_free before continue)
- Fix rte_pktmbuf_read() NULL path falling through to success counters (num_tx/tx_bytes now inside else branch only)
- Fix VLAN insert for indirect/shared mbufs: use rte_pktmbuf_adj() to advance data_off, preventing duplicated Ethernet header in the mbuf chain

v13:
- Fix VLAN insert to pass mbuf by reference so caller sees updated pointer after indirect mbuf handling
- Fix VLAN insert error path to not free mbuf (let bulk free handle it, avoiding double-free)
- Fix handling of pcap_sendpacket() errors
- Fix theoretical format string overflows in test suite

Stephen Hemminger (18):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: rework transmit burst handling net/pcap: consolidate boolean flag handling net/pcap: support VLAN strip and insert offloads net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet net/pcap: add snapshot length devarg
net/pcap: add link status change support for iface mode net/pcap: add EOF notification via link status change
test: add comprehensive test suite for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    9 +
 doc/guides/nics/pcap.rst               |   41 +
 doc/guides/rel_notes/release_26_03.rst |   12 +
 drivers/net/pcap/pcap_ethdev.c         |  921 +++++--
 drivers/net/pcap/pcap_osdep.h          |   39 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 4525 insertions(+), 239 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#222 lore raw

PATCH v15 1/18 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 25fb109ef4..9a9a7d85c7 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#223 lore raw

PATCH v15 2/18 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#224 lore raw

PATCH v15 3/18 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#225 lore raw

PATCH v15 4/18 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#226 lore raw

PATCH v15 5/18 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#227 lore raw

PATCH v15 6/18 net/pcap: rework transmit burst handling

In reply to Stephen Hemminger

Replace the 64K stack-allocated bounce buffer with a per-queue buffer allocated from hugepages via rte_malloc at queue setup. This is necessary because the buffer may be used in a secondary process transmit path where the primary process allocated it.

Fix error accounting: backpressure from pcap_sendpacket() (kernel socket buffer full) was incorrectly counted as errors. Malformed multi-segment mbufs where pkt_len exceeds actual data were silently accepted; they are now detected via rte_pktmbuf_read() failure and counted as errors.

Add datapath debug logging macros (PMD_RX_LOG, PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS in device capabilities since the driver has always supported multi-segment transmit. Add tx_queue_release to free the bounce buffer.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 122 +++++++++++++++++++++------------
 drivers/net/pcap/pcap_osdep.h  |  14 ++++
 2 files changed, 92 insertions(+), 44 deletions(-)
drivers/net/pcap/pcap_ethdev.c +78 -44
index 806451dc99..4761741edd 100644
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
@@ -91,6 +92,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -385,18 +389,17 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len, caplen;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -404,25 +407,28 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		uint32_t len, caplen;
+		const uint8_t *data;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
+			dumper_q->tx_stat.err_pkts++;
+		} else {
+			pcap_dump((u_char *)dumper, &header, data);
+
+			num_tx++;
+			tx_bytes += caplen;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
@@ -449,9 +455,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
 	for (i = 0; i < nb_pkts; i++) {
 		tx_bytes += bufs[i]->pkt_len;
 		rte_pktmbuf_free(bufs[i]);
@@ -460,60 +463,74 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return 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)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
+		struct rte_mbuf *mbuf = bufs[i];
+		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_TX_LOG(ERR,
+				"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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
+			tx_queue->tx_stat.err_pkts++;
+		} else {
+			/* Unfortunately, libpcap collapses transient (-EBUSY) and hard errors. */
+			if (pcap_sendpacket(pcap, data, len) != 0) {
+				PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				break;
+			}
+			num_tx++;
+			tx_bytes += len;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
 	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;
 }
@@ -753,6 +770,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
@@ -965,7 +983,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -973,11 +991,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1018,6 +1051,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
drivers/net/pcap/pcap_osdep.h +14 -0
index a0e2b5ace9..fe7399ff9f 100644
@@ -13,6 +13,20 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+#ifdef RTE_ETHDEV_DEBUG_RX
+#define PMD_RX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() rx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+#define PMD_TX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() tx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(...) do { } while (0)
+#endif
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
Signature · 1 line
2.51.0
#228 lore raw

Re: [PATCH v15 06/18] net/pcap: rework transmit burst handling

Quoted 18 lines · Stephen Hemminger

Replace the 64K stack-allocated bounce buffer with a per-queue buffer allocated from hugepages via rte_malloc at queue setup. This is necessary because the buffer may be used in a secondary process transmit path where the primary process allocated it.

Fix error accounting: backpressure from pcap_sendpacket() (kernel socket buffer full) was incorrectly counted as errors. Malformed multi-segment mbufs where pkt_len exceeds actual data were silently accepted; they are now detected via rte_pktmbuf_read() failure and counted as errors.

Add datapath debug logging macros (PMD_RX_LOG, PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS in device capabilities since the driver has always supported multi-segment transmit. Add tx_queue_release to free the bounce buffer.

Quoted 4 lines
Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")

It seems this commit does a lot more than fixing one issue. Please split.

Signature · 1 line
David Marchand
#229 lore raw

PATCH v15 7/18 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index 4761741edd..f6adc23463 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -103,9 +104,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -115,25 +116,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -889,7 +890,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1214,29 +1215,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1512,7 +1503,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1551,9 +1542,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1703,5 +1694,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#230 lore raw

PATCH v15 8/18 net/pcap: support VLAN strip and insert offloads

In reply to Stephen Hemminger

Add VLAN tag handling to the pcap PMD, consistent with how virtio and af_packet drivers implement it.

RX strip: when RTE_ETH_RX_OFFLOAD_VLAN_STRIP is enabled, the driver calls rte_vlan_strip() on received packets in both normal and infinite_rx modes. For infinite_rx, offloads are deferred to packet delivery rather than applied during ring fill, so the stored template packets remain unmodified.

TX insert: when RTE_MBUF_F_TX_VLAN is set on an mbuf, the driver inserts the VLAN tag via rte_vlan_insert() before writing to pcap or sending to the interface. Indirect or shared mbufs get a new header mbuf to avoid modifying the original.

Runtime reconfiguration is supported through vlan_offload_set, which propagates the strip setting to all active RX queues.

---
 doc/guides/nics/features/pcap.ini      |   1 +
 doc/guides/nics/pcap.rst               |  11 +++
 doc/guides/rel_notes/release_26_03.rst |   4 +
 drivers/net/pcap/pcap_ethdev.c         | 118 ++++++++++++++++++++++++-
 4 files changed, 130 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap.rst +11 -0
index fbfe854bb1..bed5006a42 100644
@@ -247,3 +247,14 @@ will be discarded by the Rx flushing operation.
    The network interface provided to the PMD should be up.
    The PMD will return an error if the interface is down,
    and the PMD itself won't change the status of the external network interface.
+
+Features and Limitations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
doc/guides/rel_notes/release_26_03.rst +4 -0
index afdf1af06c..fa998f1620 100644
@@ -87,6 +87,10 @@ New Features
   * Added support for AES-XTS cipher algorithm.
   * Added support for SHAKE-128 and SHAKE-256 authentication algorithms.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
 
 Removed Items
 -------------
drivers/net/pcap/pcap_ethdev.c +114 -4

220 lines not on this page · raw message

Signature · 1 line
2.51.0
#231 lore raw

PATCH v15 9/18 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  24 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 394 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index fa998f1620..c1d8c3e10c 100644
@@ -90,6 +90,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +24 -0
index fe7399ff9f..b72dd0d74c 100644
@@ -10,6 +10,7 @@
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
+
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
@@ -27,7 +28,30 @@ extern int eth_pcap_logtype;
 #define PMD_TX_LOG(...) do { } while (0)
 #endif
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#232 lore raw

PATCH v15 10/18 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Add read_clock dev_op returning current UTC time for timestamp correlation.
* Move per-burst timestamp calculation outside the packet loop in tx_dumper.
* Enable immediate mode and improve error reporting
in live capture setup.

---
 doc/guides/nics/pcap.rst               |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 157 +++++++++++++++++++------
 3 files changed, 127 insertions(+), 35 deletions(-)
doc/guides/nics/pcap.rst +3 -0
index bed5006a42..2709c6d017 100644
@@ -258,3 +258,6 @@ Features and Limitations
 *  The PMD will transparently insert a VLAN tag to transmitted packets if
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
+
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
doc/guides/rel_notes/release_26_03.rst +2 -0
index c1d8c3e10c..e7782dee20 100644
@@ -91,6 +91,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -35

269 lines not on this page · raw message

Signature · 1 line
2.51.0
#233 lore raw

PATCH v15 11/18 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index b96bda0fc8..8f44baf2e1 100644
@@ -669,6 +669,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#234 lore raw

PATCH v15 12/18 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index 8f44baf2e1..16472ca068 100644
@@ -47,11 +47,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -627,6 +625,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -738,6 +737,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1541,6 +1542,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#235 lore raw

PATCH v15 13/18 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index 16472ca068..eeac0cffc8 100644
@@ -55,10 +55,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -928,11 +928,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#236 lore raw

PATCH v15 14/18 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index eeac0cffc8..f2f05689ca 100644
@@ -911,10 +911,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#237 lore raw

PATCH v15 15/18 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap.rst               |  15 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 235 ++++++++++++++++---------
 3 files changed, 165 insertions(+), 86 deletions(-)
doc/guides/nics/pcap.rst +15 -0
index 2709c6d017..f241069ebb 100644
@@ -162,6 +162,21 @@ Runtime Config Options
 
   In this case, one dummy Rx queue is created for each Tx queue argument passed.
 
+* Set the snapshot length for packet capture
+
+  The snapshot length controls the maximum number of bytes captured per packet.
+  This affects both interface capture and pcap file output.  The default value is
+  65535 bytes, which captures complete packets up to the maximum Ethernet jumbo
+  frame size.  Reducing this value can improve performance when only packet headers
+  are needed.  This can be done with the ``snaplen`` devarg, for example::
+
+     --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+     --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+  The snapshot length also determines the reported ``max_rx_pktlen``
+  and ``max_mtu`` in device info.
+
+
 Examples of Usage
 ~~~~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index e7782dee20..70179a454e 100644
@@ -93,6 +93,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +149 -86

489 lines not on this page · raw message

Signature · 1 line
2.51.0
#238 lore raw

PATCH v15 16/18 net/pcap: add link status change support for iface mode

In reply to Stephen Hemminger

Add LSC interrupt support for pass-through (iface=) mode so applications can receive link state change notifications via the standard ethdev callback mechanism.

Uses alarm-based polling to periodically check the underlying interface state via osdep_iface_link_get(). The LSC flag is advertised only for iface mode devices, and polling is gated on the application enabling intr_conf.lsc in port configuration.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/rel_notes/release_26_03.rst |  1 +
 drivers/net/pcap/pcap_ethdev.c         | 45 +++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)
doc/guides/nics/features/pcap.ini +1 -0
index 814bc2119f..084fefbbbb 100644
@@ -5,6 +5,7 @@
 ;
 [Features]
 Link status          = Y
+Link status event    = Y
 Queue start/stop     = Y
 Scattered Rx         = Y
 Timestamp offload    = Y
doc/guides/rel_notes/release_26_03.rst +1 -0
index 70179a454e..1db54a005a 100644
@@ -94,6 +94,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added support for Link State interrupt in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +44 -1

95 lines not on this page · raw message

Signature · 1 line
2.51.0
#239 lore raw

PATCH v15 17/18 net/pcap: add EOF notification via link status change

In reply to Stephen Hemminger

Add an "eof" devarg for rx_pcap mode that signals end-of-file by setting link down and generating an LSC event. This allows applications to detect when a pcap file has been fully consumed using the standard ethdev callback mechanism.

The eof and infinite_rx options are mutually exclusive. On device restart, the EOF state is reset so the file can be replayed.

---
 doc/guides/nics/pcap.rst               | 12 +++++
 doc/guides/rel_notes/release_26_03.rst |  2 +
 drivers/net/pcap/pcap_ethdev.c         | 75 ++++++++++++++++++++++++--
 3 files changed, 86 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
index f241069ebb..6f3a4fc887 100644
@@ -144,6 +144,18 @@ Runtime Config Options
   so all queues on a device will either have this enabled or disabled.
   This option should only be provided once per device.
 
+* Signal end-of-file via link status change
+
+  In case ``rx_pcap=`` configuration is set, the user may want to be notified when
+  all packets in the pcap file have been read.  This can be done with the ``eof``
+  devarg, for example::
+
+     --vdev 'net_pcap0,rx_pcap=file_rx.pcap,eof=1'
+
+  When enabled, the driver sets link down and generates an LSC event at end of file.
+  If the device is stopped and restarted, the EOF state is reset.
+  This option cannot be combined with ``infinite_rx``.
+
 * Drop all packets on transmit
 
   To drop all packets on transmit for a device,
doc/guides/rel_notes/release_26_03.rst +2 -0
index 1db54a005a..7959b97c10 100644
@@ -95,6 +95,8 @@ New Features
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
   * Added support for Link State interrupt in ``iface`` mode.
+  * Added ``eof`` devarg to use link state to signal end of receive
+    file input.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +72 -3

156 lines not on this page · raw message

Signature · 1 line
2.51.0
#240 lore raw

PATCH v15 18/18 test: add comprehensive test suite for pcap PMD

In reply to Stephen Hemminger

Add unit tests for the pcap PMD covering file and interface modes.

Tests include:
- basic TX to file and RX from file
- varied packet sizes and jumbo frames
- infinite RX mode
- TX drop mode
- statistics
- interface (iface=) pass-through mode
- link status reporting for file and iface modes
- link status change (LSC) with interface toggle
- EOF notification via LSC
- RX timestamps and timestamp with infinite RX
- multiple TX/RX queues
- VLAN strip, insert, and runtime offload configuration
- snapshot length (snaplen) and truncation

Cross-platform helpers handle temp file creation, interface discovery, and VLAN packet generation.

The LSC link toggle test requires a pre-created dummy interface (Linux: dummy0, FreeBSD: disc0) and is skipped if unavailable.

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 3425 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index 48874037eb..a83292cf49 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +3422 -0

2,986 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 7959b97c10..7d59463d54 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#241 lore raw

v16 cover net/pcap: improvements and test suite

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Link status change (LSC) interrupt support in interface mode
- EOF notification via link status change for rx_pcap mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snaplen devarg

Bug fixes:
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v16:
- Split up the patches around transmit logic

Stephen Hemminger (21):
maintainers: update for pcap driver
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: advertise Tx multi segment
net/pcap: replace stack bounce buffer with per-queue allocation net/pcap: fix error accounting and backpressure on transmit net/pcap: add datapath debug logging
net/pcap: consolidate boolean flag handling
net/pcap: support VLAN strip and insert offloads net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces
net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet
net/pcap: add snapshot length devarg
net/pcap: add link status change support for iface mode net/pcap: add EOF notification via link status change
test: add comprehensive test suite for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    9 +
 doc/guides/nics/pcap.rst               |   41 +
 doc/guides/rel_notes/release_26_03.rst |   13 +
 drivers/net/pcap/pcap_ethdev.c         |  923 +++++--
 drivers/net/pcap/pcap_osdep.h          |   39 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   95 +-
 11 files changed, 4529 insertions(+), 238 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#242 lore raw

PATCH v16 1/21 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 1b2f1ed2ba..93ac176573 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#243 lore raw

PATCH v16 2/21 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#244 lore raw

PATCH v16 3/21 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#245 lore raw

PATCH v16 4/21 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#246 lore raw

PATCH v16 5/21 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#247 lore raw

PATCH v16 6/21 net/pcap: advertise Tx multi segment

In reply to Stephen Hemminger

The driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
index 806451dc99..fedf461be4 100644
@@ -753,6 +753,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
Signature · 1 line
2.51.0
#248 lore raw

PATCH v16 7/21 net/pcap: replace stack bounce buffer with per-queue allocation

In reply to Stephen Hemminger

Replace the 64K stack-allocated bounce buffer with a per-queue buffer allocated from hugepages via rte_malloc at queue setup. This is necessary because the buffer may be used in a secondary process transmit path where the primary process allocated it.

---
 drivers/net/pcap/pcap_ethdev.c | 57 +++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/net/pcap/pcap_ethdev.c +35 -22
index fedf461be4..4cf5319839 100644
@@ -91,6 +91,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -385,18 +388,17 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len, caplen;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -404,12 +406,10 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		size_t len, caplen;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		calculate_timestamp(&header.ts);
 		header.len = len;
@@ -449,9 +449,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
 	for (i = 0; i < nb_pkts; i++) {
 		tx_bytes += bufs[i]->pkt_len;
 		rte_pktmbuf_free(bufs[i]);
@@ -460,7 +457,7 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
@@ -470,30 +467,30 @@ static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
+		struct rte_mbuf *mbuf = bufs[i];
+		size_t len = rte_pktmbuf_pkt_len(mbuf);
+		int ret;
+
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
+				len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
 			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
+				"Dropping multi segment PCAP packet. Size (%zd) > max size (%u).",
+				len, RTE_ETH_PCAP_SNAPSHOT_LEN);
 			rte_pktmbuf_free(mbuf);
 			continue;
 		}
@@ -966,7 +963,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -974,11 +971,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1019,6 +1031,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
Signature · 1 line
2.51.0
#249 lore raw

PATCH v16 8/21 net/pcap: fix error accounting and backpressure on transmit

In reply to Stephen Hemminger

Fix error accounting: backpressure from pcap_sendpacket() (kernel socket buffer full) was incorrectly counted as errors. Malformed multi-segment mbufs where pkt_len exceeds actual data were silently accepted; they are now detected via rte_pktmbuf_read() failure and counted as errors.

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. Backpressure is not an error.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 71 +++++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 26 deletions(-)
drivers/net/pcap/pcap_ethdev.c +45 -26
index 4cf5319839..42c5a37177 100644
@@ -407,22 +407,27 @@ 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 = caplen = rte_pktmbuf_pkt_len(mbuf);
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			dumper_q->tx_stat.err_pkts++;
+		} else {
+			pcap_dump((u_char *)dumper, &header, data);
+
+			num_tx++;
+			tx_bytes += caplen;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
@@ -461,7 +466,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)
@@ -483,34 +498,38 @@ 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)) {
+		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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			tx_queue->tx_stat.err_pkts++;
+		} else {
+			/* Unfortunately, libpcap collapses transient (-EBUSY) and hard errors. */
+			if (pcap_sendpacket(pcap, data, len) != 0) {
+				PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				break;
+			}
+			num_tx++;
+			tx_bytes += len;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
 	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;
 }
Signature · 1 line
2.51.0
#250 lore raw

PATCH v16 9/21 net/pcap: add datapath debug logging

In reply to Stephen Hemminger

Add datapath debug logging macros (PMD_RX_LOG, PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. Use PMD_TX_LOG in transmit error paths to aid debugging without impacting normal datapath performance.

---
 drivers/net/pcap/pcap_ethdev.c |  8 ++++----
 drivers/net/pcap/pcap_osdep.h  | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -4
index 42c5a37177..8162e611e4 100644
@@ -419,7 +419,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
 		if (unlikely(data == NULL)) {
 			/* This only happens if mbuf is bogus pkt_len > data_len */
-			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
 			dumper_q->tx_stat.err_pkts++;
 		} else {
 			pcap_dump((u_char *)dumper, &header, data);
@@ -502,7 +502,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		const uint8_t *data;
 
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
-			PMD_LOG(ERR,
+			PMD_TX_LOG(ERR,
 				"Dropping multi segment PCAP packet. Size (%u) > max size (%u).",
 				len, RTE_ETH_PCAP_SNAPSHOT_LEN);
 			tx_queue->tx_stat.err_pkts++;
@@ -513,12 +513,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
 		if (unlikely(data == NULL)) {
 			/* This only happens if mbuf is bogus pkt_len > data_len */
-			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
 			tx_queue->tx_stat.err_pkts++;
 		} else {
 			/* Unfortunately, libpcap collapses transient (-EBUSY) and hard errors. */
 			if (pcap_sendpacket(pcap, data, len) != 0) {
-				PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
 				break;
 			}
 			num_tx++;
drivers/net/pcap/pcap_osdep.h +14 -0
index a0e2b5ace9..fe7399ff9f 100644
@@ -13,6 +13,20 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+#ifdef RTE_ETHDEV_DEBUG_RX
+#define PMD_RX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() rx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+#define PMD_TX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() tx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(...) do { } while (0)
+#endif
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
Signature · 1 line
2.51.0
#251 lore raw

PATCH v16 10/21 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index 8162e611e4..2742e0ca80 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -102,9 +103,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -114,25 +115,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -888,7 +889,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1213,29 +1214,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1511,7 +1502,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1550,9 +1541,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1702,5 +1693,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#252 lore raw

PATCH v16 11/21 net/pcap: support VLAN strip and insert offloads

In reply to Stephen Hemminger

Add VLAN tag handling to the pcap PMD, consistent with how virtio and af_packet drivers implement it.

RX strip: when RTE_ETH_RX_OFFLOAD_VLAN_STRIP is enabled, the driver calls rte_vlan_strip() on received packets in both normal and infinite_rx modes. For infinite_rx, offloads are deferred to packet delivery rather than applied during ring fill, so the stored template packets remain unmodified.

TX insert: when RTE_MBUF_F_TX_VLAN is set on an mbuf, the driver inserts the VLAN tag via rte_vlan_insert() before writing to pcap or sending to the interface. Indirect or shared mbufs get a new header mbuf to avoid modifying the original.

Runtime reconfiguration is supported through vlan_offload_set, which propagates the strip setting to all active RX queues.

---
 doc/guides/nics/features/pcap.ini      |   1 +
 doc/guides/nics/pcap.rst               |  11 +++
 doc/guides/rel_notes/release_26_03.rst |   5 ++
 drivers/net/pcap/pcap_ethdev.c         | 118 ++++++++++++++++++++++++-
 4 files changed, 131 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap.rst +11 -0
index fbfe854bb1..bed5006a42 100644
@@ -247,3 +247,14 @@ will be discarded by the Rx flushing operation.
    The network interface provided to the PMD should be up.
    The PMD will return an error if the interface is down,
    and the PMD itself won't change the status of the external network interface.
+
+Features and Limitations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
doc/guides/rel_notes/release_26_03.rst +5 -0
index cb9fda07a8..2d0208ddac 100644
@@ -92,6 +92,11 @@ New Features
   Added handling of the key combination Control+L
   to clear the screen before redisplaying the prompt.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
+
 Removed Items
 -------------
 
drivers/net/pcap/pcap_ethdev.c +114 -4

220 lines not on this page · raw message

Signature · 1 line
2.51.0
#253 lore raw

PATCH v16 12/21 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  24 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 394 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index 2d0208ddac..6a09eb1048 100644
@@ -95,6 +95,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +24 -0
index fe7399ff9f..b72dd0d74c 100644
@@ -10,6 +10,7 @@
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
+
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
@@ -27,7 +28,30 @@ extern int eth_pcap_logtype;
 #define PMD_TX_LOG(...) do { } while (0)
 #endif
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#254 lore raw

PATCH v16 13/21 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Add read_clock dev_op returning current UTC time for timestamp correlation.
* Move per-burst timestamp calculation outside the packet loop in tx_dumper.
* Enable immediate mode and improve error reporting
in live capture setup.

---
 doc/guides/nics/pcap.rst               |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 157 +++++++++++++++++++------
 3 files changed, 127 insertions(+), 35 deletions(-)
doc/guides/nics/pcap.rst +3 -0
index bed5006a42..2709c6d017 100644
@@ -258,3 +258,6 @@ Features and Limitations
 *  The PMD will transparently insert a VLAN tag to transmitted packets if
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
+
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
doc/guides/rel_notes/release_26_03.rst +2 -0
index 6a09eb1048..2cdc304539 100644
@@ -96,6 +96,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -35

269 lines not on this page · raw message

Signature · 1 line
2.51.0
#255 lore raw

PATCH v16 14/21 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index 79a8c63b72..676b928484 100644
@@ -668,6 +668,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#256 lore raw

PATCH v16 15/21 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index 676b928484..be14d7690d 100644
@@ -46,11 +46,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -626,6 +624,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -737,6 +736,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1540,6 +1541,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#257 lore raw

PATCH v16 16/21 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index be14d7690d..fc425109d5 100644
@@ -54,10 +54,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -927,11 +927,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#258 lore raw

PATCH v16 17/21 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fc425109d5..9a5bab9932 100644
@@ -910,10 +910,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#259 lore raw

PATCH v16 18/21 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap.rst               |  15 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 240 ++++++++++++++++---------
 3 files changed, 170 insertions(+), 86 deletions(-)
doc/guides/nics/pcap.rst +15 -0
index 2709c6d017..f241069ebb 100644
@@ -162,6 +162,21 @@ Runtime Config Options
 
   In this case, one dummy Rx queue is created for each Tx queue argument passed.
 
+* Set the snapshot length for packet capture
+
+  The snapshot length controls the maximum number of bytes captured per packet.
+  This affects both interface capture and pcap file output.  The default value is
+  65535 bytes, which captures complete packets up to the maximum Ethernet jumbo
+  frame size.  Reducing this value can improve performance when only packet headers
+  are needed.  This can be done with the ``snaplen`` devarg, for example::
+
+     --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+     --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+  The snapshot length also determines the reported ``max_rx_pktlen``
+  and ``max_mtu`` in device info.
+
+
 Examples of Usage
 ~~~~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 2cdc304539..3e82b51d3c 100644
@@ -98,6 +98,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +154 -86

500 lines not on this page · raw message

Signature · 1 line
2.51.0
#260 lore raw

PATCH v16 19/21 net/pcap: add link status change support for iface mode

In reply to Stephen Hemminger

Add LSC interrupt support for pass-through (iface=) mode so applications can receive link state change notifications via the standard ethdev callback mechanism.

Uses alarm-based polling to periodically check the underlying interface state via osdep_iface_link_get(). The LSC flag is advertised only for iface mode devices, and polling is gated on the application enabling intr_conf.lsc in port configuration.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/rel_notes/release_26_03.rst |  1 +
 drivers/net/pcap/pcap_ethdev.c         | 45 +++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)
doc/guides/nics/features/pcap.ini +1 -0
index 814bc2119f..084fefbbbb 100644
@@ -5,6 +5,7 @@
 ;
 [Features]
 Link status          = Y
+Link status event    = Y
 Queue start/stop     = Y
 Scattered Rx         = Y
 Timestamp offload    = Y
doc/guides/rel_notes/release_26_03.rst +1 -0
index 3e82b51d3c..314f6d615b 100644
@@ -99,6 +99,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added support for Link State interrupt in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +44 -1

95 lines not on this page · raw message

Signature · 1 line
2.51.0
#261 lore raw

PATCH v16 20/21 net/pcap: add EOF notification via link status change

In reply to Stephen Hemminger

Add an "eof" devarg for rx_pcap mode that signals end-of-file by setting link down and generating an LSC event. This allows applications to detect when a pcap file has been fully consumed using the standard ethdev callback mechanism.

The eof and infinite_rx options are mutually exclusive. On device restart, the EOF state is reset so the file can be replayed.

---
 doc/guides/nics/pcap.rst               | 12 +++++
 doc/guides/rel_notes/release_26_03.rst |  2 +
 drivers/net/pcap/pcap_ethdev.c         | 75 ++++++++++++++++++++++++--
 3 files changed, 86 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
index f241069ebb..6f3a4fc887 100644
@@ -144,6 +144,18 @@ Runtime Config Options
   so all queues on a device will either have this enabled or disabled.
   This option should only be provided once per device.
 
+* Signal end-of-file via link status change
+
+  In case ``rx_pcap=`` configuration is set, the user may want to be notified when
+  all packets in the pcap file have been read.  This can be done with the ``eof``
+  devarg, for example::
+
+     --vdev 'net_pcap0,rx_pcap=file_rx.pcap,eof=1'
+
+  When enabled, the driver sets link down and generates an LSC event at end of file.
+  If the device is stopped and restarted, the EOF state is reset.
+  This option cannot be combined with ``infinite_rx``.
+
 * Drop all packets on transmit
 
   To drop all packets on transmit for a device,
doc/guides/rel_notes/release_26_03.rst +2 -0
index 314f6d615b..1e30256f36 100644
@@ -100,6 +100,8 @@ New Features
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
   * Added support for Link State interrupt in ``iface`` mode.
+  * Added ``eof`` devarg to use link state to signal end of receive
+    file input.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +72 -3

156 lines not on this page · raw message

Signature · 1 line
2.51.0
#262 lore raw

PATCH v16 21/21 test: add comprehensive test suite for pcap PMD

In reply to Stephen Hemminger

Add unit tests for the pcap PMD covering file and interface modes.

Tests include:
- basic TX to file and RX from file
- varied packet sizes and jumbo frames
- infinite RX mode
- TX drop mode
- statistics
- interface (iface=) pass-through mode
- link status reporting for file and iface modes
- link status change (LSC) with interface toggle
- EOF notification via LSC
- RX timestamps and timestamp with infinite RX
- multiple TX/RX queues
- VLAN strip, insert, and runtime offload configuration
- snapshot length (snaplen) and truncation

Cross-platform helpers handle temp file creation, interface discovery, and VLAN packet generation.

The LSC link toggle test requires a pre-created dummy interface (Linux: dummy0, FreeBSD: disc0) and is skipped if unavailable.

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3422 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 3425 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index 48874037eb..a83292cf49 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +3422 -0

2,986 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index 1e30256f36..7fba410463 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#263 lore raw

v17 cover net/pcap: fixes, test, and ehancements

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when hardware/libpcap supports it)
- Accurate link state, speed, and duplex reporting in interface mode
- Link status change (LSC) interrupt support in interface mode
- EOF notification via link status change for rx_pcap mode
- Support for Windows interface mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snaplen devarg

Bug fixes:
- Fix build on Windows from RTE_LOG_LINE changes.
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Change Tx burst to always consume all packets; failed sends increment error counter rather than leaving mbufs for retry (pcap_sendpacket failures are not transient)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables
- Defer pcap handle opening until device start
- Use bulk free for better Tx performance

Testing:
- Add comprehensive unit test suite covering basic operations, timestamps, jumbo frames, VLAN handling, multi-queue, and more
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- New tests for runtime VLAN offload toggle, VLAN strip with infinite_rx mode, and timestamp generation in infinite_rx mode

v17:
- Fix windows build
- Fix feedback from AI review
- Cleanup tests

Stephen Hemminger (23):
maintainers: update for pcap driver
net/pcap: fix build on Windows
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: advertise Tx multi segment
net/pcap: replace stack bounce buffer
net/pcap: fix error accounting and backpressure on transmit net/pcap: add datapath debug logging
net/pcap: consolidate boolean flag handling net/pcap: support VLAN strip and insert offloads net/pcap: add link state and speed for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet eal/windows: add wrapper for access function net/pcap: add snapshot length devarg
net/pcap: add link status change support for iface mode net/pcap: add EOF notification via link status change
test: add comprehensive test suite for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3424 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    9 +
 doc/guides/nics/pcap.rst               |   41 +
 doc/guides/rel_notes/release_26_03.rst |   13 +
 drivers/net/pcap/pcap_ethdev.c         |  935 +++++--
 drivers/net/pcap/pcap_osdep.h          |   39 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   98 +-
 drivers/net/pcap/pcap_osdep_linux.c    |  124 +-
 drivers/net/pcap/pcap_osdep_windows.c  |  103 +-
 lib/eal/windows/include/rte_os_shim.h  |    1 +
 lib/eal/windows/include/unistd.h       |    7 +
 13 files changed, 4553 insertions(+), 244 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#264 lore raw

PATCH v17 1/23 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 1b2f1ed2ba..93ac176573 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#265 lore raw

PATCH v17 2/23 net/pcap: fix build on Windows

In reply to Stephen Hemminger

The log messages in the pcap OS dependent code for Windows was never converted during the last release.

It looks like the osdep part of pcap was not being built. Building requires have libpcap for Windows built which is not part of the CI infrastructure.

Fixes 2b843cac232e ("drivers: use per line logging in helpers")
---
 drivers/net/pcap/pcap_osdep_windows.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_osdep_windows.c +4 -4
index 1d398dc7ed..0965c2f5c9 100644
@@ -53,7 +53,7 @@ osdep_iface_index_get(const char *device_name)
 
 	ret = GetAdapterIndex(adapter_name, &index);
 	if (ret != NO_ERROR) {
-		PMD_LOG(ERR, "GetAdapterIndex(%S) = %lu\n", adapter_name, ret);
+		PMD_LOG(ERR, "GetAdapterIndex(%S) = %lu", adapter_name, ret);
 		return -1;
 	}
 
@@ -75,20 +75,20 @@ osdep_iface_mac_get(const char *device_name, struct rte_ether_addr *mac)
 
 	sys_ret = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size);
 	if (sys_ret != ERROR_BUFFER_OVERFLOW) {
-		PMD_LOG(ERR, "GetAdapterAddresses() = %lu, expected %lu\n",
+		PMD_LOG(ERR, "GetAdapterAddresses() = %lu, expected %lu",
 			sys_ret, ERROR_BUFFER_OVERFLOW);
 		return -1;
 	}
 
 	info = (IP_ADAPTER_ADDRESSES *)malloc(size);
 	if (info == NULL) {
-		PMD_LOG(ERR, "Cannot allocate adapter address info\n");
+		PMD_LOG(ERR, "Cannot allocate adapter address info");
 		return -1;
 	}
 
 	sys_ret = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, info, &size);
 	if (sys_ret != ERROR_SUCCESS) {
-		PMD_LOG(ERR, "GetAdapterAddresses() = %lu\n", sys_ret);
+		PMD_LOG(ERR, "GetAdapterAddresses() = %lu", sys_ret);
 		free(info);
 		return -1;
 	}
Signature · 1 line
2.51.0
#266 lore raw

PATCH v17 3/23 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..b0dac3cca7 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Scattered Rx         = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#267 lore raw

PATCH v17 4/23 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#268 lore raw

PATCH v17 5/23 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#269 lore raw

PATCH v17 6/23 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#270 lore raw

PATCH v17 7/23 net/pcap: advertise Tx multi segment

In reply to Stephen Hemminger

The driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
index 806451dc99..fedf461be4 100644
@@ -753,6 +753,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
Signature · 1 line
2.51.0
#271 lore raw

PATCH v17 8/23 net/pcap: replace stack bounce buffer

In reply to Stephen Hemminger

Replace the 64K stack-allocated bounce buffer with a per-queue buffer allocated from hugepages via rte_malloc at queue setup. This is necessary because the buffer may be used in a secondary process transmit path where the primary process allocated it.

---
 drivers/net/pcap/pcap_ethdev.c | 57 +++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/net/pcap/pcap_ethdev.c +35 -22
index fedf461be4..4cf5319839 100644
@@ -91,6 +91,9 @@ struct pcap_tx_queue {
 	struct queue_stat tx_stat;
 	char name[PATH_MAX];
 	char type[ETH_PCAP_ARG_MAXLEN];
+
+	/* Temp buffer used for non-linear packets */
+	uint8_t *bounce_buf;
 };
 
 struct pmd_internals {
@@ -385,18 +388,17 @@ static uint16_t
 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *dumper_q = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	struct pcap_pkthdr header;
 	pcap_dumper_t *dumper;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len, caplen;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[dumper_q->port_id].process_private;
 	dumper = pp->tx_dumper[dumper_q->queue_id];
+	temp_data = dumper_q->bounce_buf;
 
 	if (dumper == NULL || nb_pkts == 0)
 		return 0;
@@ -404,12 +406,10 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	/* writes the nb_pkts packets to the previously opened pcap file
 	 * dumper */
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
+		struct rte_mbuf *mbuf = bufs[i];
+		size_t len, caplen;
+
 		len = caplen = rte_pktmbuf_pkt_len(mbuf);
-		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
-			caplen = sizeof(temp_data);
-		}
 
 		calculate_timestamp(&header.ts);
 		header.len = len;
@@ -449,9 +449,6 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint32_t tx_bytes = 0;
 	struct pcap_tx_queue *tx_queue = queue;
 
-	if (unlikely(nb_pkts == 0))
-		return 0;
-
 	for (i = 0; i < nb_pkts; i++) {
 		tx_bytes += bufs[i]->pkt_len;
 		rte_pktmbuf_free(bufs[i]);
@@ -460,7 +457,7 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	tx_queue->tx_stat.pkts += nb_pkts;
 	tx_queue->tx_stat.bytes += tx_bytes;
 
-	return i;
+	return nb_pkts;
 }
 
 /*
@@ -470,30 +467,30 @@ static uint16_t
 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	int ret;
-	struct rte_mbuf *mbuf;
 	struct pmd_process_private *pp;
 	struct pcap_tx_queue *tx_queue = queue;
 	uint16_t num_tx = 0;
 	uint32_t tx_bytes = 0;
 	pcap_t *pcap;
-	unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
-	size_t len;
+	unsigned char *temp_data;
 
 	pp = rte_eth_devices[tx_queue->port_id].process_private;
 	pcap = pp->tx_pcap[tx_queue->queue_id];
+	temp_data = tx_queue->bounce_buf;
 
 	if (unlikely(nb_pkts == 0 || pcap == NULL))
 		return 0;
 
 	for (i = 0; i < nb_pkts; i++) {
-		mbuf = bufs[i];
-		len = rte_pktmbuf_pkt_len(mbuf);
+		struct rte_mbuf *mbuf = bufs[i];
+		size_t len = rte_pktmbuf_pkt_len(mbuf);
+		int ret;
+
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
-				len > sizeof(temp_data))) {
+				len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
 			PMD_LOG(ERR,
-				"Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
-				len, sizeof(temp_data));
+				"Dropping multi segment PCAP packet. Size (%zd) > max size (%u).",
+				len, RTE_ETH_PCAP_SNAPSHOT_LEN);
 			rte_pktmbuf_free(mbuf);
 			continue;
 		}
@@ -966,7 +963,7 @@ static int
 eth_tx_queue_setup(struct rte_eth_dev *dev,
 		uint16_t tx_queue_id,
 		uint16_t nb_tx_desc __rte_unused,
-		unsigned int socket_id __rte_unused,
+		unsigned int socket_id,
 		const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
@@ -974,11 +971,26 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
 
 	pcap_q->port_id = dev->data->port_id;
 	pcap_q->queue_id = tx_queue_id;
+	pcap_q->bounce_buf = rte_malloc_socket(NULL, RTE_ETH_PCAP_SNAPSHOT_LEN,
+					       RTE_CACHE_LINE_SIZE, socket_id);
+	if (pcap_q->bounce_buf == NULL)
+		return -ENOMEM;
+
 	dev->data->tx_queues[tx_queue_id] = pcap_q;
 
 	return 0;
 }
 
+static void
+eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+	struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
+
+	rte_free(pcap_q->bounce_buf);
+	pcap_q->bounce_buf = NULL;
+}
+
 static int
 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1019,6 +1031,7 @@ static const struct eth_dev_ops ops = {
 	.dev_infos_get = eth_dev_info,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
+	.tx_queue_release = eth_tx_queue_release,
 	.rx_queue_start = eth_rx_queue_start,
 	.tx_queue_start = eth_tx_queue_start,
 	.rx_queue_stop = eth_rx_queue_stop,
Signature · 1 line
2.51.0
#272 lore raw

PATCH v17 9/23 net/pcap: fix error accounting and backpressure on transmit

In reply to Stephen Hemminger

The error handling when pcap_sendpacket() was incorrect. When underlying kernel socket buffer got full the send was counted as an error. Malformed multi-segment mbufs where pkt_len exceeds actual data were silently accepted.

Malformed mbufs are now detected via rte_pktmbuf_read() failure and counted as errors.

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. Backpressure is not an error.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 77 +++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 28 deletions(-)
drivers/net/pcap/pcap_ethdev.c +49 -28
index 4cf5319839..1ab5b1755c 100644
@@ -407,22 +407,27 @@ 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 = caplen = rte_pktmbuf_pkt_len(mbuf);
 
 		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));
 
-		num_tx++;
-		tx_bytes += caplen;
+		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			dumper_q->tx_stat.err_pkts++;
+		} else {
+			pcap_dump((u_char *)dumper, &header, data);
+
+			num_tx++;
+			tx_bytes += caplen;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
@@ -434,9 +439,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;
 }
 
 /*
@@ -461,7 +465,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)
@@ -483,34 +497,41 @@ 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)) {
+		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))
-			break;
-		num_tx++;
-		tx_bytes += len;
+		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
+		if (unlikely(data == NULL)) {
+			/* This only happens if mbuf is bogus pkt_len > data_len */
+			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			tx_queue->tx_stat.err_pkts++;
+		} else {
+			/*
+			 * No good way to separate back pressure from failure here
+			 * Assume it is EBUSY, ENOMEM, or EINTR, something that can be retried.
+			 */
+			if (pcap_sendpacket(pcap, data, len) != 0) {
+				PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				break;
+			}
+			num_tx++;
+			tx_bytes += len;
+		}
+
 		rte_pktmbuf_free(mbuf);
 	}
 
 	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;
 }
Signature · 1 line
2.51.0
#273 lore raw

PATCH v17 10/23 net/pcap: add datapath debug logging

In reply to Stephen Hemminger

Add datapath debug logging macros (PMD_RX_LOG, PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. Use PMD_TX_LOG in transmit error paths to aid debugging without impacting normal datapath performance.

---
 drivers/net/pcap/pcap_ethdev.c |  8 ++++----
 drivers/net/pcap/pcap_osdep.h  | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -4
index 1ab5b1755c..5b59e9d813 100644
@@ -419,7 +419,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, caplen, temp_data);
 		if (unlikely(data == NULL)) {
 			/* This only happens if mbuf is bogus pkt_len > data_len */
-			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
 			dumper_q->tx_stat.err_pkts++;
 		} else {
 			pcap_dump((u_char *)dumper, &header, data);
@@ -501,7 +501,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		const uint8_t *data;
 
 		if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > RTE_ETH_PCAP_SNAPSHOT_LEN)) {
-			PMD_LOG(ERR,
+			PMD_TX_LOG(ERR,
 				"Dropping multi segment PCAP packet. Size (%u) > max size (%u).",
 				len, RTE_ETH_PCAP_SNAPSHOT_LEN);
 			tx_queue->tx_stat.err_pkts++;
@@ -512,7 +512,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
 		if (unlikely(data == NULL)) {
 			/* This only happens if mbuf is bogus pkt_len > data_len */
-			PMD_LOG(ERR, "rte_pktmbuf_read failed");
+			PMD_TX_LOG(ERR, "rte_pktmbuf_read failed");
 			tx_queue->tx_stat.err_pkts++;
 		} else {
 			/*
@@ -520,7 +520,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			 * Assume it is EBUSY, ENOMEM, or EINTR, something that can be retried.
 			 */
 			if (pcap_sendpacket(pcap, data, len) != 0) {
-				PMD_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
+				PMD_TX_LOG(ERR, "pcap_sendpacket() failed: %s", pcap_geterr(pcap));
 				break;
 			}
 			num_tx++;
drivers/net/pcap/pcap_osdep.h +14 -0
index a0e2b5ace9..fe7399ff9f 100644
@@ -13,6 +13,20 @@
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
+#ifdef RTE_ETHDEV_DEBUG_RX
+#define PMD_RX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() rx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+#define PMD_TX_LOG(level, ...) \
+	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s() tx: ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(...) do { } while (0)
+#endif
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
Signature · 1 line
2.51.0
#274 lore raw

PATCH v17 11/23 net/pcap: consolidate boolean flag handling

In reply to Stephen Hemminger

Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.

Merge the separate select_phy_mac() and get_infinite_rx_arg() functions into a single process_bool_flag() handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).

Also change num_of_queue from unsigned int to uint16_t since it cannot exceed RTE_PMD_PCAP_MAX_QUEUES.

---
 drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++-------------------
 1 file changed, 30 insertions(+), 39 deletions(-)
drivers/net/pcap/pcap_ethdev.c +30 -39
index 5b59e9d813..a2f0bf5687 100644
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -102,9 +103,9 @@ struct pmd_internals {
 	char devargs[ETH_PCAP_ARG_MAXLEN];
 	struct rte_ether_addr eth_addr;
 	int if_index;
-	int single_iface;
-	int phy_mac;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool phy_mac;
+	bool infinite_rx;
 };
 
 struct pmd_process_private {
@@ -114,25 +115,25 @@ struct pmd_process_private {
 };
 
 struct pmd_devargs {
-	unsigned int num_of_queue;
+	uint16_t num_of_queue;
+	bool phy_mac;
 	struct devargs_queue {
 		pcap_dumper_t *dumper;
 		pcap_t *pcap;
 		const char *name;
 		const char *type;
 	} queue[RTE_PMD_PCAP_MAX_QUEUES];
-	int phy_mac;
 };
 
 struct pmd_devargs_all {
 	struct pmd_devargs rx_queues;
 	struct pmd_devargs tx_queues;
-	int single_iface;
-	unsigned int is_tx_pcap;
-	unsigned int is_tx_iface;
-	unsigned int is_rx_pcap;
-	unsigned int is_rx_iface;
-	unsigned int infinite_rx;
+	bool single_iface;
+	bool is_tx_pcap;
+	bool is_tx_iface;
+	bool is_rx_pcap;
+	bool is_rx_iface;
+	bool infinite_rx;
 };
 
 static const char *valid_arguments[] = {
@@ -890,7 +891,7 @@ eth_dev_close(struct rte_eth_dev *dev)
 		}
 	}
 
-	if (internals->phy_mac == 0)
+	if (!internals->phy_mac)
 		/* not dynamically allocated, must not be freed */
 		dev->data->mac_addrs = NULL;
 
@@ -1215,29 +1216,19 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
 }
 
 static int
-select_phy_mac(const char *key __rte_unused, const char *value,
-		void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
 {
-	if (extra_args) {
-		const int phy_mac = atoi(value);
-		int *enable_phy_mac = extra_args;
-
-		if (phy_mac)
-			*enable_phy_mac = 1;
-	}
-	return 0;
-}
-
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
-		const char *value, void *extra_args)
-{
-	if (extra_args) {
-		const int infinite_rx = atoi(value);
-		int *enable_infinite_rx = extra_args;
-
-		if (infinite_rx > 0)
-			*enable_infinite_rx = 1;
+	bool *flag = extra_args;
+
+	if (value == NULL || *value == '\0') {
+		*flag = true; /* default with no additional argument */
+	} else if (strcmp(value, "0") == 0) {
+		*flag = false;
+	} else if (strcmp(value, "1") == 0) {
+		*flag = true;
+	} else {
+		PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+		return -1;
 	}
 	return 0;
 }
@@ -1513,7 +1504,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		dumpers.queue[0] = pcaps.queue[0];
 
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
-				&select_phy_mac, &pcaps.phy_mac);
+					 &process_bool_flag, &pcaps.phy_mac);
 		if (ret < 0)
 			goto free_kvlist;
 
@@ -1552,9 +1543,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		if (infinite_rx_arg_cnt == 1) {
 			ret = rte_kvargs_process(kvlist,
-					ETH_PCAP_INFINITE_RX_ARG,
-					&get_infinite_rx_arg,
-					&devargs_all.infinite_rx);
+						 ETH_PCAP_INFINITE_RX_ARG,
+						 &process_bool_flag,
+						 &devargs_all.infinite_rx);
 			if (ret < 0)
 				goto free_kvlist;
 			PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1704,5 +1695,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
 	ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
 	ETH_PCAP_TX_IFACE_ARG "=<ifc> "
 	ETH_PCAP_IFACE_ARG "=<ifc> "
-	ETH_PCAP_PHY_MAC_ARG "=<int>"
+	ETH_PCAP_PHY_MAC_ARG "=<0|1> "
 	ETH_PCAP_INFINITE_RX_ARG "=<0|1>");
Signature · 1 line
2.51.0
#275 lore raw

PATCH v17 12/23 net/pcap: support VLAN strip and insert offloads

In reply to Stephen Hemminger

Add VLAN tag handling to the pcap PMD, consistent with how virtio and af_packet drivers implement it.

RX strip: when RTE_ETH_RX_OFFLOAD_VLAN_STRIP is enabled, the driver calls rte_vlan_strip() on received packets in both normal and infinite_rx modes. For infinite_rx, offloads are deferred to packet delivery rather than applied during ring fill, so the stored template packets remain unmodified.

TX insert: when RTE_MBUF_F_TX_VLAN is set on an mbuf, the driver inserts the VLAN tag via rte_vlan_insert() before writing to pcap or sending to the interface. Indirect or shared mbufs get a new header mbuf to avoid modifying the original.

Runtime reconfiguration is supported through vlan_offload_set, which propagates the strip setting to all active RX queues.

---
 doc/guides/nics/features/pcap.ini      |   1 +
 doc/guides/nics/pcap.rst               |  11 +++
 doc/guides/rel_notes/release_26_03.rst |   5 ++
 drivers/net/pcap/pcap_ethdev.c         | 119 ++++++++++++++++++++++++-
 4 files changed, 132 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
index b0dac3cca7..814bc2119f 100644
@@ -10,6 +10,7 @@ Scattered Rx         = Y
 Timestamp offload    = Y
 Basic stats          = Y
 Stats per queue      = Y
+VLAN offload         = Y
 Multiprocess aware   = Y
 FreeBSD              = Y
 Linux                = Y
doc/guides/nics/pcap.rst +11 -0
index fbfe854bb1..bed5006a42 100644
@@ -247,3 +247,14 @@ will be discarded by the Rx flushing operation.
    The network interface provided to the PMD should be up.
    The PMD will return an error if the interface is down,
    and the PMD itself won't change the status of the external network interface.
+
+Features and Limitations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+*  The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+   strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+   application.
+
+*  The PMD will transparently insert a VLAN tag to transmitted packets if
+   ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+   set.
doc/guides/rel_notes/release_26_03.rst +5 -0
index b4499ec066..63f554878d 100644
@@ -106,6 +106,11 @@ New Features
   Added handling of the key combination Control+L
   to clear the screen before redisplaying the prompt.
 
+* **Updated PCAP ethernet driver.**
+
+  * Added support for VLAN insertion and stripping.
+
+
 Removed Items
 -------------
 
drivers/net/pcap/pcap_ethdev.c +115 -4

221 lines not on this page · raw message

Signature · 1 line
2.51.0
#276 lore raw

PATCH v17 13/23 net/pcap: add link state and speed for interface mode

In reply to Stephen Hemminger

When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.

Add OS-dependent functions to query the real link state, speed, duplex, and autonegotiation settings from the underlying interface. The eth_link_update() callback now returns accurate information when operating in pass-through mode.

Linux uses ETHTOOL_GLINKSETTINGS which supports all speeds up to 800 Gbps. FreeBSD uses SIOCGIFMEDIA, and Windows uses GetAdaptersAddresses().

For pcap file mode or separate rx/tx interface configurations, default values continue to be used since there is no single underlying interface to query.

---
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         |  93 ++++++++++++++++---
 drivers/net/pcap/pcap_osdep.h          |  24 +++++
 drivers/net/pcap/pcap_osdep_freebsd.c  |  86 ++++++++++++++++++
 drivers/net/pcap/pcap_osdep_linux.c    | 118 +++++++++++++++++++++++++
 drivers/net/pcap/pcap_osdep_windows.c  |  95 +++++++++++++++++---
 6 files changed, 394 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
index 63f554878d..d98b7ccf2c 100644
@@ -109,6 +109,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for VLAN insertion and stripping.
+  * Added support for reporting link state and speed in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +82 -11

113 lines not on this page · raw message

drivers/net/pcap/pcap_osdep.h +24 -0
index fe7399ff9f..b72dd0d74c 100644
@@ -10,6 +10,7 @@
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
+
 extern int eth_pcap_logtype;
 #define RTE_LOGTYPE_ETH_PCAP eth_pcap_logtype
 
@@ -27,7 +28,30 @@ extern int eth_pcap_logtype;
 #define PMD_TX_LOG(...) do { } while (0)
 #endif
 
+/**
+ * Link information returned by osdep_iface_link_get().
+ */
+struct osdep_iface_link {
+	uint32_t link_speed;    /**< Speed in Mbps, 0 if unknown */
+	uint8_t link_status;    /**< 1 = up, 0 = down */
+	uint8_t link_duplex;    /**< 1 = full, 0 = half */
+	uint8_t link_autoneg;   /**< 1 = autoneg enabled, 0 = fixed */
+};
+
+
 int osdep_iface_index_get(const char *name);
 int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac);
 
+/**
+ * Get link state and speed for a network interface.
+ *
+ * @param name
+ *   Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows).
+ * @param link
+ *   Pointer to structure to fill with link information.
+ * @return
+ *   0 on success, -1 on failure.
+ */
+int osdep_iface_link_get(const char *name, struct osdep_iface_link *link);
+
 #endif
drivers/net/pcap/pcap_osdep_freebsd.c +86 -0

101 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_linux.c +118 -0

132 lines not on this page · raw message

drivers/net/pcap/pcap_osdep_windows.c +83 -12

124 lines not on this page · raw message

Signature · 1 line
2.51.0
#277 lore raw

PATCH v17 14/23 net/pcap: support nanosecond timestamp precision

In reply to Stephen Hemminger

Enable nanosecond-precision timestamps for both live capture and pcap file reading.

Replace pcap_open_live() with the pcap_create()/pcap_activate() API, which allows setting PCAP_TSTAMP_PRECISION_NANO before activation. Similarly, use pcap_open_offline_with_tstamp_precision() for reading pcap files. The pcap_pkthdr timestamp field, despite being declared as struct timeval, actually contains nanoseconds (not microseconds) when nanosecond precision is requested.

Make receive timestamp offloading conditional: timestamps are now only written to the mbuf dynamic field when RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. Previously, timestamps were unconditionally added to every received packet.

Other related changes:
* Add read_clock dev_op returning current UTC time for timestamp correlation.
* Move per-burst timestamp calculation outside the packet loop in tx_dumper.
* Enable immediate mode and improve error reporting
in live capture setup.

---
 doc/guides/nics/pcap.rst               |   3 +
 doc/guides/rel_notes/release_26_03.rst |   2 +
 drivers/net/pcap/pcap_ethdev.c         | 157 +++++++++++++++++++------
 3 files changed, 127 insertions(+), 35 deletions(-)
doc/guides/nics/pcap.rst +3 -0
index bed5006a42..2709c6d017 100644
@@ -258,3 +258,6 @@ Features and Limitations
 *  The PMD will transparently insert a VLAN tag to transmitted packets if
    ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
    set.
+
+*  The PMD will insert the pcap header packet timestamp with nanoseconds resolution and
+   UNIX origin, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled.
doc/guides/rel_notes/release_26_03.rst +2 -0
index d98b7ccf2c..9602e0b907 100644
@@ -110,6 +110,8 @@ New Features
 
   * Added support for VLAN insertion and stripping.
   * Added support for reporting link state and speed in ``iface`` mode.
+  * Receive timestamp offload is only done if offload flag set.
+  * Receive timestamps support nanosecond precision.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -35

269 lines not on this page · raw message

Signature · 1 line
2.51.0
#278 lore raw

PATCH v17 15/23 net/pcap: reject non-Ethernet interfaces

In reply to Stephen Hemminger

The pcap PMD sends and receives raw Ethernet frames. If used with an interface that has a different link type, packets will be malformed.

On FreeBSD and macOS, the loopback interface uses DLT_NULL which expects a 4-byte address family header instead of an Ethernet header. Sending Ethernet frames to such interfaces causes kernel warnings like:
looutput: af=-1 unexpected

Add a check after pcap_activate() to verify the interface uses DLT_EN10MB (Ethernet) link type and reject others with a clear error.

Fixes 4c173302c307 ("pcap: add new driver")
---
 drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
index f0c50093f5..6fb21c96bb 100644
@@ -671,6 +671,17 @@ open_iface_live(const char *iface, pcap_t **pcap)
 		goto error;
 	}
 
+	/*
+	 * Verify interface supports Ethernet link type.
+	 * Loopback on FreeBSD/macOS uses DLT_NULL which expects a 4-byte
+	 * address family header instead of Ethernet, causing kernel warnings.
+	 */
+	if (pcap_datalink(pc) != DLT_EN10MB) {
+		PMD_LOG(ERR, "%s: not Ethernet (link type %d)",
+			iface, pcap_datalink(pc));
+		goto error;
+	}
+
 	if (pcap_setnonblock(pc, 1, errbuf)) {
 		PMD_LOG(ERR, "Couldn't set non-blocking on %s: %s", iface, errbuf);
 		goto error;
Signature · 1 line
2.51.0
#279 lore raw

PATCH v17 16/23 net/pcap: reduce scope of file-level variables

In reply to Stephen Hemminger

Move errbuf from file scope to local variables in the two functions that use it (open_iface_live and open_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Move iface_idx to a static local variable within pmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.

---
 drivers/net/pcap/pcap_ethdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -2
index 6fb21c96bb..508163c4c4 100644
@@ -46,11 +46,9 @@
 
 #define RTE_PMD_PCAP_MAX_QUEUES 16
 
-static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timespec start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
-static uint8_t iface_idx;
 
 static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
@@ -629,6 +627,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static inline int
 open_iface_live(const char *iface, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
 	pcap_t *pc;
 	int status;
 
@@ -740,6 +739,8 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
 static int
 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
 {
+	char errbuf[PCAP_ERRBUF_SIZE];
+
 	*pcap = pcap_open_offline_with_tstamp_precision(pcap_filename,
 							PCAP_TSTAMP_PRECISION_NANO, errbuf);
 	if (*pcap == NULL) {
@@ -1543,6 +1544,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
 	 * where the middle 4 characters are converted to hex.
 	 */
+	static uint8_t iface_idx;
 	(*internals)->eth_addr = (struct rte_ether_addr) {
 		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
 	};
Signature · 1 line
2.51.0
#280 lore raw

PATCH v17 17/23 net/pcap: avoid use of volatile

In reply to Stephen Hemminger

Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.

---
 drivers/net/pcap/pcap_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +9 -9
index 508163c4c4..74812c6842 100644
@@ -54,10 +54,10 @@ static uint64_t timestamp_rx_dynflag;
 static int timestamp_dynfield_offset = -1;
 
 struct queue_stat {
-	volatile unsigned long pkts;
-	volatile unsigned long bytes;
-	volatile unsigned long err_pkts;
-	volatile unsigned long rx_nombuf;
+	uint64_t pkts;
+	uint64_t bytes;
+	uint64_t err_pkts;
+	uint64_t rx_nombuf;
 };
 
 struct queue_missed_stat {
@@ -930,11 +930,11 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
 	      struct eth_queue_stats *qstats)
 {
 	unsigned int i;
-	unsigned long rx_packets_total = 0, rx_bytes_total = 0;
-	unsigned long rx_missed_total = 0;
-	unsigned long rx_nombuf_total = 0, rx_err_total = 0;
-	unsigned long tx_packets_total = 0, tx_bytes_total = 0;
-	unsigned long tx_packets_err_total = 0;
+	uint64_t rx_packets_total = 0, rx_bytes_total = 0;
+	uint64_t rx_missed_total = 0;
+	uint64_t rx_nombuf_total = 0, rx_err_total = 0;
+	uint64_t tx_packets_total = 0, tx_bytes_total = 0;
+	uint64_t tx_packets_err_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
Signature · 1 line
2.51.0
#281 lore raw

PATCH v17 18/23 net/pcap: clarify maximum received packet

In reply to Stephen Hemminger

The driver has constant RTE_ETH_PCAP_SNAPSHOT_LEN with is set to the largest value the pcap library will return, so that should also be the largest receive buffer.

---
 drivers/net/pcap/pcap_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index 74812c6842..27373ec8e8 100644
@@ -913,10 +913,11 @@ eth_dev_info(struct rte_eth_dev *dev,
 
 	dev_info->if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_rx_pktlen = (uint32_t) -1;
+	dev_info->max_rx_pktlen = RTE_ETH_PCAP_SNAPSHOT_LEN;
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->max_mtu = RTE_ETH_PCAP_SNAPSHOT_LEN - RTE_ETHER_HDR_LEN;
 	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
Signature · 1 line
2.51.0
#282 lore raw

PATCH v17 19/23 eal/windows: add wrapper for access function

In reply to Stephen Hemminger

Like other Posix functions in unistd.h add wrapper using the Windows equivalent.

---
 lib/eal/windows/include/rte_os_shim.h | 1 +
 lib/eal/windows/include/unistd.h      | 7 +++++++
 2 files changed, 8 insertions(+)
lib/eal/windows/include/rte_os_shim.h +1 -0
index f16b2230c8..44664a5062 100644
@@ -33,6 +33,7 @@
 #define unlink(path) _unlink(path)
 #define fileno(f) _fileno(f)
 #define isatty(fd) _isatty(fd)
+#define access(path, mode) _access(path, mode)
 
 #define IPVERSION	4
 
lib/eal/windows/include/unistd.h +7 -0
index 78150c6480..f95888f4e1 100644
@@ -23,4 +23,11 @@
 #define STDERR_FILENO _fileno(stderr)
 #endif
 
+/* Mode values for the _access() function.  */
+#ifndef F_OK
+#define	F_OK		0	/* test for existence of file */
+#define	W_OK		0x02	/* test for write permission */
+#define	R_OK		0x04	/* test for read permission */
+#endif
+
 #endif /* _UNISTD_H_ */
Signature · 1 line
2.51.0
#283 lore raw

PATCH v17 20/23 net/pcap: add snapshot length devarg

In reply to Stephen Hemminger

Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.

The snapshot length affects:
- The pcap_set_snaplen() call when capturing from interfaces
- The pcap_open_dead() snapshot parameter for output files
- The reported max_rx_pktlen in device info
- The reported max_mtu in device info (snaplen - ethernet header)

The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.

Example usage:
--vdev 'net_pcap0,iface=eth0,snaplen=1518'
--vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'

---
 doc/guides/nics/pcap.rst               |  15 ++
 doc/guides/rel_notes/release_26_03.rst |   1 +
 drivers/net/pcap/pcap_ethdev.c         | 237 ++++++++++++++++---------
 3 files changed, 167 insertions(+), 86 deletions(-)
doc/guides/nics/pcap.rst +15 -0
index 2709c6d017..f241069ebb 100644
@@ -162,6 +162,21 @@ Runtime Config Options
 
   In this case, one dummy Rx queue is created for each Tx queue argument passed.
 
+* Set the snapshot length for packet capture
+
+  The snapshot length controls the maximum number of bytes captured per packet.
+  This affects both interface capture and pcap file output.  The default value is
+  65535 bytes, which captures complete packets up to the maximum Ethernet jumbo
+  frame size.  Reducing this value can improve performance when only packet headers
+  are needed.  This can be done with the ``snaplen`` devarg, for example::
+
+     --vdev 'net_pcap0,iface=eth0,snaplen=1518'
+     --vdev 'net_pcap0,rx_pcap=in.pcap,tx_pcap=out.pcap,snaplen=9000'
+
+  The snapshot length also determines the reported ``max_rx_pktlen``
+  and ``max_mtu`` in device info.
+
+
 Examples of Usage
 ~~~~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_26_03.rst +1 -0
index 9602e0b907..526e157dd4 100644
@@ -112,6 +112,7 @@ New Features
   * Added support for reporting link state and speed in ``iface`` mode.
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
+  * Added ``snaplen`` devarg to configure packet capture snapshot length.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +151 -86

497 lines not on this page · raw message

Signature · 1 line
2.51.0
#284 lore raw

PATCH v17 21/23 net/pcap: add link status change support for iface mode

In reply to Stephen Hemminger

Add LSC interrupt support for pass-through (iface=) mode so applications can receive link state change notifications via the standard ethdev callback mechanism.

Uses alarm-based polling to periodically check the underlying interface state via osdep_iface_link_get(). The LSC flag is advertised only for iface mode devices, and polling is gated on the application enabling intr_conf.lsc in port configuration.

---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/rel_notes/release_26_03.rst |  1 +
 drivers/net/pcap/pcap_ethdev.c         | 45 +++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)
doc/guides/nics/features/pcap.ini +1 -0
index 814bc2119f..084fefbbbb 100644
@@ -5,6 +5,7 @@
 ;
 [Features]
 Link status          = Y
+Link status event    = Y
 Queue start/stop     = Y
 Scattered Rx         = Y
 Timestamp offload    = Y
doc/guides/rel_notes/release_26_03.rst +1 -0
index 526e157dd4..39ce14ffe7 100644
@@ -113,6 +113,7 @@ New Features
   * Receive timestamp offload is only done if offload flag set.
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
+  * Added support for Link State interrupt in ``iface`` mode.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +44 -1

95 lines not on this page · raw message

Signature · 1 line
2.51.0
#285 lore raw

PATCH v17 22/23 net/pcap: add EOF notification via link status change

In reply to Stephen Hemminger

Add an "eof" devarg for rx_pcap mode that signals end-of-file by setting link down and generating an LSC event. This allows applications to detect when a pcap file has been fully consumed using the standard ethdev callback mechanism.

The eof and infinite_rx options are mutually exclusive. On device restart, the EOF state is reset so the file can be replayed.

---
 doc/guides/nics/pcap.rst               | 12 ++++
 doc/guides/rel_notes/release_26_03.rst |  2 +
 drivers/net/pcap/pcap_ethdev.c         | 83 +++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
index f241069ebb..6f3a4fc887 100644
@@ -144,6 +144,18 @@ Runtime Config Options
   so all queues on a device will either have this enabled or disabled.
   This option should only be provided once per device.
 
+* Signal end-of-file via link status change
+
+  In case ``rx_pcap=`` configuration is set, the user may want to be notified when
+  all packets in the pcap file have been read.  This can be done with the ``eof``
+  devarg, for example::
+
+     --vdev 'net_pcap0,rx_pcap=file_rx.pcap,eof=1'
+
+  When enabled, the driver sets link down and generates an LSC event at end of file.
+  If the device is stopped and restarted, the EOF state is reset.
+  This option cannot be combined with ``infinite_rx``.
+
 * Drop all packets on transmit
 
   To drop all packets on transmit for a device,
doc/guides/rel_notes/release_26_03.rst +2 -0
index 39ce14ffe7..d8a8f2dfa5 100644
@@ -114,6 +114,8 @@ New Features
   * Receive timestamps support nanosecond precision.
   * Added ``snaplen`` devarg to configure packet capture snapshot length.
   * Added support for Link State interrupt in ``iface`` mode.
+  * Added ``eof`` devarg to use link state to signal end of receive
+    file input.
 
 
 Removed Items
drivers/net/pcap/pcap_ethdev.c +80 -3

170 lines not on this page · raw message

Signature · 1 line
2.51.0
#286 lore raw

PATCH v17 23/23 test: add comprehensive test suite for pcap PMD

In reply to Stephen Hemminger

Add unit tests for the pcap PMD covering file and interface modes.

Tests include:
- basic TX to file and RX from file
- varied packet sizes and jumbo frames
- infinite RX mode
- TX drop mode
- statistics
- interface (iface=) pass-through mode
- link status reporting for file and iface modes
- link status change (LSC) with interface toggle
- EOF notification via LSC
- RX timestamps and timestamp with infinite RX
- multiple TX/RX queues
- VLAN strip, insert, and runtime offload configuration
- snapshot length (snaplen) and truncation

Cross-platform helpers handle temp file creation, interface discovery, and VLAN packet generation.

The LSC link toggle test requires a pre-created dummy interface (Linux: dummy0, FreeBSD: disc0) and is skipped if unavailable.

---
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3424 ++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |    1 +
 3 files changed, 3427 insertions(+)
 create mode 100644 app/test/test_pmd_pcap.c
app/test/meson.build +2 -0
index 4fd8670e05..253d43d60f 100644
@@ -141,6 +141,7 @@ source_file_deps = {
     'test_per_lcore.c': [],
     'test_pflock.c': [],
     'test_pie.c': ['sched'],
+    'test_pmd_pcap.c': ['net_pcap', 'ethdev', 'bus_vdev']  + packet_burst_generator_deps,
     'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps,
     'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
     'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
@@ -216,6 +217,7 @@ source_file_deps = {
 source_file_ext_deps = {
     'test_compressdev.c': ['zlib'],
     'test_pcapng.c': ['pcap'],
+    'test_pmd_pcap.c': ['pcap'],
 }
 
 def_lib = get_option('default_library')
app/test/test_pmd_pcap.c new file +3424 -0

2,986 lines not on this page · raw message

doc/guides/rel_notes/release_26_03.rst +1 -0
index d8a8f2dfa5..e4817467d7 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#287 lore raw

v18 cover net/pcap: fixes, test, and enhancements

In reply to Stephen Hemminger

This series contains improvements to the PCAP PMD including new features, bug fixes, code cleanup, and a comprehensive test suite.

New features:
- VLAN tag insertion on Tx (via tx_prepare) and stripping on Rx
- Runtime VLAN offload configuration via vlan_offload_set callback
- Nanosecond precision timestamps (when libpcap supports it)
- Link state reporting in interface mode
- Link status change (LSC) interrupt support in interface mode
- EOF notification via link status change for rx_pcap mode
- Advertise RTE_ETH_TX_OFFLOAD_MULTI_SEGS capability
- Configurable snapshot length via snaplen devarg

Bug fixes:
- Fix build on Windows from RTE_LOG_LINE changes.
- Fix multi-segment transmit to dynamically allocate instead of silently truncating packets larger than 9K stack buffer
- Fix Tx burst error handling: distinguish malformed mbufs (counted as errors) from pcap_sendpacket backpressure (break and retry)
- Reject non-Ethernet interfaces to prevent malformed packets and kernel warnings on FreeBSD/macOS loopback
- Fix infinite_rx ring fill applying VLAN strip and timestamp offloads to template packets, preventing those offloads from working correctly during packet delivery

Code cleanup:
- Convert internal flags from int to bool
- Remove unnecessary casts of void* from rte_zmalloc
- Replace rte_malloc/rte_memcpy with libc equivalents in osdep code
- Include headers explicitly rather than relying on indirect includes
- Remove unnecessary volatile qualifier on statistics
- Reduce scope of file-level variables

Testing:
- Add comprehensive unit test suite (26 test cases) covering basic file I/O, timestamps, jumbo frames, VLAN strip/insert, multi-queue, snaplen, EOF notification, and link status
- Test discovers network interfaces using pcap_findalldevs API for portable interface enumeration across Linux, FreeBSD, macOS, and Windows
- Tests use packet_burst_generator for standardized test packet creation

v18:
- Move VLAN insert from tx burst path to tx_prepare callback, consistent with virtio and af_packet driver patterns
- Simplify link status patch to just report UP/DOWN state; remove speed and duplex querying that had cross-platform portability issues (FreeBSD ifmedia_baudrate not available in userspace, Windows GetIfEntry2 linking issues)
- Fix test_vlan_insert_tx to call rte_eth_tx_prepare() before rte_eth_tx_burst() to match the new tx_prepare VLAN insert implementation

Stephen Hemminger (23):
maintainers: update for pcap driver
net/pcap: fix build on Windows
doc: update features for PCAP PMD
net/pcap: include used headers
net/pcap: remove unnecessary casts
net/pcap: avoid using rte_malloc and rte_memcpy net/pcap: advertise Tx multi segment
net/pcap: replace stack bounce buffer
net/pcap: fix error accounting and backpressure on transmit net/pcap: add datapath debug logging
net/pcap: consolidate boolean flag handling net/pcap: support VLAN strip and insert offloads net/pcap: add link status for interface mode net/pcap: support nanosecond timestamp precision net/pcap: reject non-Ethernet interfaces net/pcap: reduce scope of file-level variables net/pcap: avoid use of volatile
net/pcap: clarify maximum received packet eal/windows: add wrapper for access function net/pcap: add snapshot length devarg
net/pcap: add link status change support for iface mode net/pcap: add EOF notification via link status change
test: add comprehensive test suite for pcap PMD

 MAINTAINERS                            |    1 +
 app/test/meson.build                   |    2 +
 app/test/test_pmd_pcap.c               | 3574 ++++++++++++++++++++++++
 doc/guides/nics/features/pcap.ini      |    9 +
 doc/guides/nics/pcap.rst               |   48 +
 doc/guides/rel_notes/release_26_03.rst |   12 +
 drivers/net/pcap/pcap_ethdev.c         |  812 ++++--
 drivers/net/pcap/pcap_osdep.h          |   27 +
 drivers/net/pcap/pcap_osdep_freebsd.c  |   43 +-
 drivers/net/pcap/pcap_osdep_linux.c    |   33 +-
 drivers/net/pcap/pcap_osdep_windows.c  |   76 +-
 lib/eal/windows/include/rte_os_shim.h  |    1 +
 lib/eal/windows/include/unistd.h       |    7 +
 13 files changed, 4423 insertions(+), 222 deletions(-)
 create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
#288 lore raw

PATCH v18 1/23 maintainers: update for pcap driver

Nominate myself to take care of this since already doing pcapng and pdump code.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 1b2f1ed2ba..93ac176573 100644
@@ -1118,6 +1118,7 @@ F: doc/guides/nics/zxdh.rst
 F: doc/guides/nics/features/zxdh.ini
 
 PCAP PMD
+M: Stephen Hemminger <[email protected]>
 F: drivers/net/pcap/
 F: doc/guides/nics/pcap.rst
 F: doc/guides/nics/features/pcap.ini
Signature · 1 line
2.51.0
#289 lore raw

PATCH v18 2/23 net/pcap: fix build on Windows

In reply to Stephen Hemminger

The log messages in the pcap OS dependent code for Windows was never converted during the last release.

It looks like the osdep part of pcap was not being built. Building requires have libpcap for Windows built which is not part of the CI infrastructure.

Fixes 2b843cac232e ("drivers: use per line logging in helpers")
---
 drivers/net/pcap/pcap_osdep_windows.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_osdep_windows.c +4 -4
index 1d398dc7ed..0965c2f5c9 100644
@@ -53,7 +53,7 @@ osdep_iface_index_get(const char *device_name)
 
 	ret = GetAdapterIndex(adapter_name, &index);
 	if (ret != NO_ERROR) {
-		PMD_LOG(ERR, "GetAdapterIndex(%S) = %lu\n", adapter_name, ret);
+		PMD_LOG(ERR, "GetAdapterIndex(%S) = %lu", adapter_name, ret);
 		return -1;
 	}
 
@@ -75,20 +75,20 @@ osdep_iface_mac_get(const char *device_name, struct rte_ether_addr *mac)
 
 	sys_ret = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size);
 	if (sys_ret != ERROR_BUFFER_OVERFLOW) {
-		PMD_LOG(ERR, "GetAdapterAddresses() = %lu, expected %lu\n",
+		PMD_LOG(ERR, "GetAdapterAddresses() = %lu, expected %lu",
 			sys_ret, ERROR_BUFFER_OVERFLOW);
 		return -1;
 	}
 
 	info = (IP_ADAPTER_ADDRESSES *)malloc(size);
 	if (info == NULL) {
-		PMD_LOG(ERR, "Cannot allocate adapter address info\n");
+		PMD_LOG(ERR, "Cannot allocate adapter address info");
 		return -1;
 	}
 
 	sys_ret = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, info, &size);
 	if (sys_ret != ERROR_SUCCESS) {
-		PMD_LOG(ERR, "GetAdapterAddresses() = %lu\n", sys_ret);
+		PMD_LOG(ERR, "GetAdapterAddresses() = %lu", sys_ret);
 		free(info);
 		return -1;
 	}
Signature · 1 line
2.51.0
Acked-by on v18 2/23
#290 lore raw

Re: [PATCH v18 02/23] net/pcap: fix build on Windows

Quoted 11 lines · Stephen Hemminger

The log messages in the pcap OS dependent code for Windows was never converted during the last release.

It looks like the osdep part of pcap was not being built. Building requires have libpcap for Windows built which is not part of the CI infrastructure.

Fixes 2b843cac232e ("drivers: use per line logging in helpers")
Acked-by on v18 2/23
#291 lore raw

Re: [PATCH v18 02/23] net/pcap: fix build on Windows

In reply to Stephen Hemminger
Quoted 4 lines · Stephen Hemminger

The log messages in the pcap OS dependent code for Windows was never converted during the last release.

Quoted 8 lines

It looks like the osdep part of pcap was not being built. Building requires have libpcap for Windows built which is not part of the CI infrastructure.

Fixes 2b843cac232e ("drivers: use per line logging in helpers")
Signature · 1 line
David Marchand
#292 lore raw

PATCH v18 3/23 doc: update features for PCAP PMD

In reply to Stephen Hemminger

The PCAP PMD supports more features that were not flagged in the feature matrix.

---
 doc/guides/nics/features/pcap.ini | 7 +++++++
 1 file changed, 7 insertions(+)
doc/guides/nics/features/pcap.ini +7 -0
index 7fd22b190e..c4f0360a06 100644
@@ -4,8 +4,15 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Link status          = Y
+Queue start/stop     = Y
+Timestamp offload    = Y
 Basic stats          = Y
+Stats per queue      = Y
 Multiprocess aware   = Y
+FreeBSD              = Y
+Linux                = Y
+Windows              = Y
 ARMv7                = Y
 ARMv8                = Y
 Power8               = Y
Signature · 1 line
2.51.0
#293 lore raw

PATCH v18 4/23 net/pcap: include used headers

In reply to Stephen Hemminger

Include the used headers instead of relying on getting the headers indirectly through other headers.

---
 drivers/net/pcap/pcap_ethdev.c | 9 ++++++++-
 drivers/net/pcap/pcap_osdep.h  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +8 -1
index f323c0b0df..4513d46d61 100644
@@ -4,16 +4,23 @@
  * All rights reserved.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
+#include <rte_ring.h>
+#include <rte_ethdev.h>
 #include <ethdev_driver.h>
 #include <ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
+#include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
 #include <bus_vdev_driver.h>
drivers/net/pcap/pcap_osdep.h +1 -0
index 2aa13f3629..a0e2b5ace9 100644
@@ -6,6 +6,7 @@
 #define _RTE_PCAP_OSDEP_
 
 #include <rte_ether.h>
+#include <rte_log.h>
 
 #define PMD_LOG(level, ...) \
 	RTE_LOG_LINE_PREFIX(level, ETH_PCAP, "%s(): ", __func__, __VA_ARGS__)
Signature · 1 line
2.51.0
#294 lore raw

PATCH v18 5/23 net/pcap: remove unnecessary casts

In reply to Stephen Hemminger

The function rte_zmalloc returns void * so cast is unnecessary.

Correct the indentation in that code. Not really worth backporting.

---
 drivers/net/pcap/pcap_ethdev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/pcap/pcap_ethdev.c +4 -7
index 4513d46d61..fbd1021c39 100644
@@ -1220,9 +1220,8 @@ pmd_init_internals(struct rte_vdev_device *vdev,
 	PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
 		numa_node);
 
-	pp = (struct pmd_process_private *)
-		rte_zmalloc(NULL, sizeof(struct pmd_process_private),
-				RTE_CACHE_LINE_SIZE);
+	pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+			 RTE_CACHE_LINE_SIZE);
 
 	if (pp == NULL) {
 		PMD_LOG(ERR,
@@ -1590,10 +1589,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		unsigned int i;
 
 		internal = eth_dev->data->dev_private;
-			pp = (struct pmd_process_private *)
-				rte_zmalloc(NULL,
-					sizeof(struct pmd_process_private),
-					RTE_CACHE_LINE_SIZE);
+		pp = rte_zmalloc(NULL, sizeof(struct pmd_process_private),
+				 RTE_CACHE_LINE_SIZE);
 
 		if (pp == NULL) {
 			PMD_LOG(ERR,
Signature · 1 line
2.51.0
#295 lore raw

PATCH v18 6/23 net/pcap: avoid using rte_malloc and rte_memcpy

In reply to Stephen Hemminger

No need to use rte_malloc or rte_memcpy in the short code to get MAC address.

---
 drivers/net/pcap/pcap_ethdev.c        |  3 ++-
 drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
 drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +2 -1
index fbd1021c39..806451dc99 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <inttypes.h>
 #include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 		return -1;
 
 	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
-	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
 	eth_dev->data->mac_addrs = mac_addrs;
 	return 0;
 }
drivers/net/pcap/pcap_osdep_freebsd.c +5 -7
index 20556b3e92..0185665f0b 100644
@@ -4,13 +4,11 @@
  * All rights reserved.
  */
 
+#include <string.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <sys/sysctl.h>
 
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
 #include "pcap_osdep.h"
 
 int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 	if (len == 0)
 		return -1;
 
-	buf = rte_malloc(NULL, len, 0);
+	buf = malloc(len);
 	if (!buf)
 		return -1;
 
 	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
-		rte_free(buf);
+		free(buf);
 		return -1;
 	}
 	ifm = (struct if_msghdr *)buf;
 	sdl = (struct sockaddr_dl *)(ifm + 1);
 
-	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
 
-	rte_free(buf);
+	free(buf);
 	return 0;
 }
drivers/net/pcap/pcap_osdep_linux.c +3 -3
index 97033f57c5..df976417cb 100644
@@ -4,12 +4,12 @@
  * All rights reserved.
  */
 
+#include <string.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 
-#include <rte_memcpy.h>
 #include <rte_string_fns.h>
 
 #include "pcap_osdep.h"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
 		return -1;
 	}
 
-	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
 
 	close(if_fd);
 	return 0;
Signature · 1 line
2.51.0
#296 lore raw

PATCH v18 7/23 net/pcap: advertise Tx multi segment

In reply to Stephen Hemminger

The driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.

Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")
---
 drivers/net/pcap/pcap_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
index 806451dc99..fedf461be4 100644
@@ -753,6 +753,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
+	dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
 	return 0;
 }
Signature · 1 line
2.51.0