[package] firewall: add support for "local" port forwards which target an internal...
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 8 Jan 2012 15:29:24 +0000 (15:29 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 8 Jan 2012 15:29:24 +0000 (15:29 +0000)
SVN-Revision: 29687

package/firewall/Makefile
package/firewall/files/lib/core_redirect.sh

index 3c5e10fe9daf6bf08e6de10549c950e1c3b5734d..746cca4882b3cfa0ac2261db5e044ac3fc8137cc 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2008-2011 OpenWrt.org
+# Copyright (C) 2008-2012 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=firewall
 
 PKG_VERSION:=2
-PKG_RELEASE:=43
+PKG_RELEASE:=44
 
 include $(INCLUDE_DIR)/package.mk
 
index a3e70d40d74fd6b051c51a9375f600240dbf75a8..fe396c1c12828c46aa66968934c5f68e548f6092 100644 (file)
@@ -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