mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 09:34:39 +00:00
interfaces: avoid does_interface_exist()
legacy_get_interface_addresses() is maybe less expensive so make the return safe in case the selected interface was not found.
This commit is contained in:
parent
d89ade7ebe
commit
dc43eeb9c3
@ -4001,7 +4001,7 @@ function get_interface_ip($interface = 'wan')
|
||||
}
|
||||
}
|
||||
|
||||
$curip = find_interface_ip($realif);
|
||||
$curip = find_interface_ip($realif, true);
|
||||
if (is_ipaddrv4($curip)) {
|
||||
return $curip;
|
||||
}
|
||||
@ -4023,7 +4023,7 @@ function get_interface_ipv6($interface = 'wan')
|
||||
}
|
||||
|
||||
$curip = isset($config['interfaces'][$interface]['dhcp6prefixonly']) ?
|
||||
find_interface_ipv6_ll($realif) : find_interface_ipv6($realif);
|
||||
find_interface_ipv6_ll($realif, true) : find_interface_ipv6($realif, true);
|
||||
if (is_ipaddrv6($curip)) {
|
||||
return $curip;
|
||||
}
|
||||
@ -4043,12 +4043,10 @@ function get_interface_subnet($interface = 'wan')
|
||||
}
|
||||
}
|
||||
|
||||
if (does_interface_exist($realif)) {
|
||||
$ifinfo = legacy_get_interface_addresses($realif);
|
||||
if (isset($ifinfo['subnetbits'])) {
|
||||
/* return first subnet size found */
|
||||
return $ifinfo['subnetbits'];
|
||||
}
|
||||
$ifinfo = legacy_get_interface_addresses($realif);
|
||||
if (isset($ifinfo['subnetbits'])) {
|
||||
/* return first subnet size found */
|
||||
return $ifinfo['subnetbits'];
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -4060,18 +4058,16 @@ function get_interface_subnetv6($interface = 'wan')
|
||||
if (!$realif) {
|
||||
if (strstr($interface, '_vip')) {
|
||||
list($interface, $vhid) = explode('_vip', $interface);
|
||||
$realif = get_real_interface($interface);
|
||||
$realif = get_real_interface($interface, 'inet6');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (does_interface_exist($realif)) {
|
||||
$ifinfo = legacy_get_interface_addresses($realif);
|
||||
if (isset($ifinfo['subnetbits6'])) {
|
||||
/* return first subnet size found */
|
||||
return $ifinfo['subnetbits6'];
|
||||
}
|
||||
$ifinfo = legacy_get_interface_addresses($realif);
|
||||
if (isset($ifinfo['subnetbits6'])) {
|
||||
/* return first subnet size found */
|
||||
return $ifinfo['subnetbits6'];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -216,7 +216,10 @@ function legacy_interfaces_details($intf = null)
|
||||
$cmd = '/sbin/ifconfig -m ' . $tmp_intf;
|
||||
exec($cmd . ' 2>&1', $ifconfig_data, $ret);
|
||||
if ($ret) {
|
||||
log_error('The command `' . $cmd . '\' failed to execute ' . implode(' ', $ifconfig_data));
|
||||
/* only error if no explicit interface was choosen */
|
||||
if (empty($intf)) {
|
||||
log_error('The command `' . $cmd . '\' failed to execute ' . implode(' ', $ifconfig_data));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -326,7 +329,14 @@ function legacy_interfaces_details($intf = null)
|
||||
*/
|
||||
function legacy_interface_details($intf)
|
||||
{
|
||||
return legacy_interfaces_details($intf)[$intf];
|
||||
$result = array();
|
||||
|
||||
$details = legacy_interfaces_details($intf);
|
||||
if (isset($details[$intf])) {
|
||||
$result = $details[$intf];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user