* [PATCH net-next] net: libwx: disable TX VLAN offload for packets with >2 VLAN tags
@ 2026-07-10 7:18 Jiawen Wu
2026-07-10 9:49 ` Przemek Kitszel
0 siblings, 1 reply; 2+ messages in thread
From: Jiawen Wu @ 2026-07-10 7:18 UTC (permalink / raw)
To: netdev
Cc: Duanqiang Wen, Mengyuan Lou, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Jacob Keller, Kees Cook, Jiawen Wu
The current hardware does not support TX VLAN offload for packets with
three or more VLAN tags. When such packets are transmitted with hardware
VLAN offload enabled, the hardware may malfunction or produce corrupted
frames.
Add a check in wx_features_check() to parse the VLAN depth of the
skb. If more than two VLAN tags are detected (including both the
hardware tag and in-band tags), strip NETIF_F_HW_VLAN_CTAG_TX and
NETIF_F_HW_VLAN_STAG_TX from the feature set. This forces the
kernel networking stack to handle VLAN insertion in software for
these specific packets, ensuring correct transmission.
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 25 +++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 814d88d2aee4..65dab6bd8a39 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -3223,12 +3223,37 @@ netdev_features_t wx_fix_features(struct net_device *netdev,
EXPORT_SYMBOL(wx_fix_features);
#define WX_MAX_TUNNEL_HDR_LEN 80
+#define WX_VLAN_MAX_DEPTH 8
netdev_features_t wx_features_check(struct sk_buff *skb,
struct net_device *netdev,
netdev_features_t features)
{
struct wx *wx = netdev_priv(netdev);
+ u16 parse_depth = WX_VLAN_MAX_DEPTH;
+ __be16 type = skb->protocol;
+ u16 vlan_depth = ETH_HLEN;
+ u32 vlan_num = 0;
+ if (!skb_vlan_tag_present(skb))
+ goto tunnel_check;
+
+ vlan_num++;
+ while (eth_type_vlan(type) && --parse_depth) {
+ struct vlan_hdr vhdr, *vh;
+
+ vh = skb_header_pointer(skb, vlan_depth, sizeof(vhdr), &vhdr);
+ if (unlikely(!vh))
+ break;
+
+ type = vh->h_vlan_encapsulated_proto;
+ vlan_depth += VLAN_HLEN;
+ vlan_num++;
+ }
+
+ if (vlan_num > 2)
+ features &= ~(NETIF_F_HW_VLAN_CTAG_TX |
+ NETIF_F_HW_VLAN_STAG_TX);
+tunnel_check:
if (!skb->encapsulation)
return features;
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net: libwx: disable TX VLAN offload for packets with >2 VLAN tags
2026-07-10 7:18 [PATCH net-next] net: libwx: disable TX VLAN offload for packets with >2 VLAN tags Jiawen Wu
@ 2026-07-10 9:49 ` Przemek Kitszel
0 siblings, 0 replies; 2+ messages in thread
From: Przemek Kitszel @ 2026-07-10 9:49 UTC (permalink / raw)
To: Jiawen Wu
Cc: Duanqiang Wen, netdev, Mengyuan Lou, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Jacob Keller, Kees Cook
On 7/10/26 09:18, Jiawen Wu wrote:
> The current hardware does not support TX VLAN offload for packets with
> three or more VLAN tags. When such packets are transmitted with hardware
> VLAN offload enabled, the hardware may malfunction or produce corrupted
> frames.
>
> Add a check in wx_features_check() to parse the VLAN depth of the
> skb. If more than two VLAN tags are detected (including both the
> hardware tag and in-band tags), strip NETIF_F_HW_VLAN_CTAG_TX and
> NETIF_F_HW_VLAN_STAG_TX from the feature set. This forces the
> kernel networking stack to handle VLAN insertion in software for
> these specific packets, ensuring correct transmission.
>
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
> drivers/net/ethernet/wangxun/libwx/wx_lib.c | 25 +++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> index 814d88d2aee4..65dab6bd8a39 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> @@ -3223,12 +3223,37 @@ netdev_features_t wx_fix_features(struct net_device *netdev,
> EXPORT_SYMBOL(wx_fix_features);
>
> #define WX_MAX_TUNNEL_HDR_LEN 80
> +#define WX_VLAN_MAX_DEPTH 8
> netdev_features_t wx_features_check(struct sk_buff *skb,
> struct net_device *netdev,
> netdev_features_t features)
> {
> struct wx *wx = netdev_priv(netdev);
> + u16 parse_depth = WX_VLAN_MAX_DEPTH;
> + __be16 type = skb->protocol;
> + u16 vlan_depth = ETH_HLEN;
> + u32 vlan_num = 0;
>
> + if (!skb_vlan_tag_present(skb))
this if jumping over the loop with essentially the same condition
does not help much, I would just remove
> + goto tunnel_check;
> +
> + vlan_num++;
> + while (eth_type_vlan(type) && --parse_depth) {
> + struct vlan_hdr vhdr, *vh;
> +
> + vh = skb_header_pointer(skb, vlan_depth, sizeof(vhdr), &vhdr);
> + if (unlikely(!vh))
> + break;
> +
> + type = vh->h_vlan_encapsulated_proto;
> + vlan_depth += VLAN_HLEN;
> + vlan_num++;
parse depth of 8 does not make sense if you are detecting
"are the three first protocols a VLAN"
> + }
> +
> + if (vlan_num > 2)
> + features &= ~(NETIF_F_HW_VLAN_CTAG_TX |
> + NETIF_F_HW_VLAN_STAG_TX);
you could move this if condition inside a loop with an added "break"
> +tunnel_check:
> if (!skb->encapsulation)
> return features;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-10 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 7:18 [PATCH net-next] net: libwx: disable TX VLAN offload for packets with >2 VLAN tags Jiawen Wu
2026-07-10 9:49 ` Przemek Kitszel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox