12404bd48f5e695f857291e7f7338a0922d8b2a3
[openwrt/svn-archive/archive.git] / net / miniupnpd / files / miniupnpd.init
1 #!/bin/sh /etc/rc.common
2 START=95
3
4 start() {
5 type miniupnpd_add_rules >/dev/null 2>/dev/null || \
6 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
7
8 config_load "upnpd"
9 local extiface intiface upload download logging secure enabled natpmp
10 local extip
11
12 config_get extiface config external_iface
13 config_get intiface config internal_iface
14 config_get extip config external_ip
15 config_get upload config upload
16 config_get download config download
17 config_get_bool logging config log_output 0
18 config_get_bool secure config secure_mode 0
19 config_get_bool natpmp config enable_natpmp 0
20 config_get_bool enabled config enabled 0
21
22 include /lib/network
23 scan_interfaces
24
25 local ifname
26 config_get ifname ${extiface:-wan} ifname
27
28 if [ -n "$ifname" ]; then
29 local args="-i $ifname"
30 local iface
31
32 [ -n "$extip" ] && \
33 append args "-o $extip"
34
35 for iface in ${intiface:-lan}; do
36 local ipaddr
37 config_get ipaddr "$iface" ipaddr
38 [ -n "$ipaddr" ] && append args "-a $ipaddr"
39 done
40
41 append args "-p 5000 -U"
42
43 [ -n "$upload" -a -n "$download" ] && \
44 append args "-B $(($download * 1024 * 8)) $(($upload * 1024 * 8))"
45
46 [ "$secure" -gt 0 ] && \
47 append args "-S"
48
49 [ "$natpmp" -gt 0 ] && \
50 append args "-N"
51
52 # start firewall
53 local zone
54 config_load firewall
55 config_get zone core "${extiface:-wan}_zone"
56 [ -n "$zone" ] && \
57 miniupnpd_add_rules "$zone" "${extiface:-wan}" "$ifname"
58
59 if [ "$logging" = "1" ]; then
60 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
61 else
62 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
63 fi
64 else
65 logger -t "upnp daemon" "external interface not found, not starting"
66 fi
67 }
68
69 stop() {
70 start-stop-daemon -K -q -x miniupnpd -p /var/run/miniupnpd.pid
71 rm -f /var/run/miniupnpd.pid
72
73 type miniupnpd_remove_rules >/dev/null 2>/dev/null || \
74 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
75
76 miniupnpd_remove_rules
77
78 iptables -t nat -F MINIUPNPD 2>/dev/null
79 iptables -t nat -X MINIUPNPD 2>/dev/null
80 iptables -t filter -F MINIUPNPD 2>/dev/null
81 iptables -t filter -X MINIUPNPD 2>/dev/null
82 }