2 # Setup NAT reflection rules
6 if [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "wan" ]; then
7 local wanip
=$
(uci
-P/var
/state get network.wan.ipaddr
)
9 iptables
-t nat
-F nat_reflection_in
2>/dev
/null ||
{
10 iptables
-t nat
-N nat_reflection_in
11 iptables
-t nat
-A prerouting_rule
-j nat_reflection_in
14 iptables
-t nat
-F nat_reflection_out
2>/dev
/null ||
{
15 iptables
-t nat
-N nat_reflection_out
16 iptables
-t nat
-A postrouting_rule
-j nat_reflection_out
23 config_get src
"$cfg" src
27 config_get dest
"$cfg" dest
"lan"
29 local lanip
=$
(uci
-P/var
/state get network.
$dest.ipaddr
)
30 local lanmk
=$
(uci
-P/var
/state get network.
$dest.netmask
)
33 config_get proto
"$cfg" proto
35 local epmin epmax extport
36 config_get extport
"$cfg" src_dport
37 [ -n "$extport" ] ||
return
39 epmin
="${extport%[-:]*}"; epmax
="${extport#*[-:]}"
40 [ "$epmin" != "$epmax" ] || epmax
=""
42 local ipmin ipmax intport
43 config_get intport
"$cfg" dest_port
"$extport"
45 ipmin
="${intport%[-:]*}"; ipmax
="${intport#*[-:]}"
46 [ "$ipmin" != "$ipmax" ] || ipmax
=""
49 config_get exthost
"$cfg" src_dip
"$wanip"
52 config_get inthost
"$cfg" dest_ip
53 [ -n "$inthost" ] ||
return
55 [ "$proto" = tcpudp
] && proto
="tcp udp"
58 for p
in ${proto:-tcp udp}; do
61 iptables
-t nat
-A nat_reflection_in \
62 -s $lanip/$lanmk -d $exthost \
63 -p $p --dport $epmin${epmax:+:$epmax} \
64 -j DNAT
--to $inthost:$ipmin${ipmax:+-$ipmax}
66 iptables
-t nat
-A nat_reflection_out \
67 -s $lanip/$lanmk -d $inthost \
68 -p $p --dport $ipmin${ipmax:+:$ipmax} \
69 -j SNAT
--to-source $lanip
77 config_foreach setup_fwd redirect