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