Thread (18 messages) 18 messages, 3 authors, 2021-10-06

Re: [dpdk-dev] [PATCH] net/af_packet: try to reinsert the stripped vlan tag

From: Ferruh Yigit <hidden>
Date: 2021-08-31 15:31:33

On 8/20/2021 1:46 PM, Tudor Cornea wrote:
The af_packet pmd driver binds to a raw socket and allows
sending and receiving of packets through the kernel.

Since commit bcc6d47903 [1], the kernel strips the vlan tags early in
__netif_receive_skb_core(), so we receive untagged packets while
running with the af_packet pmd.

Luckily for us, the skb vlan-related fields are still populated from the
stripped vlan tags, so we end up having all the information
that we need in the mbuf.

We would like to have the the vlan tag inside the mbuf.
Let's take a shot at it by trying to reinsert the stripped vlan tag.
PMD already sets 'mbuf->vlan_tci' and 'PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED'
flags, so application can be aware of the vlan tag and can consume it.

Inserting the vlan tag back to packet is costly, what is the motivation to do so?
quoted hunk ↗ jump to hunk
As a side note, something similar was done for the netvsc pmd.

[1] https://github.com/torvalds/linux/commit/bcc6d47903612c3861201cc3a866fb604f26b8b2

Signed-off-by: Tudor Cornea <redacted>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index b73b211..d116583 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -148,6 +148,10 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		if (ppd->tp_status & TP_STATUS_VLAN_VALID) {
 			mbuf->vlan_tci = ppd->tp_vlan_tci;
 			mbuf->ol_flags |= (PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED);
+
+			/* the kernel always strips the vlan tag, try to reinsert it */
+			if (rte_vlan_insert(&mbuf))
+				PMD_LOG(ERR, "Failed to reinsert vlan tag");
 		}
 
 		/* release incoming frame and advance ring buffer */
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help