interfaces: turn dhcpd function into generic function #3310

This commit is contained in:
Franco Fichtner 2020-02-10 20:24:07 +01:00
parent 08beb7b6ad
commit d75cae031a
3 changed files with 37 additions and 37 deletions

View File

@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2015-2018 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2015-2020 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2004-2008 Scott Ullrich <sullrich@gmail.com>
* 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 ];
}

View File

@ -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 ];
}

View File

@ -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'])) {