From b2d61b3d5fb49b1faeec343f88a79616ccd5a74e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 8 Jan 2015 11:07:25 +0000 Subject: [PATCH] [#193] DBI Exception for Cisco ACE MacAddr format Also standardise on IEEE MAC format now that NetAddr::MAC has that corrected. --- Netdisco/Changes | 1 + Netdisco/lib/App/Netdisco/Core/Arpnip.pm | 7 +++++-- Netdisco/lib/App/Netdisco/Core/Discover.pm | 6 +++--- Netdisco/lib/App/Netdisco/Util/Node.pm | 2 +- Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm | 2 +- Netdisco/lib/App/Netdisco/Web/Search.pm | 7 +++++-- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 93a8a52f..d780018d 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -18,6 +18,7 @@ * Delete all job queue entries (regardless of status) when deleting device * [#15] Undiscovered Neighbor report JOIN fixed, and updated to include the ports where Macsuck saw the MAC address of a known Device + * [#193] DBI Exception for Cisco ACE MacAddr format 2.029014 - 2014-11-19 diff --git a/Netdisco/lib/App/Netdisco/Core/Arpnip.pm b/Netdisco/lib/App/Netdisco/Core/Arpnip.pm index d52d7801..a0ca5249 100644 --- a/Netdisco/lib/App/Netdisco/Core/Arpnip.pm +++ b/Netdisco/lib/App/Netdisco/Core/Arpnip.pm @@ -7,6 +7,7 @@ use App::Netdisco::Util::Node 'check_mac'; use App::Netdisco::Util::DNS ':all'; use NetAddr::IP::Lite ':lower'; use Time::HiRes 'gettimeofday'; +use NetAddr::MAC (); use base 'Exporter'; our @EXPORT = (); @@ -119,9 +120,11 @@ sub store_arp { my ($hash_ref, $now) = @_; $now ||= 'now()'; my $ip = $hash_ref->{'ip'}; - my $mac = $hash_ref->{'node'}; + my $mac = NetAddr::MAC->new($hash_ref->{'node'}); my $name = $hash_ref->{'dns'}; + return if !defined $mac or $mac->errstr; + schema('netdisco')->txn_do(sub { my $current = schema('netdisco')->resultset('NodeIp') ->search( @@ -131,7 +134,7 @@ sub store_arp { schema('netdisco')->resultset('NodeIp') ->update_or_create( { - mac => $mac, + mac => $mac->as_ieee, ip => $ip, dns => $name, active => \'true', diff --git a/Netdisco/lib/App/Netdisco/Core/Discover.pm b/Netdisco/lib/App/Netdisco/Core/Discover.pm index 3a438892..c19e58f8 100644 --- a/Netdisco/lib/App/Netdisco/Core/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Core/Discover.pm @@ -756,7 +756,7 @@ sub store_neighbors { if (!defined $neigh) { my $mac = NetAddr::MAC->new(mac => $remote_id); if ($mac and not $mac->errstr) { - $neigh = $devices->single({mac => $mac->as_microsoft()}); + $neigh = $devices->single({mac => $mac->as_ieee}); } } @@ -770,8 +770,8 @@ sub store_neighbors { if ($mac and not $mac->errstr) { info sprintf '[%s] neigh - found neighbor %s by MAC %s', - $device->ip, $remote_id, $mac->as_microsoft(); - $neigh = $devices->single({mac => $mac->as_microsoft()}); + $device->ip, $remote_id, $mac->as_ieee; + $neigh = $devices->single({mac => $mac->as_ieee}); } } diff --git a/Netdisco/lib/App/Netdisco/Util/Node.pm b/Netdisco/lib/App/Netdisco/Util/Node.pm index 44c43bcc..f603ca5e 100644 --- a/Netdisco/lib/App/Netdisco/Util/Node.pm +++ b/Netdisco/lib/App/Netdisco/Util/Node.pm @@ -78,7 +78,7 @@ sub check_mac { } else { # lower case, hex, colon delimited, 8-bit groups - $node = lc $mac->as_microsoft; + $node = lc $mac->as_ieee; } # broadcast MAC addresses diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 6e370206..a2df5832 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -49,7 +49,7 @@ ajax '/ajax/content/search/node' => require_login sub { my @where_mac = ($using_wildcards ? \['me.mac::text ILIKE ?', $likeval] - : ((!defined $mac or $mac->errstr) ? \'0=1' : ('me.mac' => $mac->as_microsoft)) ); + : ((!defined $mac or $mac->errstr) ? \'0=1' : ('me.mac' => $mac->as_ieee)) ); my $sightings = schema('netdisco')->resultset('Node') ->search({-and => [@where_mac, @active, @times]}, { diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 54fa0b6d..316a88e5 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; use App::Netdisco::Util::Web 'sql_match'; +use NetAddr::MAC (); hook 'before' => sub { # view settings for node options @@ -78,6 +79,7 @@ get '/search' => require_login sub { else { my $nd = $s->resultset('Device')->search_fuzzy($q); my ($likeval, $likeclause) = sql_match($q); + my $mac = NetAddr::MAC->new($q); if ($nd and $nd->count) { if ($nd->count == 1) { @@ -96,8 +98,9 @@ get '/search' => require_login sub { ->search({ -or => [ {name => $likeclause}, - (length $q == 17 ? {mac => $q} - : \['mac::text ILIKE ?', $likeval]), + ((!defined $mac or $mac->errstr) + ? \['mac::text ILIKE ?', $likeval] + : {mac => $mac->as_ieee}), ], })->count) {