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