This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e184047b15578456ae21053da9443fb4b9a10078
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Apr 1 16:57:50 2026 +0800

    drivers/virtio/virtio-net: count the VLAN tag in the guard size check
    
    The static_assert in virtio-net validates that CONFIG_NET_LL_GUARDSIZE is
    large enough for the link-layer header. Using ETH_HDRLEN (14 bytes) does
    not account for 802.1Q VLAN tagged frames, which require 4 extra bytes.
    Change to ETH_8021Q_HDRLEN (18 bytes) to ensure the guard size is
    sufficient for VLAN tagged traffic.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 drivers/virtio/virtio-net.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/virtio/virtio-net.c b/drivers/virtio/virtio-net.c
index 37bf52d8f10..010aecd7efd 100644
--- a/drivers/virtio/virtio-net.c
+++ b/drivers/virtio/virtio-net.c
@@ -65,6 +65,14 @@
 #define VIRTIO_NET_MAX_NIOB \
     ((VIRTIO_NET_MAX_PKT_SIZE + CONFIG_IOB_BUFSIZE - 1) / CONFIG_IOB_BUFSIZE)
 
+/* Ethernet header size: wider when 802.1Q VLAN tagging is enabled */
+
+#ifdef CONFIG_NET_VLAN
+#  define VIRTIO_NET_ETH_HDRSIZE  ETH_8021Q_HDRLEN
+#else
+#  define VIRTIO_NET_ETH_HDRSIZE  ETH_HDRLEN
+#endif
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -131,10 +139,10 @@ struct virtio_net_priv_s
  * |               |<--------- datalen -------->|
  * ^base           ^data
  *
- * CONFIG_NET_LL_GUARDSIZE >= VIRTIO_NET_LLHDRSIZE + ETH_HDR_SIZE
- *                          = sizeof(uintptr) + 10 + 14
- *                          = 32 (64-Bit)
- *                          = 28 (32-Bit)
+ * CONFIG_NET_LL_GUARDSIZE >= VIRTIO_NET_LLHDRSIZE + VIRTIO_NET_ETH_HDRSIZE
+ *                          = sizeof(uintptr) + 10 + 14 or (18 for VLAN)
+ *                          = 32 or (36 for VLAN) (64-Bit)
+ *                          = 28 or (32 for VLAN) (32-Bit)
  */
 
 begin_packed_struct struct virtio_net_llhdr_s
@@ -143,9 +151,10 @@ begin_packed_struct struct virtio_net_llhdr_s
   struct virtio_net_hdr_s vhdr;        /* Virtio net header */
 } end_packed_struct;
 
-static_assert(CONFIG_NET_LL_GUARDSIZE >= VIRTIO_NET_LLHDRSIZE + ETH_HDRLEN,
-              "CONFIG_NET_LL_GUARDSIZE cannot be less than ETH_HDRLEN"
-              " + VIRTIO_NET_LLHDRSIZE");
+static_assert(CONFIG_NET_LL_GUARDSIZE >= VIRTIO_NET_LLHDRSIZE +
+              VIRTIO_NET_ETH_HDRSIZE,
+              "CONFIG_NET_LL_GUARDSIZE cannot be less than"
+              " VIRTIO_NET_ETH_HDRSIZE + VIRTIO_NET_LLHDRSIZE");
 
 /****************************************************************************
  * Private Function Prototypes

Reply via email to