[packages] gpsd: update to v2.90
[openwrt/svn-archive/archive.git] / net / miniupnpd / files / miniupnpd.init
index 5e337df5fd7ffbc07b921e3ff2f4b7aa7d6f8b6b..4705fc8fcd409eb9a7b451944fc099a641aaafbf 100644 (file)
@@ -1,38 +1,29 @@
 #!/bin/sh /etc/rc.common
 START=95
 
-include /lib/miniupnpd
-
-boot() {
-       # On boot, there's a race condition with hotplug,
-       # therfore do nothing here
-       return
-}
-
 start() {
-       local extif
-       local intif
-       local extiface
-       local upload
-       local download
-       local logging
-
        config_load "upnpd"
-       config_get extif    config external_iface
-       config_get intif    config internal_iface
+       local extiface intiface upload download logging secure enabled
+
+       config_get extiface config external_iface
+       config_get intiface config internal_iface
        config_get upload   config upload
        config_get download config download
        config_get_bool logging config log_output 0
+       config_get_bool secure config secure_mode 0
+       config_get_bool enabled config enabled 0 
+
+       include /lib/network
+       scan_interfaces
 
-       config_load "network"
-       config_get extiface ${extif:-wan} ifname
-       
-       if [ -n "$extiface" ]; then
-               upnp_firewall_start
+       local ifname
+       config_get ifname ${extiface:-wan} ifname
 
-               local args="-i $extiface"
+       if [ -n "$ifname" ]; then
+               local args="-i $ifname"
+               local iface
 
-               for iface in ${intif:-lan}; do
+               for iface in ${intiface:-lan}; do
                        local ipaddr
                        config_get ipaddr "$iface" ipaddr
                        [ -n "$ipaddr" ] && append args "-a $ipaddr"
@@ -43,17 +34,55 @@ start() {
                [ -n "$upload" -a -n "$download" ] && \
                        append args "-B $(($download * 1024 * 8)) $(($upload * 1024 * 8))"
 
+               [ "$secure" -gt 0 ] && \
+                       append args "-S"
+
                if [ "$logging" = "1" ]; then
-                       eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
+                       [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
                else
-                       eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
+                       [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
                fi
+
+               # start firewall
+               local zone
+               config_load firewall
+               config_get zone core "${extiface:-wan}_zone"
+               [ -n "$zone" ] && \
+                       ACTION="add" ZONE="$zone" INTERFACE="${extiface:-wan}" DEVICE="$ifname" \
+                               . /etc/hotplug.d/firewall/50-miniupnpd 
        else
                logger -t "upnp daemon" "external interface not found, not starting"
        fi
 }
 
+clear_rule() {
+       local state="$1"
+       local ifname ipaddr
+
+       config_get ifname "$state" ifname
+       config_get ipaddr "$state" ipaddr
+
+       [ -n "$ifname" ] && [ -n "$ipaddr" ] && {
+               iptables -t nat -D prerouting_rule -i $ifname -d $ipaddr -j MINIUPNPD
+               iptables -t filter -D forwarding_rule -i $ifname ! -o $ifname -j MINIUPNPD
+               uci_revert_state upnpd "$state"
+               unset "CONFIG_${state}_ifname"
+               unset "CONFIG_${state}_ipaddr"
+       }
+}
+
 stop() {
        start-stop-daemon -K -q -x miniupnpd -p /var/run/miniupnpd.pid
-       upnp_firewall_stop
+       rm -f /var/run/miniupnpd.pid
+
+       logger -t "upnp" "removing firewall rules"
+
+       config_load upnpd
+       config_foreach clear_rule firewall
+
+       iptables -t nat -F MINIUPNPD 2>/dev/null
+       iptables -t nat -X MINIUPNPD 2>/dev/null
+       iptables -t filter -F MINIUPNPD 2>/dev/null
+       iptables -t filter -X MINIUPNPD 2>/dev/null
 }
+