[PATCH v10 11/19] net/pcap: support VLAN insert and strip
Stephen Hemminger
stephen at networkplumber.org
Fri Jan 30 02:12:27 CET 2026
Driver can easily insert VLAN tag strip and insertion similar
to how it is handled in virtio and af_packet.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
doc/guides/nics/features/pcap.ini | 1 +
doc/guides/nics/pcap_ring.rst | 11 +++++++++
doc/guides/rel_notes/release_26_03.rst | 4 ++++
drivers/net/pcap/pcap_ethdev.c | 31 ++++++++++++++++++++++++--
4 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/doc/guides/nics/features/pcap.ini b/doc/guides/nics/features/pcap.ini
index b0dac3cca7..814bc2119f 100644
--- a/doc/guides/nics/features/pcap.ini
+++ b/doc/guides/nics/features/pcap.ini
@@ -10,6 +10,7 @@ Scattered Rx = Y
Timestamp offload = Y
Basic stats = Y
Stats per queue = Y
+VLAN offload = Y
Multiprocess aware = Y
FreeBSD = Y
Linux = Y
diff --git a/doc/guides/nics/pcap_ring.rst b/doc/guides/nics/pcap_ring.rst
index 6955e91130..c005786ce3 100644
--- a/doc/guides/nics/pcap_ring.rst
+++ b/doc/guides/nics/pcap_ring.rst
@@ -213,6 +213,17 @@ Otherwise, the first 512 packets from the input pcap file will be discarded by t
an error if interface is down, and the PMD itself won't change the status
of the external network interface.
+Features and Limitations
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+* The PMD will re-insert the VLAN tag transparently to the packet if the kernel
+ strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the
+ application.
+
+* The PMD will transparently insert a VLAN tag to transmitted packets if
+ ``RTE_ETH_TX_OFFLOAD_VLAN_INSERT`` is enabled and the mbuf has ``RTE_MBUF_F_TX_VLAN``
+ set.
+
Rings-based PMD
~~~~~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_26_03.rst b/doc/guides/rel_notes/release_26_03.rst
index 15dabee7a1..7993ce2ee0 100644
--- a/doc/guides/rel_notes/release_26_03.rst
+++ b/doc/guides/rel_notes/release_26_03.rst
@@ -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
-------------
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index 201eb97745..b19e837b97 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -77,6 +77,7 @@ struct queue_missed_stat {
struct pcap_rx_queue {
uint16_t port_id;
uint16_t queue_id;
+ bool vlan_strip;
struct rte_mempool *mb_pool;
struct queue_stat rx_stat;
struct queue_missed_stat missed_stat;
@@ -107,6 +108,7 @@ struct pmd_internals {
bool single_iface;
bool phy_mac;
bool infinite_rx;
+ bool vlan_strip;
};
struct pmd_process_private {
@@ -337,6 +339,10 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
}
mbuf->pkt_len = len;
+
+ if (pcap_q->vlan_strip)
+ rte_vlan_strip(mbuf);
+
uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec;
*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us;
@@ -412,9 +418,16 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
uint32_t len, caplen;
const uint8_t *data;
+ if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
+ /* if vlan insert fails treat it as error */
+ if (unlikely(rte_vlan_insert(&mbuf) != 0))
+ continue;
+ }
+
len = caplen = rte_pktmbuf_pkt_len(mbuf);
calculate_timestamp(&header.ts);
+
header.len = len;
header.caplen = caplen;
@@ -487,6 +500,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
uint32_t len = rte_pktmbuf_pkt_len(mbuf);
const uint8_t *data;
+ if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
+ /* if vlan insert fails treat it as error */
+ if (unlikely(rte_vlan_insert(&mbuf) != 0))
+ continue;
+ }
+
data = rte_pktmbuf_read(mbuf, 0, len, temp_data);
if (likely(data != NULL && pcap_sendpacket(pcap, data, len) == 0)) {
num_tx++;
@@ -721,8 +740,13 @@ eth_dev_stop(struct rte_eth_dev *dev)
}
static int
-eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
+eth_dev_configure(struct rte_eth_dev *dev)
{
+ struct pmd_internals *internals = dev->data->dev_private;
+ struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
+ const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
+
+ internals->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
return 0;
}
@@ -738,7 +762,9 @@ eth_dev_info(struct rte_eth_dev *dev,
dev_info->max_rx_queues = dev->data->nb_rx_queues;
dev_info->max_tx_queues = dev->data->nb_tx_queues;
dev_info->min_rx_bufsize = 0;
- dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
+ dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
+ RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
+ dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
return 0;
}
@@ -885,6 +911,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
pcap_q->mb_pool = mb_pool;
pcap_q->port_id = dev->data->port_id;
pcap_q->queue_id = rx_queue_id;
+ pcap_q->vlan_strip = internals->vlan_strip;
dev->data->rx_queues[rx_queue_id] = pcap_q;
if (internals->infinite_rx) {
--
2.51.0
More information about the dev
mailing list