yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | path_sh=`nv get path_sh` |
| 4 | . $path_sh/global.sh |
| 5 | |
| 6 | |
| 7 | echo "input param is $1 $2 $3" |
| 8 | echo "Info: wan_ipv6 $1 $2 $3 start" >> $test_log |
| 9 | |
| 10 | #Èë²ÎÖÐÓÐc_idÔòÉèÖã¬Ã»ÓÐÔòÖÃÁ㣬ÓÃÓÚÉèÖòßÂÔ·ÓɱíºÅ |
| 11 | if [ "$3" == "" ]; then |
| 12 | c_id="0" |
| 13 | else |
| 14 | c_id=$3 |
| 15 | fi |
| 16 | def_cid=`nv get default_cid` |
| 17 | |
| 18 | is_chinamobile_pd_diff=`nv get pd_chinamobile_enable` |
| 19 | pd_chinamobile=`nv get pd_chinamobile` |
| 20 | prefix_len=`nv get pd_len_chinamobile` |
| 21 | |
| 22 | b_dhcpv6stateEnabled=`nv get dhcpv6stateEnabled` |
| 23 | b_dhcpv6statelessEnabled=`nv get dhcpv6statelessEnabled` |
| 24 | |
| 25 | ############# »ñȡָ¶¨Íø¿ÚµÄÈ«¾Ö±äÁ¿ ############ |
| 26 | get_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½ø³Ì |
| 70 | slaac_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 | |
| 78 | linkup_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############ |
| 251 | linkdown_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############ |
| 280 | linkdown_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 | ip route del default |
| 301 | killall clatd |
| 302 | iptables -t nat -D POSTROUTING -o v4-$wan_if -j MASQUERADE |
| 303 | #if [ $? -ne 0 ];then |
| 304 | #echo "Error: ip -6 route del default failed." >> $test_log |
| 305 | #fi |
| 306 | |
| 307 | nv set ipv6_br0_addr="::" |
| 308 | ipv6_addr_conver $wan_addr "$wan_if" |
| 309 | ipv6_br0_addr_tmp=`nv get ipv6_br0_addr` |
| 310 | ip -6 addr del $ipv6_br0_addr_tmp/64 dev br0 |
| 311 | #if [ $? -ne 0 ];then |
| 312 | #echo "Error: ip -6 addr del $ipv6_br0_addr_tmp/64 dev br0 failed." >> $test_log |
| 313 | #fi |
| 314 | |
| 315 | #ÊÊÅäÒ³ÃæµÈÆäËûµØ·½Ê¹ÓÃÀÏNV |
| 316 | nv set ipv6_wan_ipaddr="::" |
| 317 | |
| 318 | def_cid=`nv get default_cid` |
| 319 | if [ "-$c_id" == "-$def_cid" ]; then |
| 320 | nv set default_cid="" |
| 321 | nv set $wan_if"_ipv6_state"="dead" |
| 322 | fi |
| 323 | else |
| 324 | wan_pri=`nv get $1"_priority"` |
| 325 | rt_num=`expr $wan_pri \* 10 + $c_id` |
| 326 | |
| 327 | default_gw_addr_temp=`nv get $wan_if"_ipv6_gw"` |
| 328 | echo "ipv6_wan_default_gw = $default_gw_addr_temp" |
| 329 | |
| 330 | ip -6 rule del from $wan_addr table $rt_num |
| 331 | #if [ $? -ne 0 ];then |
| 332 | #echo "Error: ip -6 rule del from $wan_addr table $rt_num failed." >> $test_log |
| 333 | #fi |
| 334 | if [ -n "$default_gw_addr_temp" ] ; then |
| 335 | ip -6 route del default via $default_gw_addr_temp dev $wan_if table $rt_num |
| 336 | #if [ $? -ne 0 ];then |
| 337 | #echo "Error: ip -6 route del default via $default_gw_addr_temp dev $wan_if table $rt_num failed." >> $test_log |
| 338 | #fi |
| 339 | else |
| 340 | ip -6 route del default dev $wan_if table $rt_num |
| 341 | #if [ $? -ne 0 ];then |
| 342 | #echo "Error: ip -6 route del default dev $wan_if table $rt_num failed." >> $test_log |
| 343 | #fi |
| 344 | fi |
| 345 | ip -6 route flush cache 2>>$test_log |
| 346 | if [ $? -ne 0 ];then |
| 347 | echo "Error: ip -6 route flush cache failed." >> $test_log |
| 348 | fi |
| 349 | |
| 350 | nv set $wan_if"_ipv6_state"="dead" |
| 351 | |
| 352 | fi |
| 353 | |
| 354 | echo 0 > /proc/sys/net/ipv6/conf/$wan_if/accept_ra |
| 355 | |
| 356 | #reset wan'nv |
| 357 | nv set $wan_if"_ipv6_ip"="::" |
| 358 | nv set $wan_if"_ipv6_pridns_auto"="::" |
| 359 | nv set $wan_if"_ipv6_secdns_auto"="::" |
| 360 | nv set $wan_if"_ipv6_gw"="::" |
| 361 | nv set $wan_if"_ipv6_interface_id"="::" |
| 362 | nv set $wan_if"_ipv6_prefix_info"="::" |
| 363 | nv set $wan_if"_dhcpv6_start"="::" |
| 364 | nv set $wan_if"_dhcpv6_end"="::" |
| 365 | nv set $wan_if"_radvd_ipv6_dns_servers"="::" |
| 366 | |
| 367 | if [ "x$dosenable" != "x0" ]; then |
| 368 | echo 0,0,0,0 > /sys/module/fast_common/parameters/$wan6_prefix |
| 369 | fi |
| 370 | if [ "$1" == "pswan" ]; then |
| 371 | ifconfig $wan_if down 2>>$test_log |
| 372 | if [ $? -ne 0 ];then |
| 373 | echo "Error: ifconfig $wan_if down failed." >> $test_log |
| 374 | fi |
| 375 | fi |
| 376 | } |
| 377 | |
| 378 | #Çå³ýÏàÓ¦µÄDHCPv6½ø³Ì |
| 379 | linkdown_dhcpv6_server_set() |
| 380 | { |
| 381 | dhcp6c_kill |
| 382 | dhcp6s_kill |
| 383 | } |
| 384 | |
| 385 | del_default_wan6() |
| 386 | { |
| 387 | default_wan6_name=`nv get default_wan6_name` |
| 388 | if [ "-$1" == "-$default_wan6_name" ]; then |
| 389 | nv set default_wan6_name="" |
| 390 | nv set default_wan6_rel="" |
| 391 | fi |
| 392 | } |
| 393 | ############ipv6 shell entry################# |
| 394 | get_wan_info $2 $3 |
| 395 | |
| 396 | case $1 in |
| 397 | "linkup") |
| 398 | linkup_get_wan_addr $2 $3 |
| 399 | |
| 400 | ;; |
| 401 | |
| 402 | "linkdown") |
| 403 | if [ "-$2" == "-pswan" ]; then |
| 404 | tc_tbf.sh down $def_cid |
| 405 | fi |
| 406 | linkdown_radvd_set |
| 407 | linkdown_dhcpv6_server_set |
| 408 | linkdown_route_set $2 |
| 409 | slaac_kill |
| 410 | ndp_kill |
| 411 | del_default_wan6 $wan_if |
| 412 | ;; |
| 413 | |
| 414 | esac |
| 415 | |
| 416 | |
| 417 | if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then |
| 418 | (router_msg_proxy ipv6 wan_ipv6.sh >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv6 wan_ipv6.sh failed." >> $test_log) & |
| 419 | fi |