From 2bc92999b879cc9a7c6fee3e397d7f6e29de18e4 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 25 Aug 2014 18:48:11 +0100 Subject: [PATCH] [#123] Allow devices with no LLDP/CDP to be found as Nodes --- Netdisco/Changes | 1 + Netdisco/lib/App/Netdisco/Core/Macsuck.pm | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index d7d051d8..16da4037 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -8,6 +8,7 @@ [ENHANCEMENTS] * Port search also searches on the Remote ID and Type + * [#123] Allow devices with no LLDP/CDP to be found as Nodes 2.029005 - 2014-08-13 diff --git a/Netdisco/lib/App/Netdisco/Core/Macsuck.pm b/Netdisco/lib/App/Netdisco/Core/Macsuck.pm index 8f0bdce5..042f28e9 100644 --- a/Netdisco/lib/App/Netdisco/Core/Macsuck.pm +++ b/Netdisco/lib/App/Netdisco/Core/Macsuck.pm @@ -346,6 +346,8 @@ sub _walk_fwtable { next; } + my $vlan = $fw_vlan->{$idx} || $comm_vlan || '0'; + # check to see if the port is connected to another device # and if we have that device in the database. @@ -371,12 +373,13 @@ sub _walk_fwtable { debug sprintf ' [%s] macsuck %s - port %s is detected uplink - skipping.', $device->ip, $mac, $port; + + $skiplist->{$port} = [ $vlan, $mac ] # remember for later + if exists $port_macs->{$mac}; next; } } - my $vlan = $fw_vlan->{$idx} || $comm_vlan || '0'; - if (exists $port_macs->{$mac}) { my $switch_ip = $port_macs->{$mac}; if ($device->ip eq $switch_ip) { @@ -395,7 +398,8 @@ sub _walk_fwtable { if (not setting('macsuck_bleed')) { debug sprintf ' [%s] macsuck %s - adding port %s to skiplist', $device->ip, $mac, $port; - $skiplist->{$port} = delete $cache->{$vlan}->{$port}; + + $skiplist->{$port} = [ $vlan, $mac ]; # remember for later next; } } @@ -410,6 +414,15 @@ sub _walk_fwtable { ++$cache->{$vlan}->{$port}->{$mac}; } + # restore MACs of neighbor devices. + # this is when we have a "possible uplink" detected but we still want to + # record the single MAC of the neighbor device so it works in Node search. + foreach my $port (keys %$skiplist) { + my ($vlan, $mac) = @{ $skiplist->{$port} }; + delete $cache->{$_}->{$port} for keys %$cache; # nuke nodes on all VLANs + ++$cache->{$vlan}->{$port}->{$mac}; + } + return $cache; }