@@ -37,23 +37,16 @@ upnpd_add_custom_acl_entry() {
3737 echo " $action $ext_port $int_addr $int_port ${desc_filter} # $comment "
3838}
3939
40- upnpd () {
41- config_load " upnpd"
42- local enabled
43- config_get enabled settings enabled 0
44- [ " $enabled " != " 1" ] && log " Service disabled, UCI enabled is not set" && exit 1
45-
40+ upnpd_generate_config () {
4641 # Daemon
47- local enabled_protocols allow_cgnat_use stun_host allow_third_party_mapping ipv6_disable system_uptime log_output lease_file config_file
42+ local enabled_protocols allow_cgnat_use stun_host allow_third_party_mapping ipv6_disable system_uptime lease_file
4843 config_get enabled_protocols settings enabled_protocols all
4944 config_get allow_cgnat_use settings allow_cgnat_use 0
5045 config_get stun_host settings stun_host stun.nextcloud.com
5146 config_get allow_third_party_mapping settings allow_third_party_mapping 0
5247 config_get ipv6_disable settings ipv6_disable 0
5348 config_get system_uptime settings system_uptime 1
54- config_get log_output settings log_output
5549 config_get lease_file settings lease_file /run/miniupnpd.leases
56- config_get config_file settings config_file
5750
5851 # UPnP IGD
5952 local upnp_igd_compat upnp_igd_download upnp_igd_upload upnp_igd_friendly_name model_number serial_number presentation_url uuid upnp_igd_http_port notify_interval
@@ -75,47 +68,34 @@ upnpd() {
7568 config_get external_zone settings external_zone
7669 config_get external_ip settings external_ip
7770
78- local conf ifname ifname6
71+ local ifname ifname6
7972 . /lib/functions/network.sh
80-
81- if [ -n " $external_iface " ] ; then
73+ if [ -n " $external_iface " ]; then
8274 network_get_device ifname " $external_iface "
75+ elif [ -n " $external_zone " ]; then
76+ ifname=$( $FW -q zone " $external_zone " 2> /dev/null | head -1)
8377 else
84- if [ -n " $external_zone " ] ; then
85- ifname=$( $FW -q zone " $external_zone " 2> /dev/null | head -1)
86- else
87- network_find_wan external_iface && \
88- network_get_device ifname " $external_iface "
89- fi
78+ network_find_wan external_iface && network_get_device ifname " $external_iface "
9079 fi
91- if [ -n " $external_iface6 " ] ; then
80+ if [ -n " $external_iface6 " ]; then
9281 network_get_device ifname6 " $external_iface6 "
82+ elif [ -n " $external_zone " ]; then
83+ ifname6=$( $FW -q zone " $external_zone " 2> /dev/null | head -1)
9384 else
94- if [ -n " $external_zone " ] ; then
95- ifname6=$( $FW -q zone " $external_zone " 2> /dev/null | head -1)
96- else
97- network_find_wan6 external_iface6 && \
98- network_get_device ifname6 " $external_iface6 "
99- fi
85+ network_find_wan6 external_iface6 && network_get_device ifname6 " $external_iface6 "
10086 fi
10187
102- if [ -n " $config_file " ]; then
103- conf=" $config_file "
104- else
105- local tmpconf=" /var/etc/miniupnpd.conf"
106- conf=" $tmpconf "
107- mkdir -p /var/etc
108- [ " $ifname " = " " ] && log " No external network interface found, not starting" daemon.err && exit 1
109- ! uci -q get upnpd.@internal_network[0].interface > /dev/null && log " No internal networks configured, not starting" daemon.err && exit 1
110- # Only perform an STUN CGNAT test when necessary with a private/CGNAT external IPv4
111- local extipv4 extipv4private
112- network_get_ipaddr extipv4 " $ifname "
113- case " $extipv4 " in 10.* | 172.1[6-9].* | 172.2[0-9].* | 172.3[0-1].* | 192.168.* | 100.6[4-9].* | 100.[7-9][0-9].* | 100.1[0-1][0-9].* | 100.12[0-7].* )
114- extipv4private=1
115- ;;
116- esac
117-
118- {
88+ [ " $ifname " = " " ] && log " No external network interface found, not starting" daemon.err && exit 1
89+ ! uci -q get upnpd.@internal_network[0].interface > /dev/null && log " No internal networks configured, not starting" daemon.err && exit 1
90+ # Only perform an STUN CGNAT test when necessary with a private/CGNAT external IPv4
91+ local extipv4 extipv4private
92+ network_get_ipaddr extipv4 " $ifname "
93+ case " $extipv4 " in 10.* | 172.1[6-9].* | 172.2[0-9].* | 172.3[0-1].* | 192.168.* | 100.6[4-9].* | 100.[7-9][0-9].* | 100.1[0-1][0-9].* | 100.12[0-7].* )
94+ extipv4private=1
95+ ;;
96+ esac
97+
98+ {
11999 echo " # Daemon"
120100 [ " $enabled_protocols " = " all" ] && echo " enable_upnp=yes" && echo " enable_pcp_pmp=yes"
121101 [ " $enabled_protocols " = " upnp-igd" ] && echo " enable_upnp=yes" && echo " enable_pcp_pmp=no"
@@ -178,24 +158,7 @@ upnpd() {
178158 config_foreach upnpd_add_int_network_preset internal_network postcustom
179159 echo " deny 1-65535 0.0.0.0/0 1-65535 # Reject ACL by default"
180160
181- } > " $tmpconf "
182- fi
183-
184- if [ -n " $ifname " ]; then
185- if [ " $FW " = " fw4" ]; then
186- nft -s -t -n list chain inet fw4 upnp_forward > /dev/null 2>&1 || fw4 reload
187- else
188- iptables -L MINIUPNPD > /dev/null 2>&1 || fw3 reload
189- fi
190- fi
191-
192- procd_open_instance
193- procd_set_param file " $conf " " /etc/config/firewall"
194- procd_set_param command " $PROG "
195- procd_append_param command -f " $conf "
196- [ " $log_output " = " info" ] && procd_append_param command -v
197- [ " $log_output " = " debug" ] && procd_append_param command -d
198- procd_close_instance
161+ } > " $1 "
199162}
200163
201164stop_service () {
@@ -214,7 +177,32 @@ stop_service() {
214177start_service () {
215178 upnpd_uci_migration
216179 config_load " upnpd"
217- config_foreach upnpd " upnpd"
180+ local enabled config_file log_output conf
181+ config_get enabled settings enabled 0
182+ config_get config_file settings config_file
183+ config_get log_output settings log_output
184+ [ " $enabled " != " 1" ] && log " Service disabled, UCI enabled is not set" && exit 1
185+ if [ -n " $config_file " ]; then
186+ conf=" $config_file "
187+ else
188+ local tmpconf=" /var/etc/miniupnpd.conf"
189+ conf=" $tmpconf "
190+ mkdir -p /var/etc
191+ upnpd_generate_config " $tmpconf "
192+ fi
193+ if [ " $FW " = " fw4" ]; then
194+ nft -s -t -n list chain inet fw4 upnp_forward > /dev/null 2>&1 || fw4 reload
195+ else
196+ iptables -L MINIUPNPD > /dev/null 2>&1 || fw3 reload
197+ fi
198+
199+ procd_open_instance
200+ procd_set_param file " $conf " " /etc/config/firewall"
201+ procd_set_param command " $PROG "
202+ procd_append_param command -f " $conf "
203+ [ " $log_output " = " info" ] && procd_append_param command -v
204+ [ " $log_output " = " debug" ] && procd_append_param command -d
205+ procd_close_instance
218206}
219207
220208service_triggers () {
0 commit comments