mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix: fdb tables multiple IPs and IPs from other devices adding extra rows (#6930)
Fix missing IPs because the ARP entries are on different port_id Update arp discovery to use snmpwalk_group() additional fix in that function Fix removal of arp entries Fix a debug output type in fdb discovery
This commit is contained in:
committed by
Neil Lathwood
parent
4a2f07cdca
commit
b56c6b6adf
@@ -1,53 +1,59 @@
|
||||
<?php
|
||||
$param = array();
|
||||
|
||||
$sql = ' FROM `ports_fdb` AS `F`';
|
||||
$select = "SELECT `F`.`port_id` AS `port_id`, `device_id`, `ifInErrors`, `ifOutErrors`, `ifOperStatus`,";
|
||||
$select .= " `ifAdminStatus`, `ifAlias` AS `interface`, `ifDescr`, `mac_address`, `V`.`vlan_vlan` AS `vlan`,";
|
||||
$select .= " `hostname`, `hostname` AS `device` , group_concat(`M`.`ipv4_address` SEPARATOR ', ') AS `ipv4_address`";
|
||||
|
||||
$sql = " FROM `ports_fdb` AS `F`";
|
||||
$sql .= " LEFT JOIN `devices` AS `D` USING(`device_id`)";
|
||||
$sql .= " LEFT JOIN `ports` AS `P` USING(`port_id`, `device_id`)";
|
||||
$sql .= " LEFT JOIN `vlans` AS `V` USING(`vlan_id`, `device_id`)";
|
||||
|
||||
$where = " WHERE 1";
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`';
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` USING (`device_id`)';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " LEFT JOIN `ports` AS `P` ON `F`.`port_id`=`P`.`port_id`";
|
||||
$sql .= " LEFT JOIN `devices` AS `D` ON `F`.`device_id`=`D`.`device_id`";
|
||||
$sql .= " LEFT JOIN `vlans` AS `V` ON `F`.`vlan_id`=`V`.`vlan_id`";
|
||||
$sql .= " LEFT JOIN `ipv4_mac` ON `F`.`mac_address`=`ipv4_mac`.`mac_address`";
|
||||
|
||||
$sql .= " WHERE 1";
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= ' AND `F`.`device_id`=?';
|
||||
$where .= ' AND `F`.`device_id`=?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['port_id'])) {
|
||||
$sql .= ' AND `F`.`port_id`=?';
|
||||
$where .= ' AND `F`.`port_id`=?';
|
||||
$param[] = $_POST['port_id'];
|
||||
}
|
||||
|
||||
if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) {
|
||||
$vlan_search = mres(trim($_POST['searchPhrase']));
|
||||
$mac_search = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['searchPhrase'])).'%';
|
||||
$search = mres(trim($_POST['searchPhrase']));
|
||||
$mac_search = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', $search).'%';
|
||||
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == 'vlan') {
|
||||
$sql .= ' AND `V`.`vlan_vlan` = ?';
|
||||
$param[] = $vlan_search;
|
||||
} elseif (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') {
|
||||
$sql .= ' AND `F`.`mac_address` LIKE ?';
|
||||
$where .= ' AND `V`.`vlan_vlan` = ?';
|
||||
$param[] = (int)$search;
|
||||
} elseif ((isset($_POST['searchby']) && $_POST['searchby'] == 'mac') ||
|
||||
(!is_numeric($search) || $search > 4096)
|
||||
) {
|
||||
$where .= ' AND `F`.`mac_address` LIKE ?';
|
||||
$param[] = $mac_search;
|
||||
} else {
|
||||
$sql .= ' AND (`V`.`vlan_vlan` = ? OR `F`.`mac_address` LIKE ?)';
|
||||
$param[] = $vlan_search;
|
||||
$where .= ' AND (`V`.`vlan_vlan` = ? OR `F`.`mac_address` LIKE ?)';
|
||||
$param[] = (int)$search;
|
||||
$param[] = $mac_search;
|
||||
}
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`F`.`port_id`) $sql";
|
||||
$total = (int)dbFetchCell("SELECT COUNT(*) $sql $where", $param);
|
||||
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
// Don't use ipv4_mac in count it will inflate the rows unless we aggregate it and it isn't used for search
|
||||
$sql .= " LEFT JOIN `ipv4_mac` AS `M` USING (`mac_address`, `device_id`)";
|
||||
$sql .= $where;
|
||||
$sql .= " GROUP BY `device_id`, `port_id`, `mac_address`, `vlan`, `hostname`, `ifAlias`,";
|
||||
$sql .= " `ifAdminStatus`, `ifDescr`, `ifOperStatus`, `ifInErrors`, `ifOutErrors`";
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`F`.`port_id` ASC';
|
||||
@@ -64,23 +70,26 @@ if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT `P`.*, `ifDescr` AS `interface`, `F`.`mac_address`, `ipv4_mac`.`ipv4_address`, `V`.`vlan_vlan` as `vlan`, `D`.`hostname` AS `device` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $entry) {
|
||||
$response = array();
|
||||
foreach (dbFetchRows($select . $sql, $param) as $entry) {
|
||||
$entry = cleanPort($entry);
|
||||
if (!$ignore) {
|
||||
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
|
||||
$error_img = generate_port_link($entry, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'port_errors');
|
||||
$error_img = generate_port_link(
|
||||
$entry,
|
||||
"<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>",
|
||||
'port_errors'
|
||||
);
|
||||
} else {
|
||||
$error_img = '';
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
'device' => generate_device_link(device_by_id_cache($entry['device_id'])),
|
||||
'mac_address' => formatMac($entry['mac_address']),
|
||||
'ipv4_address' => $entry['ipv4_address'],
|
||||
'interface' => generate_port_link($entry, makeshortif(fixifname(cleanPort($entry['label'])))).' '.$error_img,
|
||||
'vlan' => $entry['vlan'],
|
||||
'device' => generate_device_link(device_by_id_cache($entry['device_id'])),
|
||||
'mac_address' => formatMac($entry['mac_address']),
|
||||
'ipv4_address' => $entry['ipv4_address'],
|
||||
'interface' => generate_port_link($entry, makeshortif(fixifname($entry['label']))).' '.$error_img,
|
||||
'vlan' => $entry['vlan'],
|
||||
);
|
||||
}//end if
|
||||
|
||||
|
||||
Reference in New Issue
Block a user