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: clat_config.sh $1 $2 start" >> $test_log |
| 7 | |
| 8 | if [ "x$2" != "x" ]; then |
| 9 | wan1_ipv6_prefix_info=`nv get $2"_ipv6_prefix_info"` |
| 10 | fi |
| 11 | |
| 12 | if [ "x$wan1_ipv6_prefix_info" != "x" ]; then |
| 13 | clat6_ipv6="$wan1_ipv6_prefix_info"":464" |
| 14 | fi |
| 15 | |
| 16 | ipv4_fake_subnet=`nv get ipv4_fake_subnet` |
| 17 | clat_fake_subnet=`nv get clat_fake_subnet` |
| 18 | ipv6_fake_addr=`nv get ipv6_fake_subnet` |
| 19 | if [ "x$ipv6_fake_addr" != "x" ];then |
| 20 | ipv6_fake_subnet=$ipv6_fake_addr"/64" |
| 21 | fi |
| 22 | |
| 23 | case $1 in |
| 24 | "up") |
| 25 | if [ "x$ipv4_fake_subnet" == "x" -a "x$clat_fake_subnet" == "x" -a "x$ipv6_fake_addr" == "x" ];then |
| 26 | echo "Info: ipv4_fake_subnet and clat_fake_subnet not exist, please check!!!" >> $test_log |
| 27 | fi |
| 28 | |
| 29 | # for 46 |
| 30 | route add default dev clat4 metric 40 |
| 31 | route add -net $ipv4_fake_subnet netmask 255.255.0.0 dev clat4 |
| 32 | iptables -t nat -A POSTROUTING -o clat4 -j MASQUERADE |
| 33 | |
| 34 | if [ "x$clat6_ipv6" != "x" -a "x$2" != "x" ]; then |
| 35 | ip -6 neigh add proxy $clat6_ipv6 dev $2 |
| 36 | fi |
| 37 | |
| 38 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 39 | |
| 40 | #for 64 |
| 41 | #ip -6 route add $ipv6_fake_subnet dev clat |
| 42 | #route add -net $clat_fake_subnet netmask 255.255.255.0 dev clat4 |
| 43 | ;; |
| 44 | |
| 45 | "down") |
| 46 | |
| 47 | # for 46 |
| 48 | route del default dev clat4 metric 40 |
| 49 | route del -net $ipv4_fake_subnet netmask 255.255.0.0 dev clat4 |
| 50 | iptables -t nat -D POSTROUTING -o clat4 -j MASQUERADE |
| 51 | |
| 52 | if [ "x$clat6_ipv6" != "x" -a "x$2" != "x" ]; then |
| 53 | ip -6 neigh del proxy $clat6_ipv6 dev $2 |
| 54 | fi |
| 55 | |
| 56 | #for 64 |
| 57 | #ip -6 route del $ipv6_fake_subnet dev clat |
| 58 | #route del -net $clat_fake_subnet netmask 255.255.255.0 dev clat4 |
| 59 | ;; |
| 60 | |
| 61 | esac |
| 62 | |
| 63 | |