[package] firewall: also set up nat reflection rules for redirects with proto all...
[openwrt/svn-archive/archive.git] / package / firewall / files / reflection.hotplug
index 1feb21075afcb0aa30ef86032ff43764ae424257..843c615bcbb6d17d678a3e96ae93752f6713ad30 100644 (file)
@@ -1,9 +1,11 @@
 #!/bin/sh
 
-. /etc/functions.sh
+. /lib/functions.sh
+. /lib/functions/network.sh
 
 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
-       local wanip=$(uci -P/var/state get network.wan.ipaddr)
+       local wanip
+       network_get_ipaddr wanip wan || return
 
        iptables -t nat -F nat_reflection_in 2>/dev/null || {
                iptables -t nat -N nat_reflection_in
@@ -60,14 +62,14 @@ if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
 
                        local net
                        for net in $(find_networks "$dest"); do
-                               local lanip=$(uci -P/var/state get network.$net.ipaddr)
-                               local lanmk=$(uci -P/var/state get network.$net.netmask)
+                               local lannet
+                               network_get_subnet lannet "$net" || return
 
                                local proto
                                config_get proto "$cfg" proto
 
                                local epmin epmax extport
-                               config_get extport "$cfg" src_dport
+                               config_get extport "$cfg" src_dport "1-65535"
                                [ -n "$extport" ] || return
 
                                epmin="${extport%[-:]*}"; epmax="${extport#*[-:]}"
@@ -86,6 +88,7 @@ if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
                                config_get inthost "$cfg" dest_ip
                                [ -n "$inthost" ] || return
 
+                               [ "$proto" = all    ] && proto="tcp udp"
                                [ "$proto" = tcpudp ] && proto="tcp udp"
 
                                [ "${inthost#!}" = "$inthost" ] || return 0
@@ -104,17 +107,17 @@ if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
                                        case "$p" in
                                                tcp|udp|6|17)
                                                        iptables -t nat -A nat_reflection_in \
-                                                               -s $lanip/$lanmk -d $exthost \
+                                                               -s $lannet -d $exthost \
                                                                -p $p $extport \
                                                                -j DNAT --to $inthost:${ipmin#!}${ipmax:+-$ipmax}
 
                                                        iptables -t nat -A nat_reflection_out \
-                                                               -s $lanip/$lanmk -d $inthost \
+                                                               -s $lannet -d $inthost \
                                                                -p $p $intport \
-                                                               -j SNAT --to-source $lanip
+                                                               -j SNAT --to-source ${lannet%%/*}
 
                                                        iptables -t filter -A nat_reflection_fwd \
-                                                               -s $lanip/$lanmk -d $inthost \
+                                                               -s $lannet -d $inthost \
                                                                -p $p $intport \
                                                                -j ACCEPT
                                                ;;