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
// pass the real interface back. This encourages
// the usage of this function in more cases so that
// we can combine logic for more flexibility.
if (does_interface_exist($interface, $flush)) {
$wanif = $interface;
break;
}
if (empty($config['interfaces'][$interface])) { if (empty($config['interfaces'][$interface])) {
// leftover from legacy code, it's not a very bright idea to use the same function call
// for both virtual as real interface names. does_interface_exist() is quite expensive.
if (does_interface_exist($interface, $flush)) {
$wanif = $interface;
}
break; break;
} }
...@@ -4621,254 +4621,181 @@ function get_failover_interface($interface, $family = "all") ...@@ -4621,254 +4621,181 @@ 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();
$ifinfo = array(); $all_intf_details = legacy_interfaces_details();
if (empty($config['interfaces'][$ifdescr])) {
return;
}
$ifinfo['if'] = get_real_interface($ifdescr);
$chkif = $ifinfo['if'];
$ifinfotmp = legacy_get_interface_addresses($chkif);
$ifinfo['macaddr'] = $ifinfotmp['macaddr'];
$ifinfo['ipaddr'] = $ifinfotmp['ipaddr'];
$ifinfo['subnet'] = $ifinfotmp['subnet'];
$ifup = legacy_interface_listget('up'); $ifup = legacy_interface_listget('up');
$ifinfo['status'] = (is_array($ifup) && in_array($chkif, $ifup)) ? 'up' : 'down'; $all_intf_stats = legacy_interface_stats();
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifdescr => $ifcnf) {
$ifinfo['linklocal'] = get_interface_linklocal($ifdescr); $ifinfo = array();
$ifinfo['ipaddrv6'] = get_interface_ipv6($ifdescr); $ifinfo['if'] = get_real_interface($ifdescr);
$ifinfo['subnetv6'] = get_interface_subnetv6($ifdescr); $ifinfo['status'] = (is_array($ifup) && in_array($ifinfo['if'], $ifup)) ? 'up' : 'down';
if (!empty($all_intf_details[$ifinfo['if']])) {
$ifinfotmp = legacy_interface_stats($chkif); if (in_array($all_intf_details[$ifinfo['if']]['status'], array('active', 'running'))) {
$ifinfo['inerrs'] = $ifinfotmp['input errors']; $all_intf_details[$ifinfo['if']]['status'] = $ifinfo['status'];
$ifinfo['outerrs'] = $ifinfotmp['output errors'];
$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 = "";
$link_type = $config['interfaces'][$ifdescr]['ipaddr'];
switch ($link_type) {
/* DHCP? -> see if dhclient is up */
case "dhcp":
/* see if dhclient is up */
if (find_dhclient_process($ifinfo['if']) != 0) {
$ifinfo['dhcplink'] = "up";
} else {
$ifinfo['dhcplink'] = "down";
} }
$ifinfo = array_merge($ifinfo, $all_intf_details[$ifinfo['if']]);
}
break; if (!empty($ifinfo['ipv6'])) {
/* PPPoE/PPTP/L2TP interface? -> get status from virtual interface */ foreach ($ifinfo['ipv6'] as $ipv6addr) {
case "pppoe": if (!empty($ipv6addr['link-local'])) {
case "pptp": $ifinfo['linklocal'] = $ipv6addr['ipaddr'];
case "l2tp": } elseif (empty($ifinfo['ipaddrv6'])) {
if ($ifinfo['status'] == "up") { $ifinfo['ipaddrv6'] = $ipv6addr['ipaddr'];
/* XXX get PPPoE link status for dial on demand */ $ifinfo['subnetv6'] = $ipv6addr['subnetbits'];
$ifinfo["{$link_type}link"] = "up"; }
} else {
$ifinfo["{$link_type}link"] = "down";
}
break;
/* PPP interface? -> get uptime for this session and cumulative uptime from the persistent log file in conf */
case "ppp":
if ($ifinfo['status'] == "up") {
$ifinfo['ppplink'] = "up";
} else {
$ifinfo['ppplink'] = "down";
} }
}
if (!empty($ifinfo['ipv4'])) {
$ifinfo['ipaddr'] = $ifinfo['ipv4'][0]['ipaddr'];
$ifinfo['subnet'] = $ifinfo['ipv4'][0]['subnetbits'];
}
if (empty($ifinfo['status'])) { $ifinfotmp = $all_intf_stats[$ifinfo['if']];
$ifinfo['status'] = "down"; $ifinfo['inerrs'] = $ifinfotmp['input errors'];
} $ifinfo['outerrs'] = $ifinfotmp['output errors'];
$ifinfo['collisions'] = $ifinfotmp['collisions'];
if (isset($config['ppps']['ppp'])) { $ifconfiginfo = "";
foreach ($config['ppps']['ppp'] as $pppid => $ppp) { $link_type = $config['interfaces'][$ifdescr]['ipaddr'];
if ($config['interfaces'][$ifdescr]['if'] == $ppp['if']) { switch ($link_type) {
break; /* DHCP? -> see if dhclient is up */
} case "dhcp":
/* see if dhclient is up */
if (find_dhclient_process($ifinfo['if']) != 0) {
$ifinfo['dhcplink'] = "up";
} else {
$ifinfo['dhcplink'] = "down";
} }
}
$dev = $ppp['ports'];
if ($config['interfaces'][$ifdescr]['if'] != $ppp['if'] || empty($dev)) {
break;
}
if (!file_exists($dev)) {
$ifinfo['nodevice'] = 1;
$ifinfo['pppinfo'] = $dev . " " . gettext("device not present! Is the modem attached to the system?");
}
$usbmodemoutput = array(); break;
exec("usbconfig", $usbmodemoutput); /* PPPoE/PPTP/L2TP interface? -> get status from virtual interface */
$mondev = "/tmp/3gstats.{$ifdescr}"; case "pppoe":
if (file_exists($mondev)) { case "pptp":
$cellstats = file($mondev); case "l2tp":
/* skip header */ if ($ifinfo['status'] == "up") {
$a_cellstats = explode(",", $cellstats[1]); /* XXX get PPPoE link status for dial on demand */
if (preg_match("/huawei/i", implode("\n", $usbmodemoutput))) { $ifinfo["{$link_type}link"] = "up";
$ifinfo['cell_rssi'] = huawei_rssi_to_string($a_cellstats[1]); } else {
$ifinfo['cell_mode'] = huawei_mode_to_string($a_cellstats[2], $a_cellstats[3]); $ifinfo["{$link_type}link"] = "down";
$ifinfo['cell_simstate'] = huawei_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = huawei_service_to_string(trim($a_cellstats[11]));
} }
if (preg_match("/zte/i", implode("\n", $usbmodemoutput))) { break;
$ifinfo['cell_rssi'] = zte_rssi_to_string($a_cellstats[1]); /* PPP interface? -> get uptime for this session and cumulative uptime from the persistent log file in conf */
$ifinfo['cell_mode'] = zte_mode_to_string($a_cellstats[2], $a_cellstats[3]); case "ppp":
$ifinfo['cell_simstate'] = zte_simstate_to_string($a_cellstats[10]); if ($ifinfo['status'] == "up") {
$ifinfo['cell_service'] = zte_service_to_string(trim($a_cellstats[11])); $ifinfo['ppplink'] = "up";
} else {
$ifinfo['ppplink'] = "down";
} }
$ifinfo['cell_upstream'] = $a_cellstats[4];
$ifinfo['cell_downstream'] = trim($a_cellstats[5]);
$ifinfo['cell_sent'] = $a_cellstats[6];
$ifinfo['cell_received'] = trim($a_cellstats[7]);
$ifinfo['cell_bwupstream'] = $a_cellstats[8];
$ifinfo['cell_bwdownstream'] = trim($a_cellstats[9]);
}
// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
if (isset($ppp['uptime'])) {
$ifinfo['ppp_uptime_accumulated'] = "(" . get_ppp_uptime($ifinfo['if']) . ")";
}
break;
default:
break;
}
if (file_exists("/var/run/{$link_type}_{$ifdescr}.pid")) { if (empty($ifinfo['status'])) {
$sec = trim(`/usr/local/sbin/ppp-uptime.sh {$ifinfo['if']}`); $ifinfo['status'] = "down";
$ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec); }
}
if ($ifinfo['status'] == "up") {
/* try to determine media with ifconfig */
unset($ifconfiginfo);
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
$wifconfiginfo = array();
if (is_interface_wireless($ifdescr)) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $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 (isset($config['ppps']['ppp'])) {
if ($matches[1] != 'active') { foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
$ifinfo['status'] = $matches[1]; if ($config['interfaces'][$ifdescr]['if'] == $ppp['if']) {
break;
}
}
} }
if ($ifinfo['status'] == 'running') { $dev = $ppp['ports'];
$ifinfo['status'] = 'up'; if ($config['interfaces'][$ifdescr]['if'] != $ppp['if'] || empty($dev)) {
break;
} }
} if (!file_exists($dev)) {
if (preg_match("/channel (\S*)/", $ici, $matches)) { $ifinfo['nodevice'] = 1;
$ifinfo['channel'] = $matches[1]; $ifinfo['pppinfo'] = $dev . " " . gettext("device not present! Is the modem attached to the system?");
}
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)) { $usbmodemoutput = array();
$ifinfo['laggproto'] = $matches[1]; exec("usbconfig", $usbmodemoutput);
} $mondev = "/tmp/3gstats.{$ifdescr}";
if (preg_match("/laggport: (.*)$/", $ici, $matches)) { if (file_exists($mondev)) {
$ifinfo['laggport'][] = $matches[1]; $cellstats = file($mondev);
} /* skip header */
$a_cellstats = explode(",", $cellstats[1]);
if (preg_match("/huawei/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = huawei_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = huawei_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = huawei_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = huawei_service_to_string(trim($a_cellstats[11]));
}
if (preg_match("/zte/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = zte_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = zte_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = zte_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = zte_service_to_string(trim($a_cellstats[11]));
}
$ifinfo['cell_upstream'] = $a_cellstats[4];
$ifinfo['cell_downstream'] = trim($a_cellstats[5]);
$ifinfo['cell_sent'] = $a_cellstats[6];
$ifinfo['cell_received'] = trim($a_cellstats[7]);
$ifinfo['cell_bwupstream'] = $a_cellstats[8];
$ifinfo['cell_bwdownstream'] = trim($a_cellstats[9]);
}
// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
if (isset($ppp['uptime'])) {
$ifinfo['ppp_uptime_accumulated'] = "(" . get_ppp_uptime($ifinfo['if']) . ")";
}
break;
default:
break;
}
if (file_exists("/var/run/{$link_type}_{$ifdescr}.pid")) {
$sec = trim(`/usr/local/sbin/ppp-uptime.sh {$ifinfo['if']}`);
$ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec);
} }
foreach ($wifconfiginfo as $ici) {
$elements = preg_split("/[ ]+/i", $ici); if ($ifinfo['status'] == "up") {
if ($elements[0] != "") { $wifconfiginfo = array();
$ifinfo['bssid'] = $elements[0]; if (is_interface_wireless($ifdescr)) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo);
array_shift($wifconfiginfo);
} }
if ($elements[3] != "") { foreach ($wifconfiginfo as $ici) {
$ifinfo['rate'] = $elements[3]; $elements = preg_split("/[ ]+/i", $ici);
if ($elements[0] != "") {
$ifinfo['bssid'] = $elements[0];
}
if ($elements[3] != "") {
$ifinfo['rate'] = $elements[3];
}
if ($elements[4] != "") {
$ifinfo['rssi'] = $elements[4];
}
} }
if ($elements[4] != "") { /* lookup the gateway */
$ifinfo['rssi'] = $elements[4]; if (interface_has_gateway($ifdescr)) {
$ifinfo['gateway'] = get_interface_gateway($ifdescr);
$ifinfo['gatewayv6'] = get_interface_gateway_v6($ifdescr);
} }
}
/* lookup the gateway */
if (interface_has_gateway($ifdescr)) {
$ifinfo['gateway'] = get_interface_gateway($ifdescr);
$ifinfo['gatewayv6'] = get_interface_gateway_v6($ifdescr);
} }
}
$bridge = ""; $bridge = "";
$bridge = link_interface_to_bridge($ifdescr); $bridge = link_interface_to_bridge($ifdescr);
if ($bridge) { if ($bridge) {
$bridge_text = `/sbin/ifconfig {$bridge}`; $bridge_text = `/sbin/ifconfig {$bridge}`;
if (stristr($bridge_text, "blocking") <> false) { if (stristr($bridge_text, "blocking") <> false) {
$ifinfo['bridge'] = "<b><font color='red'>" . gettext("blocking") . "</font></b> - " . gettext("check for ethernet loops"); $ifinfo['bridge'] = "<b><font color='red'>" . gettext("blocking") . "</font></b> - " . gettext("check for ethernet loops");
$ifinfo['bridgeint'] = $bridge; $ifinfo['bridgeint'] = $bridge;
} elseif (stristr($bridge_text, "learning") <> false) { } elseif (stristr($bridge_text, "learning") <> false) {
$ifinfo['bridge'] = gettext("learning"); $ifinfo['bridge'] = gettext("learning");
$ifinfo['bridgeint'] = $bridge; $ifinfo['bridgeint'] = $bridge;
} elseif (stristr($bridge_text, "forwarding") <> false) { } elseif (stristr($bridge_text, "forwarding") <> false) {
$ifinfo['bridge'] = gettext("forwarding"); $ifinfo['bridge'] = gettext("forwarding");
$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);
$interface_list_ips = get_configured_ip_addresses();
$isipv6 = is_ipaddrv6($ipaddr); if (empty($interface_list_ips[$ipaddr]) || $interface_list_ips[$ipaddr] == $if) {
if ($isipv6 === true) { return false;
$interface_list_ips = get_configured_ipv6_addresses();
} else { } else {
$interface_list_ips = get_configured_ip_addresses(); return true;
}
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 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,67 +825,28 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled = ...@@ -825,67 +825,28 @@ 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; 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 * get_interface_list() - Return a list of all physical interfaces
* along with MAC, IPv4 and status. * along with MAC, IPv4 and status.
...@@ -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 = ""; <tr>
$interrupt_sec = ""; <td><?= gettext("Interrupts") ?></td>
$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>
<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