fix: Workaround bad lldp that supplies ifAlias instead of ifDescr for lldpRemPortDesc (#8666)

This commit is contained in:
Tony Murray
2018-05-07 15:17:45 -05:00
committed by Neil Lathwood
parent 9401e43eb9
commit fea3c77916

View File

@@ -1392,12 +1392,12 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
}
/**
* Try to find a port by ifDescr, ifName, or MAC
* Try to find a port by ifDescr, ifName, ifAlias, or MAC
*
* @param string $description matched against ifDescr and ifName
* @param string $identifier matched against ifDescr and ifName
* @param string $description matched against ifDescr, ifName, and ifAlias
* @param string $identifier matched against ifDescr, ifName, and ifAlias
* @param int $device_id restrict search to ports on a specific device
* @param string $mac_address check against ifPysAddress (should be in lowercase hexadecimal)
* @param string $mac_address check against ifPhysAddress (should be in lowercase hexadecimal)
* @return int
*/
function find_port_id($description, $identifier = '', $device_id = 0, $mac_address = null)
@@ -1411,11 +1411,16 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre
if ($device_id) {
if ($description) {
// order is important here, the standard says this is ifDescr, which some mfg confuse with ifName
$statements[] = "SELECT `port_id` FROM `ports` WHERE `device_id`=? AND (`ifDescr`=? OR `ifName`=?)";
$params[] = $device_id;
$params[] = $description;
$params[] = $description;
// we check ifAlias last because this is a user editable field, but some bad LLDP implementations use it
$statements[] = "SELECT `port_id` FROM `ports` WHERE `device_id`=? AND `ifAlias`=?";
$params[] = $device_id;
$params[] = $description;
}
if ($identifier) {