4 .
/usr
/share
/libubox
/jshn.sh
13 local tmp
="$(ubus call network.interface."$iface" status 2>/dev/null)"
15 json_load
"${tmp:-{}}"
16 json_get_type tmp address
18 if [ "$tmp" = array
]; then
22 json_get_type tmp
$idx
23 [ "$tmp" = object
] ||
break
25 json_select $
((idx
++))
26 json_get_var tmp address
29 *:*) json_select ..
;;
31 [ -n "$ipaddr" ] && json_get_var
$ipaddr address
32 [ -n "$prefix" ] && json_get_var
$prefix mask
42 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
44 find_iface_address wan wanip
45 [ -n "$wanip" ] ||
return
47 iptables
-t nat
-F nat_reflection_in
2>/dev
/null ||
{
48 iptables
-t nat
-N nat_reflection_in
49 iptables
-t nat
-A prerouting_rule
-j nat_reflection_in
52 iptables
-t nat
-F nat_reflection_out
2>/dev
/null ||
{
53 iptables
-t nat
-N nat_reflection_out
54 iptables
-t nat
-A postrouting_rule
-j nat_reflection_out
57 iptables
-t filter
-F nat_reflection_fwd
2>/dev
/null ||
{
58 iptables
-t filter
-N nat_reflection_fwd
59 iptables
-t filter
-A forwarding_rule
-j nat_reflection_fwd
68 config_get name
"$cfg" name
70 [ "$name" = "$zone" ] && {
72 config_get network
"$cfg" network
74 echo ${network:-$zone}
79 config_foreach find_networks_cb zone
"$1"
86 config_get_bool reflection
"$cfg" reflection
1
87 [ "$reflection" == 1 ] ||
return
90 config_get src
"$cfg" src
93 config_get target
"$cfg" target DNAT
95 [ "$src" = wan
] && [ "$target" = DNAT
] && {
97 config_get dest
"$cfg" dest
"lan"
98 [ "$dest" != "*" ] ||
return
101 for net
in $
(find_networks
"$dest"); do
103 find_iface_address
"$net" lanip lanmk
104 [ -n "$lanip" ] ||
return
107 config_get proto
"$cfg" proto
109 local epmin epmax extport
110 config_get extport
"$cfg" src_dport
111 [ -n "$extport" ] ||
return
113 epmin
="${extport%[-:]*}"; epmax
="${extport#*[-:]}"
114 [ "${epmin#!}" != "$epmax" ] || epmax
=""
116 local ipmin ipmax intport
117 config_get intport
"$cfg" dest_port
"$extport"
119 ipmin
="${intport%[-:]*}"; ipmax
="${intport#*[-:]}"
120 [ "${ipmin#!}" != "$ipmax" ] || ipmax
=""
123 config_get exthost
"$cfg" src_dip
"$wanip"
126 config_get inthost
"$cfg" dest_ip
127 [ -n "$inthost" ] ||
return
129 [ "$proto" = tcpudp
] && proto
="tcp udp"
131 [ "${inthost#!}" = "$inthost" ] ||
return 0
132 [ "${exthost#!}" = "$exthost" ] ||
return 0
134 [ "${epmin#!}" != "$epmin" ] && \
135 extport
="! --dport ${epmin#!}${epmax:+:$epmax}" || \
136 extport
="--dport $epmin${epmax:+:$epmax}"
138 [ "${ipmin#!}" != "$ipmin" ] && \
139 intport
="! --dport ${ipmin#!}${ipmax:+:$ipmax}" || \
140 intport
="--dport $ipmin${ipmax:+:$ipmax}"
143 for p
in ${proto:-tcp udp}; do
146 iptables
-t nat
-A nat_reflection_in \
147 -s $lanip/$lanmk -d $exthost \
149 -j DNAT
--to $inthost:${ipmin#!}${ipmax:+-$ipmax}
151 iptables
-t nat
-A nat_reflection_out \
152 -s $lanip/$lanmk -d $inthost \
154 -j SNAT
--to-source $lanip
156 iptables
-t filter
-A nat_reflection_fwd \
157 -s $lanip/$lanmk -d $inthost \
168 config_foreach setup_fwd redirect