mirror of
https://github.com/padavanonly/immortalwrt-mt798x.git
synced 2025-12-17 01:05:54 +00:00
mtk hnat:add spin lock to prevent multicore racing
This commit is contained in:
parent
73cdea2db0
commit
96d6459965
@ -386,6 +386,8 @@ static int hnat_hw_init(u32 ppe_id)
|
|||||||
hnat_priv->g_wandev = dev_get_by_name(&init_net, hnat_priv->wan);
|
hnat_priv->g_wandev = dev_get_by_name(&init_net, hnat_priv->wan);
|
||||||
|
|
||||||
dev_info(hnat_priv->dev, "PPE%d hwnat start\n", ppe_id);
|
dev_info(hnat_priv->dev, "PPE%d hwnat start\n", ppe_id);
|
||||||
|
|
||||||
|
spin_lock_init(&hnat_priv->entry_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -697,6 +697,7 @@ struct mtk_hnat {
|
|||||||
bool guest_en;
|
bool guest_en;
|
||||||
bool dscp_en;
|
bool dscp_en;
|
||||||
bool macvlan_support;
|
bool macvlan_support;
|
||||||
|
spinlock_t entry_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct extdev_entry {
|
struct extdev_entry {
|
||||||
|
|||||||
@ -1897,11 +1897,17 @@ int mtk_sw_nat_hook_tx(struct sk_buff *skb, int gmac_no)
|
|||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
|
||||||
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
|
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
|
||||||
|
spin_lock(&hnat_priv->entry_lock);
|
||||||
|
|
||||||
if (entry_hnat_is_bound(entry))
|
if (entry_hnat_is_bound(entry))
|
||||||
|
{spin_unlock(&hnat_priv->entry_lock);
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
if (skb_hnat_reason(skb) != HIT_UNBIND_RATE_REACH)
|
if (skb_hnat_reason(skb) != HIT_UNBIND_RATE_REACH)
|
||||||
|
{spin_unlock(&hnat_priv->entry_lock);
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
eth = eth_hdr(skb);
|
eth = eth_hdr(skb);
|
||||||
memcpy(&bfib1_tx, &entry->bfib1, sizeof(entry->bfib1));
|
memcpy(&bfib1_tx, &entry->bfib1, sizeof(entry->bfib1));
|
||||||
@ -1909,7 +1915,9 @@ int mtk_sw_nat_hook_tx(struct sk_buff *skb, int gmac_no)
|
|||||||
/*not bind multicast if PPE mcast not enable*/
|
/*not bind multicast if PPE mcast not enable*/
|
||||||
if (!hnat_priv->data->mcast) {
|
if (!hnat_priv->data->mcast) {
|
||||||
if (is_multicast_ether_addr(eth->h_dest))
|
if (is_multicast_ether_addr(eth->h_dest))
|
||||||
|
{spin_unlock(&hnat_priv->entry_lock);
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_IPV4_GRP(entry))
|
if (IS_IPV4_GRP(entry))
|
||||||
entry->ipv4_hnapt.iblk2.mcast = 0;
|
entry->ipv4_hnapt.iblk2.mcast = 0;
|
||||||
@ -2034,7 +2042,7 @@ int mtk_sw_nat_hook_tx(struct sk_buff *skb, int gmac_no)
|
|||||||
bfib1_tx.state = BIND;
|
bfib1_tx.state = BIND;
|
||||||
wmb();
|
wmb();
|
||||||
memcpy(&entry->bfib1, &bfib1_tx, sizeof(bfib1_tx));
|
memcpy(&entry->bfib1, &bfib1_tx, sizeof(bfib1_tx));
|
||||||
|
spin_unlock(&hnat_priv->entry_lock);
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2242,8 +2250,9 @@ static unsigned int mtk_hnat_nf_post_routing(
|
|||||||
|
|
||||||
if (fn && fn(skb, arp_dev, &hw_path))
|
if (fn && fn(skb, arp_dev, &hw_path))
|
||||||
break;
|
break;
|
||||||
|
spin_lock(&hnat_priv->entry_lock);
|
||||||
skb_to_hnat_info(skb, out, entry, &hw_path);
|
skb_to_hnat_info(skb, out, entry, &hw_path);
|
||||||
|
spin_unlock(&hnat_priv->entry_lock);
|
||||||
break;
|
break;
|
||||||
case HIT_BIND_KEEPALIVE_DUP_OLD_HDR:
|
case HIT_BIND_KEEPALIVE_DUP_OLD_HDR:
|
||||||
if (fn && !mtk_hnat_accel_type(skb))
|
if (fn && !mtk_hnat_accel_type(skb))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user