| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | eth=`echo $ETH` |
| 4 | port=`echo $PORT` |
| 5 | fixed_wanport=none |
| 6 | |
| 7 | PRODMODE=`uci get cmdline.PROD 2> /dev/null` |
| 8 | [ "$PRODMODE" == "0" ] || exit 0 |
| 9 | |
| 10 | case $eth in |
| 11 | asr_emac) |
| 12 | if [ "$ACTION" = "LINKDW" ]; then |
| 13 | para1=`ps|grep udhcpc|grep eth0` |
| 14 | if [ -z "$para1" ]; then |
| 15 | return 1 |
| 16 | else |
| 17 | ps | grep udhcpc-eth0 | grep -v grep | awk '{print $1}' | xargs kill -9 |
| 18 | fi |
| 19 | |
| 20 | elif [ "$ACTION" = "LINKUP" ]; then |
| 21 | para1=`ps|grep udhcpc|grep eth0` |
| 22 | if [ ! -z "$para1" ]; then |
| 23 | return 1 |
| 24 | else |
| 25 | wantype=`uci get network.autowan.proto 2> /dev/null` |
| 26 | if [ "$wantype" = "dhcp" ]; then |
| 27 | echo "no need to create the udhcpc process again!" > /dev/kmsg |
| 28 | else |
| 29 | udhcpc -p /var/run/udhcpc-eth0.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0 -C & |
| 30 | fi |
| 31 | fi |
| 32 | elif [ "$ACTION" = "DHCPCLIENT" ]; then |
| 33 | if [ "$port" -lt 0 ]; then |
| 34 | ifname=`uci get network.autowan.ifname 2> /dev/null` |
| 35 | if [ -z "$ifname" ]; then |
| 36 | uci set network.lan.ifname="usbnet0 hsicnet0" |
| 37 | uci set network.autowan="interface" |
| 38 | uci set network.autowan.ifname="eth0" |
| 39 | uci set network.autowan.proto="dhcp" |
| 40 | uci set network.autowan.force_link="1" |
| 41 | uci commit network |
| 42 | /etc/init.d/network reload |
| 43 | sleep 1 |
| 44 | fi |
| 45 | elif [ "$port" -ge 0 ]; then |
| 46 | for i in 0 1 2 3 4 |
| 47 | do |
| 48 | if [ "$port" != "$i" ]; then |
| 49 | ports=`echo $ports $i` |
| 50 | fi |
| 51 | done |
| 52 | wanports=`uci get network.@switch_port[1].ports 2> /dev/null` |
| 53 | if [ "$port" != "$wanports" ]; then |
| 54 | uci set network.eth0_1.ports="$ports 5t" |
| 55 | uci set network.eth0_2="switch_vlan" |
| 56 | uci set network.eth0_2.device="eth0" |
| 57 | uci set network.eth0_2.vlan="2" |
| 58 | uci set network.eth0_2.ports="$port 5t" |
| 59 | uci set network.autowan="interface" |
| 60 | uci set network.autowan.ifname="eth0.2" |
| 61 | uci set network.autowan.proto="dhcp" |
| 62 | uci set network.autowan.force_link="1" |
| 63 | uci set network.autowan.mtu=1496 |
| 64 | uci commit network |
| 65 | /etc/init.d/network reload |
| 66 | sleep 1 |
| 67 | uci set network.@switch_port[0].ports="$ports" |
| 68 | switch_port=`uci get network.@switch_port[1] 2> /dev/null` |
| 69 | if [ -z "$switch_port" ]; then |
| 70 | uci add network "switch_port" |
| 71 | fi |
| 72 | uci set network.@switch_port[1].ports="$port" |
| 73 | uci set network.@switch_port[1].pvid="2" |
| 74 | uci commit network |
| 75 | /etc/init.d/network reload |
| 76 | sleep 1 |
| 77 | para1=`ps|grep udhcpc|grep eth0.1` |
| 78 | if [ -z "$para1" ]; then |
| 79 | return 1 |
| 80 | else |
| 81 | ps | grep udhcpc-eth0.1 | grep -v grep | awk '{print $1}' | xargs kill -9 |
| 82 | fi |
| 83 | fi |
| 84 | fi |
| 85 | autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null` |
| 86 | if [ -z "$autowan" ]; then |
| 87 | uci add_list firewall.@zone[1].network=autowan |
| 88 | uci commit firewall |
| 89 | /etc/init.d/firewall reload |
| 90 | sleep 1 |
| 91 | fi |
| 92 | elif [ "$ACTION" = "DHCPSERVER" ]; then |
| 93 | vlan=$port |
| 94 | if [ "$vlan" -lt 0 ]; then |
| 95 | ifname=`uci get network.autowan.ifname 2> /dev/null` |
| 96 | if [ "$ifname" ]; then |
| 97 | uci set network.lan.ifname="usbnet0 hsicnet0 eth0" |
| 98 | uci delete network.autowan |
| 99 | uci commit network |
| 100 | /etc/init.d/network reload |
| 101 | sleep 1 |
| 102 | fi |
| 103 | autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null` |
| 104 | if [ "$autowan" ]; then |
| 105 | uci del_list firewall.@zone[1].network=autowan |
| 106 | uci commit firewall |
| 107 | /etc/init.d/firewall reload |
| 108 | sleep 1 |
| 109 | fi |
| 110 | para1=`ps|grep udhcpc|grep eth0` |
| 111 | if [ -z "$para1" ]; then |
| 112 | return 1 |
| 113 | else |
| 114 | ps | grep udhcpc | grep -v grep | awk '{print $1}' | xargs kill -9 |
| 115 | fi |
| 116 | elif [ "$vlan" -ge 0 ]; then |
| 117 | switch_port=`uci get network.@switch_port[1].pvid 2> /dev/null` |
| 118 | if [ "$vlan" == "$switch_port" ]; then |
| 119 | uci set network.eth0_1.ports="0 1 2 3 4 5t" |
| 120 | uci delete network.autowan |
| 121 | uci delete network.eth0_2 |
| 122 | uci delete network.@switch_port[1] |
| 123 | uci commit network |
| 124 | /etc/init.d/network reload |
| 125 | sleep 1 |
| 126 | uci set network.@switch_port[0].ports="0 1 2 3 4" |
| 127 | uci commit network |
| 128 | /etc/init.d/network reload |
| 129 | sleep 1 |
| 130 | autowan=`uci get firewall.@zone[1].network | grep autowan 2> /dev/null` |
| 131 | if [ "$autowan" ]; then |
| 132 | uci del_list firewall.@zone[1].network=autowan |
| 133 | uci commit firewall |
| 134 | /etc/init.d/firewall reload |
| 135 | sleep 1 |
| 136 | fi |
| 137 | fi |
| 138 | para1=`ps|grep udhcpc|grep eth0` |
| 139 | if [ -z "$para1" ]; then |
| 140 | return 1 |
| 141 | else |
| 142 | ps | grep udhcpc | grep -v grep | awk '{print $1}' | xargs kill -9 |
| 143 | fi |
| 144 | fi |
| 145 | elif [ "$ACTION" = "PHY_CONNECT" ]; then |
| 146 | #for IP175D, set all port to lan vlan 1 by default. |
| 147 | uci set network.lan.ifname="usbnet0 hsicnet0 eth0.1" |
| 148 | uci set network.lan.mtu=1496 |
| 149 | uci set network.eth0="switch" |
| 150 | uci set network.eth0.reset="1" |
| 151 | uci set network.eth0.enable_vlan="1" |
| 152 | uci set network.eth0_1="switch_vlan" |
| 153 | uci set network.eth0_1.device="eth0" |
| 154 | uci set network.eth0_1.vlan="1" |
| 155 | uci set network.eth0_1.ports="0 1 2 3 4 5t" |
| 156 | uci commit network |
| 157 | /etc/init.d/network reload |
| 158 | sleep 1 |
| 159 | switch_port=`uci get network.@switch_port[0] 2> /dev/null` |
| 160 | if [ -z "$switch_port" ]; then |
| 161 | uci add network "switch_port" |
| 162 | fi |
| 163 | uci set network.@switch_port[0].ports="0 1 2 3 4" |
| 164 | uci set network.@switch_port[0].pvid="1" |
| 165 | uci commit network |
| 166 | /etc/init.d/network reload |
| 167 | sleep 1 |
| 168 | elif [ "$ACTION" = "IP175D_LINKDW" ]; then |
| 169 | wanports=`uci get network.@switch_port[1].ports 2> /dev/null` |
| 170 | if [ "$port" == "$wanports" ]; then |
| 171 | echo "no need to kill the udhcpc-eth0.2 process!" > /dev/kmsg |
| 172 | else |
| 173 | para1=`ps|grep udhcpc|grep eth0.1` |
| 174 | if [ -z "$para1" ]; then |
| 175 | return 1 |
| 176 | else |
| 177 | ps | grep udhcpc-eth0.1 | grep -v grep | awk '{print $1}' | xargs kill -9 |
| 178 | fi |
| 179 | fi |
| 180 | elif [ "$ACTION" = "IP175D_LINKUP" ]; then |
| 181 | wanports=`uci get network.@switch_port[1].ports 2> /dev/null` |
| 182 | if [ "$port" == "$wanports" ]; then |
| 183 | echo "no need to create the udhcpc-eth0.2 process!" > /dev/kmsg |
| 184 | else |
| 185 | para1=`ps|grep udhcpc|grep eth0.1` |
| 186 | if [ ! -z "$para1" ]; then |
| 187 | return 1 |
| 188 | else |
| 189 | udhcpc -p /var/run/udhcpc-eth0.1.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0.1 -C & |
| 190 | fi |
| 191 | fi |
| 192 | fi |
| 193 | ;; |
| 194 | jl5106) |
| 195 | if [ "$ACTION" == "JL5106_CONNECT" ]; then |
| 196 | switch=`uci get network.@switch[0] 2> /dev/null` |
| 197 | if [ -z "$switch" ]; then |
| 198 | uci del_list network.lan_dev.ports='eth0' |
| 199 | uci add_list network.lan_dev.ports='eth0.1' |
| 200 | uci set network.eth0_1="switch_vlan" |
| 201 | uci set network.eth0_1.device="switch0" |
| 202 | uci set network.eth0_1.vlan="1" |
| 203 | uci set network.eth0_1.ports="0 1 2 3 4 5t" |
| 204 | uci add network "switch" |
| 205 | uci set network.@switch[0].name="switch0" |
| 206 | uci set network.@switch[0].reset="1" |
| 207 | uci set network.@switch[0].enable_vlan="1" |
| 208 | |
| 209 | for i in 0 1 2 3 4 |
| 210 | do |
| 211 | switch_port=`uci get network.@switch_port[$i] 2> /dev/null` |
| 212 | if [ -z "$switch_port" ]; then |
| 213 | uci add network "switch_port" |
| 214 | fi |
| 215 | uci set network.@switch_port[$i].port=$i |
| 216 | uci set network.@switch_port[$i].pvid="1" |
| 217 | done |
| 218 | uci delete network.eth0_2 2>/dev/null |
| 219 | uci delete network.autowan 2>/dev/null |
| 220 | uci commit network |
| 221 | /etc/init.d/network reload |
| 222 | fi |
| 223 | elif [ "$ACTION" == "JL5106_LINKUP" ]; then |
| 224 | if [ "none" != "$fixed_wanport" ]; then |
| 225 | [ "$port" == "$fixed_wanport" ] || exit 0 |
| 226 | fi |
| 227 | for i in 0 1 2 3 4 |
| 228 | do |
| 229 | if [ "$port" != "$i" ]; then |
| 230 | ports=`echo $ports $i` |
| 231 | fi |
| 232 | done |
| 233 | para=`swconfig dev switch0 vlan 2 get ports | awk '{print $1}'` |
| 234 | if [ -z "$para" ]; then |
| 235 | uci set network.eth0_1.ports="$ports 5t" |
| 236 | uci set network.autowan="interface" |
| 237 | uci set network.autowan.device="eth0.2" |
| 238 | uci set network.autowan.proto="dhcp" |
| 239 | uci set network.eth0_2="switch_vlan" |
| 240 | uci set network.eth0_2.device="switch0" |
| 241 | uci set network.eth0_2.vlan="2" |
| 242 | uci set network.eth0_2.ports="$port 5t" |
| 243 | uci set network.@switch_port[$port].pvid="2" |
| 244 | elif [ "$para" != "$port" ]; then |
| 245 | wan_up=`swconfig dev switch0 port $para get link | awk '{print $2}'` |
| 246 | if [ "link:down" == "$wan_up" ];then |
| 247 | uci set network.eth0_1.ports="$ports 5t" |
| 248 | uci set network.eth0_2.ports="$port 5t" |
| 249 | uci set network.@switch_port[$port].pvid="2" |
| 250 | uci set network.@switch_port[$para].pvid="1" |
| 251 | else |
| 252 | exit 0 |
| 253 | fi |
| 254 | else |
| 255 | exit 0 |
| 256 | fi |
| 257 | uci commit network |
| 258 | /etc/init.d/network reload |
| 259 | ubus wait_for network.interface.autowan |
| 260 | sleep 3 |
| 261 | adapt_wanlan eth0.2 |
| 262 | exit_code=$? |
| 263 | if [ $exit_code -eq 1 ]; then |
| 264 | echo "----hotplug:adapt port $port to wan---" >/dev/kmsg |
| 265 | uci del_list firewall.@zone[1].network=autowan |
| 266 | uci add_list firewall.@zone[1].network=autowan |
| 267 | uci commit firewall |
| 268 | /etc/init.d/firewall reload |
| 269 | else |
| 270 | echo "----hotplug:adapt port $port to lan---" >/dev/kmsg |
| 271 | uci delete network.eth0_2 2>/dev/null |
| 272 | uci delete network.autowan 2>/dev/null |
| 273 | uci set network.eth0_1.ports="0 1 2 3 4 5t" |
| 274 | uci set network.@switch_port[$port].pvid="1" |
| 275 | uci commit network |
| 276 | /etc/init.d/network reload |
| 277 | fi |
| 278 | elif [ "$ACTION" == "JL5106_LINKDW" ]; then |
| 279 | if [ "none" != "$fixed_wanport" ]; then |
| 280 | [ "$port" == "$fixed_wanport" ] || exit 0 |
| 281 | fi |
| 282 | para=`swconfig dev switch0 vlan 2 get ports | awk '{print $1}'` |
| 283 | if [ $port == $para ];then |
| 284 | uci delete network.eth0_2 |
| 285 | uci delete network.autowan |
| 286 | uci set network.eth0_1.ports="0 1 2 3 4 5t" |
| 287 | uci set network.@switch_port[$port].pvid=1 |
| 288 | uci commit network |
| 289 | /etc/init.d/network reload |
| 290 | uci del_list firewall.@zone[1].network=autowan |
| 291 | uci commit firewall |
| 292 | /etc/init.d/firewall reload |
| 293 | fi |
| 294 | fi |
| 295 | ;; |
| 296 | esac |