lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # $Id: nat.sh,v 1.4 2009-12-09 08:45:37 steven Exp $ |
| 4 | # |
| 5 | # usage: nat.sh |
| 6 | # |
| 7 | |
| 8 | path_sh=`nv get path_sh` |
you.chen | 94a5608 | 2024-06-20 21:22:25 +0800 | [diff] [blame] | 9 | rndis_ip_map=`cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/rndis_ip_map` |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 10 | . $path_sh/global.sh |
| 11 | echo "Info: nat.sh start " >> $test_log |
| 12 | |
| 13 | ZTE_FORWARD_CHAIN=port_forward |
| 14 | ZTE_DMZ_CHAIN=DMZ |
| 15 | ZTE_MAPPING_CHAIN=port_mapping |
| 16 | |
| 17 | iptables -P INPUT ACCEPT |
| 18 | iptables -P OUTPUT ACCEPT |
| 19 | iptables -P FORWARD ACCEPT |
| 20 | |
| 21 | #clear nat |
you.chen | 94a5608 | 2024-06-20 21:22:25 +0800 | [diff] [blame] | 22 | if [ "$rndis_ip_map" != "1" ];then |
| 23 | iptables -t nat -F |
| 24 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 25 | iptables -t nat -X $ZTE_FORWARD_CHAIN |
| 26 | iptables -t nat -X $ZTE_DMZ_CHAIN |
| 27 | iptables -t nat -X $ZTE_MAPPING_CHAIN |
| 28 | |
| 29 | |
| 30 | #Make a new chain for nat |
| 31 | iptables -t nat -N $ZTE_FORWARD_CHAIN |
| 32 | iptables -t nat -N $ZTE_DMZ_CHAIN |
| 33 | iptables -t nat -N $ZTE_MAPPING_CHAIN |
| 34 | |
you.chen | 94a5608 | 2024-06-20 21:22:25 +0800 | [diff] [blame] | 35 | if [ "$rndis_ip_map" == "1" ];then |
| 36 | iptables -t nat -D PREROUTING -j $ZTE_FORWARD_CHAIN |
| 37 | iptables -t nat -D PREROUTING -j $ZTE_DMZ_CHAIN |
| 38 | iptables -t nat -D PREROUTING -j $ZTE_MAPPING_CHAIN |
| 39 | fi |
| 40 | |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 41 | iptables -t nat -I PREROUTING 1 -j $ZTE_FORWARD_CHAIN |
| 42 | iptables -t nat -I PREROUTING 1 -j $ZTE_DMZ_CHAIN |
| 43 | iptables -t nat -I PREROUTING 1 -j $ZTE_MAPPING_CHAIN |
| 44 | |
| 45 | lan_en=`nv get LanEnable` |
| 46 | nat_en=`nv get natenable` |
| 47 | if [ "-$nat_en" != "-0" -a "-$lan_en" == "-2" ]; then |
| 48 | iptables -t nat -A POSTROUTING -o ${defwan_rel%:*} -j MASQUERADE |
| 49 | elif [ "-$nat_en" != "-0" -a "-$lan_en" != "-0" ]; then |
| 50 | iptables -t nat -A POSTROUTING -o $defwan_rel -j MASQUERADE |
| 51 | fi |
| 52 | |
| 53 | clat46_en=1 |
| 54 | if [ "-$clat46_en" = "-1" ]; then |
| 55 | iptables -t nat -A POSTROUTING -o clat4 -j MASQUERADE |
| 56 | fi |
| 57 | |
| 58 | |