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