From 8b2e2f8d95e9f7a05c6e6e356872ecb3ef1163cf Mon Sep 17 00:00:00 2001 From: AdamB Date: Fri, 16 Dec 2022 15:46:10 +0000 Subject: [PATCH] Prevent spurious MAC changes on multi-interface devices (#14671) --- includes/discovery/arp-table.inc.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 534bc5d0b0..bfdfadd4cb 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -36,9 +36,6 @@ foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) { $sql = 'SELECT * from `ipv4_mac` WHERE `device_id`=? AND `context_name`=?'; $existing_data = dbFetchRows($sql, [$device['device_id'], $context_name]); - $ipv4_addresses = array_map(function ($data) { - return $data['ipv4_address']; - }, $existing_data); $arp_table = []; $insert_data = []; foreach ($arp_data as $ifIndex => $data) { @@ -59,7 +56,14 @@ foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) { $mac = implode(array_map('zeropad', explode(':', $raw_mac))); $arp_table[$port_id][$ip] = $mac; - $index = array_search($ip, $ipv4_addresses); + $index = false; + foreach ($existing_data as $existing_key => $existing_value) { + if ($existing_value['ipv4_address'] == $ip && $existing_value['port_id'] == $port_id) { + $index = $existing_key; + break; + } + } + if ($index !== false) { $old_mac = $existing_data[$index]['mac_address']; if ($mac != $old_mac && $mac != '') {