Commit c14db1a3 authored by Ad Schellevis's avatar Ad Schellevis

lower call overhead in get_interface_list(), for https://github.com/opnsense/core/issues/1662

parent 9bba2092
...@@ -898,17 +898,18 @@ function get_interface_list($only_active = false, $include_dmesg = false) ...@@ -898,17 +898,18 @@ function get_interface_list($only_active = false, $include_dmesg = false)
$ifnames_up = legacy_interface_listget('up'); $ifnames_up = legacy_interface_listget('up');
$ifnames = legacy_interface_listget(); $ifnames = legacy_interface_listget();
$all_interfaces = legacy_config_get_interfaces(array('virtual' => false));
$all_interface_data = legacy_interfaces_details();
if ($only_active) { if ($only_active) {
$_ifnames = array(); $_ifnames = array();
$all_stats = legacy_interface_stats();
foreach ($ifnames as $ifname) { foreach ($ifnames as $ifname) {
$ifinfo = legacy_interface_stats($ifname); $ifinfo = $all_stats[$ifname];
if ($ifinfo['link state'] == '2') { if (!empty($ifinfo['link state']) && $ifinfo['link state'] == '2') {
$_ifnames[] = $ifname; $_ifnames[] = $ifname;
} }
} }
$ifnames = $_ifnames; $ifnames = $_ifnames;
} }
...@@ -918,16 +919,15 @@ function get_interface_list($only_active = false, $include_dmesg = false) ...@@ -918,16 +919,15 @@ function get_interface_list($only_active = false, $include_dmesg = false)
continue; continue;
} }
$ifdata = legacy_get_interface_addresses($ifname); $ifdata = !empty($all_interface_data[$ifname]) ? $all_interface_data[$ifname] : array();
$toput = array( $toput = array(
'up' => in_array($ifname, $ifnames_up), 'up' => in_array($ifname, $ifnames_up),
'ipaddr' => !empty($ifdata['ipaddr']) ? $ifdata['ipaddr'] : null, 'ipaddr' => !empty($ifdata['ipv4'][0]['ipaddr']) ? $ifdata['ipv4'][0]['ipaddr'] : null,
'mac' => $ifdata['macaddr'], 'mac' => !empty($ifdata['macaddr']) ? $ifdata['macaddr'] : null,
'dmesg' => '', 'dmesg' => '',
); );
foreach (legacy_config_get_interfaces(array('virtual' => false)) as $name => $int) { foreach ($all_interfaces as $name => $int) {
if ($int['if'] == $ifname) { if ($int['if'] == $ifname) {
$toput['friendly'] = $name; $toput['friendly'] = $name;
break; break;
......
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