diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 2f0287f11..3ad719f5b 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -1,7 +1,7 @@ + * Copyright (C) 2015-2020 Franco Fichtner * Copyright (C) 2004-2008 Scott Ullrich * Copyright (C) 2008-2009 Ermal Luçi * Copyright (C) 2005 Espen Johansen @@ -4579,3 +4579,34 @@ function interfaces_addresses($interfaces, $as_subnet = false, $ifconfig_details return $result; } + +function interfaces_primary_address6($interface, $realif = null, $ifconfig_details = null) +{ + $ifcfgipv6 = $networkv6 = null; + + if ($realif === null) { + $realif = get_real_interface($interface, 'inet6'); + } + + foreach (interfaces_addresses($realif, true, $ifconfig_details) as $tmpaddr => $info) { + if ($info['family'] != 'inet6' || $info['scope']) { + /* only care about IPv6 without a scope set */ + continue; + } + + $addrparts = explode('/', $tmpaddr); + + foreach (config_read_array('virtualip', 'vip') as $vip) { + if ($vip['interface'] == $interface && $vip['mode'] == 'ipalias' && $vip['subnet'] == $addrparts[0]) { + /* do not care about alias */ + continue 2; + } + } + + $networkv6 = gen_subnetv6($addrparts[0], $addrparts[1]) . "/{$addrparts[1]}"; + $ifcfgipv6 = $addrparts[0]; + break; /* all done */ + } + + return [ $ifcfgipv6, $networkv6 ]; +} diff --git a/src/etc/inc/plugins.inc.d/dhcpd.inc b/src/etc/inc/plugins.inc.d/dhcpd.inc index 492d5bb8f..108a1f124 100644 --- a/src/etc/inc/plugins.inc.d/dhcpd.inc +++ b/src/etc/inc/plugins.inc.d/dhcpd.inc @@ -302,7 +302,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = array()) $stanzas = array(); - list ($ifcfgipv6, $networkv6) = dhcpd_getaddr6($dhcpv6if, $realif, $ifconfig_details); + list ($ifcfgipv6, $networkv6) = interfaces_primary_address6($dhcpv6if, $realif, $ifconfig_details); if (is_subnetv6($networkv6)) { $stanzas[] = $networkv6; } @@ -454,7 +454,7 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = array()) $dnslist = array(); - list ($ifcfgipv6, $networkv6) = dhcpd_getaddr6($if, $realif, $ifconfig_details); + list ($ifcfgipv6, $networkv6) = interfaces_primary_address6($if, $realif, $ifconfig_details); if ($autotype == 'slaac') { /* XXX this may be incorrect and needs an override or revisit */ @@ -1240,7 +1240,7 @@ function dhcpd_dhcp6_configure($verbose = false, $blacklist = array()) continue; } if (!empty($config['interfaces'][$ifname]['track6-interface'])) { - list ($ifcfgipv6) = dhcpd_getaddr6($ifname, null, $ifconfig_details); + list ($ifcfgipv6) = interfaces_primary_address6($ifname, null, $ifconfig_details); if (!is_ipaddrv6($ifcfgipv6)) { continue; } @@ -1392,7 +1392,7 @@ EOD; continue; } - list ($ifcfgipv6, $networkv6) = dhcpd_getaddr6($dhcpv6if, null, $ifconfig_details); + list ($ifcfgipv6, $networkv6) = interfaces_primary_address6($dhcpv6if, null, $ifconfig_details); if (!is_ipaddrv6($ifcfgipv6) || !is_subnetv6($networkv6)) { log_error("Warning! dhcpd_dhcp6_configure() found no suitable IPv6 address on {$dhcpv6if}"); continue; @@ -1829,34 +1829,3 @@ function dhcpd_dhcrelay6_configure($verbose = false) echo "done.\n"; } } - -function dhcpd_getaddr6($interface, $realif = null, $ifconfig_details = null) -{ - $ifcfgipv6 = $networkv6 = null; - - if ($realif === null) { - $realif = get_real_interface($interface, 'inet6'); - } - - foreach (interfaces_addresses($realif, true, $ifconfig_details) as $tmpaddr => $info) { - if ($info['family'] != 'inet6' || $info['scope']) { - /* only care about IPv6 without a scope set */ - continue; - } - - $addrparts = explode('/', $tmpaddr); - - foreach (config_read_array('virtualip', 'vip') as $vip) { - if ($vip['interface'] == $interface && $vip['mode'] == 'ipalias' && $vip['subnet'] == $addrparts[0]) { - /* do not care about alias */ - continue 2; - } - } - - $networkv6 = gen_subnetv6($addrparts[0], $addrparts[1]) . "/{$addrparts[1]}"; - $ifcfgipv6 = $addrparts[0]; - break; /* all done */ - } - - return [ $ifcfgipv6, $networkv6 ]; -} diff --git a/src/www/services_dhcpv6.php b/src/www/services_dhcpv6.php index fce52918d..9325baf4a 100644 --- a/src/www/services_dhcpv6.php +++ b/src/www/services_dhcpv6.php @@ -321,7 +321,7 @@ legacy_html_escape_form_data($pconfig); include("head.inc"); -list ($wifcfgip, $networkv6) = dhcpd_getaddr6($if); +list ($wifcfgip, $networkv6) = interfaces_primary_address6($if); $wifcfgsn = explode('/', $networkv6)[1]; if (isset($config['interfaces'][$if]['dhcpd6track6allowoverride'])) {