1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2014 OpenWrt.org
9 upnpd_get_port_range
() {
10 local _var
="$1"; shift
17 export -n -- "${_var}_start=${_val%%[:-]*}"
18 export -n -- "${_var}_end=${_val##*[:-]}"
21 export -n -- "${_var}_start=$_val"
22 export -n -- "${_var}_end="
30 local action external_port_start external_port_end int_addr
31 local internal_port_start internal_port_end
33 config_get action
"$cfg" action
"deny" # allow or deny
34 upnpd_get_port_range
"ext" "$cfg" ext_ports
"0-65535" # external ports: x, x-y, x:y
35 config_get int_addr
"$cfg" int_addr
"0.0.0.0/0" # ip or network and subnet mask (internal)
36 upnpd_get_port_range
"int" "$cfg" int_ports
"0-65535" # internal ports: x, x-y, x:y or range
38 # Make a single IP IP/32 so that miniupnpd.conf can use it.
41 *) int_addr
="$int_addr/32" ;;
44 echo "${action} ${ext_start}${ext_end:+-}${ext_end} ${int_addr} ${int_start}${int_end:+-}${int_end}" >>$tmpconf
53 config_get_bool val config
"$opt" "$def"
54 if [ "$val" -eq 0 ]; then
55 echo "${alt:-$opt}=no" >> $tmpconf
57 echo "${alt:-$opt}=yes" >> $tmpconf
67 local extiface intiface upload download logging secure enabled natpmp
68 local extip port usesysuptime conffile serial_number model_number
69 local uuid notify_interval presentation_url enable_upnp
70 local upnp_lease_file clean_ruleset_threshold clean_ruleset_interval
71 local ipv6_listening_ip enabled
73 config_get_bool enabled config enabled
1
75 [ "$enabled" -gt 0 ] ||
return 1
77 config_get extiface config external_iface
78 config_get extzone config external_zone
79 config_get intiface config internal_iface
80 config_get extip config external_ip
81 config_get port config port
5000
82 config_get upload config upload
83 config_get download config download
84 config_get_bool logging config log_output
0
85 config_get conffile config config_file
86 config_get serial_number config serial_number
87 config_get model_number config model_number
88 config_get uuid config uuid
89 config_get notify_interval config notify_interval
90 config_get presentation_url config presentation_url
91 config_get upnp_lease_file config upnp_lease_file
92 config_get clean_ruleset_threshold config clean_ruleset_threshold
93 config_get clean_ruleset_interval config clean_ruleset_interval
94 config_get ipv6_listening_ip config ipv6_listening_ip
98 .
/lib
/functions
/network.sh
102 # manual external interface overrides everything
103 if [ -z "$extiface" ] ; then
104 # manual external zone (if dynamically find interfaces
105 # belonging to it) overrides network_find_wan*
106 if [ -n "$extzone" ] ; then
107 ifname
=$
(fw3
-q zone
$extzone |
head -1)
109 [ -n "$extiface" ] || network_find_wan extiface
110 [ -n "$extiface" ] || network_find_wan6 extiface
113 [ -n "$ifname" ] || network_get_device ifname
${extiface}
115 if [ -n "$conffile" ]; then
118 local tmpconf
="/var/etc/miniupnpd.conf"
122 echo "ext_ifname=$ifname" >$tmpconf
125 echo "ext_ip=$extip" >>$tmpconf
128 for iface
in ${intiface:-lan}; do
130 network_get_device device
"$iface" && {
131 echo "listening_ip=$device" >>$tmpconf
135 [ "$port" != "auto" ] && \
136 echo "port=$port" >>$tmpconf
139 upnpd_write_bool enable_natpmp
1
140 upnpd_write_bool enable_upnp
1
141 upnpd_write_bool secure_mode
1
142 upnpd_write_bool pcp_allow_thirdparty
0
143 upnpd_write_bool system_uptime
1
145 [ -n "$upnp_lease_file" ] && \
146 echo "lease_file=$upnp_lease_file" >>$tmpconf
148 [ -n "$upload" -a -n "$download" ] && {
149 echo "bitrate_down=$(($download * 1024 * 8))" >>$tmpconf
150 echo "bitrate_up=$(($upload * 1024 * 8))" >>$tmpconf
153 [ -n "${presentation_url}" ] && \
154 echo "presentation_url=${presentation_url}" >>$tmpconf
156 [ -n "${notify_interval}" ] && \
157 echo "notify_interval=${notify_interval}" >>$tmpconf
159 [ -n "${clean_ruleset_threshold}" ] && \
160 echo "clean_ruleset_threshold=${clean_ruleset_threshold}" >>$tmpconf
162 [ -n "${clean_ruleset_interval}" ] && \
163 echo "clean_ruleset_interval=${clean_ruleset_interval}" >>$tmpconf
165 [ -n "${ipv6_listening_ip}" ] && \
166 echo "ipv6_listening_ip=${ipv6_listening_ip}" >>$tmpconf
169 uuid
="$(cat /proc/sys/kernel/random/uuid)"
170 uci
set upnpd.config.uuid
=$uuid
174 [ "$uuid" = "nocli" ] || \
175 echo "uuid=$uuid" >>$tmpconf
177 [ -n "${serial_number}" ] && \
178 echo "serial=${serial_number}" >>$tmpconf
180 [ -n "${model_number}" ] && \
181 echo "model_number=${model_number}" >>$tmpconf
183 config_foreach conf_rule_add perm_rule
"$tmpconf"
187 if [ -n "$ifname" ]; then
189 iptables
-L MINIUPNPD
>/dev
/null
2>/dev
/null || fw3 reload
191 if [ "$logging" = "1" ]; then
192 SERVICE_DAEMONIZE
=1 \
193 service_start
/usr
/sbin
/miniupnpd
$args -d
196 service_start
/usr
/sbin
/miniupnpd
$args
199 logger
-t "upnp daemon" "external interface not found, not starting"
204 service_stop
/usr
/sbin
/miniupnpd
206 iptables
-t nat
-F MINIUPNPD
2>/dev
/null
207 iptables
-t filter
-F MINIUPNPD
2>/dev
/null
209 [ -x /usr
/sbin
/ip6tables
] && {
210 ip6tables
-t filter
-F MINIUPNPD
2>/dev
/null