blob: f8cae7b3fec4296c9d27036085236f7420561896 [file] [log] [blame]
#!/bin/sh
eth=`echo $ETH`
port=`echo $PORT`
fixed_wanport=none
PRODMODE=`uci get cmdline.PROD 2> /dev/null`
[ "$PRODMODE" == "0" ] || exit 0
case $eth in
asr_emac)
if [ "$ACTION" = "LINKDW" ]; then
para1=`ps|grep udhcpc|grep eth0`
if [ -z "$para1" ]; then
return 1
else
ps | grep udhcpc-eth0 | grep -v grep | awk '{print $1}' | xargs kill -9
fi
elif [ "$ACTION" = "LINKUP" ]; then
para1=`ps|grep udhcpc|grep eth0`
if [ ! -z "$para1" ]; then
return 1
else
wantype=`uci get network.autowan.proto 2> /dev/null`
if [ "$wantype" = "dhcp" ]; then
echo "no need to create the udhcpc process again!" > /dev/kmsg
else
udhcpc -p /var/run/udhcpc-eth0.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0 -C &
fi
fi
elif [ "$ACTION" = "DHCPCLIENT" ]; then
if [ "$port" -lt 0 ]; then
ifname=`uci get network.autowan.ifname 2> /dev/null`
if [ -z "$ifname" ]; then
uci set network.lan.ifname="usbnet0 hsicnet0"
uci set network.autowan="interface"
uci set network.autowan.ifname="eth0"
uci set network.autowan.proto="dhcp"
uci set network.autowan.force_link="1"
uci commit network
/etc/init.d/network reload
sleep 1
fi
elif [ "$port" -ge 0 ]; then
for i in 0 1 2 3 4
do
if [ "$port" != "$i" ]; then
ports=`echo $ports $i`
fi
done
wanports=`uci get network.@switch_port[1].ports 2> /dev/null`
if [ "$port" != "$wanports" ]; then
uci set network.eth0_1.ports="$ports 5t"
uci set network.eth0_2="switch_vlan"
uci set network.eth0_2.device="eth0"
uci set network.eth0_2.vlan="2"
uci set network.eth0_2.ports="$port 5t"
uci set network.autowan="interface"
uci set network.autowan.ifname="eth0.2"
uci set network.autowan.proto="dhcp"
uci set network.autowan.force_link="1"
uci set network.autowan.mtu=1496
uci commit network
/etc/init.d/network reload
sleep 1
uci set network.@switch_port[0].ports="$ports"
switch_port=`uci get network.@switch_port[1] 2> /dev/null`
if [ -z "$switch_port" ]; then
uci add network "switch_port"
fi
uci set network.@switch_port[1].ports="$port"
uci set network.@switch_port[1].pvid="2"
uci commit network
/etc/init.d/network reload
sleep 1
para1=`ps|grep udhcpc|grep eth0.1`
if [ -z "$para1" ]; then
return 1
else
ps | grep udhcpc-eth0.1 | grep -v grep | awk '{print $1}' | xargs kill -9
fi
fi
fi
autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null`
if [ -z "$autowan" ]; then
uci add_list firewall.@zone[1].network=autowan
uci commit firewall
/etc/init.d/firewall reload
sleep 1
fi
elif [ "$ACTION" = "DHCPSERVER" ]; then
vlan=$port
if [ "$vlan" -lt 0 ]; then
ifname=`uci get network.autowan.ifname 2> /dev/null`
if [ "$ifname" ]; then
uci set network.lan.ifname="usbnet0 hsicnet0 eth0"
uci delete network.autowan
uci commit network
/etc/init.d/network reload
sleep 1
fi
autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null`
if [ "$autowan" ]; then
uci del_list firewall.@zone[1].network=autowan
uci commit firewall
/etc/init.d/firewall reload
sleep 1
fi
para1=`ps|grep udhcpc|grep eth0`
if [ -z "$para1" ]; then
return 1
else
ps | grep udhcpc | grep -v grep | awk '{print $1}' | xargs kill -9
fi
elif [ "$vlan" -ge 0 ]; then
switch_port=`uci get network.@switch_port[1].pvid 2> /dev/null`
if [ "$vlan" == "$switch_port" ]; then
uci set network.eth0_1.ports="0 1 2 3 4 5t"
uci delete network.autowan
uci delete network.eth0_2
uci delete network.@switch_port[1]
uci commit network
/etc/init.d/network reload
sleep 1
uci set network.@switch_port[0].ports="0 1 2 3 4"
uci commit network
/etc/init.d/network reload
sleep 1
autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null`
if [ "$autowan" ]; then
uci del_list firewall.@zone[1].network=autowan
uci commit firewall
/etc/init.d/firewall reload
sleep 1
fi
fi
para1=`ps|grep udhcpc|grep eth0`
if [ -z "$para1" ]; then
return 1
else
ps | grep udhcpc | grep -v grep | awk '{print $1}' | xargs kill -9
fi
fi
elif [ "$ACTION" = "PHY_CONNECT" ]; then
#for IP175D, set all port to lan vlan 1 by default.
uci set network.lan.ifname="usbnet0 hsicnet0 eth0.1"
uci set network.lan.mtu=1496
uci set network.eth0="switch"
uci set network.eth0.reset="1"
uci set network.eth0.enable_vlan="1"
uci set network.eth0_1="switch_vlan"
uci set network.eth0_1.device="eth0"
uci set network.eth0_1.vlan="1"
uci set network.eth0_1.ports="0 1 2 3 4 5t"
uci commit network
/etc/init.d/network reload
sleep 1
switch_port=`uci get network.@switch_port[0] 2> /dev/null`
if [ -z "$switch_port" ]; then
uci add network "switch_port"
fi
uci set network.@switch_port[0].ports="0 1 2 3 4"
uci set network.@switch_port[0].pvid="1"
uci commit network
/etc/init.d/network reload
sleep 1
elif [ "$ACTION" = "IP175D_LINKDW" ]; then
wanports=`uci get network.@switch_port[1].ports 2> /dev/null`
if [ "$port" == "$wanports" ]; then
echo "no need to kill the udhcpc-eth0.2 process!" > /dev/kmsg
else
para1=`ps|grep udhcpc|grep eth0.1`
if [ -z "$para1" ]; then
return 1
else
ps | grep udhcpc-eth0.1 | grep -v grep | awk '{print $1}' | xargs kill -9
fi
fi
elif [ "$ACTION" = "IP175D_LINKUP" ]; then
wanports=`uci get network.@switch_port[1].ports 2> /dev/null`
if [ "$port" == "$wanports" ]; then
echo "no need to create the udhcpc-eth0.2 process!" > /dev/kmsg
else
para1=`ps|grep udhcpc|grep eth0.1`
if [ ! -z "$para1" ]; then
return 1
else
udhcpc -p /var/run/udhcpc-eth0.1.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0.1 -C &
fi
fi
fi
;;
jl5106)
if [ "$ACTION" == "JL5106_CONNECT" ]; then
switch=`uci get network.@switch[0] 2> /dev/null`
if [ -z "$switch" ]; then
uci del_list network.lan_dev.ports='eth0'
uci add_list network.lan_dev.ports='eth0.1'
uci set network.eth0_1="switch_vlan"
uci set network.eth0_1.device="switch0"
uci set network.eth0_1.vlan="1"
uci set network.eth0_1.ports="0 1 2 3 4 5t"
uci add network "switch"
uci set network.@switch[0].name="switch0"
uci set network.@switch[0].reset="1"
uci set network.@switch[0].enable_vlan="1"
for i in 0 1 2 3 4
do
switch_port=`uci get network.@switch_port[$i] 2> /dev/null`
if [ -z "$switch_port" ]; then
uci add network "switch_port"
fi
uci set network.@switch_port[$i].port=$i
uci set network.@switch_port[$i].pvid="1"
done
uci delete network.eth0_2 2>/dev/null
uci delete network.autowan 2>/dev/null
uci commit network
/etc/init.d/network reload
fi
elif [ "$ACTION" == "JL5106_LINKUP" ]; then
if [ "none" != "$fixed_wanport" ]; then
[ "$port" == "$fixed_wanport" ] || exit 0
fi
for i in 0 1 2 3 4
do
if [ "$port" != "$i" ]; then
ports=`echo $ports $i`
fi
done
para=`swconfig dev switch0 vlan 2 get ports | awk '{print $1}'`
if [ -z "$para" ]; then
uci set network.eth0_1.ports="$ports 5t"
uci set network.autowan="interface"
uci set network.autowan.device="eth0.2"
uci set network.autowan.proto="dhcp"
uci set network.eth0_2="switch_vlan"
uci set network.eth0_2.device="switch0"
uci set network.eth0_2.vlan="2"
uci set network.eth0_2.ports="$port 5t"
uci set network.@switch_port[$port].pvid="2"
elif [ "$para" != "$port" ]; then
wan_up=`swconfig dev switch0 port $para get link | awk '{print $2}'`
if [ "link:down" == "$wan_up" ];then
uci set network.eth0_1.ports="$ports 5t"
uci set network.eth0_2.ports="$port 5t"
uci set network.@switch_port[$port].pvid="2"
uci set network.@switch_port[$para].pvid="1"
else
exit 0
fi
else
exit 0
fi
uci commit network
/etc/init.d/network reload
ubus wait_for network.interface.autowan
sleep 3
adapt_wanlan eth0.2
exit_code=$?
if [ $exit_code -eq 1 ]; then
echo "----hotplug:adapt port $port to wan---" >/dev/kmsg
uci del_list firewall.@zone[1].network=autowan
uci add_list firewall.@zone[1].network=autowan
uci commit firewall
/etc/init.d/firewall reload
else
echo "----hotplug:adapt port $port to lan---" >/dev/kmsg
uci delete network.eth0_2 2>/dev/null
uci delete network.autowan 2>/dev/null
uci set network.eth0_1.ports="0 1 2 3 4 5t"
uci set network.@switch_port[$port].pvid="1"
uci commit network
/etc/init.d/network reload
fi
elif [ "$ACTION" == "JL5106_LINKDW" ]; then
if [ "none" != "$fixed_wanport" ]; then
[ "$port" == "$fixed_wanport" ] || exit 0
fi
para=`swconfig dev switch0 vlan 2 get ports | awk '{print $1}'`
if [ $port == $para ];then
uci delete network.eth0_2
uci delete network.autowan
uci set network.eth0_1.ports="0 1 2 3 4 5t"
uci set network.@switch_port[$port].pvid=1
uci commit network
/etc/init.d/network reload
uci del_list firewall.@zone[1].network=autowan
uci commit firewall
/etc/init.d/firewall reload
fi
fi
;;
esac