Commit 9bba2092 authored by Ad Schellevis's avatar Ad Schellevis

Replace get_configured_ip_addresses() and get_configured_ipv6_addresses() with...

Replace get_configured_ip_addresses() and get_configured_ipv6_addresses() with a more pragmatic approach, both are used to detect if an address is already configured, which gets quite sloppy when having a large number of interface
s configured.

This change probes all configured interfaces at once, and returns the full list, stripping quite some magic in the process.

Because the indexing is changed, we need to change the consumers as well here.
parent bb80ad02
......@@ -199,17 +199,11 @@ function isAuthLocalIP($http_host)
{
global $config;
$interface_list_ips = get_configured_ip_addresses();
foreach ($interface_list_ips as $ilips) {
foreach ($interface_list_ips as $ilips => $ifname) {
if (strcasecmp($http_host, $ilips) == 0) {
return true;
}
}
$interface_list_ipv6s = get_configured_ipv6_addresses();
foreach ($interface_list_ipv6s as $ilipv6s) {
if (strcasecmp($http_host, $ilipv6s) == 0) {
return true;
}
}
if (isset($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $vip) {
if ($vip['subnet'] == $http_host) {
......
......@@ -5028,35 +5028,14 @@ function get_ppp_uptime($port)
function is_ipaddr_configured($ipaddr, $ignore_if = '')
{
global $config;
$if = get_real_interface($ignore_if);
$interface_list_ips = get_configured_ip_addresses();
$isipv6 = is_ipaddrv6($ipaddr);
if ($isipv6 === true) {
$interface_list_ips = get_configured_ipv6_addresses();
if (empty($interface_list_ips[$ipaddr]) || $interface_list_ips[$ipaddr] == $if) {
return false;
} else {
$interface_list_ips = get_configured_ip_addresses();
}
foreach($interface_list_ips as $if => $ilips) {
/* Also ignore CARP interfaces, it'll be checked below */
if ($ignore_if == $if || strstr($ignore_if, "_vip")) {
continue;
}
if (strcasecmp($ipaddr, $ilips) == 0) {
return true;
}
}
$interface_list_vips = get_configured_vips_list(true);
foreach ($interface_list_vips as $id => $vip) {
if ($ignore_if == $vip['if']) {
continue;
}
if (strcasecmp($ipaddr, $vip['ipaddr']) == 0) {
return true;
}
return true;
}
return false;
}
/*
......
......@@ -827,67 +827,28 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
/*
* get_configured_ip_addresses() - Return a list of all configured
* interfaces IP Addresses
* interfaces IP Addresses (ipv4+ipv6)
*
*/
function get_configured_ip_addresses()
{
global $config;
$ip_array = array();
$interfaces = get_configured_interface_list();
if (is_array($interfaces)) {
foreach($interfaces as $int) {
$ipaddr = get_interface_ip($int);
$ip_array[$int] = $ipaddr;
}
}
$interfaces = get_configured_carp_interface_list();
if (is_array($interfaces)) {
foreach($interfaces as $int => $ipaddr) {
$ip_array[$int] = $ipaddr;
}
}
/* pppoe server */
if (isset($config['pppoes']['pppoe'])) {
foreach($config['pppoes']['pppoe'] as $pppoe) {
if ($pppoe['mode'] == "server") {
if (is_ipaddr($pppoe['localip'])) {
$int = "pppoes". $pppoe['pppoeid'];
$ip_array[$int] = $pppoe['localip'];
foreach (legacy_interfaces_details() as $ifname => $if) {
foreach (array('ipv4', 'ipv6') as $iptype) {
if (!empty($if[$iptype])) {
foreach ($if[$iptype] as $addr) {
if (!empty($addr['ipaddr'])) {
$ip_array[$addr['ipaddr']] = $ifname;
}
}
}
}
}
return $ip_array;
}
/*
* get_configured_ipv6_addresses() - Return a list of all configured
* interfaces IPv6 Addresses
*
*/
function get_configured_ipv6_addresses()
{
$ipv6_array = array();
$interfaces = get_configured_interface_list();
if (is_array($interfaces)) {
foreach($interfaces as $int) {
$ipaddrv6 = get_interface_ipv6($int);
$ipv6_array[$int] = $ipaddrv6;
}
}
$interfaces = get_configured_carp_interface_list();
if (is_array($interfaces)) {
foreach($interfaces as $int => $ipaddrv6) {
$ipv6_array[$int] = $ipaddrv6;
}
}
return $ipv6_array;
}
/*
* get_interface_list() - Return a list of all physical interfaces
* along with MAC, IPv4 and status.
......
......@@ -111,9 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors[] = gettext("A valid IP address must be specified.");
} else {
$ignore_if = isset($id) ? $a_vip[$id]['interface'] : $pconfig['interface'];
if ($pconfig['mode'] == 'carp') {
$ignore_if .= "_vip{$pconfig['vhid']}";
}
if (is_ipaddr_configured($pconfig['subnet'], $ignore_if)) {
$input_errors[] = gettext("This IP address is being used by another interface or VIP.");
}
......
......@@ -94,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($pconfig['port']) && !is_port($pconfig['port'])) {
$input_errors[] = gettext("A valid port number must be specified.");
}
if (!empty($pconfig['dnssrcip']) && !in_array($pconfig['dnssrcip'], get_configured_ip_addresses())) {
if (!empty($pconfig['dnssrcip']) && !in_array($pconfig['dnssrcip'], array_keys(get_configured_ip_addresses()))) {
$input_errors[] = gettext("An interface IP address must be specified for the DNS query source.");
}
if (count($input_errors) == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment