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"
59 [ "$dest" != "*" ] || return
62 for net in $(find_networks "$dest"); do
63 local lanip=$(uci -P/var/state get network.$net.ipaddr)
64 local lanmk=$(uci -P/var/state get network.$net.netmask)
67 config_get proto "$cfg" proto
69 local epmin epmax extport
70 config_get extport "$cfg" src_dport
71 [ -n "$extport" ] || return
73 epmin="${extport%[-:]*}"; epmax="${extport#*[-:]}"
74 [ "$epmin" != "$epmax" ] || epmax=""
76 local ipmin ipmax intport
77 config_get intport "$cfg" dest_port "$extport"
79 ipmin="${intport%[-:]*}"; ipmax="${intport#*[-:]}"
80 [ "$ipmin" != "$ipmax" ] || ipmax=""
83 config_get exthost "$cfg" src_dip "$wanip"
86 config_get inthost "$cfg" dest_ip
87 [ -n "$inthost" ] || return
89 [ "$proto" = tcpudp ] && proto="tcp udp"
91 [ "${inthost#!}" = "$inthost" ] || return 0
92 [ "${exthost#!}" = "$exthost" ] || return 0
94 [ "${epmin#!}" != "$epmin" ] && \
95 extport="! --dport ${epmin#!}${epmax:+:$epmax}" || \
96 extport="--dport $epmin${epmax:+:$epmax}"
98 [ "${ipmin#!}" != "$ipmin" ] && \
99 intport="! --dport ${ipmin#!}${ipmax:+:$ipmax}" || \
100 intport="--dport $ipmin${ipmax:+:$ipmax}"
103 for p in ${proto:-tcp udp}; do
106 iptables -t nat -A nat_reflection_in \
107 -s $lanip/$lanmk -d $exthost \
109 -j DNAT --to $inthost:${ipmin#!}${ipmax:+-$ipmax}
111 iptables -t nat -A nat_reflection_out \
112 -s $lanip/$lanmk -d $inthost \
114 -j SNAT --to-source $lanip
116 iptables -t filter -A nat_reflection_fwd \
117 -s $lanip/$lanmk -d $inthost \
128 config_foreach setup_fwd redirect