4 .
/lib
/functions
/network.sh
6 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
8 network_get_ipaddr wanip wan ||
return
10 iptables
-t nat
-F nat_reflection_in
2>/dev
/null ||
{
11 iptables
-t nat
-N nat_reflection_in
12 iptables
-t nat
-A prerouting_rule
-j nat_reflection_in
15 iptables
-t nat
-F nat_reflection_out
2>/dev
/null ||
{
16 iptables
-t nat
-N nat_reflection_out
17 iptables
-t nat
-A postrouting_rule
-j nat_reflection_out
20 iptables
-t filter
-F nat_reflection_fwd
2>/dev
/null ||
{
21 iptables
-t filter
-N nat_reflection_fwd
22 iptables
-t filter
-A forwarding_rule
-j nat_reflection_fwd
31 config_get name
"$cfg" name
33 [ "$name" = "$zone" ] && {
35 config_get network
"$cfg" network
37 echo ${network:-$zone}
42 config_foreach find_networks_cb zone
"$1"
49 config_get_bool reflection
"$cfg" reflection
1
50 [ "$reflection" == 1 ] ||
return
53 config_get src
"$cfg" src
56 config_get target
"$cfg" target DNAT
58 [ "$src" = wan
] && [ "$target" = DNAT
] && {
60 config_get dest
"$cfg" dest
"lan"
61 [ "$dest" != "*" ] ||
return
64 for net
in $
(find_networks
"$dest"); do
66 network_get_subnet lannet
"$net" ||
return
69 config_get proto
"$cfg" proto
71 local epmin epmax extport
72 config_get extport
"$cfg" src_dport
73 [ -n "$extport" ] ||
return
75 epmin
="${extport%[-:]*}"; epmax
="${extport#*[-:]}"
76 [ "${epmin#!}" != "$epmax" ] || epmax
=""
78 local ipmin ipmax intport
79 config_get intport
"$cfg" dest_port
"$extport"
81 ipmin
="${intport%[-:]*}"; ipmax
="${intport#*[-:]}"
82 [ "${ipmin#!}" != "$ipmax" ] || ipmax
=""
85 config_get exthost
"$cfg" src_dip
"$wanip"
88 config_get inthost
"$cfg" dest_ip
89 [ -n "$inthost" ] ||
return
91 [ "$proto" = tcpudp
] && proto
="tcp udp"
93 [ "${inthost#!}" = "$inthost" ] ||
return 0
94 [ "${exthost#!}" = "$exthost" ] ||
return 0
96 [ "${epmin#!}" != "$epmin" ] && \
97 extport
="! --dport ${epmin#!}${epmax:+:$epmax}" || \
98 extport
="--dport $epmin${epmax:+:$epmax}"
100 [ "${ipmin#!}" != "$ipmin" ] && \
101 intport
="! --dport ${ipmin#!}${ipmax:+:$ipmax}" || \
102 intport
="--dport $ipmin${ipmax:+:$ipmax}"
105 for p
in ${proto:-tcp udp}; do
108 iptables
-t nat
-A nat_reflection_in \
109 -s $lannet -d $exthost \
111 -j DNAT
--to $inthost:${ipmin#!}${ipmax:+-$ipmax}
113 iptables
-t nat
-A nat_reflection_out \
114 -s $lannet -d $inthost \
116 -j SNAT
--to-source ${lannet%%/*}
118 iptables
-t filter
-A nat_reflection_fwd \
119 -s $lannet -d $inthost \
130 config_foreach setup_fwd redirect