summaryrefslogtreecommitdiff
path: root/package/firewall/files/lib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-01-08 15:29:24 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-01-08 15:29:24 +0000
commit8094fa46da2d35632617ca1498148f7ad7483748 (patch)
treeee0bd71439d92893dc8cfaaff3c2a0453c6777fb /package/firewall/files/lib
parent97af76a92047a9034cd394e08c715949eea68837 (diff)
downloadmtk-20170518-8094fa46da2d35632617ca1498148f7ad7483748.zip
mtk-20170518-8094fa46da2d35632617ca1498148f7ad7483748.tar.gz
mtk-20170518-8094fa46da2d35632617ca1498148f7ad7483748.tar.bz2
firewall: add support for "local" port forwards which target an internal address on the router itself
SVN-Revision: 29687
Diffstat (limited to 'package/firewall/files/lib')
-rw-r--r--package/firewall/files/lib/core_redirect.sh15
1 files changed, 13 insertions, 2 deletions
diff --git a/package/firewall/files/lib/core_redirect.sh b/package/firewall/files/lib/core_redirect.sh
index a3e70d4..fe396c1 100644
--- a/package/firewall/files/lib/core_redirect.sh
+++ b/package/firewall/files/lib/core_redirect.sh
@@ -34,7 +34,17 @@ fw_load_redirect() {
return 0
}
- fwdchain="zone_${redirect_src}${redirect_dest_ip:+_forward}"
+ fwdopt=""
+ fwdchain=""
+
+ # Check whether only ports are given or whether the given dest ip is local,
+ # in this case match only DNATed traffic and allow it on input, not forward
+ if [ -z "$redirect_dest_ip" ] || /sbin/ifconfig | grep -qE "addr:${redirect_dest_ip//./\\.}\b"; then
+ fwdopt="-m conntrack --ctstate DNAT"
+ fwdchain="zone_${redirect_src}"
+ else
+ fwdchain="zone_${redirect_src}_forward"
+ fi
natopt="--to-destination"
natchain="zone_${redirect_src}_prerouting"
@@ -106,10 +116,11 @@ fw_load_redirect() {
fw add $mode f ${fwdchain:-forward} ACCEPT + \
{ $redirect_src_ip $redirect_dest_ip } { \
- $srcaddr ${destaddr:--m conntrack --ctstate DNAT} \
+ $srcaddr $destaddr \
$pr \
$srcports $destports \
${sm:+-m mac $sm} \
+ $fwdopt \
$redirect_extra \
}
done