1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
8 upnpd_get_port_range() {
16 export -n -- "${_var}_start=${_val%%[:-]*}"
17 export -n -- "${_var}_end=${_val##*[:-]}"
20 export -n -- "${_var}_start=$_val"
21 export -n -- "${_var}_end="
29 local action external_port_start external_port_end int_addr
30 local internal_port_start internal_port_end
32 config_get action "$cfg" action "deny" # allow or deny
33 upnpd_get_port_range "ext" "$cfg" ext_ports "0-65535" # external ports: x, x-y, x:y
34 config_get int_addr "$cfg" int_addr "0.0.0.0/0" # ip or network and subnet mask (internal)
35 upnpd_get_port_range "int" "$cfg" int_ports "0-65535" # internal ports: x, x-y, x:y or range
37 # Make a single IP IP/32 so that miniupnpd.conf can use it.
40 *) int_addr="$int_addr/32" ;;
43 echo "${action} ${ext_start}${ext_end:+-}${ext_end} ${int_addr} ${int_start}${int_end:+-}${int_end}" >>$tmpconf
52 config_get_bool val config "$opt" "$def"
53 if [ "$val" -eq 0 ]; then
54 echo "${alt:-$opt}=no" >> $tmpconf
56 echo "${alt:-$opt}=yes" >> $tmpconf
65 type miniupnpd_add_rules >/dev/null 2>/dev/null || \
66 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
69 local extiface intiface upload download logging secure enabled natpmp
70 local extip port usesysuptime conffile serial_number model_number
71 local uuid notify_interval presentation_url enable_upnp
72 local upnp_lease_file clean_ruleset_threshold clean_ruleset_interval
74 config_get extiface config external_iface
75 config_get intiface config internal_iface
76 config_get extip config external_ip
77 config_get port config port 5000
78 config_get upload config upload
79 config_get download config download
80 config_get_bool logging config log_output 0
81 config_get conffile config config_file
82 config_get serial_number config serial_number
83 config_get model_number config model_number
84 config_get uuid config uuid
85 config_get notify_interval config notify_interval
86 config_get presentation_url config presentation_url
87 config_get upnp_lease_file config upnp_lease_file
88 config_get clean_ruleset_threshold config clean_ruleset_threshold
89 config_get clean_ruleset_interval config clean_ruleset_interval
93 . /lib/functions/network.sh
96 network_get_device ifname ${extiface:-wan}
98 if [ -n "$conffile" ]; then
101 local tmpconf="/var/etc/miniupnpd.conf"
105 echo "ext_ifname=$ifname" >$tmpconf
108 echo "ext_ip=$extip" >>$tmpconf
111 for iface in ${intiface:-lan}; do
113 network_get_device device "$iface" && {
114 echo "listening_ip=$device" >>$tmpconf
118 [ "$port" != "auto" ] && \
119 echo "port=$port" >>$tmpconf
122 upnpd_write_bool enable_natpmp 1
123 upnpd_write_bool enable_upnp 1
124 upnpd_write_bool secure_mode 1
125 upnpd_write_bool system_uptime 1
127 [ -n "$upnp_lease_file" ] && \
128 echo "lease_file=$upnp_lease_file" >>$tmpconf
130 [ -n "$upload" -a -n "$download" ] && {
131 echo "bitrate_down=$(($download * 1024 * 8))" >>$tmpconf
132 echo "bitrate_up=$(($upload * 1024 * 8))" >>$tmpconf
135 [ -n "${presentation_url}" ] && \
136 echo "presentation_url=${presentation_url}" >>$tmpconf
138 [ -n "${notify_interval}" ] && \
139 echo "notify_interval=${notify_interval}" >>$tmpconf
141 [ -n "${clean_ruleset_threshold}" ] && \
142 echo "clean_ruleset_threshold=${clean_ruleset_threshold}" >>$tmpconf
144 [ -n "${clean_ruleset_interval}" ] && \
145 echo "clean_ruleset_interval=${clean_ruleset_interval}" >>$tmpconf
148 uuid="$(cat /proc/sys/kernel/random/uuid)"
149 uci set upnpd.config.uuid=$uuid
153 [ "$uuid" = "nocli" ] || \
154 echo "uuid=$uuid" >>$tmpconf
156 [ -n "${serial_number}" ] && \
157 echo "serial=${serial_number}" >>$tmpconf
159 [ -n "${model_number}" ] && \
160 echo "model_number=${model_number}" >>$tmpconf
162 config_foreach conf_rule_add perm_rule "$tmpconf"
166 if [ -n "$ifname" ]; then
170 config_get zone core "${extiface:-wan}_zone"
173 miniupnpd_add_rules "$zone" "${extiface:-wan}" "$ifname"
175 if [ "$logging" = "1" ]; then
176 SERVICE_DAEMONIZE=1 \
177 service_start /usr/sbin/miniupnpd $args -d
180 service_start /usr/sbin/miniupnpd $args
183 logger -t "upnp daemon" "external interface not found, not starting"
188 service_stop /usr/sbin/miniupnpd
190 type miniupnpd_remove_rules >/dev/null 2>/dev/null || \
191 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
193 miniupnpd_remove_rules
195 iptables -t nat -F MINIUPNPD 2>/dev/null
196 iptables -t nat -X MINIUPNPD 2>/dev/null
197 iptables -t filter -F MINIUPNPD 2>/dev/null
198 iptables -t filter -X MINIUPNPD 2>/dev/null