diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 981ea7a3d..2fe2119a2 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -4645,3 +4645,50 @@ function make_ipv6_64_address($prefix, $suffix) return implode(':', $prefix_array); } + +function interfaces_addresses($interface) +{ + global $config; + + $realifs = array(); + $result = array(); + + if ($interface == 'lo0') { + $realifs[] = 'lo0'; + } elseif (!isset($config['interfaces'][$interface])) { + return $result; + } + + foreach (array('all', 'inet6') as $af) { + $realif = get_real_interface($interface, $af); + if (!empty($realif) && !in_array($realif, $realifs)) { + $realifs[] = $realif; + } + } + + if (!count($realifs)) { + return $result; + } + + $intf_details = legacy_interfaces_details(); + + foreach ($realifs as $realif) { + foreach (array('ipv4', 'ipv6') as $proto) { + if (empty($intf_details[$realif][$proto])) { + continue; + } + foreach ($intf_details[$realif][$proto] as $address) { + if (!empty($address['tunnel']) || empty($address['ipaddr'])) { + continue; + } + $scope = ''; + if (!empty($address['link-local'])) { + $scope = "%{$realif}"; + } + $result[] = "{$address['ipaddr']}{$scope}"; + } + } + } + + return $result; +} diff --git a/src/etc/inc/plugins.inc.d/dnsmasq.inc b/src/etc/inc/plugins.inc.d/dnsmasq.inc index e2b95b8eb..d03d99e44 100644 --- a/src/etc/inc/plugins.inc.d/dnsmasq.inc +++ b/src/etc/inc/plugins.inc.d/dnsmasq.inc @@ -123,16 +123,13 @@ function dnsmasq_configure_do($verbose = false) $addresses = array(); foreach ($interfaces as $interface) { - foreach (legacy_getall_interface_addresses(get_real_interface($interface)) as $tmpaddr) { - $tmpaddr = explode('/', $tmpaddr)[0]; + foreach (interfaces_addresses($interface) as $tmpaddr) { /* no support for link-local address with scope specified */ $tmpaddr = explode('%', $tmpaddr)[0]; - if (!empty($tmpaddr)) { - if ($interface == 'lo0' && is_ipaddrv4($tmpaddr) && $tmpaddr != '127.0.0.1') { - continue; - } - $addresses[] = $tmpaddr; + if ($interface == 'lo0' && is_ipaddrv4($tmpaddr) && $tmpaddr != '127.0.0.1') { + continue; } + $addresses[] = $tmpaddr; } } diff --git a/src/etc/inc/plugins.inc.d/openssh.inc b/src/etc/inc/plugins.inc.d/openssh.inc index 2f99ceb92..0c55a8ee1 100644 --- a/src/etc/inc/plugins.inc.d/openssh.inc +++ b/src/etc/inc/plugins.inc.d/openssh.inc @@ -187,11 +187,9 @@ function openssh_configure_do($verbose = false, $interface = '') $listeners = array(); foreach ($interfaces as $interface) { - foreach (legacy_getall_interface_addresses(get_real_interface($interface)) as $tmpaddr) { - $tmpaddr = explode('/', $tmpaddr)[0]; - /* no support for link-local address with scope specified */ - $tmpaddr = explode('%', $tmpaddr)[0]; - if (!empty($tmpaddr)) { + foreach (interfaces_addresses($interface) as $tmpaddr) { + /* link-local does not seem to be supported */ + if (strstr($tmpaddr, '%') === false && !is_linklocal($tmpaddr)) { $listeners[] = $tmpaddr; } } diff --git a/src/etc/inc/plugins.inc.d/unbound.inc b/src/etc/inc/plugins.inc.d/unbound.inc index a2c49b7b2..42fb93d10 100644 --- a/src/etc/inc/plugins.inc.d/unbound.inc +++ b/src/etc/inc/plugins.inc.d/unbound.inc @@ -167,18 +167,11 @@ EOF; $addresses = array(); foreach ($active_interfaces as $ubif) { - $realif = get_real_interface($ubif); - foreach (legacy_getall_interface_addresses($realif) as $tmpaddr) { - $tmpaddr = explode('/', $tmpaddr)[0]; - if (!empty($tmpaddr)) { - if ($interface == 'lo0' && is_ipaddrv4($tmpaddr) && $tmpaddr != '127.0.0.1') { - continue; - } - if (is_linklocal($tmpaddr)) { - $tmpaddr .= "%{$realif}"; - } - $addresses[] = $tmpaddr; + foreach (interfaces_addresses($ubif) as $tmpaddr) { + if ($ubif == 'lo0' && is_ipaddrv4($tmpaddr) && $tmpaddr != '127.0.0.1') { + continue; } + $addresses[] = $tmpaddr; } } @@ -335,6 +328,7 @@ rrset-cache-size: {$rrsetcachesize}m {$anchor_file} prefetch: {$prefetch} prefetch-key: {$prefetch_key} + # Interface IP(s) to bind to {$bindints} {$outgoingints} diff --git a/src/etc/inc/plugins.inc.d/webgui.inc b/src/etc/inc/plugins.inc.d/webgui.inc index 6a35dd667..7cad1b7f8 100644 --- a/src/etc/inc/plugins.inc.d/webgui.inc +++ b/src/etc/inc/plugins.inc.d/webgui.inc @@ -59,12 +59,9 @@ function webgui_configure_do($verbose = false, $interface = '') $listeners = count($interfaces) ? array() : array('0.0.0.0', '::'); foreach ($interfaces as $interface) { - foreach (legacy_getall_interface_addresses(get_real_interface($interface)) as $tmpaddr) { - $tmpaddr = explode('/', $tmpaddr)[0]; - /* no support for link-local address with scope specified */ - $tmpaddr = explode('%', $tmpaddr)[0]; + foreach (interfaces_addresses($interface) as $tmpaddr) { /* link-local does not seem to be supported */ - if (!empty($tmpaddr) && !is_linklocal($tmpaddr)) { + if (strstr($tmpaddr, '%') === false && !is_linklocal($tmpaddr)) { $listeners[] = $tmpaddr; } }