blob: db36140548ee477d9876c22a6cd125d2b5bb86db [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/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
8path_sh=`nv get path_sh`
you.chen94a56082024-06-20 21:22:25 +08009rndis_ip_map=`cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/rndis_ip_map`
lh9ed821d2023-04-07 01:36:19 -070010. $path_sh/global.sh
11echo "Info: nat.sh start " >> $test_log
12
13ZTE_FORWARD_CHAIN=port_forward
14ZTE_DMZ_CHAIN=DMZ
15ZTE_MAPPING_CHAIN=port_mapping
16
17iptables -P INPUT ACCEPT
18iptables -P OUTPUT ACCEPT
19iptables -P FORWARD ACCEPT
20
21#clear nat
you.chen94a56082024-06-20 21:22:25 +080022if [ "$rndis_ip_map" != "1" ];then
23 iptables -t nat -F
24fi
lh9ed821d2023-04-07 01:36:19 -070025iptables -t nat -X $ZTE_FORWARD_CHAIN
26iptables -t nat -X $ZTE_DMZ_CHAIN
27iptables -t nat -X $ZTE_MAPPING_CHAIN
28
29
30#Make a new chain for nat
31iptables -t nat -N $ZTE_FORWARD_CHAIN
32iptables -t nat -N $ZTE_DMZ_CHAIN
33iptables -t nat -N $ZTE_MAPPING_CHAIN
34
you.chen94a56082024-06-20 21:22:25 +080035if [ "$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
39fi
40
lh9ed821d2023-04-07 01:36:19 -070041iptables -t nat -I PREROUTING 1 -j $ZTE_FORWARD_CHAIN
42iptables -t nat -I PREROUTING 1 -j $ZTE_DMZ_CHAIN
43iptables -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
53clat46_en=1
54 if [ "-$clat46_en" = "-1" ]; then
55 iptables -t nat -A POSTROUTING -o clat4 -j MASQUERADE
56 fi
57
58