8b643f1bfaf84bb902d1a2e6873c5d6c9829abd4
[feed/routing.git] / miniupnpd / files / miniupnpd.hotplug
1 #!/bin/sh
2
3 if [ ! /etc/init.d/miniupnpd enabled ]
4 then
5 exit 0
6 fi
7
8 . /lib/functions/service.sh
9
10 # If miniupnpd is not running:
11 # - check on _any_ event (even updates may contribute to network_find_wan*)
12
13 # If miniupnpd _is_ running:
14 # - check only on ifup (otherwise lease updates etc would cause
15 # miniupnpd state loss)
16
17 [ ! "$ACTION" = "ifup" ] && service_check /usr/sbin/miniupnpd && exit 0
18
19 local iface
20 local ifname
21 local tmpconf="/var/etc/miniupnpd.conf"
22 local extiface=$(uci get upnpd.config.external_iface)
23 local extzone=$(uci get upnpd.config.external_zone)
24
25 . /lib/functions/network.sh
26
27 for iface in $(uci get upnpd.config.internal_iface); do
28 network_get_device device $iface
29 [ "$DEVICE" = "$device" ] && /etc/init.d/miniupnpd restart && exit 0
30 done
31
32
33 if [ -z "$extiface" ] ; then
34 # manual external zone (if dynamically find interfaces
35 # belonging to it) overrides network_find_wan*
36 if [ -n "$extzone" ] ; then
37 ifname=$(fw3 -q zone $extzone | head -1)
38 fi
39 [ -n "$extiface" ] || network_find_wan extiface
40 [ -n "$extiface" ] || network_find_wan6 extiface
41 fi
42
43 [ -n "$ifname" ] || network_get_device ifname ${extiface}
44 grep -q "ext_ifname=$ifname" $tmpconf || /etc/init.d/miniupnpd restart