blob: e4463a263279e4060b4705b276006add18e3c9ed [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2#usg: wan_ipv4 linkup pswan
3
4path_sh=`nv get path_sh`
5. $path_sh/global.sh
6
7#Èë²ÎÖÐÓÐc_idÔòÉèÖã¬Ã»ÓÐÔòÖÃÁ㣬ÓÃÓÚÉèÖòßÂÔ·ÓɱíºÅ
8if [ "-$3" == "-" ]; then
9 c_id="0"
10else
11 c_id=$3
12fi
13def_cid=`nv get default_cid`
14
15#»ñÈ¡ÍøÂçÉ豸Ãû
16get_wan_if()
17{
18 case $1 in
19 "pswan")
20 wan_if="$pswan_name"$2 ;;
21 "ethwan")
22 wan_if=$ethwan_if ;;
23 "wifiwan")
24 wan_if=$wifiwan_if ;;
25 esac
26
xf.li7ccf8372024-03-07 00:08:02 -080027 ra_mtu_enable=`nv get ra_mtu_enable`
28 if ["$ra_mtu_enable" != "1" -o $1 != "pswan"]; then
29 mtu=`nv get mtu`
30 ifconfig $wan_if mtu $mtu
31 fi
lh9ed821d2023-04-07 01:36:19 -070032}
33#ÉèÖù¤×÷״̬ ÕýÔÚÁ¬½Ó£ºconnect ÒÑÁ¬½Ó£ºworking ÒѶϿª£ºdead
34state_set()
35{
36 if [ "-$wan_name" == "-wifiwan" ]; then
37 nv set wifi_state="working"
38 elif [ "-$wan_name" == "-ethwan" ]; then
39 nv set rj45_state="working"
40 fi
41}
42#¸ù¾ÝÍø¿ÚÊÇ·ñÓÃÓÚÆÕͨÉÏÍâÍø£¬È·¶¨ÊÇ·ñÐèÒª·¢ÏûÏ¢¸øzte_router
43msg_zte_router()
44{
45 if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
xf.liaa4d92f2023-09-13 00:18:58 -070046 (router_msg_proxy ipv4 $c_id >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv4 wan_ipv4.sh up failed." >> $test_log) &
47 fi
48}
49
50msg_zte_router_down()
51{
52 if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
53 (router_msg_proxy ipv4 0 >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv4 wan_ipv4.sh down failed." >> $test_log) &
lh9ed821d2023-04-07 01:36:19 -070054 fi
55}
56
57linkup()
58{
59 #$1 :pswan / usbwan / ethwan / wifiwan
60 wan_name=$1
61 wan_mode=`nv get $wan_name"_mode"`
62
63 #»ñÈ¡wan_if±äÁ¿
64 get_wan_if $1 $2
65
66 if [ "-$wan_mode" == "-static" ]; then
67 wan_ip=`nv get "static_"$wan_name"_ip"`
68 wan_gw=`nv get "static_"$wan_name"_gw"`
69 wan_pridns=`nv get "static_"$wan_name"_pridns"`
70 wan_secdns=`nv get "static_"$wan_name"_secdns"`
71 wan_nm=`nv get "static_"$wan_name"_nm"`
72 if [ "-$wan_name" != "-wifiwan" ]; then
73 ifconfig $wan_if down 2>>$test_log
74 if [ $? -ne 0 ];then
75 echo "Error: ifconfig $wan_if down failed." >> $test_log
76 fi
77 ifconfig $wan_if $wan_ip up 2>>$test_log
78 if [ $? -ne 0 ];then
79 echo "Error: ifconfig $wan_if $wan_ip up failed." >> $test_log
80 fi
81 fi
82 if [ "-$wan_name" == "-ethwan" ]; then
83 nv set eth_curmode="static"
84 #rj45¾²Ì¬Á¬½Ó£¬¹Ø±Õ³¬Ê±¼ÆÊ±Æ÷
85 (router_msg_proxy del_timer ethwan >> $test_log 2>&1 || echo "Error: router_msg_proxy del_timer failed." >> $test_log) &
86 fi
87
88 #ÉèÖÃÍøÂçÉ豸״̬±ê־Ϊworking
89 state_set
90 #set ip¡¢gw¡¢dns to nv
91 nv set $wan_if"_ip"=$wan_ip
92 nv set $wan_if"_gw"=$wan_gw
93 nv set $wan_if"_pridns"=$wan_pridns
94 nv set $wan_if"_secdns"=$wan_secdns
95
96 wan_pri=`nv get $1"_priority"`
97 rt_num=`expr $wan_pri \* 10 + $c_id`
98 ip rule add from $wan_ip table $rt_num 2>>$test_log
99 if [ $? -ne 0 ];then
100 echo "Error: ip rule add from $wan_ip table $rt_num failed." >> $test_log
101 fi
102 ip route add default via $wan_gw table $rt_num 2>>$test_log
103 if [ $? -ne 0 ];then
104 echo "Error: ip route add default via $wan_gw table $rt_num failed." >> $test_log
105 fi
106 ip route flush cache 2>>$test_log
107 if [ $? -ne 0 ];then
108 echo "Error: ip route flush cache failed." >> $test_log
109 fi
110
111 #in this proxy ,we send msg to zte_mainctrl
112 msg_zte_router
113
114 # pswan PDP
115 elif [ "-$wan_mode" == "-pdp" ]; then
116 pswan_ip=`nv get $wan_if"_ip"`
117 pswan_gw=`nv get $wan_if"_gw"`
118 pswan_pridns=`nv get $wan_if"_pridns"`
119 pswan_secdns=`nv get $wan_if"_secdns"`
120 pswan_nm=`nv get $wan_if"_nm"`
121
xf.li7ccf8372024-03-07 00:08:02 -0800122#xf.li@20240306 modify for [Bugfix][T106BUG-469]Fix the bug of probability datacall fail start
xf.lib5d48992024-01-24 23:56:18 -0800123# #ifconfig $wan_if down 2>>$test_log
124# ifconfig $wan_if $pswan_ip netmask 255.255.255.0 up 2>>$test_log
125# if [ $? -ne 0 ];then
126# echo "Error: ifconfig $wan_if $pswan_ip up failed." >> $test_log
127# fi
xf.li7ccf8372024-03-07 00:08:02 -0800128#xf.li@20240306 modify for [Bugfix][T106BUG-469]Fix the bug of probability datacall fail end
lh9ed821d2023-04-07 01:36:19 -0700129
130 pswan_pri=`nv get pswan_priority`
131 rt_num=`expr $pswan_pri \* 10 + $c_id`
132 ip rule add from $pswan_ip table $rt_num 2>>$test_log
133 if [ $? -ne 0 ];then
134 echo "Error: ip rule add from $pswan_ip table $rt_num failed." >> $test_log
135 fi
136 ip route add default via $pswan_gw table $rt_num 2>>$test_log
137 if [ $? -ne 0 ];then
138 echo "Error: ip route add default via $pswan_gw table $rt_num failed." >> $test_log
139 fi
140 ip route flush cache 2>>$test_log
141 if [ $? -ne 0 ];then
142 echo "Error: ip route flush cache failed." >> $test_log
143 fi
144
145 msg_zte_router
146
147 elif [ "-$wan_mode" == "-auto" ]; then
148 pppoe_user=`nv get pppoe_username`
149 pppoe_pass=`nv get pppoe_cc`
150 udhcpc_kill
151 pppoe_kill
152
153 if [ "-$wan_name" == "-ethwan" ]; then
154 nv set eth_curmode=""
155 fi
156 if [ "-$wan_name" != "-wifiwan" ]; then
157 ifconfig $wan_if down 2>>$test_log
158 if [ $? -ne 0 ];then
159 echo "Error: ifconfig $wan_if down failed." >> $test_log
160 fi
161 ifconfig $wan_if up 2>>$test_log
162 if [ $? -ne 0 ];then
163 echo "Error: ifconfig $wan_if up failed." >> $test_log
164 fi
165 fi
166
167 if [ "-${pppoe_user}" = "-" -a "-${pppoe_pass}" = "-" ];then
168 echo "auto wan_mode: pppoe_user is ${pppoe_user}, pppoe_pass is ${pppoe_pass}, so start dhcp client. " >> $test_log
169 udhcpc -i $wan_if -s $path_sh/udhcpc.sh &
170 else
171 sh $path_sh/pppoe_dail.sh connect
172 fi
173
174 elif [ "-$wan_mode" == "-dhcp" ]; then
175 udhcpc_kill
176 pppoe_kill
177
178 if [ "-$wan_name" == "-pswan" ]; then
179 ifconfig $wan_if arp 2>>$test_log
180 if [ $? -ne 0 ];then
181 echo "Error: ifconfig $wan_if arp failed." >> $test_log
182 fi
183 fi
184
185 if [ "-$wan_name" == "-ethwan" ]; then
186 nv set eth_curmode="dhcp"
187 fi
188
189 if [ "-$wan_name" != "-wifiwan" ]; then
190 ifconfig $wan_if down 2>>$test_log
191 if [ $? -ne 0 ];then
192 echo "Error: ifconfig $wan_if down failed." >> $test_log
193 fi
194 ifconfig $wan_if up 2>>$test_log
195 if [ $? -ne 0 ];then
196 echo "Error: ifconfig $wan_if up failed." >> $test_log
197 fi
198 fi
199 udhcpc -i $wan_if -s $path_sh/udhcpc.sh &
200
201 elif [ "-$wan_mode" == "-pppoe" ]; then
202 udhcpc_kill
203 pppoe_kill
204
205 if [ "-$wan_name" == "-ethwan" ]; then
206 nv set eth_curmode="pppoe"
207 fi
208
209 if [ "-$wan_name" != "-wifiwan" ]; then
210 ifconfig $wan_if down 2>>$test_log
211 if [ $? -ne 0 ];then
212 echo "Error: ifconfig $wan_if down failed." >> $test_log
213 fi
214 ifconfig $wan_if up 2>>$test_log
215 if [ $? -ne 0 ];then
216 echo "Error: ifconfig $wan_if up failed." >> $test_log
217 fi
218 fi
219 sh $path_sh/pppoe_dail.sh connect
220 fi
221
222}
223
224del_default_wan()
225{
226 default_wan_name=`nv get default_wan_name`
227 if [ "$1" == "$default_wan_name" ]; then
228 nv set default_wan_name=""
229 nv set default_wan_rel=""
230 fi
231}
232
233linkdown()
234{
235 wan_name=$1
236 get_wan_if $1 $2
237
238 udhcpc_kill
239 pppoe_kill
240
xf.lif1aed282024-02-06 00:31:51 -0800241 #if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
242 #echo 0 > /proc/sys/net/ipv4/ip_forward
243 #fi
xf.li64568c02024-02-27 18:35:44 -0800244 #xf.li@20240228 delete for T106BUG-520 start
245 #ifconfig $wan_if 0.0.0.0 2>>$test_log
246 #xf.li@20240228 delete for T106BUG-520 end
lh9ed821d2023-04-07 01:36:19 -0700247 if [ $? -ne 0 ];then
248 echo "Error: ifconfig $wan_if 0.0.0.0 failed." >> $test_log
249 fi
250 if [ "$wan_name" == "wifiwan" ]; then
251 echo $wan_if > /proc/net/dev_down
252 else
253 ifconfig $wan_if down 2>>$test_log
254 if [ $? -ne 0 ];then
255 echo "Error: ifconfig $wan_if down failed." >> $test_log
256 fi
257 fi
258 wan_ip=`nv get $wan_if"_ip"`
259 wan_gw=`nv get $wan_if"_gw"`
260
261 route del default gw $wan_gw dev $wan_if
262 #if [ $? -ne 0 ];then
263 # echo "Error: route del default gw $wan_gw dev $wan_if failed." >> $test_log
264 #fi
265
266 #del policy router
267 wan_pri=`nv get $1"_priority"`
268 rt_num=`expr $wan_pri \* 10 + $c_id`
269 ip rule del from $wan_ip table $rt_num
270 #if [ $? -ne 0 ];then
271 # echo "Error: ip rule del from $wan_ip table $rt_num failed." >> $test_log
272 #fi
273 ip route del default via $wan_gw table $rt_num
274 #if [ $? -ne 0 ];then
275 # echo "Error: ip route del default via $wan_gw table $rt_num failed." >> $test_log
276 #fi
277
278 #wan_ipaddÐèÒªÊÊÅä
279 if [ "$wan_if" == "$defwan_if" ]; then
280 nv set wan_ipaddr=""
281 fi
282 nv set $wan_if"_ip"=0.0.0.0
283 nv set $wan_if"_nm"=0.0.0.0
284 nv set $wan_if"_gw"=0.0.0.0
285 nv set $wan_if"_pridns"=0.0.0.0
286 nv set $wan_if"_secdns"=0.0.0.0
287 pdp_type=`nv get "pdp_act_type"$def_cid`
288 if [ "$2" == "$def_cid" -a "-$pdp_type" != "-IPv4v6" ]; then
289 nv set default_cid=""
290 fi
291 del_default_wan $wan_if
xf.liaa4d92f2023-09-13 00:18:58 -0700292 msg_zte_router_down
lh9ed821d2023-04-07 01:36:19 -0700293
294}
295
296echo "Info: wan_ipv4.sh $1 $2 $3 start" >> $test_log
297if [ "$1" == "linkup" ]; then
298 linkup $2 $3
299
300elif [ "$1" == "linkdown" ]; then
301 if [ "-$2" == "-pswan" ]; then
302 tc_tbf.sh down $def_cid
303 fi
304 linkdown $2 $3
xf.lib5d48992024-01-24 23:56:18 -0800305fi