firewall: introduce SNAT support for redirect sections
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 5 Sep 2010 19:03:17 +0000 (19:03 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 5 Sep 2010 19:03:17 +0000 (19:03 +0000)
SVN-Revision: 22937

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

index 599126ae1e2e815b8b0adaf879faa3bbdcdb5f40..b6d42cebade4f2ef6b8dec358985deb37cef5183 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=firewall
 
 PKG_VERSION:=2
-PKG_RELEASE:=11
+PKG_RELEASE:=12
 
 include $(INCLUDE_DIR)/package.mk
 
index 15d01b0a7557cd7b1b44e7dd76e6888a9bb80324..913f963562d4b6885506030393531d92bbf5d506 100644 (file)
@@ -17,6 +17,7 @@ fw_config_get_redirect() {
                string dest_port "" \
                string proto "tcpudp" \
                string family "" \
+               string target "DNAT" \
        } || return
        [ -n "$redirect_name" ] || redirect_name=$redirect__name
 }
@@ -30,6 +31,17 @@ fw_load_redirect() {
                fw_die "redirect ${redirect_name}: needs src and dest_ip or dest_port"
        }
 
+       local chain destopt
+       if [ "$redirect_target" == "DNAT" ]; then
+               chain="zone_${redirect_src}_prerouting"
+               destopt="--to-destination"
+       elif [ "$redirect_target" == "SNAT" ]; then
+               chain="zone_${redirect_src}_nat"
+               destopt="--to-source"
+       else
+               fw_die "redirect ${redirect_name}: target must be either DNAT or SNAT"
+       fi
+
        list_contains FW_CONNTRACK_ZONES $redirect_src || \
                append FW_CONNTRACK_ZONES $redirect_src
 
@@ -43,14 +55,14 @@ fw_load_redirect() {
 
        [ "$redirect_proto" == "tcpudp" ] && redirect_proto="tcp udp"
        for redirect_proto in $redirect_proto; do
-               fw add $mode n zone_${redirect_src}_prerouting DNAT $ { $redirect_src_ip $redirect_dest_ip } { \
+               fw add $mode n $chain $redirect_target $ { $redirect_src_ip $redirect_dest_ip } { \
                        ${redirect_proto:+-p $redirect_proto} \
                        ${redirect_src_ip:+-s $redirect_src_ip/$redirect_src_ip_prefixlen} \
                        ${redirect_src_dip:+-d $redirect_src_dip/$redirect_src_dip_prefixlen} \
                        ${redirect_src_port:+--sport $redirect_src_port} \
                        ${redirect_src_dport:+--dport $redirect_src_dport} \
                        ${redirect_src_mac:+-m mac --mac-source $redirect_src_mac} \
-                       --to-destination ${redirect_dest_ip}${redirect_dest_port:+:$nat_dest_port} \
+                       $destopt ${redirect_dest_ip}${redirect_dest_port:+:$nat_dest_port} \
                }
 
                [ -n "$redirect_dest_ip" ] && \
index 6b1cd60f2857b6f97ff9b32c6d8dc9b5e6fc1082..027d2ed8b1a0d73854919c2e26241ec6959be0e0 100644 (file)
@@ -41,7 +41,10 @@ if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
                local src
                config_get src "$cfg" src
 
-               [ "$src" = wan ] && {
+               local target
+               config_get target "$cfg" target DNAT
+
+               [ "$src" = wan ] && [ "$target" = DNAT ] && {
                        local dest
                        config_get dest "$cfg" dest "lan"