4 .
/usr
/share
/libubox
/jshn.sh
12 local tmp
="$(ubus call network.interface."$iface" status 2>/dev/null)"
14 json_load
"${tmp:-{}}"
15 json_get_type tmp address
17 if [ "$tmp" = array
]; then
22 if [ "$tmp" = object
]; then
25 [ -n "$ipaddr" ] && json_get_var
"$ipaddr" address
26 [ -n "$prefix" ] && json_get_var
"$prefix" mask
32 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
34 find_iface_address wan wanip
35 [ -n "$wanip" ] ||
return
37 iptables
-t nat
-F nat_reflection_in
2>/dev
/null ||
{
38 iptables
-t nat
-N nat_reflection_in
39 iptables
-t nat
-A prerouting_rule
-j nat_reflection_in
42 iptables
-t nat
-F nat_reflection_out
2>/dev
/null ||
{
43 iptables
-t nat
-N nat_reflection_out
44 iptables
-t nat
-A postrouting_rule
-j nat_reflection_out
47 iptables
-t filter
-F nat_reflection_fwd
2>/dev
/null ||
{
48 iptables
-t filter
-N nat_reflection_fwd
49 iptables
-t filter
-A forwarding_rule
-j nat_reflection_fwd
58 config_get name
"$cfg" name
60 [ "$name" = "$zone" ] && {
62 config_get network
"$cfg" network
64 echo ${network:-$zone}
69 config_foreach find_networks_cb zone
"$1"
76 config_get_bool reflection
"$cfg" reflection
1
77 [ "$reflection" == 1 ] ||
return
80 config_get src
"$cfg" src
83 config_get target
"$cfg" target DNAT
85 [ "$src" = wan
] && [ "$target" = DNAT
] && {
87 config_get dest
"$cfg" dest
"lan"
88 [ "$dest" != "*" ] ||
return
91 for net
in $
(find_networks
"$dest"); do
93 find_iface_address
"$net" lanip lanmk
94 [ -n "$lanip" ] ||
return
97 config_get proto
"$cfg" proto
99 local epmin epmax extport
100 config_get extport
"$cfg" src_dport
101 [ -n "$extport" ] ||
return
103 epmin
="${extport%[-:]*}"; epmax
="${extport#*[-:]}"
104 [ "${epmin#!}" != "$epmax" ] || epmax
=""
106 local ipmin ipmax intport
107 config_get intport
"$cfg" dest_port
"$extport"
109 ipmin
="${intport%[-:]*}"; ipmax
="${intport#*[-:]}"
110 [ "${ipmin#!}" != "$ipmax" ] || ipmax
=""
113 config_get exthost
"$cfg" src_dip
"$wanip"
116 config_get inthost
"$cfg" dest_ip
117 [ -n "$inthost" ] ||
return
119 [ "$proto" = tcpudp
] && proto
="tcp udp"
121 [ "${inthost#!}" = "$inthost" ] ||
return 0
122 [ "${exthost#!}" = "$exthost" ] ||
return 0
124 [ "${epmin#!}" != "$epmin" ] && \
125 extport
="! --dport ${epmin#!}${epmax:+:$epmax}" || \
126 extport
="--dport $epmin${epmax:+:$epmax}"
128 [ "${ipmin#!}" != "$ipmin" ] && \
129 intport
="! --dport ${ipmin#!}${ipmax:+:$ipmax}" || \
130 intport
="--dport $ipmin${ipmax:+:$ipmax}"
133 for p
in ${proto:-tcp udp}; do
136 iptables
-t nat
-A nat_reflection_in \
137 -s $lanip/$lanmk -d $exthost \
139 -j DNAT
--to $inthost:${ipmin#!}${ipmax:+-$ipmax}
141 iptables
-t nat
-A nat_reflection_out \
142 -s $lanip/$lanmk -d $inthost \
144 -j SNAT
--to-source $lanip
146 iptables
-t filter
-A nat_reflection_fwd \
147 -s $lanip/$lanmk -d $inthost \
158 config_foreach setup_fwd redirect