Commit 88855185 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

Gui slow / not responding with 150 vlan interfaces

PR: https://github.com/opnsense/core/issues/1662

(cherry picked from commit 9bba2092)
(cherry picked from commit c14db1a3)
(cherry picked from commit 24c62ed5)
(cherry picked from commit b6e4e56e)
(cherry picked from commit 6401d20e)
(cherry picked from commit de5ff59f)
(cherry picked from commit 17a9a263)
(cherry picked from commit 3b3ebbbe)
(cherry picked from commit f15eb3b2)
(cherry picked from commit 932a086e)
(cherry picked from commit 9bb3dd61)
(cherry picked from commit 89a81f3e)
(cherry picked from commit a206e8f6)
parent c3214890
......@@ -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) {
......
This diff is collapsed.
......@@ -273,8 +273,26 @@ function legacy_interfaces_details($intf = null)
return $a['link-local'] - $b['link-local'];
});
}
} elseif (preg_match("/media: (.*)/", $line, $matches)) {
// media, when link is between parenthesis grep only the link part
$result[$current_interface]['media'] = $matches[1];
if (preg_match("/media: .*? \((.*?)\)/", $line, $matches)) {
$result[$current_interface]['media'] = $matches[1];
}
} elseif (preg_match("/status: (.*)$/", $line, $matches)) {
$result[$current_interface]['status'] = $matches[1];
} elseif (preg_match("/channel (\S*)/", $line, $matches)) {
$result[$current_interface]['channel'] = $matches[1];
} elseif (preg_match("/ssid (\".*?\"|\S*)/", $line, $matches)) {
$result[$current_interface]['ssid'] = $matches[1];
} elseif (preg_match("/laggproto (.*)$/", $line, $matches)) {
$result[$current_interface]['laggproto'] = $matches[1];
} elseif (preg_match("/laggport: (.*)$/", $line, $matches)) {
if (empty($result[$current_interface]['laggport'])) {
$result[$current_interface]['laggport'] = array();
}
$result[$current_interface]['laggport'][] = $matches[1];
}
}
return $result;
......
......@@ -825,67 +825,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.
......@@ -935,17 +896,18 @@ function get_interface_list($only_active = false, $include_dmesg = false)
$ifnames_up = legacy_interface_listget('up');
$ifnames = legacy_interface_listget();
$all_interfaces = legacy_config_get_interfaces(array('virtual' => false));
$all_interface_data = legacy_interfaces_details();
if ($only_active) {
$_ifnames = array();
$all_stats = legacy_interface_stats();
foreach ($ifnames as $ifname) {
$ifinfo = legacy_interface_stats($ifname);
if ($ifinfo['link state'] == '2') {
$ifinfo = $all_stats[$ifname];
if (!empty($ifinfo['link state']) && $ifinfo['link state'] == '2') {
$_ifnames[] = $ifname;
}
}
$ifnames = $_ifnames;
}
......@@ -955,16 +917,15 @@ function get_interface_list($only_active = false, $include_dmesg = false)
continue;
}
$ifdata = legacy_get_interface_addresses($ifname);
$ifdata = !empty($all_interface_data[$ifname]) ? $all_interface_data[$ifname] : array();
$toput = array(
'up' => in_array($ifname, $ifnames_up),
'ipaddr' => !empty($ifdata['ipaddr']) ? $ifdata['ipaddr'] : null,
'mac' => $ifdata['macaddr'],
'ipaddr' => !empty($ifdata['ipv4'][0]['ipaddr']) ? $ifdata['ipv4'][0]['ipaddr'] : null,
'mac' => !empty($ifdata['macaddr']) ? $ifdata['macaddr'] : null,
'dmesg' => '',
);
foreach (legacy_config_get_interfaces(array('virtual' => false)) as $name => $int) {
foreach ($all_interfaces as $name => $int) {
if ($int['if'] == $ifname) {
$toput['friendly'] = $name;
break;
......
......@@ -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.");
}
......
......@@ -322,9 +322,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$interfaces = list_interfaces();
legacy_html_escape_form_data($interfaces);
$unused_interfaces= array();
$all_interfaces = legacy_config_get_interfaces();
foreach ($interfaces as $portname => $portinfo) {
$portused = false;
foreach (legacy_config_get_interfaces() as $ifname => $ifdata) {
foreach ($all_interfaces as $ifname => $ifdata) {
if ($ifdata['if'] == $portname) {
$portused = true;
break;
......
......@@ -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) {
......
......@@ -64,8 +64,12 @@ include("head.inc");
<section class="col-xs-12">
<?php
$mac_man = json_decode(configd_run("interface list macdb json"), true);
$pfctl_counters = json_decode(configd_run("filter list counters json"), true);
$vmstat_interupts = json_decode(configd_run("system list interrupts json"), true);
$ifsinfo = get_interfaces_info();
foreach (get_configured_interface_with_descr(false, true) as $ifdescr => $ifname):
$ifinfo = get_interface_info($ifdescr);
$ifinfo = $ifsinfo[$ifdescr];
$ifpfcounters = $pfctl_counters[$ifinfo['if']];
legacy_html_escape_form_data($ifinfo);
$ifdescr = htmlspecialchars($ifdescr);
$ifname = htmlspecialchars($ifname);
......@@ -392,20 +396,20 @@ include("head.inc");
endif; ?>
<tr>
<td><?= gettext("In/out packets") ?></td>
<td> <?= $ifinfo['inpkts'] ?> / <?= $ifinfo['outpkts'] ?>
(<?= format_bytes($ifinfo['inbytes']);?> / <?=format_bytes($ifinfo['outbytes']);?> )
<td> <?= $ifpfcounters['inpkts'] ?> / <?= $ifpfcounters['outpkts'] ?>
(<?= format_bytes($ifpfcounters['inbytes']);?> / <?=format_bytes($ifpfcounters['outbytes']);?> )
</td>
</tr>
<tr>
<td><?= gettext("In/out packets (pass)") ?></td>
<td> <?= $ifinfo['inpktspass'] ?> / <?= $ifinfo['outpktspass'] ?>
(<?= format_bytes($ifinfo['inbytespass']) ?> / <?= format_bytes($ifinfo['outbytespass']) ?> )
<td> <?= $ifpfcounters['inpktspass'] ?> / <?= $ifpfcounters['outpktspass'] ?>
(<?= format_bytes($ifpfcounters['inbytespass']) ?> / <?= format_bytes($ifpfcounters['outbytespass']) ?> )
</td>
</tr>
<tr>
<td><?= gettext("In/out packets (block)") ?></td>
<td> <?= $ifinfo['inpktsblock'] ?> / <?= $ifinfo['outpktsblock'] ?>
(<?= format_bytes($ifinfo['inbytesblock']) ?> / <?= format_bytes($ifinfo['outbytesblock']) ?> )
<td> <?= $ifpfcounters['inpktsblock'] ?> / <?= $ifpfcounters['outpktsblock'] ?>
(<?= format_bytes($ifpfcounters['inbytesblock']) ?> / <?= format_bytes($ifpfcounters['outbytesblock']) ?> )
</td>
</tr>
<?php
......@@ -433,31 +437,34 @@ include("head.inc");
</tr>
<?php
endif;
if(file_exists("/usr/bin/vmstat")):
$real_interface = "";
$interrupt_total = "";
$interrupt_sec = "";
$real_interface = $ifinfo['if'];
$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $3 }'`;
$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
if(strstr($interrupt_total, "hci")) {
$interrupt_total = `vmstat -i | grep $real_interface | awk '{ print $4 }'`;
$interrupt_sec = `vmstat -i | grep $real_interface | awk '{ print $5 }'`;
}
unset($interrupt_total); // XXX: FIX ME! Need a regex and parse correct data 100% of the time.
if($interrupt_total): ?>
<tr>
<td><?= gettext("Interrupts per Second") ?></td>
if (!empty($vmstat_interupts['interrupt_map'][$ifinfo['if']])):
$intrpts = $vmstat_interupts['interrupt_map'][$ifinfo['if']];?>
<tr>
<td><?= gettext("Interrupts") ?></td>
<td>
<?php
printf(gettext("%s total"),$interrupt_total);
echo "<br />";
printf(gettext("%s rate"),$interrupt_sec);
?>
<table class="table">
<thead>
<tr>
<th><?=gettext("irq");?></th>
<th><?=gettext("device");?></th>
<th><?=gettext("total");?></th>
<th><?=gettext("rate");?></th>
</tr>
</thead>
<?php
foreach ($intrpts as $intrpt):?>
<tr>
<td><?=$intrpt;?></td>
<td><?=implode(' ', $vmstat_interupts['interrupts'][$intrpt]['devices']);?></td>
<td><?=$vmstat_interupts['interrupts'][$intrpt]['total'];?></td>
<td><?=$vmstat_interupts['interrupts'][$intrpt]['rate'];?></td>
</tr>
<?php
endforeach; ?>
</table>
</td>
</tr>
<?php
endif;
endif; ?>
</tbody>
</table>
......
......@@ -31,15 +31,18 @@
function interfaces_api()
{
$result = array();
$ifsinfo = get_interfaces_info();
$pfctl_counters = json_decode(configd_run("filter list counters json"), true);
foreach (get_configured_interface_with_descr() as $ifdescr => $ifname) {
$ifinfo = get_interface_info($ifdescr);
$ifinfo = $ifsinfo[$ifdescr];
$ifpfcounters = $pfctl_counters[$ifinfo['if']];
$interfaceItem = array();
$interfaceItem['inpkts'] = $ifinfo['inpkts'];
$interfaceItem['outpkts'] = $ifinfo['outpkts'];
$interfaceItem['inbytes'] = $ifinfo['inbytes'];
$interfaceItem['outbytes'] = $ifinfo['outbytes'];
$interfaceItem['inbytes_frmt'] = format_bytes($ifinfo['inbytes']);
$interfaceItem['outbytes_frmt'] = format_bytes($ifinfo['outbytes']);
$interfaceItem['inpkts'] = $ifpfcounters['inpkts'];
$interfaceItem['outpkts'] = $ifpfcounters['outpkts'];
$interfaceItem['inbytes'] = $ifpfcounters['inbytes'];
$interfaceItem['outbytes'] = $ifpfcounters['outbytes'];
$interfaceItem['inbytes_frmt'] = format_bytes($ifpfcounters['inbytes']);
$interfaceItem['outbytes_frmt'] = format_bytes($ifpfcounters['outbytes']);
$interfaceItem['inerrs'] = isset($ifinfo['inerrs']) ? $ifinfo['inerrs'] : "0";
$interfaceItem['outerrs'] = isset($ifinfo['outerrs']) ? $ifinfo['outerrs'] : "0";
$interfaceItem['collisions'] = isset($ifinfo['collisions']) ? $ifinfo['collisions'] : "0";
......
......@@ -68,8 +68,9 @@ require_once("interfaces.inc");
<table class="table table-striped table-condensed" data-plugin="interfaces" data-callback="interface_widget_update">
<tbody>
<?php
$ifsinfo = get_interfaces_info();
foreach (get_configured_interface_with_descr() as $ifdescr => $ifname):
$ifinfo = get_interface_info($ifdescr);
$ifinfo = $ifsinfo[$ifdescr];
$iswireless = is_interface_wireless($ifdescr);?>
<tr id="interface_widget_item_<?=$ifname;?>">
<td>
......
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