[][kernel][common][hnat][Fix the conditions for binding VLAN to HNAT]
[Description]
Fix the conditions for binding VLAN to HNAT.
Whether egress packets carries vlan depends on skb ->vlan_present.
The previous code will fail when encountering the following situation:
PC1->eth1.45-->lan-->PC2.
PC1 send packets with vlan 45,
disable HNAT, PC2 capture packets without vlan.
enable HNAT, PC2 capture packets with vlan.
This patch fix it.
[Release-log]
N/A
Change-Id: Iaa0916680733eda810b37abea2d0bd7201932cfd
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6879837
diff --git a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
index 9c68a54..18c0324 100644
--- a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
+++ b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
@@ -1230,15 +1230,16 @@
entry.ipv4_hnapt.vlan1 = hw_path->vlan_id;
- if (skb->vlan_tci && FROM_GE_WAN(skb) &&
- IS_LAN_GRP(dev)) {
+ if (skb_vlan_tag_present(skb)) {
entry.bfib1.vlan_layer += 1;
if (entry.ipv4_hnapt.vlan1)
- entry.ipv4_hnapt.vlan2 = (skb->vlan_tci & VLAN_VID_MASK);
+ entry.ipv4_hnapt.vlan2 =
+ skb->vlan_tci;
else
- entry.ipv4_hnapt.vlan1 = (skb->vlan_tci & VLAN_VID_MASK);
- }
+ entry.ipv4_hnapt.vlan1 =
+ skb->vlan_tci;
+ }
entry.ipv4_hnapt.sip = foe->ipv4_hnapt.sip;
entry.ipv4_hnapt.dip = foe->ipv4_hnapt.dip;
@@ -1283,14 +1284,15 @@
entry.ipv6_5t_route.vlan1 = hw_path->vlan_id;
- if (skb->vlan_tci && FROM_GE_WAN(skb) &&
- IS_LAN_GRP(dev)) {
+ if (skb_vlan_tag_present(skb)) {
entry.bfib1.vlan_layer += 1;
if (entry.ipv6_5t_route.vlan1)
- entry.ipv6_5t_route.vlan2 = (skb->vlan_tci & VLAN_VID_MASK);
+ entry.ipv6_5t_route.vlan2 =
+ skb->vlan_tci;
else
- entry.ipv6_5t_route.vlan1 = (skb->vlan_tci & VLAN_VID_MASK);
+ entry.ipv6_5t_route.vlan1 =
+ skb->vlan_tci;
}
if (hnat_priv->data->per_flow_accounting)