5 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
6 local wanip
=$
(uci
-P/var
/state get network.wan.ipaddr
)
8 iptables
-t nat
-F nat_reflection_in
2>/dev
/null ||
{
9 iptables
-t nat
-N nat_reflection_in
10 iptables
-t nat
-A prerouting_rule
-j nat_reflection_in
13 iptables
-t nat
-F nat_reflection_out
2>/dev
/null ||
{
14 iptables
-t nat
-N nat_reflection_out
15 iptables
-t nat
-A postrouting_rule
-j nat_reflection_out
18 iptables
-t filter
-F nat_reflection_fwd
2>/dev
/null ||
{
19 iptables
-t filter
-N nat_reflection_fwd
20 iptables
-t filter
-A forwarding_rule
-j nat_reflection_fwd
29 config_get name
"$cfg" name
31 [ "$name" = "$zone" ] && {
33 config_get network
"$cfg" network
35 echo ${network:-$zone}
40 config_foreach find_networks_cb zone
"$1"
47 config_get_bool reflection
"$cfg" reflection
1
48 [ "$reflection" == 1 ] ||
return
51 config_get src
"$cfg" src
54 config_get target
"$cfg" target DNAT
56 [ "$src" = wan
] && [ "$target" = DNAT
] && {
58 config_get dest
"$cfg" dest
"lan"
61 for net
in $
(find_networks
"$dest"); do
62 local lanip
=$
(uci
-P/var
/state get network.
$net.ipaddr
)
63 local lanmk
=$
(uci
-P/var
/state get network.
$net.netmask
)
66 config_get proto
"$cfg" proto
68 local epmin epmax extport
69 config_get extport
"$cfg" src_dport
70 [ -n "$extport" ] ||
return
72 epmin
="${extport%[-:]*}"; epmax
="${extport#*[-:]}"
73 [ "$epmin" != "$epmax" ] || epmax
=""
75 local ipmin ipmax intport
76 config_get intport
"$cfg" dest_port
"$extport"
78 ipmin
="${intport%[-:]*}"; ipmax
="${intport#*[-:]}"
79 [ "$ipmin" != "$ipmax" ] || ipmax
=""
82 config_get exthost
"$cfg" src_dip
"$wanip"
85 config_get inthost
"$cfg" dest_ip
86 [ -n "$inthost" ] ||
return
88 [ "$proto" = tcpudp
] && proto
="tcp udp"
90 [ "${inthost#!}" = "$inthost" ] ||
return 0
91 [ "${exthost#!}" = "$exthost" ] ||
return 0
94 for p
in ${proto:-tcp udp}; do
97 iptables
-t nat
-A nat_reflection_in \
98 -s $lanip/$lanmk -d $exthost \
99 -p $p --dport $epmin${epmax:+:$epmax} \
100 -j DNAT
--to $inthost:$ipmin${ipmax:+-$ipmax}
102 iptables
-t nat
-A nat_reflection_out \
103 -s $lanip/$lanmk -d $inthost \
104 -p $p --dport $ipmin${ipmax:+:$ipmax} \
105 -j SNAT
--to-source $lanip
107 iptables
-t filter
-A nat_reflection_fwd \
108 -s $lanip/$lanmk -d $inthost \
109 -p $p --dport $ipmin${ipmax:+:$ipmax} \
119 config_foreach setup_fwd redirect