lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | path_sh=`nv get path_sh` |
| 4 | . $path_sh/global.sh |
| 5 | |
| 6 | echo "Info: ppp_updown.sh $1 $2 start" >> $test_log |
| 7 | |
| 8 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 9 | |
| 10 | path_sh=`nv get path_sh` |
| 11 | path_conf=`nv get path_conf` |
| 12 | c_id=$2 |
| 13 | |
| 14 | ps_if=`nv get pswan`$c_id |
| 15 | eth_if=`nv get ppp_name` |
| 16 | pdp_type=`nv get ppp_pdp_type` |
| 17 | |
| 18 | dhcp6s_conf=$path_conf/dhcp6s$c_id.conf |
| 19 | radvd_conf=$path_conf/radvd$c_id.conf |
| 20 | ndp_log=$path_conf/ndp$c_id.log |
| 21 | radvd_pidfile=$path_tmp/radvd$c_id.pid |
| 22 | |
| 23 | dnsconfig=0 |
| 24 | |
| 25 | b_dhcpv6stateEnabled=`nv get dhcpv6stateEnabled` |
| 26 | b_dhcpv6statelessEnabled=`nv get dhcpv6statelessEnabled` |
| 27 | |
| 28 | #ipµØÖ·¸ñʽa.b.c.d |
| 29 | #»ñÈ¡ip²¢ÅäÖÃps¡¢eth,´Ë´¦IPµØÖ·µÄÅäÖùæÔòΪpdp¼¤»îipµØÖ·×îºóһλµÄ×îºóÒ»¸öbitºÍµ¹ÊýµÚ¶þbit·Ö±ðÈ¡·´£¬¸Ã¹æÔòºóÐø¸ù¾øÐèÇó¿ÉÐÞ¸Ä |
| 30 | ipaddr_set() |
| 31 | { |
| 32 | pdp_ip=`nv get $ps_if"_ip"` |
| 33 | #´Óa.b.c.d»ñȡǰÈý×Ö½Úa.b.c |
| 34 | ps_ip_abc=${pdp_ip%.*} |
| 35 | #´Óa.b.c»ñȡǰÁ½¸ö×Ö½Úa.b |
| 36 | ps_ip_ab=${ps_ip_abc%.*} |
| 37 | #´Óa.b.c»ñÈ¡µÚÈý×Ö½Úc |
| 38 | ps_ip_c=${ps_ip_abc##*.} |
| 39 | #´Óa.b.c.d»ñÈ¡µÚËÄ×Ö½Úd |
| 40 | ps_ip_d=${pdp_ip##*.} |
| 41 | |
| 42 | #pdp_ipµÚËÄλµÄ×îºó1bitÈ¡·´ |
| 43 | [ "$ps_ip_c" -ge "254" ] && { ps_ip_c="250"; } |
| 44 | [ "$ps_ip_c" -le "2" ] && { ps_ip_c="10"; } |
| 45 | ps_ip_c1=`expr $ps_ip_c + 1` |
| 46 | ps_ip_c2=`expr $ps_ip_c - 1` |
| 47 | |
| 48 | ps_ip=$ps_ip_ab"."$ps_ip_c1"."$ps_ip_d |
| 49 | |
xf.li | df7f8ba | 2024-09-12 23:53:34 -0700 | [diff] [blame^] | 50 | ifconfig $ps_if $ps_ip up 2>>$test_log |
| 51 | wan_nm=`nv get static_wan_netmask` |
| 52 | ifconfig $ps_if netmask $wan_nm 2>>$test_log |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 53 | if [ $? -ne 0 ];then |
| 54 | echo "Error: ifconfig $ps_if $ps_ip up failed." >> $test_log |
| 55 | fi |
| 56 | echo "Info: ifconfig $ps_if $ps_ip gw $ps_ip up" >> $test_log |
| 57 | |
| 58 | #pdp_ipµÚËÄλµÄµ¹ÊýµÚ2bitÈ¡·´ |
| 59 | eth_ip=$ps_ip_ab"."$ps_ip_c2"."$ps_ip_d |
| 60 | |
| 61 | |
| 62 | nv set $eth_if"_ip"=$eth_ip |
| 63 | #ppp0Íø¿ÚÔÚpppdÖÐÒѾup£¬ÎÞÐèÔÙ´Îup |
| 64 | ifconfig $eth_if $eth_ip |
| 65 | if [ $? -ne 0 ];then |
| 66 | echo "Error: ifconfig $eth_if $eth_ip up failed." >> $test_log |
| 67 | fi |
| 68 | echo "Info: ifconfig $eth_if $eth_ip up" >> $test_log |
| 69 | nv set $ps_if"_pppip"=$ps_ip |
| 70 | } |
| 71 | |
| 72 | #·ÓɹæÔò£¬psÓëeth¼¶Áª |
| 73 | route_set() |
| 74 | { |
| 75 | marknum=`expr $c_id + 20` |
| 76 | iptables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 77 | rt_num=`expr $c_id + 120` |
| 78 | |
| 79 | echo "Info: ip route add default dev $eth_if table $rt_num " >> $test_log |
| 80 | ip route add default dev $eth_if table $rt_num |
| 81 | |
| 82 | echo "Info: ip rule add to $pdp_ip fwmark $marknum table $rt_num " >> $test_log |
| 83 | ip rule add to $pdp_ip fwmark $marknum table $rt_num |
| 84 | |
| 85 | marknum=`expr $c_id + 10` |
| 86 | iptables -t mangle -A PREROUTING -i $eth_if -d ! $eth_ip/24 -j MARK --set-mark $marknum |
| 87 | rt_num=`expr $c_id + 100` |
| 88 | |
| 89 | echo "Info: ip route add default dev $ps_if table $rt_num " >> $test_log |
| 90 | ip route add default dev $ps_if table $rt_num |
| 91 | |
| 92 | echo "Info: ip rule add from $pdp_ip fwmark $marknum table $rt_num " >> $test_log |
| 93 | ip rule add from $pdp_ip fwmark $marknum table $rt_num |
| 94 | |
| 95 | ip route flush cache |
| 96 | |
| 97 | #±¾µØÍøÂçÅäÖà |
| 98 | iptables -t nat -I POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip |
| 99 | |
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 100 | route_info=`ip route|grep default` |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 101 | |
| 102 | if [ "$route_info" == "" ];then |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 103 | dns=`nv get $ps_if"_pridns"` |
| 104 | dns2=`nv get $ps_if"_secdns"` |
| 105 | if [ "-$dns" == "-" -o "-$dns" == "-0.0.0.0" ] && [ "-$dns2" == "-" -o "-$dns2" == "-0.0.0.0" ]; then |
| 106 | echo "Error:PPP no valid dns, use default dns." >> $test_log |
| 107 | dns="114.114.114.114" |
| 108 | dns2="8.8.8.8" |
| 109 | fi |
| 110 | if [ "-$dns" != "-" -a "-$dns" != "-0.0.0.0" ]; then |
| 111 | echo "nameserver $dns" >> /etc/resolv.conf |
| 112 | fi |
| 113 | if [ "-$dns2" != "-" -a "-$dns2" != "-0.0.0.0" ]; then |
| 114 | echo "nameserver $dns2" >> /etc/resolv.conf |
| 115 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 116 | route add default dev $ps_if |
| 117 | else |
| 118 | echo "Debug: default route already exist." >> $test_log |
| 119 | fi |
| 120 | } |
| 121 | |
| 122 | #ɾ³ý¶ÔÓ¦µÄ·ÓɹæÔò |
| 123 | route_del() |
| 124 | { |
| 125 | pdp_ip=`nv get $ps_if"_ip"` |
| 126 | |
| 127 | eth_ip=`nv get $eth_if"_ip"` |
| 128 | |
| 129 | ps_ip=`nv get $ps_if"_pppip"` |
| 130 | |
| 131 | marknum=`expr $c_id + 10` |
| 132 | rt_num=`expr $c_id + 100` |
| 133 | |
| 134 | iptables -t mangle -D PREROUTING -i $eth_if -d ! $eth_ip/24 -j MARK --set-mark $marknum |
| 135 | ip rule del from $pdp_ip fwmark $marknum table $rt_num |
| 136 | ip route del default dev $ps_if table $rt_num |
| 137 | |
| 138 | marknum=`expr $c_id + 20` |
| 139 | rt_num=`expr $c_id + 120` |
| 140 | iptables -t mangle -D PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 141 | ip rule del to $pdp_ip fwmark $marknum table $rt_num |
| 142 | ip route del default dev $eth_if table $rt_num |
| 143 | |
| 144 | iptables -t nat -D POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip |
| 145 | |
| 146 | ifconfig $ps_if down |
| 147 | if [ $? -ne 0 ];then |
| 148 | echo "Error: ifconfig $ps_if down failed." >> $test_log |
| 149 | fi |
| 150 | |
| 151 | #reset nv |
| 152 | nv set ppp_cid="" |
| 153 | nv set $eth_if"_ip"=0.0.0.0 |
| 154 | nv set $eth_if"_nm"=0.0.0.0 |
| 155 | nv set $ps_if"_ip"=0.0.0.0 |
| 156 | nv set $ps_if"_pridns"=0.0.0.0 |
| 157 | nv set $ps_if"_secdns"=0.0.0.0 |
| 158 | nv set $ps_if"_pppip"=0.0.0.0 |
| 159 | } |
| 160 | |
| 161 | #############linkup dhcpserver set############ |
| 162 | linkup_add_dns_to_dhcp6s_radvd_conf() |
| 163 | { |
| 164 | #Ö±Á¬Ä£Ê½Ã»ÓÐÊÖ¶¯DNS |
| 165 | ipv6_pridns_auto=`nv get $ps_if"_ipv6_pridns_auto"` |
| 166 | ipv6_secdns_auto=`nv get $ps_if"_ipv6_secdns_auto"` |
| 167 | |
| 168 | if [ -n "$ipv6_pridns_auto" ] && [ "-$ipv6_pridns_auto" != "-::" ] && [ "-$ipv6_pridns_auto" != "-::0" ];then |
| 169 | ipv6_prefer_dns=$ipv6_pridns_auto |
| 170 | fi |
| 171 | |
| 172 | if [ -n "$ipv6_secdns_auto" ] && [ "-$ipv6_secdns_auto" != "-::" ] && [ "-$ipv6_secdns_auto" != "-::0" ];then |
| 173 | ipv6_standby_dns=$ipv6_secdns_auto |
| 174 | fi |
| 175 | |
| 176 | if [ "-$ipv6_prefer_dns" == "-" -a "-$ipv6_standby_dns" == "-" ]; then |
| 177 | return |
| 178 | else |
| 179 | if [ -n "$1" ] && [ "-$1" == "-dhcp6s" ] ;then |
| 180 | echo -e "\toption dns_servers $ipv6_prefer_dns $ipv6_standby_dns;" >> $dhcp6s_conf |
| 181 | elif [ -n "$1" ] && [ "-$1" == "-radvd" ] ;then |
| 182 | # del last line |
| 183 | sed -i '$d' $radvd_conf |
| 184 | echo -e "\tRDNSS $ipv6_prefer_dns $ipv6_standby_dns\n\t{" >> $radvd_conf |
| 185 | echo -e "\t\tAdvRDNSSPreference 15;" >> $radvd_conf |
| 186 | echo -e "\t\tAdvRDNSSOpen on;" >> $radvd_conf |
| 187 | echo -e "\t};\n};" >> $radvd_conf |
| 188 | fi |
| 189 | |
| 190 | if [ "-$dnsconfig" == "-0" ]; then |
| 191 | echo "dnsconfig $1 $ipv6_prefer_dns, $ipv6_standby_dns" >> $test_log |
| 192 | if [ "-$ipv6_prefer_dns" != "-" ]; then |
| 193 | echo "nameserver $ipv6_prefer_dns" >> /etc/resolv.conf |
| 194 | fi |
| 195 | if [ "-$ipv6_standby_dns" != "-" ]; then |
| 196 | echo "nameserver $ipv6_standby_dns" >> /etc/resolv.conf |
| 197 | fi |
| 198 | dnsconfig=1 |
| 199 | fi |
| 200 | fi |
| 201 | } |
| 202 | |
| 203 | linkup_dhcpv6_set() |
| 204 | { |
| 205 | dhcpv6_start=$pdp_ip |
| 206 | dhcpv6_end=$pdp_ip |
| 207 | |
| 208 | #nvÖµ·Ç¿ÕÔò±íʾÓû§ÉèÖÃÁ˾²Ì¬ip¡¢gw |
| 209 | gw=`nv get $ps_if"_ipv6_gw"` |
| 210 | |
| 211 | echo -e "interface $eth_if {" > $dhcp6s_conf |
| 212 | if [ "-$b_dhcpv6stateEnabled" = "-1" ];then |
| 213 | echo -e "\tserver-preference 255;\n\trenew-time 6000;" >> $dhcp6s_conf |
| 214 | echo -e "\trebind-time 9000;\n\tprefer-life-time 1300;" >> $dhcp6s_conf |
| 215 | echo -e "\tvalid-life-time 2000;\n\tallow rapid-commit;" >> $dhcp6s_conf |
| 216 | echo -e "\tlink $eth_if {\n\t\tallow unicast;\n\t\tsend unicast;" >> $dhcp6s_conf |
| 217 | echo -e "\t\tpool {\n\t\t\trange $dhcpv6_start to $dhcpv6_end/$prefix_len;" >> $dhcp6s_conf |
| 218 | echo -e "\t\t};\n\t};" >> $dhcp6s_conf |
| 219 | linkup_add_dns_to_dhcp6s_radvd_conf dhcp6s |
| 220 | echo -e "};" >> $dhcp6s_conf |
| 221 | dhcp6s -dDf -c $dhcp6s_conf $eth_if & |
| 222 | else |
| 223 | #slaac with dhcp statelessset dns info |
| 224 | if [ "-$b_dhcpv6statelessEnabled" = "-1" ];then |
| 225 | echo -e "\tlink $eth_if {\n\t};" >> $dhcp6s_conf |
| 226 | linkup_add_dns_to_dhcp6s_radvd_conf dhcp6s |
| 227 | echo -e "};" >> $dhcp6s_conf |
| 228 | dhcp6s -dDf -c $dhcp6s_conf $eth_if & |
| 229 | if [ $? -ne 0 ];then |
| 230 | echo "Error: dhcp6s -dDf -c $dhcp6s_conf $eth_if failed." >> $test_log |
| 231 | fi |
| 232 | fi |
| 233 | fi |
| 234 | } |
| 235 | |
| 236 | #»ñÈ¡ip²¢ÅäÖÃps¡¢eth |
| 237 | ip6addr_set() |
| 238 | { |
| 239 | #disable the forwarding to send RS and not set the addr when receive ra packet |
| 240 | echo 0 > /proc/sys/net/ipv6/conf/all/forwarding |
| 241 | echo 0 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra |
| 242 | echo 0 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra |
| 243 | |
| 244 | #call the slaac program to get the prefix addr |
| 245 | ifconfig $ps_if up 2>>$test_log |
| 246 | if [ $? -ne 0 ];then |
| 247 | echo "Error: ifconfig $ps_if up failed." >> $test_log |
| 248 | fi |
| 249 | prefix_info_temp=`nv get $ps_if"_ipv6_prefix_info"` |
| 250 | #Èç¹ûµ±Ç°Ã»ÓÐǰ׺£¬ÔòÖ±½ÓÆô¶¯slaac£¬Èç¹ûµ±Ç°Ç°×ºÒѾÉèÖã¬Ôò˵Ã÷ÒѾ»ñÈ¡µ½£¬Ö±½ÓÅäÖÃIPµØÖ·¼´¿É |
| 251 | if [ -n "$prefix_info_temp" -a "-$prefix_info_temp" != "-::" ]; then |
| 252 | ret_code=0 |
| 253 | else |
| 254 | sleep 1 |
| 255 | interface_id_temp1=`nv get $ps_if"_ipv6_interface_id"` |
| 256 | local_ipv6_addr="fe80::"$interface_id_temp1 |
| 257 | local_ipv6_addr_nv="$ps_if""_local_ipv6_addr" |
| 258 | nv set $local_ipv6_addr_nv=$local_ipv6_addr |
| 259 | ip -6 addr add $local_ipv6_addr/64 dev $ps_if 2>>$test_log |
| 260 | zte_ipv6_slaac -i "$ps_if" |
| 261 | ret_code=$? |
| 262 | fi |
| 263 | |
| 264 | echo "Info: zte_ipv6_slaac return: $ret_code" >> $test_log |
| 265 | echo "the program zte_ipv6_slaac return = $ret_code" |
| 266 | if [ $ret_code -eq 0 ]; then |
| 267 | echo "the zte_ipv6_slaac success" |
| 268 | interface_id_temp=`nv get $ps_if"_ipv6_interface_id"` |
| 269 | prefix_info_temp=`nv get $ps_if"_ipv6_prefix_info"` |
| 270 | |
| 271 | echo "##############1##########" |
| 272 | echo "$interface_id_temp" |
| 273 | echo "$prefix_info_temp" |
| 274 | echo "##############2##########" |
| 275 | |
| 276 | #pdp ¼¤»îµÄipv6µØÖ· |
| 277 | pdp_ip6=$prefix_info_temp$interface_id_temp |
| 278 | #pdp¼¤»îµØÖ·£¬ÊÊÅäÒ³ÃæÊ¹Óà |
| 279 | nv set ipv6_wan_ipaddr="$pdp_ip6" |
| 280 | |
| 281 | ipv6_addr_conver $pdp_ip6 "$ps_if" |
| 282 | |
| 283 | #¸øeth·ÖÅ䵨ַ£¬Ê¹ÓÃipv6_addr_converÔÚµÚ15+1 |
| 284 | eth_ip6=`nv get ipv6_br0_addr` |
| 285 | |
| 286 | ip -6 addr add $eth_ip6/64 dev $eth_if |
| 287 | if [ $? -ne 0 ];then |
| 288 | echo "Error: ip -6 addr add $eth_ip6/64 dev $eth_if failed." >> $test_log |
| 289 | fi |
| 290 | #¸øÍâÍø¿Ú·ÖÅ䵨ַ£¬Ê¹ÓÃipv6_addr_converÔÚµÚ15+2 |
| 291 | ps_ip6=`nv get $ps_if"_dhcpv6_start"` |
| 292 | nv set $ps_if"_ipv6_ip"=$ps_ip6 |
| 293 | ip -6 addr add $ps_ip6/126 dev $ps_if 2>>$test_log |
| 294 | if [ $? -ne 0 ];then |
| 295 | echo "Error: ip -6 addr add $ps_ip6/126 dev $ps_if failed." >> $test_log |
| 296 | fi |
| 297 | nv set $ps_if"_ipv6_state"="working" |
| 298 | |
| 299 | echo "Info: zte_ipv6_slaac pdp_ip6: $pdp_ip6" >> $test_log |
| 300 | echo "Info: zte_ipv6_slaac ps_ip6: $ps_ip6" >> $test_log |
| 301 | echo "Info: zte_ipv6_slaac eth_ip6: $eth_ip6" >> $test_log |
| 302 | else |
| 303 | echo "the zte_ipv6_slaac fail" |
| 304 | nv set $ps_if"_ipv6_state"="dead" |
| 305 | exit 1 |
| 306 | fi |
| 307 | } |
| 308 | |
| 309 | #·ÓɹæÔò£¬psÓëeth¼¶Áª |
| 310 | route6_set() |
| 311 | { |
| 312 | echo 0 > /proc/sys/net/ipv6/conf/all/forwarding |
| 313 | |
| 314 | marknum=`expr $c_id + 60` |
| 315 | ip6tables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 316 | rt_num=`expr $c_id + 160` |
| 317 | ip -6 route add default dev $eth_if table $rt_num |
| 318 | ip -6 rule add to $pdp_ip6/64 fwmark $marknum table $rt_num |
| 319 | |
| 320 | marknum=`expr $c_id + 50` |
| 321 | ip6tables -t mangle -A PREROUTING -i $eth_if -j MARK --set-mark $marknum |
| 322 | rt_num=`expr $c_id + 150` |
| 323 | ip -6 route add default dev $ps_if table $rt_num |
| 324 | ip -6 rule add from $pdp_ip6/64 fwmark $marknum table $rt_num |
| 325 | |
| 326 | ip6tables -t filter -A FORWARD -p icmpv6 --icmpv6-type 135 -j DROP |
| 327 | |
| 328 | ip -6 route flush cache |
| 329 | |
| 330 | #Õâ¾äÉèÍ꣬ÀïÃæ¿ÉÒÔpingͨÍâÍøÁË |
| 331 | echo "Info: route6_set pdp_ip6=$pdp_ip6" >> $test_log |
| 332 | |
| 333 | ip -6 route add default dev $ps_if 2>>$test_log |
| 334 | if [ $? -ne 0 ];then |
| 335 | echo "Error: ip -6 route add default dev $ps_if failed." >> $test_log |
| 336 | fi |
| 337 | |
| 338 | #enable ipv6 packet forwarding |
| 339 | echo 1 > /proc/sys/net/ipv6/conf/all/forwarding |
| 340 | echo 1 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra |
| 341 | echo 1 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra |
| 342 | #enable ipv6 neigh discovery proxy |
| 343 | echo 1 > /proc/sys/net/ipv6/conf/all/proxy_ndp |
| 344 | |
| 345 | ndp_kill |
| 346 | zte_ndp -a -s $eth_if -d $ps_if -l $ndp_log -p & |
| 347 | } |
| 348 | |
| 349 | #############linkup radvd set############ |
| 350 | linkup_radvd_set() |
| 351 | { |
| 352 | echo "enter linkup_radvd_set " |
| 353 | |
| 354 | prefix_len=64 |
| 355 | |
| 356 | rm -rf $radvd_conf |
| 357 | |
| 358 | if [ "-$b_dhcpv6stateEnabled" = "-1" ];then |
| 359 | echo -e "interface $eth_if\n{\n\tAdvSendAdvert on;" > $radvd_conf |
| 360 | echo -e "\tAdvManagedFlag on;\n};" >> $radvd_conf |
| 361 | radvd_kill |
| 362 | rm -rf $radvd_pidfile |
| 363 | radvd -d 3 -C $radvd_conf -p $radvd_pidfile& |
| 364 | echo "leave linkup_radvd_set " |
| 365 | return |
| 366 | fi |
| 367 | |
| 368 | echo "Info: psext_updown_ipv6.sh eth_if:$eth_if, prefix_len:$prefix_len" >> $test_log |
| 369 | echo "prefix_len:$prefix_len" |
| 370 | |
| 371 | cp $path_ro/radvd_template.conf $radvd_conf |
| 372 | |
| 373 | sed -i -e 's/#ipv6_wan_addr#\/64/#ipv6_wan_addr#\/#prefix_len#/g' $radvd_conf |
| 374 | sed -i -e s/br0/$eth_if/g $radvd_conf |
| 375 | sed -i -e s/#ipv6_wan_addr#/$eth_ip6/g $radvd_conf |
| 376 | sed -i -e s/#prefix_len#/$prefix_len/g $radvd_conf |
| 377 | sed -i -e s/#adv_switch#/on/g $radvd_conf |
| 378 | |
| 379 | #slaac with dns info |
| 380 | if [ "-$b_dhcpv6statelessEnabled" = "-1" ];then |
| 381 | echo "use dhcpv6stateless for dns" |
| 382 | else |
| 383 | sed -i -e 's/AdvOtherConfigFlag on;/AdvOtherConfigFlag off;/g' $radvd_conf |
| 384 | linkup_add_dns_to_dhcp6s_radvd_conf radvd |
| 385 | fi |
| 386 | |
| 387 | radvd_kill |
| 388 | sleep 1 |
| 389 | rm -rf $radvd_pidfile |
| 390 | radvd -d 3 -C $radvd_conf -p $radvd_pidfile & |
| 391 | |
| 392 | echo "leave linkup_radvd_set " |
| 393 | } |
| 394 | |
| 395 | #Çå³ýÏàÓ¦µÄradvd½ø³Ì |
| 396 | linkdown_radvd_set() |
| 397 | { |
| 398 | #¸úÖÕ¶ËÁ¬½ÓµÄÍø¿ÚÖ±½Ó»ádown£¬ËùÒÔ²»ÓÃÏñufiÒ»ÑùÉèÖóÉ1sÓÐЧÆÚ |
| 399 | radvd_kill |
| 400 | } |
| 401 | |
| 402 | #Çå³ýÏàÓ¦µÄDHCPv6½ø³Ì |
| 403 | linkdown_dhcpv6_server_set() |
| 404 | { |
| 405 | dhcp6s_kill |
| 406 | } |
| 407 | |
| 408 | #ɾ³ýÏàÓ¦µÄipv6·ÓɹæÔò |
| 409 | route6_del() |
| 410 | { |
| 411 | eth_ip6=`nv get ipv6_br0_addr` |
| 412 | ps_ip6=`nv get $ps_if"_ipv6_ip"` |
| 413 | pdp_ip6=`nv get ipv6_wan_ipaddr` |
| 414 | |
| 415 | ip6tables -t filter -D FORWARD -p icmpv6 --icmpv6-type 135 -j DROP |
| 416 | |
| 417 | marknum=`expr $c_id + 50` |
| 418 | rt_num=`expr $c_id + 150` |
| 419 | ip -6 rule del from $pdp_ip6/64 fwmark $marknum table $rt_num |
| 420 | ip6tables -t mangle -D PREROUTING -i $eth_if -j MARK --set-mark $marknum |
| 421 | ip -6 route del default dev $ps_if table $rt_num |
| 422 | |
| 423 | marknum=`expr $c_id + 60` |
| 424 | rt_num=`expr $c_id + 160` |
| 425 | ip -6 rule del to $pdp_ip6/64 fwmark $marknum table $rt_num |
| 426 | ip6tables -t mangle -D PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 427 | ip -6 route del default dev $eth_if table $rt_num |
| 428 | |
| 429 | ip -6 addr del $eth_ip6/64 dev $eth_if |
| 430 | #if [ $? -ne 0 ];then |
| 431 | # echo "Error: ip -6 addr del $eth_ip/64 dev $eth_if failed." >> $test_log |
| 432 | #fi |
| 433 | ip -6 addr del $ps_ip6/126 dev $ps_if |
| 434 | #if [ $? -ne 0 ];then |
| 435 | # echo "Error: ip -6 addr del $ps_ip6/126 dev $ps_if failed." >> $test_log |
| 436 | #fi |
| 437 | ip -6 route del default |
| 438 | #if [ $? -ne 0 ];then |
| 439 | # echo "Error: ip -6 route del default failed." >> $test_log |
| 440 | #fi |
| 441 | |
| 442 | ifconfig $eth_if down 2>>$test_log |
| 443 | #if [ $? -ne 0 ];then |
| 444 | # echo "Error: ifconfig $eth_if down failed." >> $test_log |
| 445 | #fi |
| 446 | ifconfig $ps_if down 2>>$test_log |
| 447 | if [ $? -ne 0 ];then |
| 448 | echo "Error: ifconfig $ps_if down failed." >> $test_log |
| 449 | fi |
| 450 | |
| 451 | echo 0 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra |
| 452 | |
| 453 | #reset nv |
| 454 | nv set ppp_cid="" |
| 455 | nv set $ps_if"_pppv6_ip"="::" |
| 456 | nv set $ps_if"_ipv6_ip"="::" |
| 457 | nv set $ps_if"_ipv6_pridns_auto"="::" |
| 458 | nv set $ps_if"_ipv6_secdns_auto"="::" |
| 459 | nv set $ps_if"_ipv6_gw"="::" |
| 460 | nv set $ps_if"_ipv6_interface_id"="::" |
| 461 | nv set $ps_if"_ipv6_prefix_info"="::" |
| 462 | nv set $ps_if"_dhcpv6_start"="::" |
| 463 | nv set $ps_if"_dhcpv6_end"="::" |
| 464 | |
| 465 | #ÊÊÅäÒ³ÃæµÈÆäËûµØ·½Ê¹ÓÃÀÏNV |
| 466 | nv set ipv6_wan_ipaddr="::" |
| 467 | nv set $ps_if"_ipv6_state"="dead" |
| 468 | |
| 469 | local_ipv6_addr_nv="$ps_if""_local_ipv6_addr" |
| 470 | nv set $local_ipv6_addr_nv="::" |
| 471 | |
| 472 | ndp_kill |
| 473 | } |
| 474 | |
| 475 | if [ "$1" == "linkup" ]; then |
| 476 | if [ "$pdp_type" != "IPV6" ]; then |
| 477 | ipaddr_set |
| 478 | route_set |
| 479 | fi |
| 480 | if [ "$pdp_type" == "IPV6" -o "$pdp_type" == "IPV4V6" ]; then |
| 481 | ip6addr_set |
| 482 | route6_set |
| 483 | linkup_dhcpv6_set |
| 484 | linkup_radvd_set |
| 485 | fi |
| 486 | elif [ "$1" == "linkdown" ]; then |
| 487 | if [ "$pdp_type" != "IPV6" ]; then |
| 488 | route_del |
| 489 | fi |
| 490 | if [ "$pdp_type" == "IPV6" -o "$pdp_type" == "IPV4V6" ]; then |
| 491 | linkdown_radvd_set |
| 492 | linkdown_dhcpv6_server_set |
| 493 | route6_del |
| 494 | slaac_kill |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 495 | fi |
| 496 | route_info=`ip route|grep default` |
| 497 | if [ "$route_info" == "" ];then |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 498 | echo "" > /etc/resolv.conf |
| 499 | fi |
| 500 | fi |
| 501 | |
| 502 | echo "Info: ppp_updown.sh $1 $2 leave" >> $test_log |