From 34f503afb8ca520642398bbe2038492ba8280d55 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Mon, 15 Aug 2016 11:40:11 -0600 Subject: [PATCH 1/4] Use port instead of chassis ID for port matching Code was improperly using chassis id for port matching. Fixes #4069 . --- includes/discovery/discovery-protocols.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 17dbfe4623..b8b10399c6 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -158,11 +158,11 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { } // normalize MAC address if present if ($lldp['lldpRemChassisIdSubtype'] == 'macAddress') { - $remote_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemChassisId'])); + $remote_port_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId'])); } // get remote device hostname from db by MAC address and replace lldpRemSysName if absent - if (!$remote_device_id && $remote_mac_address) { - $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_mac_address, '0')); + if (!$remote_device_id && $remote_port_mac_address) { + $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_port_mac_address, '0')); if ($remote_device_id) { $remote_device_hostname = dbFetchRow('SELECT `hostname` FROM `devices` WHERE `device_id` = ?', array($remote_device_id)); } @@ -173,7 +173,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { if ($remote_device_id) { $if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId']; - $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_mac_address, $remote_device_id)); + $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_port_mac_address, $remote_device_id)); } else { $remote_port_id = '0'; From c405c38effaabad1891cbafe4d6a9bef13c84df7 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Mon, 15 Aug 2016 11:52:21 -0600 Subject: [PATCH 2/4] Check against the proper subtype variable, initialize variable --- includes/discovery/discovery-protocols.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index b8b10399c6..204301f68e 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -157,7 +157,8 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface); } // normalize MAC address if present - if ($lldp['lldpRemChassisIdSubtype'] == 'macAddress') { + $remote_port_mac_address = '' + if ($lldp['lldpRemPortIdSubtype'] == 'macAddress') { $remote_port_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId'])); } // get remote device hostname from db by MAC address and replace lldpRemSysName if absent From 71625f6abad038016722b67c2f6ac633f4c80818 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Mon, 15 Aug 2016 14:44:19 -0600 Subject: [PATCH 3/4] fix whitespace (spaces, not tabs) --- includes/discovery/discovery-protocols.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 204301f68e..b60261a6ca 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -157,7 +157,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface); } // normalize MAC address if present - $remote_port_mac_address = '' + $remote_port_mac_address = '' if ($lldp['lldpRemPortIdSubtype'] == 'macAddress') { $remote_port_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId'])); } From f019a28d8cb2e63470d52096dd27985ea9a53510 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Mon, 15 Aug 2016 14:53:44 -0600 Subject: [PATCH 4/4] and a semicolon --- includes/discovery/discovery-protocols.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index b60261a6ca..ac7135ab2f 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -157,7 +157,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface); } // normalize MAC address if present - $remote_port_mac_address = '' + $remote_port_mac_address = ''; if ($lldp['lldpRemPortIdSubtype'] == 'macAddress') { $remote_port_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemPortId'])); }