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

Signed-off-by: Stephen Hemminger <[email protected]>
---
 doc/guides/nics/features/pcap.ini      |  1 +
 doc/guides/rel_notes/release_26_03.rst |  1 +
 drivers/net/pcap/pcap_ethdev.c         | 30 ++++++++++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/doc/guides/nics/features/pcap.ini 
b/doc/guides/nics/features/pcap.ini
index d2f5ee6039..7043213c5f 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/rel_notes/release_26_03.rst 
b/doc/guides/rel_notes/release_26_03.rst
index 41f96ad1af..4e31d85e50 100644
--- a/doc/guides/rel_notes/release_26_03.rst
+++ b/doc/guides/rel_notes/release_26_03.rst
@@ -58,6 +58,7 @@ New Features
 * **Updated PCAP ethernet driver.**
 
   * Added support for setting MTU in single interface mode.
+  * Added support for VLAN insertion and stripping.
   * Changed transmit burst to always return the number of packets requested.
     Failed sends are counted as transmit errors.
 
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index 9ebb9c8633..85225fca2d 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -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;
@@ -103,6 +104,7 @@ struct pmd_internals {
        bool single_iface;
        bool phy_mac;
        bool infinite_rx;
+       bool vlan_strip;
 };
 
 struct pmd_process_private {
@@ -333,6 +335,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;
@@ -421,6 +427,12 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, 
uint16_t nb_pkts)
                void *temp = NULL;
                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;
+               }
+
                calculate_timestamp(&header.ts);
                header.len = len;
                header.caplen = len;
@@ -498,6 +510,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t 
nb_pkts)
                void *temp = NULL;
                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 = pcap_pktmbuf_read(mbuf, 0, len, &temp);
                if (likely(data != NULL &&
                    pcap_sendpacket(pcap, data, len) == 0)) {
@@ -732,8 +750,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;
 }
 
@@ -751,7 +774,9 @@ eth_dev_info(struct rte_eth_dev *dev,
        dev_info->min_rx_bufsize = 0;
        dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - 
RTE_ETHER_CRC_LEN;
        dev_info->max_mtu = RTE_ETH_PCAP_SNAPLEN;
-       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;
 }
@@ -898,6 +923,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

Reply via email to