net/pcap: cleanups and test
Subsystems (2)
PATCH v10 17/19 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v10 18/19 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v10 19/19 test: add test for pcap PMD
In reply to Stephen HemmingerThis 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
@@ -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
@@ -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
v11 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v11 2/19 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v11 3/19 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v11 4/19 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v11 5/19 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v11 6/19 net/pcap: use bulk free
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v11 7/19 net/pcap: allocate Tx bounce buffer
In reply to Stephen HemmingerTo 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
@@ -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
PATCH v11 8/19 net/pcap: cleanup transmit buffer handling
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v11 9/19 net/pcap: report multi-segment transmit capability
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v11 10/19 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v11 11/19 net/pcap: support VLAN insert and strip
In reply to Stephen HemmingerDriver 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v11 12/19 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v11 13/19 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v11 14/19 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v11 15/19 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v11 16/19 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v11 17/19 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v11 18/19 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v11 19/19 test: add test for pcap PMD
In reply to Stephen HemmingerThis 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
@@ -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
@@ -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
v12 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v12 2/19 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v12 3/19 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v12 4/19 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v12 5/19 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v12 6/19 net/pcap: use bulk free
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v12 7/19 net/pcap: allocate Tx bounce buffer
In reply to Stephen HemmingerTo 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
@@ -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
PATCH v12 8/19 net/pcap: cleanup transmit buffer handling
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v12 9/19 net/pcap: report multi-segment transmit capability
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v12 10/19 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v12 11/19 net/pcap: support VLAN insert and strip
In reply to Stephen HemmingerDriver 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
@@ -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
@@ -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
@@ -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
PATCH v12 12/19 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v12 13/19 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v12 14/19 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v12 15/19 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v12 16/19 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v12 17/19 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v12 18/19 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v12 19/19 test: add test for pcap PMD
In reply to Stephen HemmingerThis 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
@@ -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
@@ -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
v13 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v13 2/16 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v13 3/16 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v13 4/16 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v13 5/16 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v13 6/16 net/pcap: cleanup transmit burst logic
In reply to Stephen HemmingerTo 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
@@ -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
@@ -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
PATCH v13 7/16 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v13 8/16 net/pcap: support VLAN insert and strip
In reply to Stephen HemmingerDriver 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
@@ -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
@@ -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
@@ -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
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.Signed-off-by Stephen Hemminger <[email protected]>
[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
PATCH v13 9/16 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v13 10/16 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v13 11/16 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v13 12/16 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v13 13/16 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v13 14/16 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v13 15/16 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v13 16/16 test: add test for pcap PMD
In reply to Stephen HemmingerThis 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
@@ -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
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.
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
Signed-off-by Stephen Hemminger <[email protected]>
[...]
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
v14 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v14 2/18 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v14 3/18 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v14 4/18 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v14 5/18 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v14 6/18 net/pcap: rework transmit burst handling
In reply to Stephen HemmingerReplace 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.
--- 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
@@ -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
@@ -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
PATCH v14 7/18 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v14 8/18 net/pcap: support VLAN strip and insert offloads
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
@@ -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
PATCH v14 9/18 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v14 10/18 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v14 11/18 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v14 12/18 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v14 13/18 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v14 14/18 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v14 15/18 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v14 16/18 net/pcap: add link status change support for iface mode
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v14 17/18 net/pcap: add EOF notification via link status change
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v14 18/18 test: add comprehensive test suite for pcap PMD
In reply to Stephen HemmingerAdd 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
@@ -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
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.
v15 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v15 2/18 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v15 3/18 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v15 4/18 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v15 5/18 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v15 6/18 net/pcap: rework transmit burst handling
In reply to Stephen HemmingerReplace 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.
--- 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
@@ -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
@@ -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
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_mallocat 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 wherepkt_lenexceeds actual data were silently accepted; they are now detected viarte_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. AdvertiseRTE_ETH_TX_OFFLOAD_MULTI_SEGSin device capabilities since the driver has always supported multi-segment transmit. Addtx_queue_releaseto free the bounce buffer.
Quoted 4 lines
Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")Signed-off-by Stephen Hemminger <[email protected]>
It seems this commit does a lot more than fixing one issue. Please split.
Signature · 1 line
David Marchand
PATCH v15 7/18 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v15 8/18 net/pcap: support VLAN strip and insert offloads
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
@@ -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
PATCH v15 9/18 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v15 10/18 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v15 11/18 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v15 12/18 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v15 13/18 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v15 14/18 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v15 15/18 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v15 16/18 net/pcap: add link status change support for iface mode
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v15 17/18 net/pcap: add EOF notification via link status change
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v15 18/18 test: add comprehensive test suite for pcap PMD
In reply to Stephen HemmingerAdd 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
@@ -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
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.
v16 cover net/pcap: improvements and test suite
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v16 2/21 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v16 3/21 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v16 4/21 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v16 5/21 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v16 6/21 net/pcap: advertise Tx multi segment
In reply to Stephen HemmingerThe driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.
--- drivers/net/pcap/pcap_ethdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
@@ -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
PATCH v16 7/21 net/pcap: replace stack bounce buffer with per-queue allocation
In reply to Stephen HemmingerReplace 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
@@ -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
PATCH v16 8/21 net/pcap: fix error accounting and backpressure on transmit
In reply to Stephen HemmingerFix 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.
--- drivers/net/pcap/pcap_ethdev.c | 71 +++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 26 deletions(-)
drivers/net/pcap/pcap_ethdev.c +45 -26
@@ -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
PATCH v16 9/21 net/pcap: add datapath debug logging
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v16 10/21 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v16 11/21 net/pcap: support VLAN strip and insert offloads
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
@@ -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
PATCH v16 12/21 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v16 13/21 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v16 14/21 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v16 15/21 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v16 16/21 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v16 17/21 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v16 18/21 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v16 19/21 net/pcap: add link status change support for iface mode
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v16 20/21 net/pcap: add EOF notification via link status change
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v16 21/21 test: add comprehensive test suite for pcap PMD
In reply to Stephen HemmingerAdd 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
@@ -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
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.
v17 cover net/pcap: fixes, test, and ehancements
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v17 2/23 net/pcap: fix build on Windows
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_osdep_windows.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_osdep_windows.c +4 -4
@@ -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
PATCH v17 3/23 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v17 4/23 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v17 5/23 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v17 6/23 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v17 7/23 net/pcap: advertise Tx multi segment
In reply to Stephen HemmingerThe driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.
--- drivers/net/pcap/pcap_ethdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
@@ -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
PATCH v17 8/23 net/pcap: replace stack bounce buffer
In reply to Stephen HemmingerReplace 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
@@ -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
PATCH v17 9/23 net/pcap: fix error accounting and backpressure on transmit
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 77 +++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 28 deletions(-)
drivers/net/pcap/pcap_ethdev.c +49 -28
@@ -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
PATCH v17 10/23 net/pcap: add datapath debug logging
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v17 11/23 net/pcap: consolidate boolean flag handling
In reply to Stephen HemmingerConvert 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
@@ -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
PATCH v17 12/23 net/pcap: support VLAN strip and insert offloads
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
@@ -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
PATCH v17 13/23 net/pcap: add link state and speed for interface mode
In reply to Stephen HemmingerWhen 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
@@ -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
@@ -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
PATCH v17 14/23 net/pcap: support nanosecond timestamp precision
In reply to Stephen HemmingerEnable 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
@@ -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
@@ -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
PATCH v17 15/23 net/pcap: reject non-Ethernet interfaces
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/pcap/pcap_ethdev.c +11 -0
@@ -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
PATCH v17 16/23 net/pcap: reduce scope of file-level variables
In reply to Stephen HemmingerMove 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
@@ -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
PATCH v17 17/23 net/pcap: avoid use of volatile
In reply to Stephen HemmingerUsing 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
@@ -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
PATCH v17 18/23 net/pcap: clarify maximum received packet
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v17 19/23 eal/windows: add wrapper for access function
In reply to Stephen HemmingerLike 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
@@ -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
@@ -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
PATCH v17 20/23 net/pcap: add snapshot length devarg
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v17 21/23 net/pcap: add link status change support for iface mode
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v17 22/23 net/pcap: add EOF notification via link status change
In reply to Stephen HemmingerAdd 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
@@ -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
@@ -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
PATCH v17 23/23 test: add comprehensive test suite for pcap PMD
In reply to Stephen HemmingerAdd 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
@@ -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
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.
v18 cover net/pcap: fixes, test, and enhancements
In reply to Stephen HemmingerThis 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
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
@@ -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
PATCH v18 2/23 net/pcap: fix build on Windows
In reply to Stephen HemmingerThe 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.
--- drivers/net/pcap/pcap_osdep_windows.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/pcap/pcap_osdep_windows.c +4 -4
@@ -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
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")Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH v18 02/23] net/pcap: fix build on Windows
In reply to Stephen HemmingerQuoted 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")Signed-off-by Stephen Hemminger <[email protected]>
Signature · 1 line
David Marchand
PATCH v18 3/23 doc: update features for PCAP PMD
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v18 4/23 net/pcap: include used headers
In reply to Stephen HemmingerInclude 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
@@ -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
@@ -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
PATCH v18 5/23 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe 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
@@ -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
PATCH v18 6/23 net/pcap: avoid using rte_malloc and rte_memcpy
In reply to Stephen HemmingerNo 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
@@ -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
@@ -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
@@ -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
PATCH v18 7/23 net/pcap: advertise Tx multi segment
In reply to Stephen HemmingerThe driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.
--- drivers/net/pcap/pcap_ethdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/pcap/pcap_ethdev.c +1 -0
@@ -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