[package] firewall: don't setup nat reflection if negations are used
[openwrt/svn-archive/archive.git] / package / firewall / files / reflection.hotplug
index af88fe0243fdb2e550b3837d87d7d85323b9da1c..b3b5e5ecce29336b6931583d0a98d34cb3ed34c1 100644 (file)
@@ -2,7 +2,7 @@
 
 . /etc/functions.sh
 
-if [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "wan" ]; then
+if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
        local wanip=$(uci -P/var/state get network.wan.ipaddr)
 
        iptables -t nat -F nat_reflection_in 2>/dev/null || {
@@ -41,7 +41,10 @@ if [ "$ACTION" = "ifup" ] && [ "$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"
 
@@ -53,6 +56,10 @@ if [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "wan" ]; then
                                local proto
                                config_get proto "$cfg" proto
 
+                               local reflection
+                               config_get_bool reflection "$cfg" reflection 1
+                               [ "$reflection" == 1 ] || return
+
                                local epmin epmax extport
                                config_get extport "$cfg" src_dport
                                [ -n "$extport" ] || return
@@ -75,6 +82,9 @@ if [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "wan" ]; then
 
                                [ "$proto" = tcpudp ] && proto="tcp udp"
 
+                               [ "${inthost#!}" = "$inthost" ] || return 0
+                               [ "${exthost#!}" = "$exthost" ] || return 0
+
                                local p
                                for p in ${proto:-tcp udp}; do
                                        case "$p" in