hnat:refine ppd device setting

This commit is contained in:
padavanonly 2025-04-05 04:20:31 +08:00
parent 8aadb539a5
commit 352a36cbd0

View File

@ -34,10 +34,9 @@
#include "../mtk_eth_reset.h" #include "../mtk_eth_reset.h"
extern atomic_t eth1_in_br; extern atomic_t eth1_in_br;
atomic_t eth0_in_br;
struct net_device *br_dev; struct net_device *br_dev;
struct net_device *eth1_dev; struct net_device *eth1_dev;
struct net_device *eth0_dev;
#define do_ge2ext_fast(dev, skb) \ #define do_ge2ext_fast(dev, skb) \
((IS_LAN(dev) || IS_WAN(dev) || IS_PPD(dev)) && \ ((IS_LAN(dev) || IS_WAN(dev) || IS_PPD(dev)) && \
@ -338,26 +337,12 @@ static void gmac_ppe_fwd_enable(struct net_device *dev)
set_gmac_ppe_fwd(1, 1); set_gmac_ppe_fwd(1, 1);
} }
int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event, void ppd_dev_setting(void)
void *ptr)
{ {
struct net_device *dev; br_dev = __dev_get_by_name(&init_net, "br-lan");
eth1_dev = __dev_get_by_name(&init_net, "eth1");
dev = netdev_notifier_info_to_dev(ptr); atomic_set(&eth1_in_br, 0);
if (br_dev && eth1_dev) {
switch (event) {
case NETDEV_UP:
if (!hnat_priv->guest_en) {
if (!strcmp(dev->name, "ra1") || !strcmp(dev->name, "rax1"))
break;
}
br_dev = __dev_get_by_name(&init_net, "br-lan");
eth1_dev = __dev_get_by_name(&init_net, "eth1");
eth0_dev = __dev_get_by_name(&init_net, "eth0");
atomic_set(&eth1_in_br, 0);
atomic_set(&eth0_in_br, 0);
if (br_dev && eth1_dev) {
struct net_device *dev; struct net_device *dev;
struct list_head *pos; struct list_head *pos;
netdev_for_each_lower_dev(br_dev, dev, pos) { netdev_for_each_lower_dev(br_dev, dev, pos) {
@ -367,29 +352,38 @@ int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
} }
} }
} }
if (br_dev && eth0_dev) {
struct net_device *dev;
struct list_head *pos;
netdev_for_each_lower_dev(br_dev, dev, pos) {
if (dev == eth0_dev) {
atomic_set(&eth0_in_br, 1);
break;
}
}
}
if (atomic_read(&eth1_in_br)){ if (atomic_read(&eth1_in_br)){
printk("eth1 in br-lan"); printk("eth1 in br-lan");
hnat_priv->g_ppdev = __dev_get_by_name(&init_net, "eth1"); } hnat_priv->g_ppdev = __dev_get_by_name(&init_net, "eth1");
else if (atomic_read(&eth0_in_br)){ }
printk("eth0 in br-lan"); else {
printk("eth0 in br-lan");
hnat_priv->g_ppdev = __dev_get_by_name(&init_net, "eth0"); hnat_priv->g_ppdev = __dev_get_by_name(&init_net, "eth0");
} }
}
int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
void *ptr)
{
struct net_device *dev;
dev = netdev_notifier_info_to_dev(ptr);
switch (event) {
case NETDEV_UP:
ppd_dev_setting();
if (!hnat_priv->guest_en) {
if (!strcmp(dev->name, "ra1") || !strcmp(dev->name, "rax1"))
break;
}
gmac_ppe_fwd_enable(dev); gmac_ppe_fwd_enable(dev);
extif_set_dev(dev, 1); extif_set_dev(dev, 1);
break; break;
case NETDEV_GOING_DOWN: case NETDEV_GOING_DOWN:
ppd_dev_setting();
if (!get_wifi_hook_if_index_from_dev(dev)) if (!get_wifi_hook_if_index_from_dev(dev))
extif_put_dev(dev); extif_put_dev(dev);
@ -397,6 +391,7 @@ int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
break; break;
case NETDEV_CHANGE: case NETDEV_CHANGE:
ppd_dev_setting();
/* Clear PPE entries if the slave of bond device physical link down */ /* Clear PPE entries if the slave of bond device physical link down */
if (!netif_is_bond_slave(dev) || if (!netif_is_bond_slave(dev) ||
(!IS_LAN(dev) && !IS_WAN(dev))) (!IS_LAN(dev) && !IS_WAN(dev)))
@ -406,6 +401,7 @@ int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
foe_clear_ethdev_bind_entries(dev); foe_clear_ethdev_bind_entries(dev);
break; break;
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
ppd_dev_setting();
if (hnat_priv->g_ppdev == dev) { if (hnat_priv->g_ppdev == dev) {
hnat_priv->g_ppdev = NULL; hnat_priv->g_ppdev = NULL;
} }
@ -416,6 +412,7 @@ int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
break; break;
case NETDEV_REGISTER: case NETDEV_REGISTER:
ppd_dev_setting();
if (IS_WAN(dev) && !hnat_priv->g_wandev) if (IS_WAN(dev) && !hnat_priv->g_wandev)
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);
@ -425,6 +422,7 @@ int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
hnat_warm_init(); hnat_warm_init();
break; break;
default: default:
ppd_dev_setting();
break; break;
} }