Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bridge: fix C-VLAN preservation in 802.1ad vlan_tunnel egress

When using an 802.1ad bridge with vlan_tunnel, the C-VLAN tag is
incorrectly stripped from frames during egress processing.

br_handle_egress_vlan_tunnel() uses skb_vlan_pop() to remove the S-VLAN
from hwaccel before VXLAN encapsulation. However, skb_vlan_pop() also
moves any "next" VLAN from the payload into hwaccel:

/* move next vlan tag to hw accel tag */
__skb_vlan_pop(skb, &vlan_tci);
__vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci);

For QinQ frames where the C-VLAN sits in the payload, this moves it to
hwaccel where it gets lost during VXLAN encapsulation.

Fix by calling __vlan_hwaccel_clear_tag() directly, which clears only
the hwaccel S-VLAN and leaves the payload untouched.

This path is only taken when vlan_tunnel is enabled and tunnel_info
is configured, so 802.1Q bridges are unaffected.

Tested with 802.1ad bridge + VXLAN vlan_tunnel, verified C-VLAN
preserved in VXLAN payload via tcpdump.

Fixes: 11538d039ac6 ("bridge: vlan dst_metadata hooks in ingress and egress paths")
Signed-off-by: Alexandre Knecht <knecht.alexandre@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Link: https://patch.msgid.link/20251228020057.2788865-1-knecht.alexandre@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Alexandre Knecht and committed by
Jakub Kicinski
3128df6b d7065436

+7 -4
+7 -4
net/bridge/br_vlan_tunnel.c
··· 189 189 IP_TUNNEL_DECLARE_FLAGS(flags) = { }; 190 190 struct metadata_dst *tunnel_dst; 191 191 __be64 tunnel_id; 192 - int err; 193 192 194 193 if (!vlan) 195 194 return 0; ··· 198 199 return 0; 199 200 200 201 skb_dst_drop(skb); 201 - err = skb_vlan_pop(skb); 202 - if (err) 203 - return err; 202 + /* For 802.1ad (QinQ), skb_vlan_pop() incorrectly moves the C-VLAN 203 + * from payload to hwaccel after clearing S-VLAN. We only need to 204 + * clear the hwaccel S-VLAN; the C-VLAN must stay in payload for 205 + * correct VXLAN encapsulation. This is also correct for 802.1Q 206 + * where no C-VLAN exists in payload. 207 + */ 208 + __vlan_hwaccel_clear_tag(skb); 204 209 205 210 if (BR_INPUT_SKB_CB(skb)->backup_nhid) { 206 211 __set_bit(IP_TUNNEL_KEY_BIT, flags);