blob: 3f4330fb9c17c4e152bad2903de5a488d7c3b1b3 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2
3path_sh=`nv get path_sh`
4. $path_sh/global.sh
5
6
7echo "input param is $1 $2 $3"
8echo "Info: wan_ipv6 $1 $2 $3 start" >> $test_log
9
10#Èë²ÎÖÐÓÐc_idÔòÉèÖã¬Ã»ÓÐÔòÖÃÁ㣬ÓÃÓÚÉèÖòßÂÔ·ÓɱíºÅ
11if [ "$3" == "" ]; then
12 c_id="0"
13else
14 c_id=$3
15fi
16def_cid=`nv get default_cid`
17
18is_chinamobile_pd_diff=`nv get pd_chinamobile_enable`
19pd_chinamobile=`nv get pd_chinamobile`
20prefix_len=`nv get pd_len_chinamobile`
21
22b_dhcpv6stateEnabled=`nv get dhcpv6stateEnabled`
23b_dhcpv6statelessEnabled=`nv get dhcpv6statelessEnabled`
24
25############# »ñȡָ¶¨Íø¿ÚµÄÈ«¾Ö±äÁ¿ ############
26get_wan_info()
27{
28 echo "wan_name_info = $1"
29
30 #»ñÈ¡¶ÔÓ¦wan¿ÚµÄip mode
31 wan_mode=`nv get $1"_mode"`
32
33 #»ñÈ¡¶ÔÓ¦µÄÍø¿ÚÃû
34 case $1 in
35 "pswan")
36 wan_if=$pswan_name$2 ;;
37 "usbwan")
38 wan_if=$usbwan_if ;;
39 "ethwan")
40 wan_if=$ethwan_if ;;
41 "wifiwan")
42 wan_if=$wifiwan_if ;;
43 esac
44 mtu=`nv get mtu`
45 ifconfig $wan_if mtu $mtu
46
47 #ÐèÒªÓõ½Ïà¹ØÅäÖÃÎļþ
48 dhcp6s_conf=$path_conf/dhcp6s_$wan_if.conf
49 radvd_conf=$path_conf/radvd_$wan_if.conf
50 radvd_pidfile=$path_tmp/radvd_$wan_if.pid
51 #resolv_conf=$path_conf/resolv_$wan_if.conf
52 ndp_log=$path_conf/ndp_$wan_if.log
53
54 #·ÀdosÏà¹ØÅäÖÃ
55 dosenable=`nv get dosenable`
56 if [ "x$dosenable" != "x0" ]; then
57 if [ "$1" == "pswan" ]; then
58 wan6_prefix=$1$2"_prefix"
59 else
60 wan6_prefix=$1"_prefix"
61 fi
62 echo 1 > /sys/module/fast_common/parameters/lan_dos_enable
63 echo "wan6_prefix_name = $wan6_prefix"
64 fi
65
66 echo "wan_if_info = $wan_if"
67}
68
69#Çå³ýÏàÓ¦µÄslaac½ø³Ì
70slaac_kill()
71{
72 ps > ${path_tmp}/zte_ipv6_slaac.${wan_if}.$$
73 slaac_pid=`awk 'BEGIN{temp1="'"${wan_if}"'";temp2="zte_ipv6_slaac"}{if(index($0,temp1)>0 && index($0,temp2)>0){print $1}}' ${path_tmp}/zte_ipv6_slaac.${wan_if}.$$`
74 rm -f ${path_tmp}/zte_ipv6_slaac.${wan_if}.$$
75 [ -n "$slaac_pid" ] && { kill $slaac_pid; echo "Info: kill slaac $slaac_pid " >> $test_log ; }
76}
77
78linkup_get_wan_addr()
79{
80 echo "wan_name_info = $wan_if"
81
82 #disable the forwarding to send RS and not set the addr when receive ra packet
83 #echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
84 echo 0 > /proc/sys/net/ipv6/conf/$wan_if/accept_ra
85
86 # IPv6ÔÝʱ²»¿¼ÂÇstaticģʽ£¬È罫À´ÓÐÐèÇ󣬲ο¼ipv4ÅäÖÃ
87 # µ±wan_modeΪDHCP£¬»òÕßusbwan¡¢ethwanΪPPP¡¢PPPOEʱ£¬Æô¶¯dhcp6c
88 if [ "$1" == "pswan" ]; then
89
90 if [ "-$wan_mode" == "-dhcp" ]; then
91 ifconfig $wan_if arp 2>>$test_log
92 if [ $? -ne 0 ];then
93 echo "Error: ifconfig $wan_if arp failed." >> $test_log
94 fi
95 fi
96 #call the slaac program to get the prefix addr
97 ifconfig $wan_if up 2>>$test_log
98 if [ $? -ne 0 ];then
99 echo "Error: ifconfig $wan_if up failed." >> $test_log
100 fi
101 prefix_info_temp=`nv get $wan_if"_ipv6_prefix_info"`
102 #Èç¹ûµ±Ç°Ã»ÓÐǰ׺£¬ÔòÖ±½ÓÆô¶¯slaac£¬Èç¹ûµ±Ç°Ç°×ºÒѾ­ÉèÖã¬Ôò˵Ã÷ÒѾ­»ñÈ¡µ½£¬Ö±½ÓÅäÖÃIPµØÖ·¼´¿É
103 if [ -n "$prefix_info_temp" -a "-$prefix_info_temp" != "-::" ]; then
104 ret_code=0
105 else
106 sleep 1
107 interface_id_temp1=`nv get $wan_if"_ipv6_interface_id"`
108 local_ipv6_addr="fe80::"$interface_id_temp1
109 local_ipv6_addr_nv="$wan_if""_local_ipv6_addr"
110 nv set $local_ipv6_addr_nv=$local_ipv6_addr
111 ip -6 addr add $local_ipv6_addr/64 dev $wan_if 2>>$test_log
112 zte_ipv6_slaac -i "$wan_if"
113 ret_code=$?
114 fi
115
116 echo "the program zte_ipv6_slaac return = $ret_code"
117 if [ $ret_code -eq 0 ]; then
118 echo "the zte_ipv6_slaac success"
119 interface_id_temp=`nv get $wan_if"_ipv6_interface_id"`
120 prefix_info_temp=`nv get $wan_if"_ipv6_prefix_info"`
121
122 echo "##############1##########"
123 echo "$interface_id_temp"
124 echo "$prefix_info_temp"
125 echo "##############2##########"
126
127 if [ "x$dosenable" != "x0" ]; then
128 ip6_prefix=`echo "$prefix_info_temp" | awk -F ':' '{printf "0x"$1",0x"$2",0x"$3",0x"$4}'`
129 echo "ip6_prefix1=$ip6_prefix"
130 echo $ip6_prefix > /sys/module/fast_common/parameters/$wan6_prefix
131 fi
132
133
134 wan_addr=$prefix_info_temp$interface_id_temp
135 wan_addr_nv=$wan_if"_ipv6_ip"
136 nv set $wan_addr_nv="$wan_addr"
137 echo "wan_addr = $wan_addr"
138
139 ip -6 addr add $wan_addr/126 dev $wan_if 2>>$test_log
140 if [ $? -ne 0 ];then
141 echo "Error: ip -6 addr add $wan_addr/126 dev $wan_if failed." >> $test_log
142 fi
143
144 killall -9 clatd
145 clatd -i $wan_if -p 1:1:1:123:: &
146
147 if [ "-$c_id" != "-$def_cid" ]; then
148 wan_pri=`nv get $1"_priority"`
149 rt_num=`expr $wan_pri \* 10 + $c_id`
150 default_gw_addr_temp=`nv get $wan_if"_ipv6_gw"`
151 echo "ipv6_wan_default_gw = $default_gw_addr_temp"
152 ip -6 rule add from $wan_addr table $rt_num 2>>$test_log
153 if [ $? -ne 0 ];then
154 echo "Error: ip -6 rule add from $wan_addr table $rt_num failed." >> $test_log
155 fi
156 if [ -n "$default_gw_addr_temp" -a "-$default_gw_addr_temp" != "-::" ] ; then
157 ip -6 route add default via $default_gw_addr_temp dev $wan_if table $rt_num 2>>$test_log
158 if [ $? -ne 0 ];then
159 echo "Error: ip -6 route add default via $default_gw_addr_temp dev $wan_if table $rt_num failed." >> $test_log
160 fi
161 else
162 ip -6 route add default dev $wan_if table $rt_num 2>>$test_log
163 if [ $? -ne 0 ];then
164 echo "Error: ip -6 route add default dev $wan_if table $rt_num failed." >> $test_log
165 fi
166 fi
167 ip -6 route flush cache 2>>$test_log
168 if [ $? -ne 0 ];then
169 echo "Error: ip -6 route flush cache failed." >> $test_log
170 fi
171 #sleep 1
172 fi
173 nv set $wan_if"_ipv6_state"="working"
174 else
175 echo "the zte_ipv6_slaac fail"
176 nv set $wan_if"_ipv6_state"="dead"
177 #exit 1
178 fi
179 else
180 #if [ "-$wan_mode" == "-DHCP" -o "-$wan_mode" == "-PPP" -o "-$wan_mode" == "-PPPOE" ]; then
181 #dhcp6c -dDf -z $wan_if &
182 # ²ÉÓÃPDP¼¤»î·ÖÅäµÄipv6µØÖ·
183 #else
184 #call the slaac program to get the prefix addr
185 ifconfig $wan_if up 2>>$test_log
186 if [ $? -ne 0 ];then
187 echo "Error: ifconfig $wan_if up failed." >> $test_log
188 fi
189 #sleep 1
190 #interface_id_temp1=`nv get $wan_if"_ipv6_interface_id"`
191 interface_id_temp1="0001:0002:0003:0004"
192 nv set $wan_if"_ipv6_interface_id"=$interface_id_temp1
193 local_ipv6_addr="fe80::"$interface_id_temp1
194 local_ipv6_addr_nv="$wan_if""_local_ipv6_addr"
195 nv set $local_ipv6_addr_nv=$local_ipv6_addr
196 ip -6 addr add $local_ipv6_addr/64 dev $wan_if 2>>$test_log
197
198 zte_ipv6_slaac -i "$wan_if"
199 ret_code=$?
200
201 echo "the program zte_ipv6_slaac return = $ret_code"
202 if [ $ret_code -eq 0 ]; then
203 echo "the zte_ipv6_slaac success"
204 #ifconfig $wan_if up 2>>$test_log
205 dhcp6c -dDf -z $wan_if &
206 interface_id_temp=`nv get $wan_if"_ipv6_interface_id"`
207 prefix_info_temp=`nv get $wan_if"_ipv6_prefix_info"`
208 if [ "-$prefix_info_temp" == "-" -o "-$prefix_info_temp" == "-::" ]; then
209 echo "wait dhcp6c get ipv6_prefix"
210 sleep 2
211 prefix_info_temp=`nv get $wan_if"_ipv6_prefix_info"`
212 fi
213
214 echo "##############1##########"
215 echo "$interface_id_temp"
216 echo "$prefix_info_temp"
217 echo "##############2##########"
218 if [ "-$prefix_info_temp" == "-" -o "-$prefix_info_temp" == "-::" ]; then
219 echo "get ipv6_prefix fail"
220 nv set $wan_if"_ipv6_state"="dead"
221 exit 1
222 fi
223 if [ "x$dosenable" != "x0" ]; then
224 ip6_prefix=`echo "$prefix_info_temp" | awk -F ':' '{printf "0x"$1",0x"$2",0x"$3",0x"$4}'`
225 echo "ip6_prefix2=$ip6_prefix"
226 echo $ip6_prefix > /sys/module/fast_common/parameters/$wan6_prefix
227 fi
228
229 wan_addr=$prefix_info_temp$interface_id_temp
230 wan_addr_nv=$wan_if"_ipv6_ip"
231 nv set $wan_addr_nv="$wan_addr"
232 echo "wan_addr = $wan_addr"
233
234 ip -6 addr add $wan_addr/126 dev $wan_if 2>>$test_log
235 if [ $? -ne 0 ];then
236 echo "Error: ip -6 addr add $wan_addr/126 dev $wan_if failed." >> $test_log
237 fi
238
239 killall -9 clatd
240 clatd -i $wan_if -p 1:1:1:123:: &
241 else
242 echo "the zte_ipv6_slaac fail"
243 nv set $wan_if"_ipv6_state"="dead"
244 exit 1
245 fi
246 #fi
247 fi
248}
249
250#############linkdown radvd set############
251linkdown_radvd_set()
252{
253 if [ "-$b_dhcpv6stateEnabled" = "-1" ];then
254 radvd_kill
255 return
256 else
257 sed -i -e s/AdvValidLifetime.*/'AdvValidLifetime 30;'/g $radvd_conf
258 sed -i -e s/AdvPreferredLifetime.*/'AdvPreferredLifetime 1;'/g $radvd_conf
259 fi
260
261 if [ "-$is_chinamobile_pd_diff" = "-1" ] ; then
262 if [ "-$pd_chinamobile" == "-" ] ; then
263 echo "no pd info get"
264 else
265 radvd_kill
266 rm -rf $radvd_pidfile
267 radvd -d 3 -C $radvd_conf -s -p $radvd_pidfile &
268 nv set pd_chinamobile=""
269 nv set pd_len_chinamobile=""
270 radvd_kill
271 fi
272 fi
273
274 radvd_kill
275 rm -rf $radvd_pidfile
276 radvd -d 3 -C $radvd_conf -s -p $radvd_pidfile &
277}
278
279#############linkdown wanaddr route set############
280linkdown_route_set()
281{
282 echo "wan_name_info = $wan_if"
283
284 wan_addr=`nv get $wan_if"_ipv6_ip"`
285 ip -6 addr del $wan_addr/126 dev $wan_if
286
287 local_ipv6_addr_nv="$wan_if""_local_ipv6_addr"
288 local_ipv6_addr=`nv get $local_ipv6_addr_nv`
289 ip -6 addr del $local_ipv6_addr/64 dev $wan_if 2>>$test_log
290 #if [ $? -ne 0 ];then
291 # echo "Error: ip -6 addr del $wan_addr/126 dev $wan_if failed." >> $test_log
292 #fi
293
294 killall clatd
295 sh $path_sh/clat_config.sh down $wan_if
296
297 if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
298 echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
299 ip -6 route del default
300 #if [ $? -ne 0 ];then
301 #echo "Error: ip -6 route del default failed." >> $test_log
302 #fi
303
304 nv set ipv6_br0_addr="::"
305 ipv6_addr_conver $wan_addr "$wan_if"
306 ipv6_br0_addr_tmp=`nv get ipv6_br0_addr`
307 ip -6 addr del $ipv6_br0_addr_tmp/64 dev br0
308 #if [ $? -ne 0 ];then
309 #echo "Error: ip -6 addr del $ipv6_br0_addr_tmp/64 dev br0 failed." >> $test_log
310 #fi
311
312 #ÊÊÅäÒ³ÃæµÈÆäËûµØ·½Ê¹ÓÃÀÏNV
313 nv set ipv6_wan_ipaddr="::"
314
315 def_cid=`nv get default_cid`
316 if [ "-$c_id" == "-$def_cid" ]; then
317 nv set default_cid=""
318 nv set $wan_if"_ipv6_state"="dead"
319 fi
320 else
321 wan_pri=`nv get $1"_priority"`
322 rt_num=`expr $wan_pri \* 10 + $c_id`
323
324 default_gw_addr_temp=`nv get $wan_if"_ipv6_gw"`
325 echo "ipv6_wan_default_gw = $default_gw_addr_temp"
326
327 ip -6 rule del from $wan_addr table $rt_num
328 #if [ $? -ne 0 ];then
329 #echo "Error: ip -6 rule del from $wan_addr table $rt_num failed." >> $test_log
330 #fi
xf.li742dd022023-06-08 01:43:32 -0700331 if [ -n "$default_gw_addr_temp" ] && [ "-$default_gw_addr_temp" != "-::" ] ; then
lh9ed821d2023-04-07 01:36:19 -0700332 ip -6 route del default via $default_gw_addr_temp dev $wan_if table $rt_num
333 #if [ $? -ne 0 ];then
334 #echo "Error: ip -6 route del default via $default_gw_addr_temp dev $wan_if table $rt_num failed." >> $test_log
335 #fi
336 else
337 ip -6 route del default dev $wan_if table $rt_num
338 #if [ $? -ne 0 ];then
339 #echo "Error: ip -6 route del default dev $wan_if table $rt_num failed." >> $test_log
340 #fi
341 fi
342 ip -6 route flush cache 2>>$test_log
343 if [ $? -ne 0 ];then
344 echo "Error: ip -6 route flush cache failed." >> $test_log
345 fi
346
347 nv set $wan_if"_ipv6_state"="dead"
348
349 fi
350
351 echo 0 > /proc/sys/net/ipv6/conf/$wan_if/accept_ra
352
353 #reset wan'nv
354 nv set $wan_if"_ipv6_ip"="::"
355 nv set $wan_if"_ipv6_pridns_auto"="::"
356 nv set $wan_if"_ipv6_secdns_auto"="::"
357 nv set $wan_if"_ipv6_gw"="::"
358 nv set $wan_if"_ipv6_interface_id"="::"
359 nv set $wan_if"_ipv6_prefix_info"="::"
360 nv set $wan_if"_dhcpv6_start"="::"
361 nv set $wan_if"_dhcpv6_end"="::"
362 nv set $wan_if"_radvd_ipv6_dns_servers"="::"
363
364 if [ "x$dosenable" != "x0" ]; then
365 echo 0,0,0,0 > /sys/module/fast_common/parameters/$wan6_prefix
366 fi
367 if [ "$1" == "pswan" ]; then
368 ifconfig $wan_if down 2>>$test_log
369 if [ $? -ne 0 ];then
370 echo "Error: ifconfig $wan_if down failed." >> $test_log
371 fi
372 fi
373}
374
375#Çå³ýÏàÓ¦µÄDHCPv6½ø³Ì
376linkdown_dhcpv6_server_set()
377{
378 dhcp6c_kill
379 dhcp6s_kill
380}
381
382del_default_wan6()
383{
384 default_wan6_name=`nv get default_wan6_name`
385 if [ "-$1" == "-$default_wan6_name" ]; then
386 nv set default_wan6_name=""
387 nv set default_wan6_rel=""
388 fi
389}
390############ipv6 shell entry#################
391get_wan_info $2 $3
392
393case $1 in
394 "linkup")
395 linkup_get_wan_addr $2 $3
396
397 ;;
398
399 "linkdown")
400 if [ "-$2" == "-pswan" ]; then
401 tc_tbf.sh down $def_cid
402 fi
403 linkdown_radvd_set
404 linkdown_dhcpv6_server_set
405 linkdown_route_set $2
406 slaac_kill
407 ndp_kill
408 del_default_wan6 $wan_if
409 ;;
410
411esac
412
413
414if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
415 (router_msg_proxy ipv6 wan_ipv6.sh >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv6 wan_ipv6.sh failed." >> $test_log) &
416fi