[packages] miniupnpd: restart daemon if internal iface is ifup'd
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 19 Feb 2011 19:11:11 +0000 (19:11 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 19 Feb 2011 19:11:11 +0000 (19:11 +0000)
SVN-Revision: 25593

net/miniupnpd/Makefile
net/miniupnpd/files/miniupnpd.firewall.hotplug [new file with mode: 0644]
net/miniupnpd/files/miniupnpd.hotplug [deleted file]
net/miniupnpd/files/miniupnpd.iface.hotplug [new file with mode: 0644]

index 18d0899..8dd08a4 100644 (file)
@@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=miniupnpd
 PKG_VERSION:=1.5
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 PKG_MD5SUM:=063f03a2a8363b9d4cb0f73b20b8dfce
 
 PKG_SOURCE_URL:=http://miniupnp.free.fr/files
@@ -41,11 +41,12 @@ define Build/Compile
 endef
 
 define Package/miniupnpd/install
-       $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/init.d $(1)/etc/config $(1)/etc/hotplug.d/firewall
+       $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/init.d $(1)/etc/config $(1)/etc/hotplug.d/iface $(1)/etc/hotplug.d/firewall
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/miniupnpd $(1)/usr/bin/miniupnpd
        $(INSTALL_BIN) ./files/miniupnpd.init $(1)/etc/init.d/miniupnpd
        $(INSTALL_CONF) ./files/upnpd.config $(1)/etc/config/upnpd
-       $(INSTALL_DATA) ./files/miniupnpd.hotplug $(1)/etc/hotplug.d/firewall/50-miniupnpd
+       $(INSTALL_DATA) ./files/miniupnpd.iface.hotplug $(1)/etc/hotplug.d/iface/50-miniupnpd
+       $(INSTALL_DATA) ./files/miniupnpd.firewall.hotplug $(1)/etc/hotplug.d/firewall/50-miniupnpd
 endef
 
 $(eval $(call BuildPackage,miniupnpd))
diff --git a/net/miniupnpd/files/miniupnpd.firewall.hotplug b/net/miniupnpd/files/miniupnpd.firewall.hotplug
new file mode 100644 (file)
index 0000000..f2d980c
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+miniupnpd_add_rules() {
+       local zone="$1"
+       local network="$2"
+       local iface="$3"
+
+       miniupnpd_remove_rules
+
+       logger -t miniupnpd "adding firewall rules for $iface to zone $zone"
+
+       iptables -t nat -N MINIUPNPD 2>/dev/null
+       iptables -t nat -I zone_${zone}_prerouting -i $iface -j MINIUPNPD
+       iptables -t filter -N MINIUPNPD 2>/dev/null
+       iptables -t filter -I zone_${zone}_forward -i $iface ! -o $iface -j MINIUPNPD
+
+       uci_set_state upnpd state "" state
+       uci_set_state upnpd state zone "$zone"
+       uci_set_state upnpd state ifname "$iface"
+       uci_set_state upnpd state network "$network"
+}
+
+miniupnpd_remove_rules() {
+       local zone="$(uci_get_state upnpd state zone)"
+       local iface="$(uci_get_state upnpd state ifname)"
+
+       [ -n "$zone" ] && [ -n "$iface" ] && {
+               logger -t miniupnpd "removing firewall rules for $iface from zone $zone"
+
+               while iptables -t nat -D zone_${zone}_prerouting \
+                       -i $iface -j MINIUPNPD 2>/dev/null; do :; done
+
+               while iptables -t filter -D zone_${zone}_forward \
+                       -i $iface ! -o $iface -j MINIUPNPD 2>/dev/null; do :; done
+       }
+
+       uci_revert_state upnpd
+}
+
+/etc/init.d/miniupnpd enabled && [ -n "`pidof miniupnpd`" ] && {
+
+       local extif="$(uci_get upnpd config external_iface)"
+       local curif="$(uci_get_state upnpd state network)"
+
+       if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "$extif" ]; then
+               miniupnpd_add_rules "$ZONE" "$INTERFACE" "$DEVICE"
+       elif [ "$ACTION" = "remove" ] && [ "$INTERFACE" = "$curif" ]; then
+               miniupnpd_remove_rules
+       fi
+}
diff --git a/net/miniupnpd/files/miniupnpd.hotplug b/net/miniupnpd/files/miniupnpd.hotplug
deleted file mode 100644 (file)
index f2d980c..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-
-miniupnpd_add_rules() {
-       local zone="$1"
-       local network="$2"
-       local iface="$3"
-
-       miniupnpd_remove_rules
-
-       logger -t miniupnpd "adding firewall rules for $iface to zone $zone"
-
-       iptables -t nat -N MINIUPNPD 2>/dev/null
-       iptables -t nat -I zone_${zone}_prerouting -i $iface -j MINIUPNPD
-       iptables -t filter -N MINIUPNPD 2>/dev/null
-       iptables -t filter -I zone_${zone}_forward -i $iface ! -o $iface -j MINIUPNPD
-
-       uci_set_state upnpd state "" state
-       uci_set_state upnpd state zone "$zone"
-       uci_set_state upnpd state ifname "$iface"
-       uci_set_state upnpd state network "$network"
-}
-
-miniupnpd_remove_rules() {
-       local zone="$(uci_get_state upnpd state zone)"
-       local iface="$(uci_get_state upnpd state ifname)"
-
-       [ -n "$zone" ] && [ -n "$iface" ] && {
-               logger -t miniupnpd "removing firewall rules for $iface from zone $zone"
-
-               while iptables -t nat -D zone_${zone}_prerouting \
-                       -i $iface -j MINIUPNPD 2>/dev/null; do :; done
-
-               while iptables -t filter -D zone_${zone}_forward \
-                       -i $iface ! -o $iface -j MINIUPNPD 2>/dev/null; do :; done
-       }
-
-       uci_revert_state upnpd
-}
-
-/etc/init.d/miniupnpd enabled && [ -n "`pidof miniupnpd`" ] && {
-
-       local extif="$(uci_get upnpd config external_iface)"
-       local curif="$(uci_get_state upnpd state network)"
-
-       if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "$extif" ]; then
-               miniupnpd_add_rules "$ZONE" "$INTERFACE" "$DEVICE"
-       elif [ "$ACTION" = "remove" ] && [ "$INTERFACE" = "$curif" ]; then
-               miniupnpd_remove_rules
-       fi
-}
diff --git a/net/miniupnpd/files/miniupnpd.iface.hotplug b/net/miniupnpd/files/miniupnpd.iface.hotplug
new file mode 100644 (file)
index 0000000..4772df9
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+/etc/init.d/miniupnpd enabled && [ -n "`pidof miniupnpd`" ] && {
+       local intif="$(uci_get upnpd config internal_iface)"
+       [ "$ACTION" = "ifup" ] && [ "$INTERFACE" = "$intif" ] && \
+               /etc/init.d/miniupnpd restart
+}