net/pcap: cleanups and test
Subsystems (2)
PATCH v18 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 | 60 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/net/pcap/pcap_ethdev.c +37 -23
@@ -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,11 @@ 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]; - len = caplen =rte_pktmbuf_pkt_len (mbuf); -if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && - len >sizeof (temp_data))) { - caplen =sizeof (temp_data); - } +struct rte_mbuf *mbuf = bufs[i]; +size_t len, caplen; + + len =rte_pktmbuf_pkt_len (mbuf); + caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );calculate_timestamp (&header.ts); header.len = len;
@@ -449,9 +450,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 +458,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 +468,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 +964,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 +972,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 +1032,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 v18 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,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );
@@ -415,15 +416,19 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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); }
@@ -435,9 +440,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; }/*
@@ -462,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)
@@ -484,34 +498,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 v18 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
@@ -420,7 +420,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,7 +513,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 {/*
@@ -521,7 +521,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 v18 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[] = {
@@ -891,7 +892,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 ;
@@ -1216,29 +1217,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 ; }
@@ -1514,7 +1505,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;
@@ -1553,9 +1544,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",
@@ -1705,5 +1696,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 v18 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. This also gets used for capture of VLAN tagged packets when legacy pdump is used.
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 | 96 ++++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
@@ -9,6 +9,7 @@ Queue start/stop = 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 +92 -4
200 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 13/23 net/pcap: add link status 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 function to query the real link state from the underlying interface.
Linux and FreeBSD use SIOCGIFFLAGS to check IFF_UP and IFF_RUNNING. Windows uses GetAdaptersAddresses() to check OperStatus.
--- doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 38 +++++++++----- drivers/net/pcap/pcap_osdep.h | 12 +++++ drivers/net/pcap/pcap_osdep_freebsd.c | 31 ++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 27 ++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 68 +++++++++++++++++++++----- 6 files changed, 154 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 in ``iface`` mode. Removed Items
drivers/net/pcap/pcap_ethdev.c +27 -11
@@ -150,13 +150,6 @@ static const char *valid_arguments[] = {NULL }; -static struct rte_eth_link pmd_link = { - .link_speed =RTE_ETH_SPEED_NUM_10G , - .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , - .link_status =RTE_ETH_LINK_DOWN , - .link_autoneg =RTE_ETH_LINK_FIXED , -}; -RTE_LOG_REGISTER_DEFAULT (eth_pcap_logtype,NOTICE ); static struct queue_missed_stat*
@@ -952,10 +945,28 @@ eth_dev_close(struct rte_eth_dev *dev) }static int -eth_link_update(struct rte_eth_dev *dev __rte_unused, - int wait_to_complete __rte_unused) +eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { -return 0 ; +struct pmd_internals *internals = dev->data->dev_private; +struct rte_eth_link link = { + .link_speed =RTE_ETH_SPEED_NUM_10G , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; + +/* +* For pass-through mode (single_iface), query whether the +* underlying interface is up. Otherwise use default values. +*/ +if (internals->single_iface) { + link.link_status = (osdep_iface_link_status (internals->rx_queue[0 ].name) >0 ) ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + }else { + link.link_status = dev->data->dev_started ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + } + +return rte_eth_linkstatus_set (dev, &link); } static int
@@ -1370,7 +1381,12 @@ pmd_init_internals(struct rte_vdev_device *vdev, data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t )nb_rx_queues; data->nb_tx_queues = (uint16_t )nb_tx_queues; - data->dev_link = pmd_link; + data->dev_link = (struct rte_eth_link ) { + .link_speed =RTE_ETH_SPEED_NUM_NONE , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_status =RTE_ETH_LINK_DOWN , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; data->mac_addrs = &(*internals)->eth_addr; data->promiscuous =1 ; data->all_multicast =1 ;
drivers/net/pcap/pcap_osdep.h +12 -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
@@ -30,4 +31,15 @@ extern int eth_pcap_logtype;int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); +/** +* Get link status for a network interface. +* +* @param name +* Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows). +* @return +* 1 if link is up, 0 if link is down, -1 on error. +*/ +int osdep_iface_link_status (const char *name); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c +31 -0
@@ -5,8 +5,13 @@*/ #include <string.h> +#include <stdlib.h> +#include <unistd.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> +#include <sys/ioctl.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include "pcap_osdep.h"
@@ -55,3 +60,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)free (buf);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifmediareq ifmr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&ifmr,0 ,sizeof (ifmr)); +strlcpy (ifmr.ifm_name, if_name,sizeof (ifmr.ifm_name)); + +if (ioctl (fd,SIOCGIFMEDIA , &ifmr) ==0 ) { +/* IFM_AVALID means status is valid, IFM_ACTIVE means link up */ +if ((ifmr.ifm_status &IFM_AVALID ) && + (ifmr.ifm_status &IFM_ACTIVE )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_linux.c +27 -0
@@ -40,3 +40,30 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)close (if_fd);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifreq ifr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +rte_strscpy (ifr.ifr_name, if_name,sizeof (ifr.ifr_name)); +if (ioctl (fd,SIOCGIFFLAGS , &ifr) ==0 ) { +/* +* IFF_UP means administratively up. +* IFF_RUNNING means operationally up (carrier detected). +* Both must be set for link to be considered up. +*/ +if ((ifr.ifr_flags &IFF_UP ) && (ifr.ifr_flags &IFF_RUNNING )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_windows.c +56 -12
97 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 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 | 1 + drivers/net/pcap/pcap_ethdev.c | 156 +++++++++++++++++++------ 3 files changed, 126 insertions(+), 34 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 +1 -0
@@ -110,6 +110,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -34
268 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 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
@@ -649,6 +649,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 v18 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 ;
@@ -607,6 +605,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;
@@ -718,6 +717,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 ) {
@@ -1466,6 +1467,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 v18 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 {
@@ -908,11 +908,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 v18 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
@@ -891,10 +891,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 v18 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 v18 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.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'
--- doc/guides/nics/pcap.rst | 17 ++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 235 ++++++++++++++++--------- 3 files changed, 167 insertions(+), 86 deletions(-)
doc/guides/nics/pcap.rst +17 -0
@@ -15,6 +15,23 @@ For more information about the pcap library, see the The pcap-based PMD requires the libpcap development files to be installed. This applies to all supported operating systems: Linux, FreeBSD, and Windows. +* 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. + + The ``snaplen`` argument is used when opening capture handles, so it should + be specified before the interface or file arguments. Example:: + + --vdev 'net_pcap0,snaplen=1518,iface=eth0' + --vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap' + + The snapshot length also determines the reported ``max_rx_pktlen`` + and ``max_mtu`` in device info. + Using the Driver from the EAL Command Line ------------------------------------------
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -111,6 +111,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. * Receive timestamps support nanosecond precision. + * Added ``snaplen`` devarg to configure packet capture snapshot length. Removed Items
drivers/net/pcap/pcap_ethdev.c +149 -86
468 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 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/nics/pcap.rst | 5 +++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 45 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+)
doc/guides/nics/features/pcap.ini +1 -0
@@ -5,6 +5,7 @@ ; [Features] Link status = Y +Link status event = Y Queue start/stop = Y Timestamp offload = Y Basic stats = Y
doc/guides/nics/pcap.rst +5 -0
@@ -278,3 +278,8 @@ Features and Limitations * 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. + +* In ``iface`` mode, the PMD supports link status change (LSC) notifications. + When the application enables ``intr_conf.lsc`` in the port configuration, + the driver polls the underlying network interface once per second and generates an + ``RTE_ETH_EVENT_INTR_LSC`` callback when the link state changes.
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -112,6 +112,7 @@ New Features * Added support for reporting link state in ``iface`` mode. * 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 +45 -0
93 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 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 | 80 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
@@ -161,6 +161,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
@@ -113,6 +113,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 +77 -3
167 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v18 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 | 3574 ++++++++++++++++++++++++ doc/guides/rel_notes/release_26_03.rst | 1 + 3 files changed, 3577 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 +3574 -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.
v19 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
- Rx scatter offload support with mbuf pool validation
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 covering basic file I/O, timestamps, jumbo frames, VLAN strip/insert, multi-queue, scatter receive, 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
v19:
- Restore Rx scatter offload patch
- minor fix to tx_burst
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 (24):
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 Rx scatter offload
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
Stephen Hemminger (25):
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 Rx scatter offload
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 check patch warn in test
MAINTAINERS | 1 + app/test/meson.build | 2 + app/test/test_pmd_pcap.c | 3755 ++++++++++++++++++++++++ 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 | 850 ++++-- 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, 4643 insertions(+), 221 deletions(-) create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
PATCH v19 1/25 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
@@ -1116,6 +1116,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 v19 2/25 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 v19 3/25 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 v19 4/25 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 v19 5/25 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 v19 6/25 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 v19 7/25 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 v19 8/25 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 | 60 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/net/pcap/pcap_ethdev.c +37 -23
@@ -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,11 @@ 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]; - len = caplen =rte_pktmbuf_pkt_len (mbuf); -if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && - len >sizeof (temp_data))) { - caplen =sizeof (temp_data); - } +struct rte_mbuf *mbuf = bufs[i]; +size_t len, caplen; + + len =rte_pktmbuf_pkt_len (mbuf); + caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );calculate_timestamp (&header.ts); header.len = len;
@@ -449,9 +450,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 +458,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 +468,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 +964,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 +972,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 +1032,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 v19 9/25 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.
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 | 58 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-)
drivers/net/pcap/pcap_ethdev.c +36 -22
@@ -407,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );
@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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)); + + data =rte_pktmbuf_read (mbuf,0 , caplen, temp_data); + +/* This could only happen if mbuf is bogus pkt_len > data_len */ +RTE_ASSERT (data !=NULL ); +pcap_dump ((u_char *)dumper, &header, data); num_tx++; tx_bytes += caplen; +rte_pktmbuf_free (mbuf); }
@@ -435,9 +437,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; }/*
@@ -462,7 +463,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) }/* -* Callback to handle sending packets through a real NIC. +* Send a burst of packets to a pcap device. +* +* On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET +* socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). +* The send() call only blocks when the kernel socket send buffer is full, +* providing limited backpressure. +* +* On error, pcap_sendpacket() returns non-zero and the loop breaks, +* leaving remaining packets unsent. +* +* Bottom line: backpressure is not an error. */ static uint16_t eth_pcap_tx (void *queue,struct rte_mbuf **bufs,uint16_t nb_pkts)
@@ -484,34 +495,37 @@ 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. + data =rte_pktmbuf_read (mbuf,0 , len, temp_data); +RTE_ASSERT (data !=NULL ); + +/* +* No good way to separate back pressure from failure here +* Assume it is EBUSY, ENOMEM, or EINTR, something that can be retried. */ - ret =pcap_sendpacket (pcap, -rte_pktmbuf_read (mbuf,0 , len, temp_data), len); -if (unlikely (ret !=0 )) +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 v19 10/25 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 | 2 +- drivers/net/pcap/pcap_osdep.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +1 -1
@@ -499,7 +499,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++;
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 v19 11/25 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[] = {
@@ -884,7 +885,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 ;
@@ -1209,29 +1210,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 ; }
@@ -1507,7 +1498,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;
@@ -1546,9 +1537,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",
@@ -1698,5 +1689,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 v19 12/25 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. This also gets used for capture of VLAN tagged packets when legacy pdump is used.
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 | 96 ++++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
@@ -9,6 +9,7 @@ Queue start/stop = 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 +92 -4
200 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 13/25 net/pcap: add link status 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 function to query the real link state from the underlying interface.
Linux and FreeBSD use SIOCGIFFLAGS to check IFF_UP and IFF_RUNNING. Windows uses GetAdaptersAddresses() to check OperStatus.
--- doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 38 +++++++++----- drivers/net/pcap/pcap_osdep.h | 12 +++++ drivers/net/pcap/pcap_osdep_freebsd.c | 31 ++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 27 ++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 68 +++++++++++++++++++++----- 6 files changed, 154 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 in ``iface`` mode. Removed Items
drivers/net/pcap/pcap_ethdev.c +27 -11
@@ -150,13 +150,6 @@ static const char *valid_arguments[] = {NULL }; -static struct rte_eth_link pmd_link = { - .link_speed =RTE_ETH_SPEED_NUM_10G , - .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , - .link_status =RTE_ETH_LINK_DOWN , - .link_autoneg =RTE_ETH_LINK_FIXED , -}; -RTE_LOG_REGISTER_DEFAULT (eth_pcap_logtype,NOTICE ); static struct queue_missed_stat*
@@ -945,10 +938,28 @@ eth_dev_close(struct rte_eth_dev *dev) }static int -eth_link_update(struct rte_eth_dev *dev __rte_unused, - int wait_to_complete __rte_unused) +eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { -return 0 ; +struct pmd_internals *internals = dev->data->dev_private; +struct rte_eth_link link = { + .link_speed =RTE_ETH_SPEED_NUM_10G , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; + +/* +* For pass-through mode (single_iface), query whether the +* underlying interface is up. Otherwise use default values. +*/ +if (internals->single_iface) { + link.link_status = (osdep_iface_link_status (internals->rx_queue[0 ].name) >0 ) ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + }else { + link.link_status = dev->data->dev_started ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + } + +return rte_eth_linkstatus_set (dev, &link); } static int
@@ -1363,7 +1374,12 @@ pmd_init_internals(struct rte_vdev_device *vdev, data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t )nb_rx_queues; data->nb_tx_queues = (uint16_t )nb_tx_queues; - data->dev_link = pmd_link; + data->dev_link = (struct rte_eth_link ) { + .link_speed =RTE_ETH_SPEED_NUM_NONE , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_status =RTE_ETH_LINK_DOWN , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; data->mac_addrs = &(*internals)->eth_addr; data->promiscuous =1 ; data->all_multicast =1 ;
drivers/net/pcap/pcap_osdep.h +12 -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
@@ -30,4 +31,15 @@ extern int eth_pcap_logtype;int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); +/** +* Get link status for a network interface. +* +* @param name +* Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows). +* @return +* 1 if link is up, 0 if link is down, -1 on error. +*/ +int osdep_iface_link_status (const char *name); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c +31 -0
@@ -5,8 +5,13 @@*/ #include <string.h> +#include <stdlib.h> +#include <unistd.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> +#include <sys/ioctl.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include "pcap_osdep.h"
@@ -55,3 +60,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)free (buf);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifmediareq ifmr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&ifmr,0 ,sizeof (ifmr)); +strlcpy (ifmr.ifm_name, if_name,sizeof (ifmr.ifm_name)); + +if (ioctl (fd,SIOCGIFMEDIA , &ifmr) ==0 ) { +/* IFM_AVALID means status is valid, IFM_ACTIVE means link up */ +if ((ifmr.ifm_status &IFM_AVALID ) && + (ifmr.ifm_status &IFM_ACTIVE )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_linux.c +27 -0
@@ -40,3 +40,30 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)close (if_fd);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifreq ifr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +rte_strscpy (ifr.ifr_name, if_name,sizeof (ifr.ifr_name)); +if (ioctl (fd,SIOCGIFFLAGS , &ifr) ==0 ) { +/* +* IFF_UP means administratively up. +* IFF_RUNNING means operationally up (carrier detected). +* Both must be set for link to be considered up. +*/ +if ((ifr.ifr_flags &IFF_UP ) && (ifr.ifr_flags &IFF_RUNNING )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_windows.c +56 -12
97 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 14/25 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 | 1 + drivers/net/pcap/pcap_ethdev.c | 156 +++++++++++++++++++------ 3 files changed, 126 insertions(+), 34 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 +1 -0
@@ -110,6 +110,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -34
268 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 15/25 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
@@ -642,6 +642,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 v19 16/25 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 ;
@@ -600,6 +598,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;
@@ -711,6 +710,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 ) {
@@ -1459,6 +1460,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 v19 17/25 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 {
@@ -901,11 +901,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 v19 18/25 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
@@ -884,10 +884,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 v19 19/25 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 v19 20/25 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.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'
--- doc/guides/nics/pcap.rst | 17 ++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 211 ++++++++++++++++--------- 3 files changed, 158 insertions(+), 71 deletions(-)
doc/guides/nics/pcap.rst +17 -0
@@ -15,6 +15,23 @@ For more information about the pcap library, see the The pcap-based PMD requires the libpcap development files to be installed. This applies to all supported operating systems: Linux, FreeBSD, and Windows. +* 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. + + The ``snaplen`` argument is used when opening capture handles, so it should + be specified before the interface or file arguments. Example:: + + --vdev 'net_pcap0,snaplen=1518,iface=eth0' + --vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap' + + The snapshot length also determines the reported ``max_rx_pktlen`` + and ``max_mtu`` in device info. + Using the Driver from the EAL Command Line ------------------------------------------
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -111,6 +111,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. * Receive timestamps support nanosecond precision. + * Added ``snaplen`` devarg to configure packet capture snapshot length. Removed Items
drivers/net/pcap/pcap_ethdev.c +140 -71
444 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 21/25 net/pcap: add Rx scatter offload
In reply to Stephen HemmingerAdd RTE_ETH_RX_OFFLOAD_SCATTER to the advertised receive offload capabilities. Validate in rx_queue_setup that the mbuf pool data room is large enough when scatter is not enabled, following the same pattern as the virtio driver.
Gate the multi-segment receive path on the scatter offload flag and drop oversized packets when scatter is disabled. Reject scatter with infinite_rx mode since the ring-based replay path does not support multi-segment mbufs.
--- drivers/net/pcap/pcap_ethdev.c | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-)
drivers/net/pcap/pcap_ethdev.c +44 -3
@@ -79,6 +79,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;
@@ -112,6 +113,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading; };
@@ -342,14 +344,19 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)/* pcap packet will fit in the mbuf, can copy it */ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); mbuf->data_len = len; - }else { -/* Try read jumbo frame into multi mbufs. */ + }else if (pcap_q->rx_scatter) { +/* Scatter into multi-segment mbufs. */ if (unlikely (eth_pcap_rx_jumbo (pcap_q->mb_pool, mbuf, packet, len) ==-1 )) { pcap_q->rx_stat.err_pkts++;rte_pktmbuf_free (mbuf);break ; } + }else { +/* Packet too large and scatter not enabled, drop it. */ + pcap_q->rx_stat.err_pkts++; +rte_pktmbuf_free (mbuf); +continue ; } mbuf->pkt_len = len;
@@ -907,6 +914,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->rx_scatter = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ); internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );return 0 ; }
@@ -927,7 +935,8 @@ eth_dev_info(struct rte_eth_dev *dev, 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 | -RTE_ETH_RX_OFFLOAD_TIMESTAMP ; +RTE_ETH_RX_OFFLOAD_TIMESTAMP | +RTE_ETH_RX_OFFLOAD_SCATTER ;return 0 ; }
@@ -1088,11 +1097,37 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, {struct pmd_internals *internals = dev->data->dev_private;struct pcap_rx_queue *pcap_q = &internals->rx_queue[rx_queue_id]; +uint16_t buf_size; +bool rx_scatter; + + buf_size =rte_pktmbuf_data_room_size (mb_pool) -RTE_PKTMBUF_HEADROOM ; + rx_scatter = !!(dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_SCATTER ); + +/* +* If Rx scatter is not enabled, verify that the mbuf data room +* can hold the largest received packet in a single segment. +* Use the MTU-derived frame size as the expected maximum, not +* snapshot_len which is a capture truncation limit rather than +* an expected packet size. +*/ +if (!rx_scatter) { +uint32_t max_rx_pktlen = dev->data->mtu +RTE_ETHER_HDR_LEN ; + +if (max_rx_pktlen > buf_size) { +PMD_LOG (ERR , +"Rx scatter is disabled and RxQ mbuf pool object size is too small " +"(buf_size=%u, max_rx_pkt_len=%u)" , + buf_size, max_rx_pktlen); +return -EINVAL ; + } + } 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; + pcap_q->rx_scatter = rx_scatter; dev->data->rx_queues[rx_queue_id] = pcap_q; pcap_q->timestamp_offloading = internals->timestamp_offloading;
@@ -1105,6 +1140,12 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,pcap_t **pcap;bool save_vlan_strip; +if (rx_scatter) { +PMD_LOG (ERR , +"Rx scatter is not supported with infinite_rx mode" ); +return -EINVAL ; + } + pp = rte_eth_devices[pcap_q->port_id].process_private; pcap = &pp->rx_pcap[pcap_q->queue_id];
Signature · 1 line
2.51.0
PATCH v19 22/25 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/nics/pcap.rst | 5 +++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 45 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+)
doc/guides/nics/features/pcap.ini +1 -0
@@ -5,6 +5,7 @@ ; [Features] Link status = Y +Link status event = Y Queue start/stop = Y Timestamp offload = Y Basic stats = Y
doc/guides/nics/pcap.rst +5 -0
@@ -278,3 +278,8 @@ Features and Limitations * 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. + +* In ``iface`` mode, the PMD supports link status change (LSC) notifications. + When the application enables ``intr_conf.lsc`` in the port configuration, + the driver polls the underlying network interface once per second and generates an + ``RTE_ETH_EVENT_INTR_LSC`` callback when the link state changes.
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -112,6 +112,7 @@ New Features * Added support for reporting link state in ``iface`` mode. * 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 +45 -0
93 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 23/25 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 | 80 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
@@ -161,6 +161,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
@@ -113,6 +113,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 +77 -3
167 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v19 24/25 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 | 3755 ++++++++++++++++++++++++ doc/guides/rel_notes/release_26_03.rst | 1 + 3 files changed, 3758 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'], } # the NULL ethdev is used by a number of tests, in some cases as an optional dependency.
app/test/test_pmd_pcap.c new file +3755 -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.
PATCH v19 25/25 check patch warn in test
In reply to Stephen Hemminger--- app/test/test_pmd_pcap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_pmd_pcap.c +1 -1
@@ -1912,7 +1912,7 @@ set_iface_up_down(const char *ifname, int up)static const char *find_lsc_test_iface (void ) { -static const char *candidates[] = {"dummy0" ,"disc0" }; +static const char *const candidates[] = {"dummy0" ,"disc0" };unsigned int i;for (i =0 ; i <RTE_DIM (candidates); i++) {
Signature · 1 line
2.51.0
v20 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
- Rx scatter offload support with mbuf pool validation
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
- Preserve VLAN tags in dpdk-pdump captures by converting stripped VLAN metadata to Tx insert requests and calling rte_eth_tx_prepare() on the pcap vdev
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 covering basic file I/O, timestamps, jumbo frames, VLAN strip/insert, multi-queue, scatter receive, 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
v20:
- Add dpdk-pdump VLAN tag preservation patch
v19:
- Restore Rx scatter offload patch that was inadvertently dropped in v18
Stephen Hemminger (25):
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 Rx scatter offload
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 app/pdump: preserve VLAN tags in captured packets
MAINTAINERS | 1 + app/test/meson.build | 2 + app/test/test_pmd_pcap.c | 3755 ++++++++++++++++++++++++ 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 | 850 ++++-- 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 + lib/pdump/rte_pdump.c | 32 +- 14 files changed, 4674 insertions(+), 222 deletions(-) create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.51.0
PATCH v20 1/25 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
@@ -1116,6 +1116,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
Re: [PATCH v20 01/25] maintainers: update for pcap driver
Quoted 4 lines · Stephen Hemminger
Nominate myself to take care of this since already doing pcapng and pdump code.
Signed-off-by Stephen Hemminger <[email protected]>
Thanks for agreeing to step up here, Stephen.
Quoted 19 lines
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)MAINTAINERS +1
-0@@ -1116,6 +1116,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.iniSignature · 1 line
2.51.0
PATCH v20 2/25 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 v20 3/25 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
Re: [PATCH v20 03/25] doc: update features for PCAP PMD
Quoted 5 lines · Stephen Hemminger
The PCAP PMD supports more features that were not flagged in the feature matrix.
Signed-off-by Stephen Hemminger <[email protected]>---
With one item below fixed:
Quoted 8 lines
doc/guides/nics/features/pcap.ini | 7 +++++++ 1 file changed, 7 insertions(+)doc/guides/nics/features/pcap.ini +0
-0
doc/guides/nics/features/pcap.ini line 9
Quoted 6 lines
doc/guides/nics/features/pcap.ini +3
-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
I'd omit this or put it as partial. There is no support for Timestamps on Tx, so you can't use this for PTP, for example, as you can't get the exact time a packet was transmitted.
Quoted 12 lines
doc/guides/nics/features/pcap.ini +4
-0Basic stats = Y +Stats per queue = Y Multiprocess aware = Y +FreeBSD = Y +Linux = Y +Windows = Y ARMv7 = Y ARMv8 = Y Power8 = YSignature · 1 line
2.51.0
PATCH v20 4/25 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
Re: [PATCH v20 04/25] net/pcap: include used headers
Quoted 5 lines · Stephen Hemminger
Include the used headers instead of relying on getting the headers indirectly through other headers.
Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 5/25 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
Re: [PATCH v20 05/25] net/pcap: remove unnecessary casts
Quoted 6 lines · Stephen Hemminger
The function
rte_zmallocreturns void * so cast is unnecessary.Correct the indentation in that code. Not really worth backporting.
Signed-off-by Stephen Hemminger <[email protected]>---
Though one comment (and mini-rant, sorry!) inline below. Ok with this change as-is if you aren't respinning the set.
Quoted 8 lines
drivers/net/pcap/pcap_ethdev.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/net/pcap/pcap_ethdev.c +0
-0
drivers/net/pcap/pcap_ethdev.c pmd_init_internals(struct rte_vdev_device *vdev, · line 1225
Quoted 9 lines
drivers/net/pcap/pcap_ethdev.c +2
-3@@ -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 );
Not a major issue, but scanning through the existing file it uses more double-tab indent than aligning with braces. Personally for a refactor like this I'd just avoid unnecessarily changing the second line. [This is one reason why I hate this aligning with brackets, if you change the first line, you have to change the following ones too! Makes refactoring or renaming have either broken indentation or far larger diffs. Given the capabilities of AI, I would very much tend towards making our code more "refactor safe", as changes are less likely to made manually.]
Quoted 18 lines
drivers/net/pcap/pcap_ethdev.c +2
-4if (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 v20 6/25 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
Re: [PATCH v20 06/25] net/pcap: avoid using rte_malloc and rte_memcpy
Quoted 5 lines · Stephen Hemminger
No need to use
rte_mallocorrte_memcpyin the short code to get MAC address.Signed-off-by Stephen Hemminger <[email protected]>---
Quoted 46 lines
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 +1
-3@@ -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
drivers/net/pcap/pcap_osdep_freebsd.c osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac) · line 45
Quoted 8 lines
drivers/net/pcap/pcap_osdep_freebsd.c +1
-1@@ -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 ;
It's a pity there is no defined max length here that we can use a static buffer, but since there isn't using malloc rather than rte_malloc is best.
Quoted 46 lines
drivers/net/pcap/pcap_osdep_freebsd.c +3
-3if (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 v20 7/25 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
Re: [PATCH v20 07/25] net/pcap: advertise Tx multi segment
Quoted 9 lines · Stephen Hemminger
The driver supports multi-segment transmit, but the did not set the offload flag. Therefore applications would not know about that capability.
Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 8/25 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 | 60 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/net/pcap/pcap_ethdev.c +37 -23
@@ -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,11 @@ 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]; - len = caplen =rte_pktmbuf_pkt_len (mbuf); -if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && - len >sizeof (temp_data))) { - caplen =sizeof (temp_data); - } +struct rte_mbuf *mbuf = bufs[i]; +size_t len, caplen; + + len =rte_pktmbuf_pkt_len (mbuf); + caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );calculate_timestamp (&header.ts); header.len = len;
@@ -449,9 +450,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 +458,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 +468,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 +964,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 +972,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 +1032,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
Re: [PATCH v20 08/25] net/pcap: replace stack bounce buffer
Quoted 7 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.Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 9/25 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.
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 | 58 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-)
drivers/net/pcap/pcap_ethdev.c +36 -22
@@ -407,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );
@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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)); + + data =rte_pktmbuf_read (mbuf,0 , caplen, temp_data); + +/* This could only happen if mbuf is bogus pkt_len > data_len */ +RTE_ASSERT (data !=NULL ); +pcap_dump ((u_char *)dumper, &header, data); num_tx++; tx_bytes += caplen; +rte_pktmbuf_free (mbuf); }
@@ -435,9 +437,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; }/*
@@ -462,7 +463,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) }/* -* Callback to handle sending packets through a real NIC. +* Send a burst of packets to a pcap device. +* +* On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET +* socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). +* The send() call only blocks when the kernel socket send buffer is full, +* providing limited backpressure. +* +* On error, pcap_sendpacket() returns non-zero and the loop breaks, +* leaving remaining packets unsent. +* +* Bottom line: backpressure is not an error. */ static uint16_t eth_pcap_tx (void *queue,struct rte_mbuf **bufs,uint16_t nb_pkts)
@@ -484,34 +495,37 @@ 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. + data =rte_pktmbuf_read (mbuf,0 , len, temp_data); +RTE_ASSERT (data !=NULL ); + +/* +* No good way to separate back pressure from failure here +* Assume it is EBUSY, ENOMEM, or EINTR, something that can be retried. */ - ret =pcap_sendpacket (pcap, -rte_pktmbuf_read (mbuf,0 , len, temp_data), len); -if (unlikely (ret !=0 )) +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
Re: [PATCH v20 09/25] net/pcap: fix error accounting and backpressure on transmit
Quoted 10 lines · Stephen Hemminger
The error handling when
pcap_sendpacket()was incorrect. When underlying kernel socket buffer got full the send was counted as an error. Malformed multi-segment mbufs wherepkt_lenexceeds actual data were silently accepted.On Linux,
pcap_sendpacket()callssend()on a blockingPF_PACKETsocket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). Thesend()call only blocks when the kernel socket send buffer is full, providing limited backpressure. Backpressure is not an error.
I think we need a clearer explanation of what this patch does, this didn't make sense to me on reading it. See also comments inline below - I think we can get a better patch with a clearer explanation by just focusing on the changes to eth_pcap_tx. If you want to update the tx_dumper function put it in a different patch with a different explanation.
Quoted 4 lines
Fixes fbbbf553f268 ("net/pcap: fix concurrent multiseg Tx")Signed-off-by Stephen Hemminger <[email protected]>
With commit log clarified, I'm ok with this, but would prefer a smaller patch.
Quoted 42 lines
--- drivers/net/pcap/pcap_ethdev.c | 58 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-)drivers/net/pcap/pcap_ethdev.c +9
-7@@ -407,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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)); + + data =rte_pktmbuf_read (mbuf,0 , caplen, temp_data); + +/* This could only happen if mbuf is bogus pkt_len > data_len */ +RTE_ASSERT (data !=NULL ); +pcap_dump ((u_char *)dumper, &header, data); num_tx++; tx_bytes += caplen; +rte_pktmbuf_free (mbuf); }
drivers/net/pcap/pcap_ethdev.c eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) · line 442
Quoted 8 lines
drivers/net/pcap/pcap_ethdev.c +1
-2@@ -435,9 +437,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; }
While not wrong or problematic, the changes here are unnecessary IMHO, since there is no error that I can see in this function. The changes I see are:
* change datatype from size_t to uint32_t - ok but the original code wasn't really wrong for this.
* having an RTE_ASSERT for the data being NULL - I suppose this is useful for certain debug builds, but only if the user knows to define RTE_ENABLE_ASSERT.
* extra whitespace line - unnecessary
* drop status increment - the num_tx value would always equal nb_pkts, so this was an increment of zero. Removing it is good, as it saves a store.
* change return value from nb_pkts to i - this is equivalent since the loop always completes so that i == nb_pkts, so change is not needed.
The change I would keep is the unnecessary error increment since it was always zero - however, it doesn't go far enough, as num_tx can be removed in the function completely. By function end, i == num_tx == nb_pkts, so let's just use nb_pkts directly, and we can also make "i" a loop-local variable.
Quoted 74 lines
drivers/net/pcap/pcap_ethdev.c +26
-13/* @@ -462,7 +463,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) }/* -* Callback to handle sending packets through a real NIC. +* Send a burst of packets to a pcap device. +* +* On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET +* socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). +* The send() call only blocks when the kernel socket send buffer is full, +* providing limited backpressure. +* +* On error, pcap_sendpacket() returns non-zero and the loop breaks, +* leaving remaining packets unsent. +* +* Bottom line: backpressure is not an error. */ static uint16_t eth_pcap_tx (void *queue,struct rte_mbuf **bufs,uint16_t nb_pkts)@@ -484,34 +495,37 @@ 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. + data =rte_pktmbuf_read (mbuf,0 , len, temp_data); +RTE_ASSERT (data !=NULL ); + +/* +* No good way to separate back pressure from failure here +* Assume it is EBUSY, ENOMEM, or EINTR, something that can be retried. */ - ret =pcap_sendpacket (pcap, -rte_pktmbuf_read (mbuf,0 , len, temp_data), len); -if (unlikely (ret !=0 )) +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 v20 10/25 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 | 2 +- drivers/net/pcap/pcap_osdep.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +1 -1
@@ -499,7 +499,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++;
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 v20 10/25] net/pcap: add datapath debug logging
Quoted 6 lines · Stephen Hemminger
Add datapath debug logging macros (
PMD_RX_LOG,PMD_TX_LOG) gated on RTE_ETHDEV_DEBUG_RX/TX. UsePMD_TX_LOGin transmit error paths to aid debugging without impacting normal datapath performance.Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 11/25 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[] = {
@@ -884,7 +885,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 ;
@@ -1209,29 +1210,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 ; }
@@ -1507,7 +1498,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;
@@ -1546,9 +1537,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",
@@ -1698,5 +1689,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
Re: [PATCH v20 11/25] net/pcap: consolidate boolean flag handling
Quoted 8 lines · Stephen Hemminger
Convert internal flag fields from int/unsigned int to bool for clarity and reduced structure size.
Merge the separate
select_phy_mac()andget_infinite_rx_arg()functions into a singleprocess_bool_flag()handler. The new function also adds proper validation, rejecting values other than "0", "1", or empty (which defaults to true).
Quoted 4 lines
Also change
num_of_queuefrom unsigned int touint16_tsince it cannot exceedRTE_PMD_PCAP_MAX_QUEUES.Signed-off-by Stephen Hemminger <[email protected]>
One minor comment inline below.
Quoted 124 lines
--- drivers/net/pcap/pcap_ethdev.c | 69 +++++++++++++++------------------- 1 file changed, 30 insertions(+), 39 deletions(-)drivers/net/pcap/pcap_ethdev.c +26
-35@@ -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[] = {@@ -884,7 +885,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 ;@@ -1209,29 +1210,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 ; }@@ -1507,7 +1498,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;
drivers/net/pcap/pcap_ethdev.c pmd_pcap_probe(struct rte_vdev_device *dev) · line 1542
Quoted 9 lines
drivers/net/pcap/pcap_ethdev.c +3
-3@@ -1546,9 +1537,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);
You can shrink the diff by leaving the indentation alone, there is nothing wrong with it! :-)
Quoted 13 lines
drivers/net/pcap/pcap_ethdev.c +1
-1if (ret <0 ) goto free_kvlist; PMD_LOG(INFO, "infinite_rx has been %s for %s",@@ -1698,5 +1689,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 v20 12/25 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. This also gets used for capture of VLAN tagged packets when legacy pdump is used.
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 | 96 ++++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
@@ -9,6 +9,7 @@ Queue start/stop = 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
@@ -118,6 +118,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 +92 -4
200 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 12/25] net/pcap: support VLAN strip and insert offloads
Quoted 144 lines · Stephen Hemminger
Add VLAN tag handling to the pcap PMD, consistent with how virtio and
af_packetdrivers implement it. This also gets used for capture of VLAN tagged packets when legacy pdump is used.RX strip: when
RTE_ETH_RX_OFFLOAD_VLAN_STRIPis enabled, the driver callsrte_vlan_strip()on received packets in both normal andinfinite_rxmodes. Forinfinite_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_VLANis set on an mbuf, the driver inserts the VLAN tag viarte_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.Signed-off-by Stephen Hemminger <[email protected]>--- 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 | 96 ++++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 4 deletions(-)doc/guides/nics/features/pcap.ini +1
-0@@ -9,6 +9,7 @@ Queue start/stop = Y Timestamp offload = Y Basic stats = Y Stats per queue = Y +VLAN offload = Y Multiprocess aware = Y FreeBSD = Y Linux = Ydoc/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@@ -118,6 +118,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 +34
-1@@ -76,6 +76,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;@@ -106,6 +107,7 @@ struct pmd_internals {bool single_iface;bool phy_mac;bool infinite_rx; +bool vlan_strip; };struct pmd_process_private {@@ -270,7 +272,11 @@ eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) bufs[i]->data_len = pcap_buf->data_len; bufs[i]->pkt_len = pcap_buf->pkt_len; bufs[i]->port = pcap_q->port_id; - rx_bytes += pcap_buf->data_len; + +if (pcap_q->vlan_strip) +rte_vlan_strip (bufs[i]); + + rx_bytes += bufs[i]->data_len;/* Enqueue packet back on ring to allow infinite rx. */ rte_ring_enqueue (pcap_q->pkts, pcap_buf);@@ -336,6 +342,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;@@ -382,6 +392,39 @@ calculate_timestamp(struct timeval *ts) { } } +static uint16_t +eth_pcap_tx_prepare(void *queue __rte_unused, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) +{ +uint16_t nb_tx; +int error; + +for (nb_tx =0 ; nb_tx < nb_pkts; nb_tx++) { +struct rte_mbuf *m = tx_pkts[nb_tx]; + +#ifdef RTE_LIBRTE_ETHDEV_DEBUG + error =rte_validate_tx_offload (m); +if (unlikely (error)) { + rte_errno = -error; +break ; + } +#endif +/* Do VLAN tag insertion */ +if (unlikely (m->ol_flags &RTE_MBUF_F_TX_VLAN )) { + error =rte_vlan_insert (&m); + +/* rte_vlan_insert() could change pointer (currently does not) */ + tx_pkts[nb_tx] = m; +
drivers/net/pcap/pcap_ethdev.c calculate_timestamp(struct timeval *ts) { · line 427
Quoted 10 lines
drivers/net/pcap/pcap_ethdev.c +10
-0+if (unlikely (error !=0 )) { +PMD_TX_LOG (ERR ,"rte_vlan_insert failed: %s" ,strerror (-error)); + rte_errno = -error; +break ; + } + } + } +return nb_tx; +} +
Are we sure this is the correct way to do this? To behave like a normal NIC the Tx VLAN tag should be inserted in the Tx function, rather than tx prepare should it not? There is no guarantee apps will call tx_prepare before Tx.
/Bruce
Re: [PATCH v20 12/25] net/pcap: support VLAN strip and insert offloads
Quoted 6 lines · On Mon, 16 Mar 2026 14:04:59 +0000 Bruce Richardson…
Are we sure this is the correct way to do this? To behave like a normal NIC the Tx VLAN tag should be inserted in the Tx function, rather than tx prepare should it not? There is no guarantee apps will call
tx_preparebefore Tx./Bruce
I wasn't sure, but copied what virtio PMD was doing.
If application is using VLAN's on virtio it would need to call prepare.
uint16_t
virtio_xmit_pkts_prepare(void *tx_queue __rte_unused, struct rte_mbuf **tx_pkts,
uint16_t nb_pkts)
{
uint16_t nb_tx;
int error;
for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
struct rte_mbuf *m = tx_pkts[nb_tx];...
/* Do VLAN tag insertion */
if (unlikely(m->ol_flags & RTE_MBUF_F_TX_VLAN)) {
error = rte_vlan_insert(&m);
/* rte_vlan_insert() may change pointer
* even in the case of failure
*/
tx_pkts[nb_tx] = m;
if (unlikely(error)) {
rte_errno = -error;
break;
}
}PATCH v20 13/25 net/pcap: add link status 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 function to query the real link state from the underlying interface.
Linux and FreeBSD use SIOCGIFFLAGS to check IFF_UP and IFF_RUNNING. Windows uses GetAdaptersAddresses() to check OperStatus.
--- doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 38 +++++++++----- drivers/net/pcap/pcap_osdep.h | 12 +++++ drivers/net/pcap/pcap_osdep_freebsd.c | 31 ++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 27 ++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 68 +++++++++++++++++++++----- 6 files changed, 154 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -121,6 +121,7 @@ New Features * **Updated PCAP ethernet driver.** * Added support for VLAN insertion and stripping. + * Added support for reporting link state in ``iface`` mode. Removed Items
drivers/net/pcap/pcap_ethdev.c +27 -11
@@ -150,13 +150,6 @@ static const char *valid_arguments[] = {NULL }; -static struct rte_eth_link pmd_link = { - .link_speed =RTE_ETH_SPEED_NUM_10G , - .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , - .link_status =RTE_ETH_LINK_DOWN , - .link_autoneg =RTE_ETH_LINK_FIXED , -}; -RTE_LOG_REGISTER_DEFAULT (eth_pcap_logtype,NOTICE ); static struct queue_missed_stat*
@@ -945,10 +938,28 @@ eth_dev_close(struct rte_eth_dev *dev) }static int -eth_link_update(struct rte_eth_dev *dev __rte_unused, - int wait_to_complete __rte_unused) +eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { -return 0 ; +struct pmd_internals *internals = dev->data->dev_private; +struct rte_eth_link link = { + .link_speed =RTE_ETH_SPEED_NUM_10G , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; + +/* +* For pass-through mode (single_iface), query whether the +* underlying interface is up. Otherwise use default values. +*/ +if (internals->single_iface) { + link.link_status = (osdep_iface_link_status (internals->rx_queue[0 ].name) >0 ) ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + }else { + link.link_status = dev->data->dev_started ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + } + +return rte_eth_linkstatus_set (dev, &link); } static int
@@ -1363,7 +1374,12 @@ pmd_init_internals(struct rte_vdev_device *vdev, data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t )nb_rx_queues; data->nb_tx_queues = (uint16_t )nb_tx_queues; - data->dev_link = pmd_link; + data->dev_link = (struct rte_eth_link ) { + .link_speed =RTE_ETH_SPEED_NUM_NONE , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_status =RTE_ETH_LINK_DOWN , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; data->mac_addrs = &(*internals)->eth_addr; data->promiscuous =1 ; data->all_multicast =1 ;
drivers/net/pcap/pcap_osdep.h +12 -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
@@ -30,4 +31,15 @@ extern int eth_pcap_logtype;int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); +/** +* Get link status for a network interface. +* +* @param name +* Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows). +* @return +* 1 if link is up, 0 if link is down, -1 on error. +*/ +int osdep_iface_link_status (const char *name); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c +31 -0
@@ -5,8 +5,13 @@*/ #include <string.h> +#include <stdlib.h> +#include <unistd.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> +#include <sys/ioctl.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include "pcap_osdep.h"
@@ -55,3 +60,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)free (buf);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifmediareq ifmr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&ifmr,0 ,sizeof (ifmr)); +strlcpy (ifmr.ifm_name, if_name,sizeof (ifmr.ifm_name)); + +if (ioctl (fd,SIOCGIFMEDIA , &ifmr) ==0 ) { +/* IFM_AVALID means status is valid, IFM_ACTIVE means link up */ +if ((ifmr.ifm_status &IFM_AVALID ) && + (ifmr.ifm_status &IFM_ACTIVE )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_linux.c +27 -0
@@ -40,3 +40,30 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)close (if_fd);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifreq ifr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +rte_strscpy (ifr.ifr_name, if_name,sizeof (ifr.ifr_name)); +if (ioctl (fd,SIOCGIFFLAGS , &ifr) ==0 ) { +/* +* IFF_UP means administratively up. +* IFF_RUNNING means operationally up (carrier detected). +* Both must be set for link to be considered up. +*/ +if ((ifr.ifr_flags &IFF_UP ) && (ifr.ifr_flags &IFF_RUNNING )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_windows.c +56 -12
97 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 13/25] net/pcap: add link status for interface mode
Quoted 7 lines · Stephen Hemminger
When the PCAP PMD is used in pass-through mode with a physical interface (iface=X), the link status was always reported with hardcoded values regardless of the actual interface state.
Add OS-dependent function to query the real link state from the underlying interface.
Quoted 6 lines
Linux and FreeBSD use SIOCGIFFLAGS to check
IFF_UPandIFF_RUNNING. Windows usesGetAdaptersAddresses()to check OperStatus.Signed-off-by Stephen Hemminger <[email protected]>---
Any reason we can't in future similarly query the link speed of the interface in use, and the other link parameters?
Re: [PATCH v20 13/25] net/pcap: add link status for interface mode
Quoted 4 lines · On Mon, 16 Mar 2026 14:11:47 +0000 Bruce Richardson…
Acked-by Bruce Richardson <[email protected]>Any reason we can't in future similarly query the link speed of the interface in use, and the other link parameters?
I did that in earlier version but it adds more complexity. Each OS has its own way, and doesn't work for most common case of read/write to file.
PATCH v20 14/25 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 | 1 + drivers/net/pcap/pcap_ethdev.c | 156 +++++++++++++++++++------ 3 files changed, 126 insertions(+), 34 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 +1 -0
@@ -122,6 +122,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Items
drivers/net/pcap/pcap_ethdev.c +122 -34
268 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 14/25] net/pcap: support nanosecond timestamp precision
Quoted 322 lines · Stephen Hemminger
Enable nanosecond-precision timestamps for both live capture and pcap file reading.
Replace
pcap_open_live()with the pcap_create()/pcap_activate() API, which allows settingPCAP_TSTAMP_PRECISION_NANObefore activation. Similarly, usepcap_open_offline_with_tstamp_precision()for reading pcap files. Thepcap_pkthdrtimestamp 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_TIMESTAMPis enabled. Previously, timestamps were unconditionally added to every received packet.Other related changes:
* Addread_clockdev_opreturning current UTC time for timestamp correlation.
* Move per-burst timestamp calculation outside the packet loop intx_dumper.
* Enable immediate mode and improve error reporting
in live capture setup.Signed-off-by Stephen Hemminger <[email protected]>--- doc/guides/nics/pcap.rst | 3 + doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 156 +++++++++++++++++++------ 3 files changed, 126 insertions(+), 34 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 +1
-0@@ -122,6 +122,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Itemsdrivers/net/pcap/pcap_ethdev.c +112
-29@@ -27,13 +27,11 @@#include <rte_mbuf_dyn.h> #include <bus_vdev_driver.h> #include <rte_os_shim.h> +#include <rte_time.h> #include "pcap_osdep.h" #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535 -#define RTE_ETH_PCAP_SNAPLEN RTE_ETHER_MAX_JUMBO_FRAME_LEN -#define RTE_ETH_PCAP_PROMISC 1 -#define RTE_ETH_PCAP_TIMEOUT -1#define ETH_PCAP_RX_PCAP_ARG "rx_pcap"#define ETH_PCAP_TX_PCAP_ARG "tx_pcap"@@ -77,6 +75,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;struct queue_missed_stat missed_stat;@@ -108,6 +107,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool timestamp_offloading; };struct pmd_process_private {@@ -269,6 +269,15 @@ eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)if (pcap_q->vlan_strip)rte_vlan_strip (bufs[i]); +if (pcap_q->timestamp_offloading) { +struct timespec ts; + +timespec_get (&ts,TIME_UTC ); + *RTE_MBUF_DYNFIELD (bufs[i], timestamp_dynfield_offset, + rte_mbuf_timestamp_t *) = rte_timespec_to_ns(&ts); + bufs[i]->ol_flags |= timestamp_rx_dynflag; + } + rx_bytes += bufs[i]->data_len;/* Enqueue packet back on ring to allow infinite rx. */ @@ -339,10 +348,21 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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; +if (pcap_q->timestamp_offloading) { +/* +* The use of tv_usec as nanoseconds is not a bug here. +* Interface is always created with nanosecond precision, and +* that is how pcap API bodged in nanoseconds support. +*/ +uint64_t ns = (uint64_t )header->ts.tv_sec *NSEC_PER_SEC + + header->ts.tv_usec; + + *RTE_MBUF_DYNFIELD (mbuf, timestamp_dynfield_offset, + rte_mbuf_timestamp_t *) = ns; + + mbuf->ol_flags |= timestamp_rx_dynflag; + } - *RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us; - mbuf->ol_flags |= timestamp_rx_dynflag; mbuf->port = pcap_q->port_id; bufs[num_rx] = mbuf; num_rx++;@@ -362,14 +382,19 @@ eth_null_rx(void *queue __rte_unused,return 0 ; } -#define NSEC_PER_SEC 1000000000L -/* -* This function stores nanoseconds in `tv_usec` field of `struct timeval`, -* because `ts` goes directly to nanosecond-precision dump. +* Calculate current timestamp in nanoseconds by computing +* offset from starting time value. +* +* Note: it is not a bug that this code is putting nanosecond +* value into microsecond timeval field. The pcap API is old +* and nanoseconds were bodged on as an after thought. +* As long as the pcap stream is set to nanosecond precision +* it expects nanoseconds here. */ static inline void -calculate_timestamp (struct timeval *ts) { +calculate_timestamp (struct timeval *ts) +{uint64_t cycles;struct timespec cur_time;@@ -440,8 +465,10 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)if (dumper ==NULL || nb_pkts ==0 )return 0 ; -/* writes the nb_pkts packets to the previously opened pcap file -* dumper */ +/* all packets in burst have same timestamp */ +calculate_timestamp (&header.ts); + +/* writes the nb_pkts packets to the previously opened pcap file dumper */ for (i =0 ; i < nb_pkts; i++) {struct rte_mbuf *mbuf = bufs[i];uint32_t len, caplen;@@ -450,8 +477,6 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) len =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN ); -calculate_timestamp (&header.ts); - header.len = len; header.caplen = caplen;@@ -573,22 +598,62 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)* pcap_open_live wrapper function */ static inline int -open_iface_live (const char *iface,pcap_t **pcap) { - *pcap =pcap_open_live (iface,RTE_ETH_PCAP_SNAPLEN , -RTE_ETH_PCAP_PROMISC ,RTE_ETH_PCAP_TIMEOUT , errbuf); +open_iface_live (const char *iface,pcap_t **pcap) +{ +pcap_t *pc; +int status; -if (*pcap ==NULL ) { -PMD_LOG (ERR ,"Couldn't open %s: %s" , iface, errbuf); -return -1 ; + pc =pcap_create (iface, errbuf); +if (pc ==NULL ) { +PMD_LOG (ERR ,"Couldn't create %s: %s" , iface, errbuf); + goto error; + } + + status =pcap_set_tstamp_precision (pc,PCAP_TSTAMP_PRECISION_NANO ); +if (status !=0 ) { +PMD_LOG (ERR ,"%s: Could not set to ns precision: %s" , + iface,pcap_statustostr (status)); + goto error; + } + + status =pcap_set_immediate_mode (pc,1 ); +if (status !=0 ) +PMD_LOG (WARNING ,"%s: Could not set to immediate mode: %s" , + iface,pcap_statustostr (status)); + + status =pcap_set_promisc (pc,1 ); +if (status !=0 ) +PMD_LOG (WARNING ,"%s: Could not set to promiscuous: %s" , + iface,pcap_statustostr (status)); + + status =pcap_set_snaplen (pc,RTE_ETH_PCAP_SNAPSHOT_LEN ); +if (status !=0 ) +PMD_LOG (WARNING ,"%s: Could not set snapshot length: %s" , + iface,pcap_statustostr (status)); + + status =pcap_activate (pc); +if (status <0 ) { +char *cp =pcap_geterr (pc); + +if (status ==PCAP_ERROR ) +PMD_LOG (ERR ,"%s: could not activate: %s" , iface, cp); +else +PMD_LOG (ERR ,"%s: %s (%s)" , iface,pcap_statustostr (status), cp); + goto error; } -if (pcap_setnonblock (*pcap,1 , errbuf)) { +if (pcap_setnonblock (pc,1 , errbuf)) {PMD_LOG (ERR ,"Couldn't set non-blocking on %s: %s" , iface, errbuf); -pcap_close (*pcap); -return -1 ; + goto error; } + *pcap = pc;return 0 ; + +error: +if (pc !=NULL ) +pcap_close (pc); +return -1 ; } static int@@ -635,7 +700,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) { - *pcap =pcap_open_offline (pcap_filename, errbuf); + *pcap =pcap_open_offline_with_tstamp_precision (pcap_filename, +PCAP_TSTAMP_PRECISION_NANO , errbuf);if (*pcap ==NULL ) {PMD_LOG (ERR ,"Couldn't open %s: %s" , pcap_filename, errbuf);@@ -794,6 +860,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );return 0 ; }@@ -811,7 +878,8 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->min_rx_bufsize =0 ; 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 ; + dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_VLAN_STRIP | +RTE_ETH_RX_OFFLOAD_TIMESTAMP ;return 0 ; }@@ -978,6 +1046,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_q->queue_id = rx_queue_id; pcap_q->vlan_strip = internals->vlan_strip; dev->data->rx_queues[rx_queue_id] = pcap_q; + pcap_q->timestamp_offloading = internals->timestamp_offloading;if (internals->infinite_rx) {struct pmd_process_private *pp;@@ -1116,6 +1185,17 @@ eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)return 0 ; } +/* Timestamp values in receive packets from libpcap are in nanoseconds */ +static int +eth_dev_read_clock(struct rte_eth_dev *dev __rte_unused, uint64_t *timestamp) +{ +struct timespec cur_time; + +timespec_get (&cur_time,TIME_UTC ); + *timestamp =rte_timespec_to_ns (&cur_time); +return 0 ; +} +static int eth_vlan_offload_set (struct rte_eth_dev *dev,int mask) {@@ -1142,6 +1222,7 @@ static const struct eth_dev_ops ops = { .dev_close = eth_dev_close, .dev_configure = eth_dev_configure, .dev_infos_get = eth_dev_info, + .read_clock = eth_dev_read_clock, .rx_queue_setup = eth_rx_queue_setup, .tx_queue_setup = eth_tx_queue_setup, .tx_queue_release = eth_tx_queue_release,@@ -1558,15 +1639,22 @@ pmd_pcap_probe(struct rte_vdev_device *dev) name =rte_vdev_device_name (dev);PMD_LOG (INFO ,"Initializing pmd_pcap for %s" , name); -timespec_get (&start_time,TIME_UTC ); - start_cycles =rte_get_timer_cycles (); - hz =rte_get_timer_hz (); +/* Record info for timestamps on first probe */ +if (hz ==0 ) { + hz =rte_get_timer_hz (); +if (hz ==0 ) { +PMD_LOG (ERR ,"Reported hz is zero!" );
drivers/net/pcap/pcap_ethdev.c pmd_pcap_probe(struct rte_vdev_device *dev) · line 1651
Quoted 10 lines
drivers/net/pcap/pcap_ethdev.c +4
-5+return -1 ; + } - ret =rte_mbuf_dyn_rx_timestamp_register (×tamp_dynfield_offset, - ×tamp_rx_dynflag); -if (ret !=0 ) { -PMD_LOG (ERR ,"Failed to register Rx timestamp field/flag" ); -return -1 ; + ret =rte_mbuf_dyn_rx_timestamp_register (×tamp_dynfield_offset, + ×tamp_rx_dynflag);
Should we not check if timestamps are requested before registering the dynamic field?
Quoted 12 lines
drivers/net/pcap/pcap_ethdev.c +6
-0+if (ret !=0 ) { +PMD_LOG (ERR ,"Failed to register Rx timestamp field/flag" ); +return ret; + } +timespec_get (&start_time,TIME_UTC ); + start_cycles =rte_get_timer_cycles (); }if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) {Signature · 1 line
2.51.0
PATCH v20 15/25 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
@@ -642,6 +642,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 v20 16/25 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 ;
@@ -600,6 +598,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;
@@ -711,6 +710,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 ) {
@@ -1459,6 +1460,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
Re: [PATCH v20 16/25] net/pcap: reduce scope of file-level variables
Quoted 11 lines · Stephen Hemminger
Move errbuf from file scope to local variables in the two functions that use it (
open_iface_liveandopen_single_rx_pcap). This avoids potential issues if these functions were called concurrently, since each call now has its own error buffer. Moveiface_idxto a static local variable withinpmd_init_internals(), the only function that uses it. The variable remains static to preserve the MAC address uniqueness counter across calls.Signed-off-by Stephen Hemminger <[email protected]>Acked-by Marat Khalili <[email protected]>---
PATCH v20 17/25 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 {
@@ -901,11 +901,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
Re: [PATCH v20 17/25] net/pcap: avoid use of volatile
Quoted 5 lines · Stephen Hemminger
Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.
Signed-off-by Stephen Hemminger <[email protected]>---
Well only one queue is allowed to change them, but other threads could read them, so using volatile is correct in that it tells the compiler not to cache the values in registers or on the stack. Technically the compiler could have the stats stored locally somewhere between updates, but in practice I don't think that situation could ever arise for stats. Therefore I'm ok with stats being either volatile or not, I doubt the resulting code will be any different.
Quoted 42 lines
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 {@@ -901,11 +901,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
Re: [PATCH v20 17/25] net/pcap: avoid use of volatile
Quoted 15 lines · On Mon, 16 Mar 2026 14:31:43 +0000 Bruce Richardson…
Quoted 5 lines · Stephen Hemminger
Using volatile for statistics is not necessary since only one thread is allowed to operate on a queue at a time.
Signed-off-by Stephen Hemminger <[email protected]>---
Well only one queue is allowed to change them, but other threads could read them, so using volatile is correct in that it tells the compiler not to cache the values in registers or on the stack. Technically the compiler could have the stats stored locally somewhere between updates, but in practice I don't think that situation could ever arise for stats. Therefore I'm ok with stats being either volatile or not, I doubt the resulting code will be any different.
Quoted 1 line
Acked-by Bruce Richardson <[email protected]>
I went back and forth on this. The compiler unless statically linked with LTO has no chance or seeing across calls.
The other option would be relaxed atomics would also solve the torn 32 bit counter roll over problem on 32 bit CPU's.
PATCH v20 18/25 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
@@ -884,10 +884,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
Re: [PATCH v20 18/25] net/pcap: clarify maximum received packet
Quoted 6 lines · Stephen Hemminger
The driver has constant
RTE_ETH_PCAP_SNAPSHOT_LENwith is set to the largest value the pcap library will return, so that should also be the largest receive buffer.Signed-off-by Stephen Hemminger <[email protected]>---
Quoted 23 lines
drivers/net/pcap/pcap_ethdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/pcap/pcap_ethdev.c +2
-1@@ -884,10 +884,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 v20 19/25 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
Re: [PATCH v20 19/25] eal/windows: add wrapper for access function
Quoted 9 lines · Stephen Hemminger
Like other Posix functions in
unistd.hadd wrapper using the Windows equivalent.Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/windows/include/rte_os_shim.h | 1 + lib/eal/windows/include/unistd.h | 7 +++++++ 2 files changed, 8 insertions(+)
PATCH v20 20/25 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.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'
--- doc/guides/nics/pcap.rst | 17 ++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 211 ++++++++++++++++--------- 3 files changed, 158 insertions(+), 71 deletions(-)
doc/guides/nics/pcap.rst +17 -0
@@ -15,6 +15,23 @@ For more information about the pcap library, see the The pcap-based PMD requires the libpcap development files to be installed. This applies to all supported operating systems: Linux, FreeBSD, and Windows. +* 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. + + The ``snaplen`` argument is used when opening capture handles, so it should + be specified before the interface or file arguments. Example:: + + --vdev 'net_pcap0,snaplen=1518,iface=eth0' + --vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap' + + The snapshot length also determines the reported ``max_rx_pktlen`` + and ``max_mtu`` in device info. + Using the Driver from the EAL Command Line ------------------------------------------
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -123,6 +123,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. * Receive timestamps support nanosecond precision. + * Added ``snaplen`` devarg to configure packet capture snapshot length. Removed Items
drivers/net/pcap/pcap_ethdev.c +140 -71
444 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 20/25] net/pcap: add snapshot length devarg
Quoted 16 lines · Stephen Hemminger
Add a new devarg 'snaplen' to configure the pcap snapshot length, which controls the maximum packet size for capture and output.
The snapshot length affects:
- Thepcap_set_snaplen()call when capturing from interfaces
- Thepcap_open_dead()snapshot parameter for output files
- The reportedmax_rx_pktlenin device info
- The reportedmax_mtuin device info (snaplen - ethernet header)The default value is 65535 bytes, preserving backward compatibility with previous driver behavior.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Quoted 6 lines
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 21/25 net/pcap: add Rx scatter offload
In reply to Stephen HemmingerAdd RTE_ETH_RX_OFFLOAD_SCATTER to the advertised receive offload capabilities. Validate in rx_queue_setup that the mbuf pool data room is large enough when scatter is not enabled, following the same pattern as the virtio driver.
Gate the multi-segment receive path on the scatter offload flag and drop oversized packets when scatter is disabled. Reject scatter with infinite_rx mode since the ring-based replay path does not support multi-segment mbufs.
--- drivers/net/pcap/pcap_ethdev.c | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-)
drivers/net/pcap/pcap_ethdev.c +44 -3
@@ -79,6 +79,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;
@@ -112,6 +113,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading; };
@@ -342,14 +344,19 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)/* pcap packet will fit in the mbuf, can copy it */ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); mbuf->data_len = len; - }else { -/* Try read jumbo frame into multi mbufs. */ + }else if (pcap_q->rx_scatter) { +/* Scatter into multi-segment mbufs. */ if (unlikely (eth_pcap_rx_jumbo (pcap_q->mb_pool, mbuf, packet, len) ==-1 )) { pcap_q->rx_stat.err_pkts++;rte_pktmbuf_free (mbuf);break ; } + }else { +/* Packet too large and scatter not enabled, drop it. */ + pcap_q->rx_stat.err_pkts++; +rte_pktmbuf_free (mbuf); +continue ; } mbuf->pkt_len = len;
@@ -907,6 +914,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->rx_scatter = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ); internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );return 0 ; }
@@ -927,7 +935,8 @@ eth_dev_info(struct rte_eth_dev *dev, 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 | -RTE_ETH_RX_OFFLOAD_TIMESTAMP ; +RTE_ETH_RX_OFFLOAD_TIMESTAMP | +RTE_ETH_RX_OFFLOAD_SCATTER ;return 0 ; }
@@ -1088,11 +1097,37 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, {struct pmd_internals *internals = dev->data->dev_private;struct pcap_rx_queue *pcap_q = &internals->rx_queue[rx_queue_id]; +uint16_t buf_size; +bool rx_scatter; + + buf_size =rte_pktmbuf_data_room_size (mb_pool) -RTE_PKTMBUF_HEADROOM ; + rx_scatter = !!(dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_SCATTER ); + +/* +* If Rx scatter is not enabled, verify that the mbuf data room +* can hold the largest received packet in a single segment. +* Use the MTU-derived frame size as the expected maximum, not +* snapshot_len which is a capture truncation limit rather than +* an expected packet size. +*/ +if (!rx_scatter) { +uint32_t max_rx_pktlen = dev->data->mtu +RTE_ETHER_HDR_LEN ; + +if (max_rx_pktlen > buf_size) { +PMD_LOG (ERR , +"Rx scatter is disabled and RxQ mbuf pool object size is too small " +"(buf_size=%u, max_rx_pkt_len=%u)" , + buf_size, max_rx_pktlen); +return -EINVAL ; + } + } 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; + pcap_q->rx_scatter = rx_scatter; dev->data->rx_queues[rx_queue_id] = pcap_q; pcap_q->timestamp_offloading = internals->timestamp_offloading;
@@ -1105,6 +1140,12 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,pcap_t **pcap;bool save_vlan_strip; +if (rx_scatter) { +PMD_LOG (ERR , +"Rx scatter is not supported with infinite_rx mode" ); +return -EINVAL ; + } + pp = rte_eth_devices[pcap_q->port_id].process_private; pcap = &pp->rx_pcap[pcap_q->queue_id];
Signature · 1 line
2.51.0
Re: [PATCH v20 21/25] net/pcap: add Rx scatter offload
Quoted 66 lines · Stephen Hemminger
Add
RTE_ETH_RX_OFFLOAD_SCATTERto the advertised receive offload capabilities. Validate inrx_queue_setupthat the mbuf pool data room is large enough when scatter is not enabled, following the same pattern as the virtio driver.Gate the multi-segment receive path on the scatter offload flag and drop oversized packets when scatter is disabled. Reject scatter with
infinite_rxmode since the ring-based replay path does not support multi-segment mbufs.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/pcap/pcap_ethdev.c | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-)drivers/net/pcap/pcap_ethdev.c +10
-2@@ -79,6 +79,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;@@ -112,6 +113,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading; };@@ -342,14 +344,19 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)/* pcap packet will fit in the mbuf, can copy it */ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); mbuf->data_len = len; - }else { -/* Try read jumbo frame into multi mbufs. */ + }else if (pcap_q->rx_scatter) { +/* Scatter into multi-segment mbufs. */ if (unlikely (eth_pcap_rx_jumbo (pcap_q->mb_pool, mbuf, packet, len) ==-1 )) { pcap_q->rx_stat.err_pkts++;rte_pktmbuf_free (mbuf);break ; } + }else { +/* Packet too large and scatter not enabled, drop it. */ + pcap_q->rx_stat.err_pkts++; +rte_pktmbuf_free (mbuf); +continue ; } mbuf->pkt_len = len;@@ -907,6 +914,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->rx_scatter = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ); internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );return 0 ; }
drivers/net/pcap/pcap_ethdev.c eth_dev_info(struct rte_eth_dev *dev, · line 940
Quoted 7 lines
drivers/net/pcap/pcap_ethdev.c +2
-1@@ -927,7 +935,8 @@ eth_dev_info(struct rte_eth_dev *dev, 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 | -RTE_ETH_RX_OFFLOAD_TIMESTAMP ; +RTE_ETH_RX_OFFLOAD_TIMESTAMP | +RTE_ETH_RX_OFFLOAD_SCATTER ;
You should check for the infinite_rx mode here and only add the capability if it's not set.
With that fixed:
PATCH v20 22/25 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/nics/pcap.rst | 5 +++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 45 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+)
doc/guides/nics/features/pcap.ini +1 -0
@@ -5,6 +5,7 @@ ; [Features] Link status = Y +Link status event = Y Queue start/stop = Y Timestamp offload = Y Basic stats = Y
doc/guides/nics/pcap.rst +5 -0
@@ -278,3 +278,8 @@ Features and Limitations * 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. + +* In ``iface`` mode, the PMD supports link status change (LSC) notifications. + When the application enables ``intr_conf.lsc`` in the port configuration, + the driver polls the underlying network interface once per second and generates an + ``RTE_ETH_EVENT_INTR_LSC`` callback when the link state changes.
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -124,6 +124,7 @@ New Features * Added support for reporting link state in ``iface`` mode. * 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 +45 -0
93 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 22/25] net/pcap: add link status change support for iface mode
Quoted 11 lines · Stephen Hemminger
Add LSC interrupt support for pass-through (iface=) mode so applications can receive link state change notifications via the standard ethdev callback mechanism.
Uses alarm-based polling to periodically check the underlying interface state via
osdep_iface_link_get(). The LSC flag is advertised only for iface mode devices, and polling is gated on the application enabling intr_conf.lsc in port configuration.Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 23/25 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 | 80 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
@@ -161,6 +161,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
@@ -125,6 +125,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 +77 -3
167 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v20 23/25] net/pcap: add EOF notification via link status change
Quoted 10 lines · Stephen Hemminger
Add an "eof" devarg for
rx_pcapmode 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_rxoptions are mutually exclusive. On device restart, the EOF state is reset so the file can be replayed.Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v20 24/25 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 | 3755 ++++++++++++++++++++++++ doc/guides/rel_notes/release_26_03.rst | 1 + 3 files changed, 3758 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'], } # the NULL ethdev is used by a number of tests, in some cases as an optional dependency.
app/test/test_pmd_pcap.c new file +3755 -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 v20 24/25] test: add comprehensive test suite for pcap PMD
Quoted 23 lines · Stephen Hemminger
Add unit tests for the pcap PMD covering file and interface modes.
Tests include:
- basic TX to file and RX from file
- varied packet sizes and jumbo frames
- infinite RX mode
- TX drop mode
- statistics
- interface (iface=) pass-through mode
- link status reporting for file and iface modes
- link status change (LSC) with interface toggle
- EOF notification via LSC
- RX timestamps and timestamp with infinite RX
- multiple TX/RX queues
- VLAN strip, insert, and runtime offload configuration
- snapshot length (snaplen) and truncationCross-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.
Quoted 8 lines
Signed-off-by Stephen Hemminger <[email protected]>--- app/test/meson.build | 2 + app/test/test_pmd_pcap.c | 3755 ++++++++++++++++++++++++ doc/guides/rel_notes/release_26_03.rst | 1 + 3 files changed, 3758 insertions(+) create mode 100644 app/test/test_pmd_pcap.c
Ran this patch through AI for a code review. Below is the output. In general seems a good addition.
/Bruce
Code Review: test: add comprehensive test suite for pcap PMD
The patch adds a 3755-line test file. The breadth of coverage is commendable — it exercises most of the pcap PMD's devargs. However, there are several concrete problems:
Bugs / Incorrect Logic
1. Duplicate values in test_tx_varied_sizes test array (test_pmd_pcap.c:1203-1205)
PKT_SIZE_SMALL (128) == PACKET_BURST_GEN_PKT_LEN_128 (128), so only two distinct sizes are tested. Furthermore, PKT_SIZE_MIN(60) == PACKET_BURST_GEN_PKT_LEN (60) — the whole point of mixing these constants obscures the fact. The array should use distinct, intentional sizes like PKT_SIZE_MIN, PKT_SIZE_MEDIUM, PKT_SIZE_LARGE.
2. Timestamp exact-match check is non-asserting (test_pmd_pcap.c:2322-2325)
A timestamp accuracy mismatch only prints a warning; the test still passes. This should be a TEST_ASSERT_EQUAL(ts, expected, ...). This is the entire point of having controllable timestamps via create_timestamped_pcap().
Test Quality / Weak Assertions
3. test_tx_varied_sizes doesn't verify file content (test_pmd_pcap.c:1240-1244)
It only checks nb_tx > 0 — it never reads the pcap file back to confirm the sizes were written correctly. Compare with test_jumbo_tx which does read back via get_pcap_packet_sizes(). Both tests should do the same.
4. Statistics test doesn't verify ibytes/obytes values (test_pmd_pcap.c:1462-1474)test_stats validates ipackets/opackets but despite checking ibytes == 0 && obytes == 0 at init, it never asserts the actual byte totals after traffic. The driver tracks bytes; the test should verify ibytes == received * sizeof(test_packet).
5. test_lsc_iface skips with TEST_SUCCESS instead of TEST_SKIPPED (test_pmd_pcap.c:1981-2000) Three early-exit paths when no interface is available return TEST_SUCCESS:
Compare with test_iface() at test_pmd_pcap.c:1644 which correctly returns TEST_SKIPPED. This makes CI results misleading — a skipped test looks like a passing one.
6. Similarly in test_rx_timestamp (test_pmd_pcap.c:2308)
When the timestamp dynamic field isn't available, return TEST_SUCCESS is used instead of TEST_SKIPPED.
Racy / Fragile Tests
7. LSC callback detection relies entirely on usleep(1500ms) (test_pmd_pcap.c:2050, test_pmd_pcap.c:2074)
The test sleeps 1.5 seconds twice waiting for the pcap LSC polling thread to detect the interface state change. With no retry/poll loop, this is fragile under load and adds 3 seconds to every run. A small polling loop (for (i = 0; i < 20; i++) { if (lsc_callback_count >= 1) break; usleep(100000); }) would be more robust.
8. EOF callback timing (test_pmd_pcap.c:2229)usleep(100 * 1000) (100 ms) is used to wait for the EOF alarm to fire, then immediately asserts eof_callback_count == 1. The driver uses rte_eal_alarm_set(1, ...) (1 µs delay), but alarm delivery is not instantaneous under load. The same polling loop pattern would be safer.
Missing Coverage
9. No tests for rx_iface=/tx_iface=/rx_iface_in= devargs
The test covers iface= (symmetric single-interface mode) but completely misses rx_iface=, tx_iface=, and rx_iface_in= (asymmetric / separate RX and TX interface modes). These are distinct code paths in the driver including PCAP_D_IN direction filtering for rx_iface_in.
10. No test for per-queue start/stop
The driver implements rx_queue_start, tx_queue_start, rx_queue_stop, tx_queue_stop. None of these are exercised.
11. imissed stat not tested
The driver has queue_missed_stat_update() using pcap_stats() to track kernel-level drops. This code path (iface mode under load, or mocked via the pcap stat interface) is never exercised.
Minor Issues
12. Shared state between tests (test_pmd_pcap.c:60-61)tx_pcap_path and vlan_rx_pcap_path are global state shared between test pairs (test_tx_to_file→test_rx_from_file, test_vlan_strip_rx→test_vlan_no_strip_rx). Both have fallback access() checks, but this creates implicit ordering dependencies. The comment documents this, but it's an unusual pattern for a test suite that should have independent cases.
13. Missing rte_cycles.h include for NS_PER_S (test_pmd_pcap.c:2319)NS_PER_S is used in test_rx_timestamp() but <rte_cycles.h> (where it's defined) is not explicitly included. It compiles today because another included header transitively pulls it in, but the dependency is fragile. A direct #include <rte_cycles.h> should be added.
PATCH v20 25/25 app/pdump: preserve VLAN tags in captured packets
In reply to Stephen HemmingerWhen the source port has VLAN strip enabled, captured packets have the VLAN tag in mbuf metadata (vlan_tci) but not in the packet data. Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.
Convert RX_VLAN_STRIPPED metadata to TX_VLAN offload requests on dequeued mbufs and call rte_eth_tx_prepare() before rte_eth_tx_burst() so the pcap vdev inserts the tag into the packet data.
--- lib/pdump/rte_pdump.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
lib/pdump/rte_pdump.c +31 -1
@@ -9,6 +9,7 @@#include <rte_mbuf.h> #include <rte_ethdev.h> #include <rte_lcore.h> +#include <rte_ether.h> #include <rte_log.h> #include <rte_memzone.h> #include <rte_errno.h>
@@ -135,6 +136,29 @@ pdump_cb_release(struct pdump_rxtx_cbs *cbs)rte_atomic_store_explicit (&cbs->use_count, count, rte_memory_order_release); } +/* +* Reconstruct VLAN tag in packet data if it was offloaded to metadata. +* +* When VLAN strip is active on RX, or VLAN insert is pending on TX, +* the VLAN tag exists only in mbuf metadata (vlan_tci / ol_flags) +* and not in the packet data. For packet capture we need the +* complete wire-format packet, so insert the tag back into the +* cloned mbuf. +*/ +static inline void +pdump_vlan_restore (struct rte_mbuf *m) +{ +if (m->ol_flags & (RTE_MBUF_F_RX_VLAN_STRIPPED |RTE_MBUF_F_TX_VLAN )) { +if (rte_vlan_insert (&m) !=0 ) +return ; +/* +* Clear offload flags so the pcap writer sees the packet +* as a plain tagged frame rather than acting on these again. +*/ + m->ol_flags &= ~(RTE_MBUF_F_RX_VLAN_STRIPPED |RTE_MBUF_F_TX_VLAN ); + } +} +/* Create a clone of mbuf to be placed into ring. */ static void pdump_copy_burst(uint16_t port_id, uint16_t queue_id,
@@ -182,8 +206,14 @@ pdump_copy_burst(uint16_t port_id, uint16_t queue_id,if (unlikely (p ==NULL ))rte_atomic_fetch_add_explicit (&stats->nombuf,1 , rte_memory_order_relaxed); -else +else { +/* +* Restore any VLAN tag that was offloaded to metadata +* so the captured packet has the complete wire format. +*/ +pdump_vlan_restore (p); dup_bufs[d_pkts++] = p; + } }if (d_pkts ==0 )
Signature · 1 line
2.51.0
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 9 lines · Stephen Hemminger
When the source port has VLAN strip enabled, captured packets have the VLAN tag in mbuf metadata (
vlan_tci) but not in the packet data. Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.Convert
RX_VLAN_STRIPPEDmetadata toTX_VLANoffload requests on dequeued mbufs and callrte_eth_tx_prepare()beforerte_eth_tx_burst()so the pcap vdev inserts the tag into the packet data.
This is an example of something I previously flagged. Like with real hardware, I think the PMD should be inserting the VLAN tag into the packet as part of the Tx function, not the prepare function.
Quoted 5 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/pdump/rte_pdump.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
RE: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 11 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 16 March 2026 16.34Quoted 7 lines · Stephen Hemminger
When the source port has VLAN strip enabled, captured packets have the VLAN tag in mbuf metadata (
vlan_tci) but not in the packet data. Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.Convert
RX_VLAN_STRIPPEDmetadata toTX_VLANoffload requests on dequeued mbufs and callrte_eth_tx_prepare()before
Quoted 8 lines
rte_eth_tx_burst()Quoted 2 lines
so the pcap vdev inserts the tag into the packet data.
This is an example of something I previously flagged. Like with real hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.
Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not be required to call tx_prep first.
However, the Tx function is supposed to not modify the packets; relevant when refcnt > 1.
Instead of modifying the packet data to insert/strip the VLAN tag,
perhaps the driver can split the write/read operation into multiple write/read operations:
1. the Ethernet header
2. the VLAN tag
3. the remaining packet data
I haven't really followed the pcap driver, so maybe my suggestion doesn't make sense.
Let's say an application adds 1 to the mbufs' refcnt before each Tx, so the mbufs still exist after Tx.
Then, the application captures/mirrors the packets consumed by the driver, and logs/drops the packets the driver was unable to consume. If the capture/mirror is filtering by VLAN ID, modifying the packets in the driver's Tx function is bad.
-Morten
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 20 lines · Morten Brørup
Quoted 11 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 16 March 2026 16.34Quoted 7 lines · Stephen Hemminger
When the source port has VLAN strip enabled, captured packets have the VLAN tag in mbuf metadata (
vlan_tci) but not in the packet data. Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.Convert
RX_VLAN_STRIPPEDmetadata toTX_VLANoffload requests on dequeued mbufs and callrte_eth_tx_prepare()beforeQuoted 8 lines
rte_eth_tx_burst()Quoted 2 lines
so the pcap vdev inserts the tag into the packet data.
This is an example of something I previously flagged. Like with real hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.
Quoted 5 lines
Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not be required to calltx_prepfirst.However, the Tx function is supposed to not modify the packets; relevant when refcnt > 1.
Reading the doc on tx_burst it can modify the packets (obviously enough) if refcnt is one, so only the edge case of refcnt > 1 needs to be worried about. The other thing worth noting is that there is already an exception for bonding driver - if we need to, I suppose we can look to make a more general exception for a set of virtual drivers under specific circumstances. I'd be ok with documenting that "the following drivers modify packets for VLAN insertion..." or something like that.
Quoted 6 lines
Instead of modifying the packet data to insert/strip the VLAN tag,
perhaps the driver can split the write/read operation into multiple write/read operations:
1. the Ethernet header
2. the VLAN tag
3. the remaining packet data
Quoted 7 lines
I haven't really followed the pcap driver, so maybe my suggestion doesn't make sense.
Let's say an application adds 1 to the mbufs' refcnt before each Tx, so the mbufs still exist after Tx.
Then, the application captures/mirrors the packets consumed by the driver, and logs/drops the packets the driver was unable to consume. If the capture/mirror is filtering by VLAN ID, modifying the packets in the driver's Tx function is bad.
Worth investigating. We already have copies for scattered packets, I think, so doing some copying for VLAN insertion if refcnt > 1 wouldn't be the end of the world.
/Bruce
RE: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 35 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 16 March 2026 17.06Quoted 5 lines · Morten Brørup
Quoted 5 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 16 March 2026 16.34Quoted 1 line · Stephen Hemminger
When the source port has VLAN strip enabled, captured packets
have
Quoted 1 line
Quoted 1 line
Quoted 1 line
the VLAN tag in mbuf metadata (
vlan_tci) but not in the packetdata.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.
Convert
RX_VLAN_STRIPPEDmetadata toTX_VLANoffload requests on dequeued mbufs and callrte_eth_tx_prepare()before
rte_eth_tx_burst()Quoted 2 lines
so the pcap vdev inserts the tag into the packet data.
This is an example of something I previously flagged. Like with
real
Quoted 6 lines
Quoted 3 lines
hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 1 line
Quoted 11 lines
Reading the doc on
tx_burstit can modify the packets (obviously enough) if
refcnt is one, so only the edge case of refcnt > 1 needs to be worried about. The other thing worth noting is that there is already an exception
for bonding driver - if we need to, I suppose we can look to make a more
general exception for a set of virtual drivers under specific circumstances. I'd be ok with documenting that "the following drivers modify
packets for VLAN insertion..." or something like that.
I'm opposed to API contract exceptions for virtual drivers.
They should be just as well behaved as physical device drivers.
Otherwise, applications need to behave differently, depending on which driver they are using.
I cannot remember the reason for the exception in the bonding driver, but optimally it should be treated as a bug and fixed.
Quoted 16 lines
Quoted 3 lines
Instead of modifying the packet data to insert/strip the VLAN tag, perhaps the driver can split the write/read operation into multiple
write/read operations:
Quoted 5 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet dataI haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
Quoted 3 lines
Let's say an application adds 1 to the mbufs' refcnt before each Tx,
so the mbufs still exist after Tx.
Quoted 1 line
Then, the application captures/mirrors the packets consumed by the
driver, and logs/drops the packets the driver was unable to consume.
Quoted 8 lines
Quoted 1 line
If the capture/mirror is filtering by VLAN ID, modifying the packets
in the driver's Tx function is bad.
Quoted 1 line
Worth investigating. We already have copies for scattered packets, I think,
so doing some copying for VLAN insertion if refcnt > 1 wouldn't be the end
of the world.
+1
Quoted 2 lines
/Bruce
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
In reply to Morten BrørupQuoted 11 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 5 lines
This is an example of something I previously flagged. Like with real hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not be required to calltx_prepfirst.However, the Tx function is supposed to not modify the packets; relevant when refcnt > 1.
Quoted 7 lines
Instead of modifying the packet data to insert/strip the VLAN tag,
perhaps the driver can split the write/read operation into multiple write/read operations:
1. the Ethernet header
2. the VLAN tag
3. the remaining packet dataI haven't really followed the pcap driver, so maybe my suggestion doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.
RE: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 27 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 24 March 2026 18.12Quoted 2 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 2 lines
This is an example of something I previously flagged. Like with
real
Quoted 6 lines
Quoted 3 lines
hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 3 lines
Instead of modifying the packet data to insert/strip the VLAN tag, perhaps the driver can split the write/read operation into multiple
write/read operations:
Quoted 4 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet data
Quoted 5 lines
Quoted 1 line
I haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.
OK, that makes it harder to object to.
<rant>
I checked out the virtio code. virtio_xmit_pkts_prepare() calls rte_vlan_insert(). And rte_vlan_insert() doesn't support mbuf refcnt > 1.
So basically, these drivers don't support simple VLAN tagging when mbuf refcnt > 1. This seems like a major limitation, which should be prominently documented.
A decade ago, when we started using DPDK for our projects, one of the things I loved about it was its documentation. But after a while, I noticed that a lot of the documented mbuf library features weren't fully implemented. These limitations should be documented.
E.g. if an important driver like virtio doesn't support VLAN tagging of indirect/cloned mbufs, this should be prominently highlighted in documentation!
</rant>
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 27 lines · Morten Brørup
Quoted 27 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 24 March 2026 18.12Quoted 2 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 2 lines
This is an example of something I previously flagged. Like with
real
Quoted 6 lines
Quoted 3 lines
hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 3 lines
Instead of modifying the packet data to insert/strip the VLAN tag, perhaps the driver can split the write/read operation into multiple
write/read operations:
Quoted 4 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet data
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.OK, that makes it harder to object to.
Yes, but I also believe that the topic was not previously discussed and that the virtio driver may be wrong in how it behaves.
I still think, for consistency with HW drivers, SW drivers should do the tagging in the Tx function.
I also think that we should provide a DPDK-lib level helper function (be it in ethdev or elsewhere) for doing this sort of thing for all drivers. That way we can put in the necessary copying of packets with refcnt > 1 and have it apply globally.
/Bruce
RE: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 43 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 25 March 2026 10.13Quoted 10 lines · Morten Brørup
Quoted 10 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 24 March 2026 18.12Quoted 2 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 2 lines
This is an example of something I previously flagged. Like with
real
Quoted 1 line
Quoted 1 line
hardware, I think the PMD should be inserting the VLAN tag into
the
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 2 lines
Instead of modifying the packet data to insert/strip the VLAN
tag,
Quoted 1 line
Quoted 1 line
Quoted 1 line
perhaps the driver can split the write/read operation into
multiple
Quoted 5 lines
Quoted 5 lines
write/read operations:
Quoted 4 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet dataQuoted 8 lines
Quoted 5 lines
Quoted 1 line
I haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.OK, that makes it harder to object to.
Quoted 6 lines
Yes, but I also believe that the topic was not previously discussed and that the virtio driver may be wrong in how it behaves.
I still think, for consistency with HW drivers, SW drivers should do the
tagging in the Tx function.
+1
Quoted 8 lines
I also think that we should provide a DPDK-lib level helper function (be it in
ethdev or elsewhere) for doing this sort of thing for all drivers. That way
we can put in the necessary copying of packets with refcnt > 1 and have it
apply globally.
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>
Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
Quoted 2 lines
/Bruce
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 69 lines · Morten Brørup
Quoted 43 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 25 March 2026 10.13Quoted 10 lines · Morten Brørup
Quoted 10 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 24 March 2026 18.12Quoted 2 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 2 lines
This is an example of something I previously flagged. Like with
real
Quoted 1 line
Quoted 1 line
hardware, I think the PMD should be inserting the VLAN tag into
the
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 2 lines
Instead of modifying the packet data to insert/strip the VLAN
tag,
Quoted 1 line
Quoted 1 line
Quoted 1 line
perhaps the driver can split the write/read operation into
multiple
Quoted 5 lines
Quoted 5 lines
write/read operations:
Quoted 4 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet dataQuoted 8 lines
Quoted 5 lines
Quoted 1 line
I haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.OK, that makes it harder to object to.
Quoted 6 lines
Yes, but I also believe that the topic was not previously discussed and that the virtio driver may be wrong in how it behaves.
I still think, for consistency with HW drivers, SW drivers should do the
tagging in the Tx function.+1
Quoted 8 lines
I also think that we should provide a DPDK-lib level helper function (be it in
ethdev or elsewhere) for doing this sort of thing for all drivers. That way
we can put in the necessary copying of packets with refcnt > 1 and have it
apply globally.If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>
Quoted 6 lines
Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
Yes, agree on using a chain of buffers for Tx in this case. Not bothered much either way about the separate mempool.
/Bruce
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
In reply to Morten BrørupQuoted 8 lines · On Wed, 25 Mar 2026 10:36:56 +0100 Morten Brørup <[email protected]>…
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>
Quoted 5 lines
Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
The problem with the Tx function is how backpressure gets handled. Not sure that it is documented well enough that if a packet is not sent due to backpressure, the mbuf in the array may still have been replaced.
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 18 lines · Stephen Hemminger
Quoted 8 lines · On Wed, 25 Mar 2026 10:36:56 +0100 Morten Brørup <[email protected]>…
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>Quoted 5 lines
Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
Quoted 3 lines
The problem with the Tx function is how backpressure gets handled. Not sure that it is documented well enough that if a packet is not sent due to backpressure, the mbuf in the array may still have been replaced.
Most drivers should be able to check for space in a Tx ring, or whatever other backpressure mechanism is being used, before modifying a buffer.
/Bruce
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 19 lines · On Wed, 25 Mar 2026 16:22:45 +0000 Bruce Richardson…
Quoted 18 lines · Stephen Hemminger
Quoted 13 lines · On Wed, 25 Mar 2026 10:36:56 +0100 Morten Brørup <[email protected]>…
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
Quoted 8 lines
Quoted 3 lines
The problem with the Tx function is how backpressure gets handled. Not sure that it is documented well enough that if a packet is not sent due to backpressure, the mbuf in the array may still have been replaced.
Most drivers should be able to check for space in a Tx ring, or whatever other backpressure mechanism is being used, before modifying a buffer.
/Bruce
Not in case of drivers that need syscall to push packets.
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
Quoted 26 lines · Stephen Hemminger
Quoted 23 lines · On Wed, 25 Mar 2026 16:22:45 +0000 Bruce Richardson…
Quoted 21 lines · Stephen Hemminger
Quoted 8 lines · On Wed, 25 Mar 2026 10:36:56 +0100 Morten Brørup <[email protected]>…
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>Quoted 5 lines
Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.The problem with the Tx function is how backpressure gets handled. Not sure that it is documented well enough that if a packet is not sent due to backpressure, the mbuf in the array may still have been replaced.
Quoted 6 lines
Quoted 4 lines
Most drivers should be able to check for space in a Tx ring, or whatever other backpressure mechanism is being used, before modifying a buffer.
/Bruce
Not in case of drivers that need syscall to push packets.
Modifications will have to be rolled back in that case. Alternatively, the driver just doesn't offer the offload, which is IMHO a perfectly reasonable approach to take.
/Bruce
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
In reply to Bruce RichardsonQuoted 19 lines · On Wed, 25 Mar 2026 16:22:45 +0000 Bruce Richardson…
Quoted 18 lines · Stephen Hemminger
Quoted 13 lines · On Wed, 25 Mar 2026 10:36:56 +0100 Morten Brørup <[email protected]>…
If an application clones packets instead of copying them, it is probably for performance reasons. If the drivers start copying those clones, it may defeat the performance purpose.
<brainstorming>
Maybe segmentation can be used instead of copying the full packet:
Make the "copy" packet of two (or more) segments, where the header is copied into a new mbuf (where the VLAN tag is added), and the remaining part of the packet uses an indirect mbuf referring to the "original" packet at the offset after the header. </brainstorming>Furthermore...
If drivers start copying packets in the Tx function, the Tx queue should have its own mbuf pool to allocate these mbufs from. Drivers should not steal mbufs from the pools used by the packets being transmitted.
E.g. if a segmented packet has a small mbuf for the first few bytes, followed by a large mbuf (from another pool) for the remaining bytes. Or if the "original" mbuf comes from a mempool allocated on different CPU socket, the "copy" would too.
Quoted 8 lines
Quoted 3 lines
The problem with the Tx function is how backpressure gets handled. Not sure that it is documented well enough that if a packet is not sent due to backpressure, the mbuf in the array may still have been replaced.
Most drivers should be able to check for space in a Tx ring, or whatever other backpressure mechanism is being used, before modifying a buffer.
/Bruce
The wording in tx_prepare documentation mentions checksums requirement but not vlans.
Re: [PATCH v20 25/25] app/pdump: preserve VLAN tags in captured packets
In reply to Bruce RichardsonQuoted 43 lines · On Wed, 25 Mar 2026 09:12:38 +0000 Bruce Richardson…
Quoted 27 lines · Morten Brørup
Quoted 27 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 24 March 2026 18.12Quoted 2 lines · On Mon, 16 Mar 2026 16:55:29 +0100 Morten Brørup <[email protected]>…
Quoted 2 lines
This is an example of something I previously flagged. Like with
real
Quoted 6 lines
Quoted 3 lines
hardware, I think the PMD should be inserting the VLAN tag into the packet
as part of the Tx function, not the prepare function.Agree with Bruce on this.
For simple stuff like VLAN offload, applications should not berequired to call
tx_prepfirst.Quoted 2 lines
However, the Tx function is supposed to not modify the packets;
relevant when refcnt > 1.
Quoted 3 lines
Instead of modifying the packet data to insert/strip the VLAN tag, perhaps the driver can split the write/read operation into multiple
write/read operations:
Quoted 4 lines
1. the Ethernet header
2. the VLAN tag
3. the remaining packet dataQuoted 8 lines
Quoted 5 lines
Quoted 1 line
I haven't really followed the pcap driver, so maybe my suggestion
doesn't make sense.
The prepare code and VLAN was copied from virtio.
I assume virtio is widely used already.OK, that makes it harder to object to.
Yes, but I also believe that the topic was not previously discussed and that the virtio driver may be wrong in how it behaves.
I still think, for consistency with HW drivers, SW drivers should do the tagging in the Tx function.
Quoted 6 lines
I also think that we should provide a DPDK-lib level helper function (be it in ethdev or elsewhere) for doing this sort of thing for all drivers. That way we can put in the necessary copying of packets with refcnt > 1 and have it apply globally.
/Bruce
Virtio also requires tx_prepare if doing any form of segmentation offload.
If this is not ok, it should be put somewhere in the docs and virtio fixed.
v21 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
- Rx scatter offload support with mbuf pool validation
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
- Preserve VLAN tags in dpdk-pdump captures by converting stripped VLAN metadata to Tx insert requests and calling rte_eth_tx_prepare() on the pcap vdev
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
- Reduce scope of file-level variables
Testing:
- Add comprehensive unit test suite covering basic file I/O, timestamps, jumbo frames, VLAN strip/insert, multi-queue, scatter receive, 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
v21:
- Drop volatile patch, existing code is acceptable (Bruce)
- Split Tx burst cleanup into two patches: error accounting fix and dumper return value cleanup (Bruce)
- Add more tests
v20:
- Add dpdk-pdump VLAN tag preservation patch
v19:
- Restore Rx scatter offload patch that was inadvertently dropped in v18
Stephen Hemminger (25):
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: clean up TX dumper return value and types net/pcap: add datapath debug logging
net/pcap: consolidate boolean flag handling net/pcap: support VLAN strip and insert offloads app/pdump: preserve VLAN tags in captured packets 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: clarify maximum received packet eal/windows: add wrapper for access function net/pcap: add snapshot length devarg
net/pcap: add Rx scatter offload
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 | 4122 ++++++++++++++++++++++++ doc/guides/nics/features/pcap.ini | 9 + doc/guides/nics/pcap.rst | 48 + doc/guides/rel_notes/release_26_03.rst | 11 + drivers/net/pcap/pcap_ethdev.c | 842 +++-- 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 + lib/pdump/rte_pdump.c | 32 +- 14 files changed, 5036 insertions(+), 218 deletions(-) create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.53.0
PATCH v21 1/25 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
@@ -1116,6 +1116,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.53.0
PATCH v21 2/25 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.53.0
PATCH v21 3/25 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 = P 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.53.0
PATCH v21 4/25 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.53.0
PATCH v21 5/25 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe function rte_zmalloc returns void * so cast is unnecessary. Use numa aware allocation and add tag for tracing.
--- drivers/net/pcap/pcap_ethdev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +6 -11
@@ -1217,13 +1217,11 @@ pmd_init_internals(struct rte_vdev_device *vdev,struct pmd_process_private *pp;unsigned int numa_node = vdev->device.numa_node; -PMD_LOG (INFO ,"Creating pcap-backed ethdev on numa socket %d" , +PMD_LOG (INFO ,"Creating pcap-backed ethdev on numa socket %u" , numa_node); - pp = (struct pmd_process_private *) -rte_zmalloc (NULL ,sizeof (struct pmd_process_private ), -RTE_CACHE_LINE_SIZE ); - + pp =rte_zmalloc_socket ("pcap_private" ,sizeof (struct pmd_process_private ), +RTE_CACHE_LINE_SIZE , numa_node);if (pp ==NULL ) {PMD_LOG (ERR ,"Failed to allocate memory for process private" );
@@ -1284,7 +1282,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,if (osdep_iface_mac_get (if_name, &mac) <0 )return -1 ; - mac_addrs =rte_zmalloc_socket (NULL ,RTE_ETHER_ADDR_LEN ,0 , numa_node); + mac_addrs =rte_zmalloc_socket ("pcap_mac" ,RTE_ETHER_ADDR_LEN ,0 , numa_node);if (mac_addrs ==NULL )return -1 ;
@@ -1590,11 +1588,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 ("pcap_private" ,sizeof (struct pmd_process_private ), +RTE_CACHE_LINE_SIZE );if (pp ==NULL ) {PMD_LOG (ERR ,"Failed to allocate memory for process private" );
Signature · 1 line
2.53.0
PATCH v21 6/25 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>
@@ -1287,7 +1288,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.53.0
PATCH v21 7/25 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.53.0
PATCH v21 8/25 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 | 60 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/net/pcap/pcap_ethdev.c +37 -23
@@ -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,11 @@ 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]; - len = caplen =rte_pktmbuf_pkt_len (mbuf); -if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && - len >sizeof (temp_data))) { - caplen =sizeof (temp_data); - } +struct rte_mbuf *mbuf = bufs[i]; +size_t len, caplen; + + len =rte_pktmbuf_pkt_len (mbuf); + caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );calculate_timestamp (&header.ts); header.len = len;
@@ -449,9 +450,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 +458,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 +468,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 +964,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 +972,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 +1032,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.53.0
PATCH v21 9/25 net/pcap: fix error accounting and backpressure on transmit
In reply to Stephen HemmingerFix two problems in eth_pcap_tx():
Oversized multi-segment packets that exceed the bounce buffer are dropped but were not counted as errors. Add err_pkts accounting for these drops.
When pcap_sendpacket() fails due to kernel socket backpressure, the remaining unsent packets were counted as TX errors. Since backpressure is transient (EAGAIN/EBUSY/EINTR), break the loop and return the number of packets attempted so the caller retains ownership of the unsent mbufs per tx_burst semantics.
--- drivers/net/pcap/pcap_ethdev.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/net/pcap/pcap_ethdev.c +22 -12
@@ -462,7 +462,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) }/* -* Callback to handle sending packets through a real NIC. +* Send a burst of packets to a pcap device. +* +* On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET +* socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). +* The send() call only blocks when the kernel socket send buffer is full, +* providing limited backpressure. +* +* On error, pcap_sendpacket() returns non-zero and the loop breaks, +* leaving remaining packets unsent. +* +* Bottom line: backpressure is not an error. */ static uint16_t eth_pcap_tx (void *queue,struct rte_mbuf **bufs,uint16_t nb_pkts)
@@ -484,26 +494,27 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)for (i =0 ; i < nb_pkts; i++) {struct rte_mbuf *mbuf = bufs[i]; -size_t len =rte_pktmbuf_pkt_len (mbuf); -int ret; +uint32_t len =rte_pktmbuf_pkt_len (mbuf); +const uint8_t *data;if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && len >RTE_ETH_PCAP_SNAPSHOT_LEN )) {PMD_LOG (ERR , -"Dropping multi segment PCAP packet. Size (%zd) > max size (%u)." , +"Dropping multi segment PCAP packet. Size (%u) > max size (%u)." , len,RTE_ETH_PCAP_SNAPSHOT_LEN ); + tx_queue->tx_stat.err_pkts++;rte_pktmbuf_free (mbuf);continue ; } -/* rte_pktmbuf_read() returns a pointer to the data directly -* in the mbuf (when the mbuf is contiguous) or, otherwise, -* a pointer to temp_data after copying into it. -*/ - ret =pcap_sendpacket (pcap, -rte_pktmbuf_read (mbuf,0 , len, temp_data), len); -if (unlikely (ret !=0 )) + data =rte_pktmbuf_read (mbuf,0 , len, temp_data); +RTE_ASSERT (data !=NULL ); + +if (unlikely (pcap_sendpacket (pcap, data, len) !=0 )) { +/* Assume failure is backpressure */ +PMD_LOG (ERR ,"pcap_sendpacket() failed: %s" ,pcap_geterr (pcap));break ; + } num_tx++; tx_bytes += len;rte_pktmbuf_free (mbuf);
@@ -511,7 +522,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) tx_queue->tx_stat.pkts += num_tx; tx_queue->tx_stat.bytes += tx_bytes; - tx_queue->tx_stat.err_pkts += i - num_tx;return i; }
Signature · 1 line
2.53.0
PATCH v21 10/25 net/pcap: clean up TX dumper return value and types
In reply to Stephen HemmingerUse uint32_t for packet lengths to match rte_pktmbuf_pkt_len() return type. Split rte_pktmbuf_read() out of the pcap_dump() call and add RTE_ASSERT for bogus mbuf detection. Remove incorrect err_pkts accounting since the dumper loop cannot partially fail, and return the loop index for consistency with eth_pcap_tx.
--- drivers/net/pcap/pcap_ethdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +10 -9
@@ -407,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );
@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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)); + + data =rte_pktmbuf_read (mbuf,0 , caplen, temp_data); + +/* This could only happen if mbuf is bogus pkt_len > data_len */ +RTE_ASSERT (data !=NULL ); +pcap_dump ((u_char *)dumper, &header, data); num_tx++; tx_bytes += caplen; +rte_pktmbuf_free (mbuf); }
@@ -435,9 +437,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; }/*
Signature · 1 line
2.53.0
PATCH v21 11/25 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 | 2 +- drivers/net/pcap/pcap_osdep.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +1 -1
@@ -500,7 +500,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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++;
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.53.0
PATCH v21 12/25 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 | 67 +++++++++++++++------------------- 1 file changed, 29 insertions(+), 38 deletions(-)
drivers/net/pcap/pcap_ethdev.c +29 -38
@@ -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[] = {
@@ -881,7 +882,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 ;
@@ -1206,29 +1207,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 ; }
@@ -1503,7 +1494,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;
@@ -1543,8 +1534,8 @@ 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); + &process_bool_flag, + &devargs_all.infinite_rx);if (ret <0 ) goto free_kvlist; PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1693,5 +1684,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.53.0
PATCH v21 13/25 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. This also gets used for capture of VLAN tagged packets when legacy pdump is used.
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 | 93 +++++++++++++++++++++++++- 4 files changed, 106 insertions(+), 3 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
@@ -9,6 +9,7 @@ Queue start/stop = Y Timestamp offload = P 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
@@ -136,6 +136,10 @@ 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 +90 -3
189 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 14/25 app/pdump: preserve VLAN tags in captured packets
In reply to Stephen HemmingerWhen the source port has VLAN strip enabled, captured packets have the VLAN tag in mbuf metadata (vlan_tci) but not in the packet data. Similarly, TX captures with pending VLAN insert have the tag only in metadata. The resulting pcap files contain untagged packets.
Convert RX_VLAN_STRIPPED metadata to TX_VLAN offload requests on dequeued mbufs and call rte_eth_tx_prepare() before rte_eth_tx_burst() so the pcap vdev inserts the tag into the packet data.
--- lib/pdump/rte_pdump.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
lib/pdump/rte_pdump.c +31 -1
@@ -9,6 +9,7 @@#include <rte_mbuf.h> #include <rte_ethdev.h> #include <rte_lcore.h> +#include <rte_ether.h> #include <rte_log.h> #include <rte_memzone.h> #include <rte_errno.h>
@@ -135,6 +136,29 @@ pdump_cb_release(struct pdump_rxtx_cbs *cbs)rte_atomic_store_explicit (&cbs->use_count, count, rte_memory_order_release); } +/* +* Reconstruct VLAN tag in packet data if it was offloaded to metadata. +* +* When VLAN strip is active on RX, or VLAN insert is pending on TX, +* the VLAN tag exists only in mbuf metadata (vlan_tci / ol_flags) +* and not in the packet data. For packet capture we need the +* complete wire-format packet, so insert the tag back into the +* cloned mbuf. +*/ +static inline void +pdump_vlan_restore (struct rte_mbuf *m) +{ +if (m->ol_flags & (RTE_MBUF_F_RX_VLAN_STRIPPED |RTE_MBUF_F_TX_VLAN )) { +if (rte_vlan_insert (&m) !=0 ) +return ; +/* +* Clear offload flags so the pcap writer sees the packet +* as a plain tagged frame rather than acting on these again. +*/ + m->ol_flags &= ~(RTE_MBUF_F_RX_VLAN_STRIPPED |RTE_MBUF_F_TX_VLAN ); + } +} +/* Create a clone of mbuf to be placed into ring. */ static void pdump_copy_burst(uint16_t port_id, uint16_t queue_id,
@@ -182,8 +206,14 @@ pdump_copy_burst(uint16_t port_id, uint16_t queue_id,if (unlikely (p ==NULL ))rte_atomic_fetch_add_explicit (&stats->nombuf,1 , rte_memory_order_relaxed); -else +else { +/* +* Restore any VLAN tag that was offloaded to metadata +* so the captured packet has the complete wire format. +*/ +pdump_vlan_restore (p); dup_bufs[d_pkts++] = p; + } }if (d_pkts ==0 )
Signature · 1 line
2.53.0
PATCH v21 15/25 net/pcap: add link status 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 function to query the real link state from the underlying interface.
Linux and FreeBSD use SIOCGIFFLAGS to check IFF_UP and IFF_RUNNING. Windows uses GetAdaptersAddresses() to check OperStatus.
--- doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 38 +++++++++----- drivers/net/pcap/pcap_osdep.h | 12 +++++ drivers/net/pcap/pcap_osdep_freebsd.c | 31 ++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 27 ++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 68 +++++++++++++++++++++----- 6 files changed, 154 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -139,6 +139,7 @@ New Features * **Updated PCAP ethernet driver.** * Added support for VLAN insertion and stripping. + * Added support for reporting link state in ``iface`` mode. Removed Items
drivers/net/pcap/pcap_ethdev.c +27 -11
@@ -150,13 +150,6 @@ static const char *valid_arguments[] = {NULL }; -static struct rte_eth_link pmd_link = { - .link_speed =RTE_ETH_SPEED_NUM_10G , - .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , - .link_status =RTE_ETH_LINK_DOWN , - .link_autoneg =RTE_ETH_LINK_FIXED , -}; -RTE_LOG_REGISTER_DEFAULT (eth_pcap_logtype,NOTICE ); static struct queue_missed_stat*
@@ -941,10 +934,28 @@ eth_dev_close(struct rte_eth_dev *dev) }static int -eth_link_update(struct rte_eth_dev *dev __rte_unused, - int wait_to_complete __rte_unused) +eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { -return 0 ; +struct pmd_internals *internals = dev->data->dev_private; +struct rte_eth_link link = { + .link_speed =RTE_ETH_SPEED_NUM_10G , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; + +/* +* For pass-through mode (single_iface), query whether the +* underlying interface is up. Otherwise use default values. +*/ +if (internals->single_iface) { + link.link_status = (osdep_iface_link_status (internals->rx_queue[0 ].name) >0 ) ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + }else { + link.link_status = dev->data->dev_started ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + } + +return rte_eth_linkstatus_set (dev, &link); } static int
@@ -1358,7 +1369,12 @@ pmd_init_internals(struct rte_vdev_device *vdev, data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t )nb_rx_queues; data->nb_tx_queues = (uint16_t )nb_tx_queues; - data->dev_link = pmd_link; + data->dev_link = (struct rte_eth_link ) { + .link_speed =RTE_ETH_SPEED_NUM_NONE , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_status =RTE_ETH_LINK_DOWN , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; data->mac_addrs = &(*internals)->eth_addr; data->promiscuous =1 ; data->all_multicast =1 ;
drivers/net/pcap/pcap_osdep.h +12 -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
@@ -30,4 +31,15 @@ extern int eth_pcap_logtype;int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); +/** +* Get link status for a network interface. +* +* @param name +* Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows). +* @return +* 1 if link is up, 0 if link is down, -1 on error. +*/ +int osdep_iface_link_status (const char *name); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c +31 -0
@@ -5,8 +5,13 @@*/ #include <string.h> +#include <stdlib.h> +#include <unistd.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> +#include <sys/ioctl.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include "pcap_osdep.h"
@@ -55,3 +60,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)free (buf);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifmediareq ifmr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&ifmr,0 ,sizeof (ifmr)); +strlcpy (ifmr.ifm_name, if_name,sizeof (ifmr.ifm_name)); + +if (ioctl (fd,SIOCGIFMEDIA , &ifmr) ==0 ) { +/* IFM_AVALID means status is valid, IFM_ACTIVE means link up */ +if ((ifmr.ifm_status &IFM_AVALID ) && + (ifmr.ifm_status &IFM_ACTIVE )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_linux.c +27 -0
@@ -40,3 +40,30 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)close (if_fd);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifreq ifr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +rte_strscpy (ifr.ifr_name, if_name,sizeof (ifr.ifr_name)); +if (ioctl (fd,SIOCGIFFLAGS , &ifr) ==0 ) { +/* +* IFF_UP means administratively up. +* IFF_RUNNING means operationally up (carrier detected). +* Both must be set for link to be considered up. +*/ +if ((ifr.ifr_flags &IFF_UP ) && (ifr.ifr_flags &IFF_RUNNING )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_windows.c +56 -12
97 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 16/25 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 | 1 + drivers/net/pcap/pcap_ethdev.c | 161 +++++++++++++++++++------ 3 files changed, 130 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 +1 -0
@@ -140,6 +140,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Items
drivers/net/pcap/pcap_ethdev.c +126 -35
272 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 17/25 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
@@ -638,6 +638,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.53.0
PATCH v21 18/25 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 ;
@@ -596,6 +594,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;
@@ -707,6 +706,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 ) {
@@ -1464,6 +1465,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.53.0
PATCH v21 19/25 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
@@ -890,10 +890,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.53.0
PATCH v21 20/25 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.53.0
PATCH v21 21/25 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.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'
--- doc/guides/nics/pcap.rst | 17 ++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 208 +++++++++++++++++-------- 3 files changed, 157 insertions(+), 69 deletions(-)
doc/guides/nics/pcap.rst +17 -0
@@ -15,6 +15,23 @@ For more information about the pcap library, see the The pcap-based PMD requires the libpcap development files to be installed. This applies to all supported operating systems: Linux, FreeBSD, and Windows. +* 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. + + The ``snaplen`` argument is used when opening capture handles, so it should + be specified before the interface or file arguments. Example:: + + --vdev 'net_pcap0,snaplen=1518,iface=eth0' + --vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap' + + The snapshot length also determines the reported ``max_rx_pktlen`` + and ``max_mtu`` in device info. + Using the Driver from the EAL Command Line ------------------------------------------
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -141,6 +141,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. * Receive timestamps support nanosecond precision. + * Added ``snaplen`` devarg to configure packet capture snapshot length. Removed Items
drivers/net/pcap/pcap_ethdev.c +139 -69
435 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 22/25 net/pcap: add Rx scatter offload
In reply to Stephen HemmingerAdd RTE_ETH_RX_OFFLOAD_SCATTER to the advertised receive offload capabilities if not using infinite_rx mode.
Validate in rx_queue_setup that the mbuf pool data room is large enough when scatter is not enabled, following the same pattern as the virtio driver.
Gate the multi-segment receive path on the scatter offload flag and drop oversized packets when scatter is disabled. Reject scatter with infinite_rx mode since the ring-based replay path does not support multi-segment mbufs.
--- drivers/net/pcap/pcap_ethdev.c | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +45 -2
@@ -79,6 +79,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;
@@ -112,6 +113,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading; };
@@ -342,14 +344,19 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)/* pcap packet will fit in the mbuf, can copy it */ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); mbuf->data_len = len; - }else { -/* Try read jumbo frame into multi mbufs. */ + }else if (pcap_q->rx_scatter) { +/* Scatter into multi-segment mbufs. */ if (unlikely (eth_pcap_rx_jumbo (pcap_q->mb_pool, mbuf, packet, len) ==-1 )) { pcap_q->rx_stat.err_pkts++;rte_pktmbuf_free (mbuf);break ; } + }else { +/* Packet too large and scatter not enabled, drop it. */ + pcap_q->rx_stat.err_pkts++; +rte_pktmbuf_free (mbuf); +continue ; } mbuf->pkt_len = len;
@@ -904,6 +911,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->rx_scatter = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ); internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );if (internals->timestamp_offloading && timestamp_rx_dynflag ==0 ) {
@@ -936,6 +944,9 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_VLAN_STRIP |RTE_ETH_RX_OFFLOAD_TIMESTAMP ; +if (!internals->infinite_rx) + dev_info->rx_offload_capa |=RTE_ETH_RX_OFFLOAD_SCATTER ; +return 0 ; }
@@ -1095,11 +1106,37 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, {struct pmd_internals *internals = dev->data->dev_private;struct pcap_rx_queue *pcap_q = &internals->rx_queue[rx_queue_id]; +uint16_t buf_size; +bool rx_scatter; + + buf_size =rte_pktmbuf_data_room_size (mb_pool) -RTE_PKTMBUF_HEADROOM ; + rx_scatter = !!(dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_SCATTER ); + +/* +* If Rx scatter is not enabled, verify that the mbuf data room +* can hold the largest received packet in a single segment. +* Use the MTU-derived frame size as the expected maximum, not +* snapshot_len which is a capture truncation limit rather than +* an expected packet size. +*/ +if (!rx_scatter) { +uint32_t max_rx_pktlen = dev->data->mtu +RTE_ETHER_HDR_LEN ; + +if (max_rx_pktlen > buf_size) { +PMD_LOG (ERR , +"Rx scatter is disabled and RxQ mbuf pool object size is too small " +"(buf_size=%u, max_rx_pkt_len=%u)" , + buf_size, max_rx_pktlen); +return -EINVAL ; + } + } 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; + pcap_q->rx_scatter = rx_scatter; dev->data->rx_queues[rx_queue_id] = pcap_q; pcap_q->timestamp_offloading = internals->timestamp_offloading;
@@ -1112,6 +1149,12 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,pcap_t **pcap;bool save_vlan_strip; +if (rx_scatter) { +PMD_LOG (ERR , +"Rx scatter is not supported with infinite_rx mode" ); +return -EINVAL ; + } + pp = rte_eth_devices[pcap_q->port_id].process_private; pcap = &pp->rx_pcap[pcap_q->queue_id];
Signature · 1 line
2.53.0
PATCH v21 23/25 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/nics/pcap.rst | 5 +++ doc/guides/rel_notes/release_26_03.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 45 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+)
doc/guides/nics/features/pcap.ini +1 -0
@@ -5,6 +5,7 @@ ; [Features] Link status = Y +Link status event = Y Queue start/stop = Y Timestamp offload = P Basic stats = Y
doc/guides/nics/pcap.rst +5 -0
@@ -278,3 +278,8 @@ Features and Limitations * 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. + +* In ``iface`` mode, the PMD supports link status change (LSC) notifications. + When the application enables ``intr_conf.lsc`` in the port configuration, + the driver polls the underlying network interface once per second and generates an + ``RTE_ETH_EVENT_INTR_LSC`` callback when the link state changes.
doc/guides/rel_notes/release_26_03.rst +1 -0
@@ -142,6 +142,7 @@ New Features * Added support for reporting link state in ``iface`` mode. * 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 +45 -0
93 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 24/25 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 | 80 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-)
doc/guides/nics/pcap.rst +12 -0
@@ -161,6 +161,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
@@ -143,6 +143,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 +77 -3
167 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v21 25/25 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 (ipackets, opackets, ibytes, obytes)
- interface (iface=) pass-through mode
- asymmetric rx_iface/tx_iface mode
- rx_iface_in direction filtering
- 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
- scatter RX and oversized packet drop
- per-queue start/stop
- imissed statistic (pcap_stats kernel drops)
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 | 4122 ++++++++++++++++++++++++ doc/guides/rel_notes/release_26_03.rst | 1 + 3 files changed, 4125 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'],
@@ -217,6 +218,7 @@ source_file_deps = { source_file_ext_deps = { 'test_compressdev.c': ['zlib'], 'test_pcapng.c': ['pcap'], + 'test_pmd_pcap.c': ['pcap'], } # the NULL ethdev is used by a number of tests, in some cases as an optional dependency.
app/test/test_pmd_pcap.c new file +4122 -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.53.0
Part of the diff is not shown here. View the raw message.
v22 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
- Rx scatter offload support with mbuf pool validation
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
- Preserve VLAN tags in dpdk-pdump captures by converting stripped VLAN metadata to Tx insert requests and calling rte_eth_tx_prepare() on the pcap vdev
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
- Reduce scope of file-level variables
Testing:
- Add comprehensive unit test suite covering basic file I/O, timestamps, jumbo frames, VLAN strip/insert, multi-queue, scatter receive, 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
v22 - don't use tx_prepare
rebase for 26.07
Stephen Hemminger (24):
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: clean up TX dumper return value and types 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: clarify maximum received packet eal/windows: add wrapper for access function net/pcap: add snapshot length devarg
net/pcap: add Rx scatter offload
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 | 3448 ++++++++++++++++++++++++ doc/guides/nics/features/pcap.ini | 9 + doc/guides/nics/pcap.rst | 47 + doc/guides/rel_notes/release_26_07.rst | 11 + drivers/net/pcap/pcap_ethdev.c | 859 ++++-- 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, 4349 insertions(+), 215 deletions(-) create mode 100644 app/test/test_pmd_pcap.c
Signature · 1 line
2.53.0
PATCH v22 1/24 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
@@ -1116,6 +1116,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.53.0
PATCH v22 2/24 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.53.0
PATCH v22 3/24 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 = P 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.53.0
PATCH v22 4/24 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.53.0
PATCH v22 5/24 net/pcap: remove unnecessary casts
In reply to Stephen HemmingerThe function rte_zmalloc returns void * so cast is unnecessary. Use numa aware allocation and add tag for tracing.
--- drivers/net/pcap/pcap_ethdev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/net/pcap/pcap_ethdev.c +6 -11
@@ -1217,13 +1217,11 @@ pmd_init_internals(struct rte_vdev_device *vdev,struct pmd_process_private *pp;unsigned int numa_node = vdev->device.numa_node; -PMD_LOG (INFO ,"Creating pcap-backed ethdev on numa socket %d" , +PMD_LOG (INFO ,"Creating pcap-backed ethdev on numa socket %u" , numa_node); - pp = (struct pmd_process_private *) -rte_zmalloc (NULL ,sizeof (struct pmd_process_private ), -RTE_CACHE_LINE_SIZE ); - + pp =rte_zmalloc_socket ("pcap_private" ,sizeof (struct pmd_process_private ), +RTE_CACHE_LINE_SIZE , numa_node);if (pp ==NULL ) {PMD_LOG (ERR ,"Failed to allocate memory for process private" );
@@ -1284,7 +1282,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,if (osdep_iface_mac_get (if_name, &mac) <0 )return -1 ; - mac_addrs =rte_zmalloc_socket (NULL ,RTE_ETHER_ADDR_LEN ,0 , numa_node); + mac_addrs =rte_zmalloc_socket ("pcap_mac" ,RTE_ETHER_ADDR_LEN ,0 , numa_node);if (mac_addrs ==NULL )return -1 ;
@@ -1590,11 +1588,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 ("pcap_private" ,sizeof (struct pmd_process_private ), +RTE_CACHE_LINE_SIZE );if (pp ==NULL ) {PMD_LOG (ERR ,"Failed to allocate memory for process private" );
Signature · 1 line
2.53.0
PATCH v22 6/24 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>
@@ -1287,7 +1288,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.53.0
PATCH v22 7/24 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.53.0
PATCH v22 8/24 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 | 60 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 23 deletions(-)
drivers/net/pcap/pcap_ethdev.c +37 -23
@@ -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,11 @@ 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]; - len = caplen =rte_pktmbuf_pkt_len (mbuf); -if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && - len >sizeof (temp_data))) { - caplen =sizeof (temp_data); - } +struct rte_mbuf *mbuf = bufs[i]; +size_t len, caplen; + + len =rte_pktmbuf_pkt_len (mbuf); + caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );calculate_timestamp (&header.ts); header.len = len;
@@ -449,9 +450,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 +458,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 +468,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 +964,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 +972,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 +1032,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.53.0
PATCH v22 9/24 net/pcap: fix error accounting and backpressure on transmit
In reply to Stephen HemmingerFix two problems in eth_pcap_tx():
Oversized multi-segment packets that exceed the bounce buffer are dropped but were not counted as errors. Add err_pkts accounting for these drops.
When pcap_sendpacket() fails due to kernel socket backpressure, the remaining unsent packets were counted as TX errors. Since backpressure is transient (EAGAIN/EBUSY/EINTR), break the loop and return the number of packets attempted so the caller retains ownership of the unsent mbufs per tx_burst semantics.
--- drivers/net/pcap/pcap_ethdev.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/net/pcap/pcap_ethdev.c +22 -12
@@ -462,7 +462,17 @@ eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) }/* -* Callback to handle sending packets through a real NIC. +* Send a burst of packets to a pcap device. +* +* On Linux, pcap_sendpacket() calls send() on a blocking PF_PACKET +* socket with default kernel buffer sizes and no TX ring (PACKET_TX_RING). +* The send() call only blocks when the kernel socket send buffer is full, +* providing limited backpressure. +* +* On error, pcap_sendpacket() returns non-zero and the loop breaks, +* leaving remaining packets unsent. +* +* Bottom line: backpressure is not an error. */ static uint16_t eth_pcap_tx (void *queue,struct rte_mbuf **bufs,uint16_t nb_pkts)
@@ -484,26 +494,27 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)for (i =0 ; i < nb_pkts; i++) {struct rte_mbuf *mbuf = bufs[i]; -size_t len =rte_pktmbuf_pkt_len (mbuf); -int ret; +uint32_t len =rte_pktmbuf_pkt_len (mbuf); +const uint8_t *data;if (unlikely (!rte_pktmbuf_is_contiguous (mbuf) && len >RTE_ETH_PCAP_SNAPSHOT_LEN )) {PMD_LOG (ERR , -"Dropping multi segment PCAP packet. Size (%zd) > max size (%u)." , +"Dropping multi segment PCAP packet. Size (%u) > max size (%u)." , len,RTE_ETH_PCAP_SNAPSHOT_LEN ); + tx_queue->tx_stat.err_pkts++;rte_pktmbuf_free (mbuf);continue ; } -/* rte_pktmbuf_read() returns a pointer to the data directly -* in the mbuf (when the mbuf is contiguous) or, otherwise, -* a pointer to temp_data after copying into it. -*/ - ret =pcap_sendpacket (pcap, -rte_pktmbuf_read (mbuf,0 , len, temp_data), len); -if (unlikely (ret !=0 )) + data =rte_pktmbuf_read (mbuf,0 , len, temp_data); +RTE_ASSERT (data !=NULL ); + +if (unlikely (pcap_sendpacket (pcap, data, len) !=0 )) { +/* Assume failure is backpressure */ +PMD_LOG (ERR ,"pcap_sendpacket() failed: %s" ,pcap_geterr (pcap));break ; + } num_tx++; tx_bytes += len;rte_pktmbuf_free (mbuf);
@@ -511,7 +522,6 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) tx_queue->tx_stat.pkts += num_tx; tx_queue->tx_stat.bytes += tx_bytes; - tx_queue->tx_stat.err_pkts += i - num_tx;return i; }
Signature · 1 line
2.53.0
PATCH v22 10/24 net/pcap: clean up TX dumper return value and types
In reply to Stephen HemmingerUse uint32_t for packet lengths to match rte_pktmbuf_pkt_len() return type. Split rte_pktmbuf_read() out of the pcap_dump() call and add RTE_ASSERT for bogus mbuf detection. Remove incorrect err_pkts accounting since the dumper loop cannot partially fail, and return the loop index for consistency with eth_pcap_tx.
--- drivers/net/pcap/pcap_ethdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/pcap/pcap_ethdev.c +10 -9
@@ -407,7 +407,8 @@ 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 =rte_pktmbuf_pkt_len (mbuf); caplen =RTE_MIN (len,RTE_ETH_PCAP_SNAPSHOT_LEN );
@@ -415,15 +416,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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)); + + data =rte_pktmbuf_read (mbuf,0 , caplen, temp_data); + +/* This could only happen if mbuf is bogus pkt_len > data_len */ +RTE_ASSERT (data !=NULL ); +pcap_dump ((u_char *)dumper, &header, data); num_tx++; tx_bytes += caplen; +rte_pktmbuf_free (mbuf); }
@@ -435,9 +437,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; }/*
Signature · 1 line
2.53.0
PATCH v22 11/24 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 | 2 +- drivers/net/pcap/pcap_osdep.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/pcap/pcap_ethdev.c +1 -1
@@ -500,7 +500,7 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)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++;
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.53.0
PATCH v22 12/24 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 | 67 +++++++++++++++------------------- 1 file changed, 29 insertions(+), 38 deletions(-)
drivers/net/pcap/pcap_ethdev.c +29 -38
@@ -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[] = {
@@ -881,7 +882,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 ;
@@ -1206,29 +1207,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 ; }
@@ -1503,7 +1494,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;
@@ -1543,8 +1534,8 @@ 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); + &process_bool_flag, + &devargs_all.infinite_rx);if (ret <0 ) goto free_kvlist; PMD_LOG(INFO, "infinite_rx has been %s for %s",
@@ -1693,5 +1684,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.53.0
PATCH v22 13/24 net/pcap: support VLAN strip and insert offloads
In reply to Stephen HemmingerAdd VLAN tag handling to the pcap PMD, similar to virtio and af_packet drivers. This also helps if with capture of VLAN tagged packets when legacy pdump is used.
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 | 10 +++ doc/guides/rel_notes/release_26_07.rst | 4 + drivers/net/pcap/pcap_ethdev.c | 120 ++++++++++++++++++++++++- 4 files changed, 131 insertions(+), 4 deletions(-)
doc/guides/nics/features/pcap.ini +1 -0
@@ -9,6 +9,7 @@ Queue start/stop = Y Timestamp offload = P Basic stats = Y Stats per queue = Y +VLAN offload = Y Multiprocess aware = Y FreeBSD = Y Linux = Y
doc/guides/nics/pcap.rst +10 -0
@@ -247,3 +247,13 @@ 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 +~~~~~~~~~~~~~~~~~~~~~~~~ + +* When ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is enabled, the driver removes the + outermost VLAN tag from received packets via ``rte_vlan_strip()``. + The strip setting can be changed at runtime through ``vlan_offload_set``. + +* The PMD will transparently insert a VLAN tag to transmitted packets if + the mbuf has ``RTE_MBUF_F_TX_VLAN`` set.
doc/guides/rel_notes/release_26_07.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 +116 -4
222 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v22 14/24 net/pcap: add link status 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 function to query the real link state from the underlying interface.
Linux and FreeBSD use SIOCGIFFLAGS to check IFF_UP and IFF_RUNNING. Windows uses GetAdaptersAddresses() to check OperStatus.
--- doc/guides/rel_notes/release_26_07.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 38 +++++++++----- drivers/net/pcap/pcap_osdep.h | 12 +++++ drivers/net/pcap/pcap_osdep_freebsd.c | 31 ++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 27 ++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 68 +++++++++++++++++++++----- 6 files changed, 154 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_07.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 in ``iface`` mode. Removed Items
drivers/net/pcap/pcap_ethdev.c +27 -11
@@ -150,13 +150,6 @@ static const char *valid_arguments[] = {NULL }; -static struct rte_eth_link pmd_link = { - .link_speed =RTE_ETH_SPEED_NUM_10G , - .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , - .link_status =RTE_ETH_LINK_DOWN , - .link_autoneg =RTE_ETH_LINK_FIXED , -}; -RTE_LOG_REGISTER_DEFAULT (eth_pcap_logtype,NOTICE ); static struct queue_missed_stat*
@@ -967,10 +960,28 @@ eth_dev_close(struct rte_eth_dev *dev) }static int -eth_link_update(struct rte_eth_dev *dev __rte_unused, - int wait_to_complete __rte_unused) +eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { -return 0 ; +struct pmd_internals *internals = dev->data->dev_private; +struct rte_eth_link link = { + .link_speed =RTE_ETH_SPEED_NUM_10G , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; + +/* +* For pass-through mode (single_iface), query whether the +* underlying interface is up. Otherwise use default values. +*/ +if (internals->single_iface) { + link.link_status = (osdep_iface_link_status (internals->rx_queue[0 ].name) >0 ) ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + }else { + link.link_status = dev->data->dev_started ? +RTE_ETH_LINK_UP :RTE_ETH_LINK_DOWN ; + } + +return rte_eth_linkstatus_set (dev, &link); } static int
@@ -1384,7 +1395,12 @@ pmd_init_internals(struct rte_vdev_device *vdev, data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t )nb_rx_queues; data->nb_tx_queues = (uint16_t )nb_tx_queues; - data->dev_link = pmd_link; + data->dev_link = (struct rte_eth_link ) { + .link_speed =RTE_ETH_SPEED_NUM_NONE , + .link_duplex =RTE_ETH_LINK_FULL_DUPLEX , + .link_status =RTE_ETH_LINK_DOWN , + .link_autoneg =RTE_ETH_LINK_FIXED , + }; data->mac_addrs = &(*internals)->eth_addr; data->promiscuous =1 ; data->all_multicast =1 ;
drivers/net/pcap/pcap_osdep.h +12 -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
@@ -30,4 +31,15 @@ extern int eth_pcap_logtype;int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); +/** +* Get link status for a network interface. +* +* @param name +* Interface name (e.g., "eth0" on Linux, "{GUID}" on Windows). +* @return +* 1 if link is up, 0 if link is down, -1 on error. +*/ +int osdep_iface_link_status (const char *name); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c +31 -0
@@ -5,8 +5,13 @@*/ #include <string.h> +#include <stdlib.h> +#include <unistd.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> +#include <sys/ioctl.h> +#include <sys/socket.h> #include <sys/sysctl.h> #include "pcap_osdep.h"
@@ -55,3 +60,29 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)free (buf);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifmediareq ifmr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&ifmr,0 ,sizeof (ifmr)); +strlcpy (ifmr.ifm_name, if_name,sizeof (ifmr.ifm_name)); + +if (ioctl (fd,SIOCGIFMEDIA , &ifmr) ==0 ) { +/* IFM_AVALID means status is valid, IFM_ACTIVE means link up */ +if ((ifmr.ifm_status &IFM_AVALID ) && + (ifmr.ifm_status &IFM_ACTIVE )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_linux.c +27 -0
@@ -40,3 +40,30 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)close (if_fd);return 0 ; } + +int +osdep_iface_link_status (const char *if_name) +{ +struct ifreq ifr; +int fd, status =0 ; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (fd ==-1 ) +return -1 ; + +rte_strscpy (ifr.ifr_name, if_name,sizeof (ifr.ifr_name)); +if (ioctl (fd,SIOCGIFFLAGS , &ifr) ==0 ) { +/* +* IFF_UP means administratively up. +* IFF_RUNNING means operationally up (carrier detected). +* Both must be set for link to be considered up. +*/ +if ((ifr.ifr_flags &IFF_UP ) && (ifr.ifr_flags &IFF_RUNNING )) + status =1 ; + }else { + status =-1 ; + } + +close (fd); +return status; +}
drivers/net/pcap/pcap_osdep_windows.c +56 -12
97 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v22 15/24 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_07.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 161 +++++++++++++++++++------ 3 files changed, 130 insertions(+), 35 deletions(-)
doc/guides/nics/pcap.rst +3 -0
@@ -257,3 +257,6 @@ Features and Limitations * The PMD will transparently insert a VLAN tag to transmitted packets if the mbuf has ``RTE_MBUF_F_TX_VLAN`` set. + +* If ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled then the timestamp + from the pcap file is converted to DPDK format.
doc/guides/rel_notes/release_26_07.rst +1 -0
@@ -59,6 +59,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. + * Receive timestamps support nanosecond precision. Removed Items
drivers/net/pcap/pcap_ethdev.c +126 -35
272 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v22 16/24 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
@@ -664,6 +664,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.53.0
PATCH v22 17/24 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 ;
@@ -622,6 +620,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;
@@ -733,6 +732,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 ) {
@@ -1490,6 +1491,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.53.0
PATCH v22 18/24 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
@@ -916,10 +916,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.53.0
PATCH v22 19/24 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.53.0
PATCH v22 20/24 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.
The snaplen argument is parsed before interface and file arguments so that its value is available when pcap handles are opened during device creation.
Example usage:
--vdev 'net_pcap0,snaplen=1518,iface=eth0'
--vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap'
--- doc/guides/nics/pcap.rst | 17 ++ doc/guides/rel_notes/release_26_07.rst | 1 + drivers/net/pcap/pcap_ethdev.c | 206 ++++++++++++++++--------- 3 files changed, 154 insertions(+), 70 deletions(-)
doc/guides/nics/pcap.rst +17 -0
@@ -15,6 +15,23 @@ For more information about the pcap library, see the The pcap-based PMD requires the libpcap development files to be installed. This applies to all supported operating systems: Linux, FreeBSD, and Windows. +* 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. + + The ``snaplen`` argument is used when opening capture handles, so it should + be specified before the interface or file arguments. Example:: + + --vdev 'net_pcap0,snaplen=1518,iface=eth0' + --vdev 'net_pcap0,snaplen=9000,rx_pcap=in.pcap,tx_pcap=out.pcap' + + The snapshot length also determines the reported ``max_rx_pktlen`` + and ``max_mtu`` in device info. + Using the Driver from the EAL Command Line ------------------------------------------
doc/guides/rel_notes/release_26_07.rst +1 -0
@@ -60,6 +60,7 @@ New Features * Added support for VLAN insertion and stripping. * Added support for reporting link state in ``iface`` mode. * Receive timestamps support nanosecond precision. + * Added ``snaplen`` devarg to configure packet capture snapshot length. Removed Items
drivers/net/pcap/pcap_ethdev.c +136 -70
426 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v22 21/24 net/pcap: add Rx scatter offload
In reply to Stephen HemmingerAdd RTE_ETH_RX_OFFLOAD_SCATTER to the advertised receive offload capabilities if not using infinite_rx mode.
Validate in rx_queue_setup that the mbuf pool data room is large enough when scatter is not enabled, following the same pattern as the virtio driver.
Gate the multi-segment receive path on the scatter offload flag and drop oversized packets when scatter is disabled. Reject scatter with infinite_rx mode since the ring-based replay path does not support multi-segment mbufs.
--- drivers/net/pcap/pcap_ethdev.c | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
drivers/net/pcap/pcap_ethdev.c +45 -2
@@ -79,6 +79,7 @@ struct pcap_rx_queue {uint16_t port_id;uint16_t queue_id;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading;struct rte_mempool *mb_pool;struct queue_stat rx_stat;
@@ -112,6 +113,7 @@ struct pmd_internals {bool phy_mac;bool infinite_rx;bool vlan_strip; +bool rx_scatter;bool timestamp_offloading; };
@@ -342,14 +344,19 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)/* pcap packet will fit in the mbuf, can copy it */ rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); mbuf->data_len = len; - }else { -/* Try read jumbo frame into multi mbufs. */ + }else if (pcap_q->rx_scatter) { +/* Scatter into multi-segment mbufs. */ if (unlikely (eth_pcap_rx_jumbo (pcap_q->mb_pool, mbuf, packet, len) ==-1 )) { pcap_q->rx_stat.err_pkts++;rte_pktmbuf_free (mbuf);break ; } + }else { +/* Packet too large and scatter not enabled, drop it. */ + pcap_q->rx_stat.err_pkts++; +rte_pktmbuf_free (mbuf); +continue ; } mbuf->pkt_len = len;
@@ -926,6 +933,7 @@ eth_dev_configure(struct rte_eth_dev *dev)const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; internals->vlan_strip = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ); + internals->rx_scatter = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ); internals->timestamp_offloading = !!(rxmode->offloads &RTE_ETH_RX_OFFLOAD_TIMESTAMP );if (internals->timestamp_offloading && timestamp_rx_dynflag ==0 ) {
@@ -958,6 +966,9 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_VLAN_STRIP |RTE_ETH_RX_OFFLOAD_TIMESTAMP ; +if (!internals->infinite_rx) + dev_info->rx_offload_capa |=RTE_ETH_RX_OFFLOAD_SCATTER ; +return 0 ; }
@@ -1117,11 +1128,37 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, {struct pmd_internals *internals = dev->data->dev_private;struct pcap_rx_queue *pcap_q = &internals->rx_queue[rx_queue_id]; +uint16_t buf_size; +bool rx_scatter; + + buf_size =rte_pktmbuf_data_room_size (mb_pool) -RTE_PKTMBUF_HEADROOM ; + rx_scatter = !!(dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_SCATTER ); + +/* +* If Rx scatter is not enabled, verify that the mbuf data room +* can hold the largest received packet in a single segment. +* Use the MTU-derived frame size as the expected maximum, not +* snapshot_len which is a capture truncation limit rather than +* an expected packet size. +*/ +if (!rx_scatter) { +uint32_t max_rx_pktlen = dev->data->mtu +RTE_ETHER_HDR_LEN ; + +if (max_rx_pktlen > buf_size) { +PMD_LOG (ERR , +"Rx scatter is disabled and RxQ mbuf pool object size is too small " +"(buf_size=%u, max_rx_pkt_len=%u)" , + buf_size, max_rx_pktlen); +return -EINVAL ; + } + } 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; + pcap_q->rx_scatter = rx_scatter; dev->data->rx_queues[rx_queue_id] = pcap_q; pcap_q->timestamp_offloading = internals->timestamp_offloading;
@@ -1134,6 +1171,12 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,pcap_t **pcap;bool save_vlan_strip; +if (rx_scatter) { +PMD_LOG (ERR , +"Rx scatter is not supported with infinite_rx mode" ); +return -EINVAL ; + } + pp = rte_eth_devices[pcap_q->port_id].process_private; pcap = &pp->rx_pcap[pcap_q->queue_id];
Signature · 1 line
2.53.0