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) ...@@ -199,17 +199,11 @@ function isAuthLocalIP($http_host)
{ {
global $config; global $config;
$interface_list_ips = get_configured_ip_addresses(); $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) { if (strcasecmp($http_host, $ilips) == 0) {
return true; 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'])) { if (isset($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $vip) { foreach ($config['virtualip']['vip'] as $vip) {
if ($vip['subnet'] == $http_host) { if ($vip['subnet'] == $http_host) {
......
...@@ -3747,11 +3747,15 @@ function convert_real_interface_to_friendly_interface_name($interface = 'wan') ...@@ -3747,11 +3747,15 @@ function convert_real_interface_to_friendly_interface_name($interface = 'wan')
return null; return null;
} }
foreach (legacy_config_get_interfaces() as $if => $ifname) { // search direct
foreach ($config['interfaces'] as $if => $ifname) {
if ($if == $interface || $ifname['if'] == $interface) { if ($if == $interface || $ifname['if'] == $interface) {
return $if; return $if;
} }
}
// search related
foreach ($config['interfaces'] as $if => $ifname) {
if (get_real_interface($if) == $interface) { if (get_real_interface($if) == $interface) {
return $if; return $if;
} }
...@@ -3947,16 +3951,12 @@ function get_real_interface($interface = "wan", $family = "all", $realv6iface = ...@@ -3947,16 +3951,12 @@ function get_real_interface($interface = "wan", $family = "all", $realv6iface =
$wanif = "enc0"; $wanif = "enc0";
break; break;
default: default:
// If a real interface was alread passed simply if (empty($config['interfaces'][$interface])) {
// pass the real interface back. This encourages // leftover from legacy code, it's not a very bright idea to use the same function call
// the usage of this function in more cases so that // for both virtual as real interface names. does_interface_exist() is quite expensive.
// we can combine logic for more flexibility.
if (does_interface_exist($interface, $flush)) { if (does_interface_exist($interface, $flush)) {
$wanif = $interface; $wanif = $interface;
break;
} }
if (empty($config['interfaces'][$interface])) {
break; break;
} }
...@@ -4621,79 +4621,44 @@ function get_failover_interface($interface, $family = "all") ...@@ -4621,79 +4621,44 @@ function get_failover_interface($interface, $family = "all")
} }
//returns interface information //returns interface information
function get_interface_info($ifdescr) function get_interfaces_info()
{ {
global $config; global $config;
$result = array();
$all_intf_details = legacy_interfaces_details();
$ifup = legacy_interface_listget('up');
$all_intf_stats = legacy_interface_stats();
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifdescr => $ifcnf) {
$ifinfo = array(); $ifinfo = array();
if (empty($config['interfaces'][$ifdescr])) {
return;
}
$ifinfo['if'] = get_real_interface($ifdescr); $ifinfo['if'] = get_real_interface($ifdescr);
$ifinfo['status'] = (is_array($ifup) && in_array($ifinfo['if'], $ifup)) ? 'up' : 'down';
if (!empty($all_intf_details[$ifinfo['if']])) {
if (in_array($all_intf_details[$ifinfo['if']]['status'], array('active', 'running'))) {
$all_intf_details[$ifinfo['if']]['status'] = $ifinfo['status'];
}
$ifinfo = array_merge($ifinfo, $all_intf_details[$ifinfo['if']]);
}
$chkif = $ifinfo['if']; if (!empty($ifinfo['ipv6'])) {
$ifinfotmp = legacy_get_interface_addresses($chkif); foreach ($ifinfo['ipv6'] as $ipv6addr) {
$ifinfo['macaddr'] = $ifinfotmp['macaddr']; if (!empty($ipv6addr['link-local'])) {
$ifinfo['ipaddr'] = $ifinfotmp['ipaddr']; $ifinfo['linklocal'] = $ipv6addr['ipaddr'];
$ifinfo['subnet'] = $ifinfotmp['subnet']; } elseif (empty($ifinfo['ipaddrv6'])) {
$ifinfo['ipaddrv6'] = $ipv6addr['ipaddr'];
$ifup = legacy_interface_listget('up'); $ifinfo['subnetv6'] = $ipv6addr['subnetbits'];
$ifinfo['status'] = (is_array($ifup) && in_array($chkif, $ifup)) ? 'up' : 'down'; }
}
$ifinfo['linklocal'] = get_interface_linklocal($ifdescr); }
$ifinfo['ipaddrv6'] = get_interface_ipv6($ifdescr); if (!empty($ifinfo['ipv4'])) {
$ifinfo['subnetv6'] = get_interface_subnetv6($ifdescr); $ifinfo['ipaddr'] = $ifinfo['ipv4'][0]['ipaddr'];
$ifinfo['subnet'] = $ifinfo['ipv4'][0]['subnetbits'];
}
$ifinfotmp = legacy_interface_stats($chkif); $ifinfotmp = $all_intf_stats[$ifinfo['if']];
$ifinfo['inerrs'] = $ifinfotmp['input errors']; $ifinfo['inerrs'] = $ifinfotmp['input errors'];
$ifinfo['outerrs'] = $ifinfotmp['output errors']; $ifinfo['outerrs'] = $ifinfotmp['output errors'];
$ifinfo['collisions'] = $ifinfotmp['collisions']; $ifinfo['collisions'] = $ifinfotmp['collisions'];
/* Use pfctl for non wrapping 64 bit counters */
/* Pass */
exec("/sbin/pfctl -vvsI -i {$chkif}", $pfctlstats);
$pf_in4_pass = preg_split("/ +/ ", $pfctlstats[3]);
$pf_out4_pass = preg_split("/ +/", $pfctlstats[5]);
$pf_in6_pass = preg_split("/ +/ ", $pfctlstats[7]);
$pf_out6_pass = preg_split("/ +/", $pfctlstats[9]);
$in4_pass = $pf_in4_pass[5];
$out4_pass = $pf_out4_pass[5];
$in4_pass_packets = $pf_in4_pass[3];
$out4_pass_packets = $pf_out4_pass[3];
$in6_pass = $pf_in6_pass[5];
$out6_pass = $pf_out6_pass[5];
$in6_pass_packets = $pf_in6_pass[3];
$out6_pass_packets = $pf_out6_pass[3];
$ifinfo['inbytespass'] = $in4_pass + $in6_pass;
$ifinfo['outbytespass'] = $out4_pass + $out6_pass;
$ifinfo['inpktspass'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpktspass'] = $out4_pass_packets + $out6_pass_packets;
/* Block */
$pf_in4_block = preg_split("/ +/", $pfctlstats[4]);
$pf_out4_block = preg_split("/ +/", $pfctlstats[6]);
$pf_in6_block = preg_split("/ +/", $pfctlstats[8]);
$pf_out6_block = preg_split("/ +/", $pfctlstats[10]);
$in4_block = $pf_in4_block[5];
$out4_block = $pf_out4_block[5];
$in4_block_packets = $pf_in4_block[3];
$out4_block_packets = $pf_out4_block[3];
$in6_block = $pf_in6_block[5];
$out6_block = $pf_out6_block[5];
$in6_block_packets = $pf_in6_block[3];
$out6_block_packets = $pf_out6_block[3];
$ifinfo['inbytesblock'] = $in4_block + $in6_block;
$ifinfo['outbytesblock'] = $out4_block + $out6_block;
$ifinfo['inpktsblock'] = $in4_block_packets + $in6_block_packets;
$ifinfo['outpktsblock'] = $out4_block_packets + $out6_block_packets;
$ifinfo['inbytes'] = $in4_pass + $in6_pass;
$ifinfo['outbytes'] = $out4_pass + $out6_pass;
$ifinfo['inpkts'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpkts'] = $out4_pass_packets + $out6_pass_packets;
$ifconfiginfo = ""; $ifconfiginfo = "";
$link_type = $config['interfaces'][$ifdescr]['ipaddr']; $link_type = $config['interfaces'][$ifdescr]['ipaddr'];
switch ($link_type) { switch ($link_type) {
...@@ -4787,51 +4752,11 @@ function get_interface_info($ifdescr) ...@@ -4787,51 +4752,11 @@ function get_interface_info($ifdescr)
} }
if ($ifinfo['status'] == "up") { if ($ifinfo['status'] == "up") {
/* try to determine media with ifconfig */
unset($ifconfiginfo);
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
$wifconfiginfo = array(); $wifconfiginfo = array();
if (is_interface_wireless($ifdescr)) { if (is_interface_wireless($ifdescr)) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo); exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo);
array_shift($wifconfiginfo); array_shift($wifconfiginfo);
} }
$matches = "";
foreach ($ifconfiginfo as $ici) {
/* don't list media/speed for wireless cards, as it always
displays 2 Mbps even though clients can connect at 11 Mbps */
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} elseif (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} elseif (preg_match("/media: IEEE 802.11 Wireless Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
}
if (preg_match("/status: (.*)$/", $ici, $matches)) {
if ($matches[1] != 'active') {
$ifinfo['status'] = $matches[1];
}
if ($ifinfo['status'] == 'running') {
$ifinfo['status'] = 'up';
}
}
if (preg_match("/channel (\S*)/", $ici, $matches)) {
$ifinfo['channel'] = $matches[1];
}
if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
if ($matches[1][0] == '"') {
$ifinfo['ssid'] = substr($matches[1], 1, -1);
} else {
$ifinfo['ssid'] = $matches[1];
}
}
if (preg_match("/laggproto (.*)$/", $ici, $matches)) {
$ifinfo['laggproto'] = $matches[1];
}
if (preg_match("/laggport: (.*)$/", $ici, $matches)) {
$ifinfo['laggport'][] = $matches[1];
}
}
foreach ($wifconfiginfo as $ici) { foreach ($wifconfiginfo as $ici) {
$elements = preg_split("/[ ]+/i", $ici); $elements = preg_split("/[ ]+/i", $ici);
if ($elements[0] != "") { if ($elements[0] != "") {
...@@ -4867,8 +4792,10 @@ function get_interface_info($ifdescr) ...@@ -4867,8 +4792,10 @@ function get_interface_info($ifdescr)
$ifinfo['bridgeint'] = $bridge; $ifinfo['bridgeint'] = $bridge;
} }
} }
$result[$ifdescr] = $ifinfo;
}
return $ifinfo; return $result;
} }
function convert_seconds_to_hms($sec) function convert_seconds_to_hms($sec)
...@@ -5028,35 +4955,14 @@ function get_ppp_uptime($port) ...@@ -5028,35 +4955,14 @@ function get_ppp_uptime($port)
function is_ipaddr_configured($ipaddr, $ignore_if = '') function is_ipaddr_configured($ipaddr, $ignore_if = '')
{ {
global $config; global $config;
$if = get_real_interface($ignore_if);
$isipv6 = is_ipaddrv6($ipaddr);
if ($isipv6 === true) {
$interface_list_ips = get_configured_ipv6_addresses();
} else {
$interface_list_ips = get_configured_ip_addresses(); $interface_list_ips = get_configured_ip_addresses();
}
foreach($interface_list_ips as $if => $ilips) { if (empty($interface_list_ips[$ipaddr]) || $interface_list_ips[$ipaddr] == $if) {
/* Also ignore CARP interfaces, it'll be checked below */ return false;
if ($ignore_if == $if || strstr($ignore_if, "_vip")) { } else {
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;
} }
/* /*
......
...@@ -273,8 +273,26 @@ function legacy_interfaces_details($intf = null) ...@@ -273,8 +273,26 @@ function legacy_interfaces_details($intf = null)
return $a['link-local'] - $b['link-local']; 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; return $result;
......
...@@ -825,65 +825,26 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled = ...@@ -825,65 +825,26 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
/* /*
* get_configured_ip_addresses() - Return a list of all configured * get_configured_ip_addresses() - Return a list of all configured
* interfaces IP Addresses * interfaces IP Addresses (ipv4+ipv6)
* *
*/ */
function get_configured_ip_addresses() function get_configured_ip_addresses()
{ {
global $config; global $config;
$ip_array = array(); $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 */ foreach (legacy_interfaces_details() as $ifname => $if) {
if (isset($config['pppoes']['pppoe'])) { foreach (array('ipv4', 'ipv6') as $iptype) {
foreach($config['pppoes']['pppoe'] as $pppoe) { if (!empty($if[$iptype])) {
if ($pppoe['mode'] == "server") { foreach ($if[$iptype] as $addr) {
if (is_ipaddr($pppoe['localip'])) { if (!empty($addr['ipaddr'])) {
$int = "pppoes". $pppoe['pppoeid']; $ip_array[$addr['ipaddr']] = $ifname;
$ip_array[$int] = $pppoe['localip'];
} }
} }
} }
} }
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; return $ip_array;
} }
/* /*
...@@ -935,17 +896,18 @@ function get_interface_list($only_active = false, $include_dmesg = false) ...@@ -935,17 +896,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;
} }
...@@ -955,16 +917,15 @@ function get_interface_list($only_active = false, $include_dmesg = false) ...@@ -955,16 +917,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;
......
...@@ -111,9 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -111,9 +111,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors[] = gettext("A valid IP address must be specified."); $input_errors[] = gettext("A valid IP address must be specified.");
} else { } else {
$ignore_if = isset($id) ? $a_vip[$id]['interface'] : $pconfig['interface']; $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)) { if (is_ipaddr_configured($pconfig['subnet'], $ignore_if)) {
$input_errors[] = gettext("This IP address is being used by another interface or VIP."); $input_errors[] = gettext("This IP address is being used by another interface or VIP.");
} }
......
...@@ -322,9 +322,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ...@@ -322,9 +322,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$interfaces = list_interfaces(); $interfaces = list_interfaces();
legacy_html_escape_form_data($interfaces); legacy_html_escape_form_data($interfaces);
$unused_interfaces= array(); $unused_interfaces= array();
$all_interfaces = legacy_config_get_interfaces();
foreach ($interfaces as $portname => $portinfo) { foreach ($interfaces as $portname => $portinfo) {
$portused = false; $portused = false;
foreach (legacy_config_get_interfaces() as $ifname => $ifdata) { foreach ($all_interfaces as $ifname => $ifdata) {
if ($ifdata['if'] == $portname) { if ($ifdata['if'] == $portname) {
$portused = true; $portused = true;
break; break;
......
...@@ -94,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -94,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($pconfig['port']) && !is_port($pconfig['port'])) { if (!empty($pconfig['port']) && !is_port($pconfig['port'])) {
$input_errors[] = gettext("A valid port number must be specified."); $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."); $input_errors[] = gettext("An interface IP address must be specified for the DNS query source.");
} }
if (count($input_errors) == 0) { if (count($input_errors) == 0) {
......
...@@ -64,8 +64,12 @@ include("head.inc"); ...@@ -64,8 +64,12 @@ include("head.inc");
<section class="col-xs-12"> <section class="col-xs-12">
<?php <?php
$mac_man = json_decode(configd_run("interface list macdb json"), true); $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): 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); legacy_html_escape_form_data($ifinfo);
$ifdescr = htmlspecialchars($ifdescr); $ifdescr = htmlspecialchars($ifdescr);
$ifname = htmlspecialchars($ifname); $ifname = htmlspecialchars($ifname);
...@@ -392,20 +396,20 @@ include("head.inc"); ...@@ -392,20 +396,20 @@ include("head.inc");
endif; ?> endif; ?>
<tr> <tr>
<td><?= gettext("In/out packets") ?></td> <td><?= gettext("In/out packets") ?></td>
<td> <?= $ifinfo['inpkts'] ?> / <?= $ifinfo['outpkts'] ?> <td> <?= $ifpfcounters['inpkts'] ?> / <?= $ifpfcounters['outpkts'] ?>
(<?= format_bytes($ifinfo['inbytes']);?> / <?=format_bytes($ifinfo['outbytes']);?> ) (<?= format_bytes($ifpfcounters['inbytes']);?> / <?=format_bytes($ifpfcounters['outbytes']);?> )
</td> </td>
</tr> </tr>
<tr> <tr>
<td><?= gettext("In/out packets (pass)") ?></td> <td><?= gettext("In/out packets (pass)") ?></td>
<td> <?= $ifinfo['inpktspass'] ?> / <?= $ifinfo['outpktspass'] ?> <td> <?= $ifpfcounters['inpktspass'] ?> / <?= $ifpfcounters['outpktspass'] ?>
(<?= format_bytes($ifinfo['inbytespass']) ?> / <?= format_bytes($ifinfo['outbytespass']) ?> ) (<?= format_bytes($ifpfcounters['inbytespass']) ?> / <?= format_bytes($ifpfcounters['outbytespass']) ?> )
</td> </td>
</tr> </tr>
<tr> <tr>
<td><?= gettext("In/out packets (block)") ?></td> <td><?= gettext("In/out packets (block)") ?></td>
<td> <?= $ifinfo['inpktsblock'] ?> / <?= $ifinfo['outpktsblock'] ?> <td> <?= $ifpfcounters['inpktsblock'] ?> / <?= $ifpfcounters['outpktsblock'] ?>
(<?= format_bytes($ifinfo['inbytesblock']) ?> / <?= format_bytes($ifinfo['outbytesblock']) ?> ) (<?= format_bytes($ifpfcounters['inbytesblock']) ?> / <?= format_bytes($ifpfcounters['outbytesblock']) ?> )
</td> </td>
</tr> </tr>
<?php <?php
...@@ -433,31 +437,34 @@ include("head.inc"); ...@@ -433,31 +437,34 @@ include("head.inc");
</tr> </tr>
<?php <?php
endif; endif;
if(file_exists("/usr/bin/vmstat")): if (!empty($vmstat_interupts['interrupt_map'][$ifinfo['if']])):
$real_interface = ""; $intrpts = $vmstat_interupts['interrupt_map'][$ifinfo['if']];?>
$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> <tr>
<td><?= gettext("Interrupts per Second") ?></td> <td><?= gettext("Interrupts") ?></td>
<td> <td>
<?php <table class="table">
printf(gettext("%s total"),$interrupt_total); <thead>
echo "<br />"; <tr>
printf(gettext("%s rate"),$interrupt_sec); <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> </td>
</tr> </tr>
<?php <?php
endif;
endif; ?> endif; ?>
</tbody> </tbody>
</table> </table>
......
...@@ -31,15 +31,18 @@ ...@@ -31,15 +31,18 @@
function interfaces_api() function interfaces_api()
{ {
$result = array(); $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) { 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 = array();
$interfaceItem['inpkts'] = $ifinfo['inpkts']; $interfaceItem['inpkts'] = $ifpfcounters['inpkts'];
$interfaceItem['outpkts'] = $ifinfo['outpkts']; $interfaceItem['outpkts'] = $ifpfcounters['outpkts'];
$interfaceItem['inbytes'] = $ifinfo['inbytes']; $interfaceItem['inbytes'] = $ifpfcounters['inbytes'];
$interfaceItem['outbytes'] = $ifinfo['outbytes']; $interfaceItem['outbytes'] = $ifpfcounters['outbytes'];
$interfaceItem['inbytes_frmt'] = format_bytes($ifinfo['inbytes']); $interfaceItem['inbytes_frmt'] = format_bytes($ifpfcounters['inbytes']);
$interfaceItem['outbytes_frmt'] = format_bytes($ifinfo['outbytes']); $interfaceItem['outbytes_frmt'] = format_bytes($ifpfcounters['outbytes']);
$interfaceItem['inerrs'] = isset($ifinfo['inerrs']) ? $ifinfo['inerrs'] : "0"; $interfaceItem['inerrs'] = isset($ifinfo['inerrs']) ? $ifinfo['inerrs'] : "0";
$interfaceItem['outerrs'] = isset($ifinfo['outerrs']) ? $ifinfo['outerrs'] : "0"; $interfaceItem['outerrs'] = isset($ifinfo['outerrs']) ? $ifinfo['outerrs'] : "0";
$interfaceItem['collisions'] = isset($ifinfo['collisions']) ? $ifinfo['collisions'] : "0"; $interfaceItem['collisions'] = isset($ifinfo['collisions']) ? $ifinfo['collisions'] : "0";
......
...@@ -68,8 +68,9 @@ require_once("interfaces.inc"); ...@@ -68,8 +68,9 @@ require_once("interfaces.inc");
<table class="table table-striped table-condensed" data-plugin="interfaces" data-callback="interface_widget_update"> <table class="table table-striped table-condensed" data-plugin="interfaces" data-callback="interface_widget_update">
<tbody> <tbody>
<?php <?php
$ifsinfo = get_interfaces_info();
foreach (get_configured_interface_with_descr() as $ifdescr => $ifname): foreach (get_configured_interface_with_descr() as $ifdescr => $ifname):
$ifinfo = get_interface_info($ifdescr); $ifinfo = $ifsinfo[$ifdescr];
$iswireless = is_interface_wireless($ifdescr);?> $iswireless = is_interface_wireless($ifdescr);?>
<tr id="interface_widget_item_<?=$ifname;?>"> <tr id="interface_widget_item_<?=$ifname;?>">
<td> <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