This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 1467eb0da67234ea57fd413ed7fa1d073f208c93 Author: gaohedong <[email protected]> AuthorDate: Wed Apr 29 14:41:50 2026 +0800 net/vlan: undo VLAN encapsulation on transmit failure When lower driver transmit fails, the packet is re-queued to txq for retry. On the next transmit attempt, vlan_transmit is called again, which inserts another VLAN tag into an already-encapsulated packet, corrupting the frame and shifting io_offset further each time. Fix this by saving the original reserved headroom before VLAN encapsulation and restoring the packet to its pre-encapsulation state when transmit fails. This ensures the packet can be safely retransmitted through vlan_transmit without double encapsulation. Signed-off-by: gaohedong <[email protected]> --- drivers/net/vlan.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/net/vlan.c b/drivers/net/vlan.c index 4252d4277a4..9221877d5c0 100644 --- a/drivers/net/vlan.c +++ b/drivers/net/vlan.c @@ -144,12 +144,14 @@ static int vlan_transmit(FAR struct netdev_lowerhalf_s *dev, FAR struct eth_8021qhdr_s *vlan_hdr; FAR uint8_t *base = netpkt_getbase(pkt); FAR uint8_t *data = netpkt_getdata(dev, pkt); + unsigned int reserved = data - base; + int ret; /* Check space for the VLAN tag, normally we want user to set bigger * CONFIG_NET_LL_GUARDSIZE to allow inserting VLAN tag in the headroom. */ - if (data - base < 4) + if (reserved < 4) { /* TODO: Support backup path for too small CONFIG_NET_LL_GUARDSIZE */ @@ -161,7 +163,7 @@ static int vlan_transmit(FAR struct netdev_lowerhalf_s *dev, /* Move the data to make space for the VLAN tag */ netpkt_copyin(dev, pkt, data, offsetof(struct eth_hdr_s, type), -4); - netpkt_reset_reserved(dev, pkt, data - base - 4); + netpkt_reset_reserved(dev, pkt, reserved - 4); /* Set value of the VLAN tag */ @@ -173,7 +175,20 @@ static int vlan_transmit(FAR struct netdev_lowerhalf_s *dev, /* TODO: Call pkt_input to allow tcpdump capture tx packet on real dev. */ - return real->ops->transmit(real, pkt); + ret = real->ops->transmit(real, pkt); + if (ret != OK) + { + /* Undo VLAN encapsulation so the packet can be safely retransmitted + * through vlan_transmit again (e.g. after being re-queued to txq). + * Move DST+SRC back to original position and restore io_offset. + */ + + data = netpkt_getdata(dev, pkt); + netpkt_copyin(dev, pkt, data, offsetof(struct eth_hdr_s, type), 4); + netpkt_reset_reserved(dev, pkt, reserved); + } + + return ret; } /****************************************************************************
