lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | test_log=`nv get telog_path` |
| 3 | if [ "$test_log" == "" ]; then |
| 4 | test_log=`nv get path_log`"te.log" |
| 5 | fi |
| 6 | |
| 7 | c_id=$1 |
| 8 | path_conf=`nv get path_conf` |
| 9 | path_tmp=`nv get path_tmp` |
| 10 | dhcp6s_conf=$path_conf/dhcp6s$c_id.conf |
| 11 | radvd_conf=$path_conf/radvd$c_id.conf |
| 12 | ndp_log=$path_conf/ndp$c_id.log |
| 13 | radvd_pidfile=$path_tmp/radvd$c_id.pid |
| 14 | |
| 15 | ps_if=`nv get pswan`$c_id |
| 16 | eth_if=`nv get "ps_ext"$c_id` |
| 17 | br_if="br"$c_id |
| 18 | |
| 19 | echo "Info: psext_updown_ipv6.sh $ps_if $eth_if $br_if start" >> $test_log |
| 20 | |
| 21 | prefix_len=`nv get $ps_if"_ipv6_prefix_len"` |
| 22 | br_ip=`nv get $br_if"_ipv6_ip"` |
| 23 | ps_ip=`nv get $ps_if"_ipv6_ip"` |
| 24 | pdp_ip=`nv get $ps_if"_ipv6_pdp"` |
| 25 | local_ipv6_addr=`nv get $ps_if"_ipv6_local"` |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 26 | dhcps_in_cap=`nv get dhcps_in_cap` |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 27 | |
| 28 | #获取ip并配置ps、eth |
| 29 | linkup_get_addr() |
| 30 | { |
| 31 | #disable the forwarding to send RS and not set the addr when receive ra packet |
| 32 | echo 0 > /proc/sys/net/ipv6/conf/all/forwarding |
| 33 | echo 0 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra |
| 34 | echo 0 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra |
| 35 | echo 0 > /proc/sys/net/ipv6/conf/$br_if/accept_ra |
| 36 | #call the slaac program to get the prefix addr |
| 37 | ifconfig $ps_if up 2>>$test_log |
| 38 | if [ $? -ne 0 ];then |
| 39 | echo "Error: ifconfig $ps_if up failed." >> $test_log |
| 40 | fi |
| 41 | ip -6 addr add $local_ipv6_addr/64 dev $ps_if 2>>$test_log |
| 42 | brctl addbr $br_if |
| 43 | brctl setfd $br_if 0.1 |
| 44 | ifconfig $br_if up 2>>$test_log |
| 45 | if [ $? -ne 0 ];then |
| 46 | echo "Error: ifconfig $br_if up failed." >> $test_log |
| 47 | fi |
| 48 | ip -6 addr add $br_ip/64 dev $br_if |
| 49 | ip -6 addr add $ps_ip/126 dev $ps_if 2>>$test_log |
| 50 | if [ $? -ne 0 ];then |
| 51 | echo "Error: ip -6 addr add $ps_ip/126 dev $ps_if failed." >> $test_log |
| 52 | fi |
| 53 | nv set $ps_if"_ipv6_state"="working" |
| 54 | } |
| 55 | |
| 56 | #路由规则,ps与eth级联 |
| 57 | linkup_route_set() |
| 58 | { |
| 59 | echo 0 > /proc/sys/net/ipv6/conf/all/forwarding |
| 60 | |
| 61 | marknum=`expr $c_id + 60` |
| 62 | ip6tables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 63 | rt_num=`expr $c_id + 160` |
| 64 | ip -6 route add default dev $br_if table $rt_num |
| 65 | ip -6 rule add to $pdp_ip/64 fwmark $marknum table $rt_num |
| 66 | |
| 67 | marknum=`expr $c_id + 50` |
| 68 | ip6tables -t mangle -A PREROUTING -i $br_if -j MARK --set-mark $marknum |
| 69 | rt_num=`expr $c_id + 150` |
| 70 | ip -6 route add default dev $ps_if table $rt_num |
| 71 | ip -6 rule add from $pdp_ip/64 fwmark $marknum table $rt_num |
| 72 | |
| 73 | ip6tables -t filter -A FORWARD -p icmpv6 --icmpv6-type 135 -j DROP |
| 74 | |
| 75 | ip -6 route flush cache |
| 76 | |
| 77 | #这句设完,里面可以ping通外网了 |
| 78 | echo "Info: route_set ps_ip=$ps_ip" >> $test_log |
| 79 | #ip -6 route add default via $ps_ip dev $ps_if |
| 80 | ip -6 route add default dev $ps_if 2>>$test_log |
| 81 | if [ $? -ne 0 ];then |
| 82 | echo "Error: ip -6 route add default dev $ps_if failed." >> $test_log |
| 83 | fi |
| 84 | |
| 85 | #enable ipv6 packet forwarding |
| 86 | echo 1 > /proc/sys/net/ipv6/conf/all/forwarding |
| 87 | echo 1 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra |
| 88 | echo 1 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra |
| 89 | echo 1 > /proc/sys/net/ipv6/conf/$br_if/accept_ra |
| 90 | #enable ipv6 neigh discovery proxy |
| 91 | echo 1 > /proc/sys/net/ipv6/conf/all/proxy_ndp |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 92 | if [ "x$dhcps_in_cap" != "x1" ]; then |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 93 | zte_ndp -a -s $br_if -d $ps_if -l $ndp_log -p & |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 94 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | linkup_dhcpv6_set() |
| 98 | { |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 99 | if [ "x$dhcps_in_cap" != "x1" ]; then |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 100 | dhcp6s -dDf -c $dhcp6s_conf $br_if & |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 101 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | linkup_radvd_set() |
| 105 | { |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 106 | if [ "x$dhcps_in_cap" != "x1" ]; then |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 107 | radvd -d 3 -C $radvd_conf -p $radvd_pidfile & |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 108 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | mtu=`nv get mtu` |
| 112 | ifconfig $ps_if mtu $mtu |
| 113 | linkup_get_addr |
| 114 | linkup_route_set |
| 115 | linkup_dhcpv6_set |
| 116 | linkup_radvd_set |
| 117 | brctl addif $br_if $eth_if |
| 118 | ifconfig $eth_if up |
| 119 | tc_tbf.sh up $c_id |
| 120 | echo "Info: psext_up_ipv6.sh leave" >> $test_log |