diff --git a/net/upnp/Makefile b/net/upnp/Makefile index f96762686..c69f84af2 100644 --- a/net/upnp/Makefile +++ b/net/upnp/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= upnp -PLUGIN_VERSION= 1.4 -PLUGIN_REVISION= 2 +PLUGIN_VERSION= 1.5 PLUGIN_DEPENDS= miniupnpd-devel PLUGIN_COMMENT= Universal Plug and Play Service PLUGIN_MAINTAINER= franco@opnsense.org diff --git a/net/upnp/src/etc/inc/plugins.inc.d/miniupnpd.inc b/net/upnp/src/etc/inc/plugins.inc.d/miniupnpd.inc index 9ded4aeb4..9314cd2f6 100644 --- a/net/upnp/src/etc/inc/plugins.inc.d/miniupnpd.inc +++ b/net/upnp/src/etc/inc/plugins.inc.d/miniupnpd.inc @@ -147,7 +147,11 @@ function miniupnpd_configure_do($verbose = false) if ($if != $iface) { $addr = get_interface_ip($iface); if (!empty($addr)) { - $config_text .= "listening_ip={$if}\n"; + if (isset($upnp_config['overridesubnet'])) { + $config_text .= "listening_ip={$if}{$upnp_config['overridesubnet']}\n"; + } else { + $config_text .= "listening_ip={$if}\n"; + } if (!$ifaces_active) { $webgui_ip = $addr; $ifaces_active = $iface; @@ -164,9 +168,17 @@ function miniupnpd_configure_do($verbose = false) if (!empty($ifaces_active)) { /* override wan ip address, common for carp, etc */ - if (!empty($upnp_config['overridewanip'])) { + if (!empty($upnp_config['overridewanip']) && empty($upnp_config['stun_host'])) { $config_text .= "ext_ip={$upnp_config['overridewanip']}\n"; } + + /* configure STUN server if needed */ + if (empty($upnp_config['overridewanip']) && !empty($upnp_config['stun_host'])) { + $config_text .= "ext_perform_stun=yes\n"; + $config_text .= "ext_stun_host=" . ($upnp_config['stun_host']) ."\n"; + $config_text .= "ext_stun_port=" . ($upnp_config['stun_port'] ?? "3478") . "\n"; + } + /* set upload and download bitrates */ if (!empty($upnp_config['download']) && !empty($upnp_config['upload'])) { $download = $upnp_config['download'] * 1000; diff --git a/net/upnp/src/www/services_upnp.php b/net/upnp/src/www/services_upnp.php index e3512ae83..d4b59d264 100644 --- a/net/upnp/src/www/services_upnp.php +++ b/net/upnp/src/www/services_upnp.php @@ -68,8 +68,9 @@ function miniupnpd_validate_port($port) if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); - $copy_fields = array('enable', 'enable_upnp', 'enable_natpmp', 'ext_iface', 'iface_array', 'download', - 'upload', 'overridewanip', 'logpackets', 'sysuptime', 'permdefault'); + $copy_fields = array('enable', 'enable_upnp', 'enable_natpmp', 'ext_iface', 'iface_array', 'stun_host', + 'stun_port', 'overridesubnet', 'download', 'upload', 'overridewanip', 'logpackets', 'sysuptime', + 'permdefault'); foreach (miniupnpd_permuser_list() as $permuser) { $copy_fields[] = $permuser; @@ -104,6 +105,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($pconfig['overridewanip']) && !is_ipaddr($pconfig['overridewanip'])) { $input_errors[] = gettext('You must specify a valid ip address in the \'Override WAN address\' field'); } + if (!empty($pconfig['overridewanip']) && !empty($pconfig['stun_host'])) { + $input_errors[] = gettext('You cannot override the WAN IP if you have a STUN host set.'); + } + if (!empty($pconfig['stun_host']) && !is_addr($pconfig['stun_host']) && !is_hostname($pconfig['stun_host'])) { + $input_errors[] = gettext('The STUN host must be a valid IP address or hostname.'); + } + if (!empty($pconfig['stun_port']) && !is_port($pconfig['stun_port'])) { + $input_errors[] = gettext('STUN port must contain a valid port number.'); + } + if (!empty($pconfig['overridesubnet']) && count($pconfig['iface_array']) > 1) { + $input_errors[] = gettext('You can only override the interface subnet when one LAN interface is selected'); + } if ((!empty($pconfig['download']) && empty($pconfig['upload'])) || (!empty($pconfig['upload']) && empty($pconfig['download']))) { $input_errors[] = gettext('You must fill in both \'Maximum Download Speed\' and \'Maximum Upload Speed\' fields'); } @@ -146,7 +159,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $upnp[$fieldname] = !empty($pconfig[$fieldname]); } // text field types - foreach (array('ext_iface', 'download', 'upload', 'overridewanip') as $fieldname) { + foreach (array('ext_iface', 'download', 'upload', 'overridewanip', 'overridesubnet', 'stun_host', 'stun_port') as $fieldname) { $upnp[$fieldname] = $pconfig[$fieldname]; } foreach (miniupnpd_permuser_list() as $fieldname) { @@ -255,6 +268,44 @@ include("head.inc"); + +