diff --git a/Netdisco/Changes b/Netdisco/Changes index 6c2cd9c7..4fd140d9 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * Increase default snmptimeout from 1 to 3 seconds * Add documentation note about non-standard pg port + * [#23] Move to NetAddr::MAC for better handling of MACs [BUG FIXES] diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index fa9678b1..7e8fffc4 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -33,7 +33,7 @@ requires 'MCE' => 1.408; requires 'Net::Domain' => 1.23; requires 'Net::DNS' => 0.72; requires 'Net::LDAP' => 0; -requires 'Net::MAC' => 2.103622; +requires 'NetAddr::MAC' => 0.82; requires 'Net::NBName' => 0.26; requires 'NetAddr::IP' => 4.068; requires 'Opcode' => 1.07; diff --git a/Netdisco/lib/App/Netdisco/Core/Discover.pm b/Netdisco/lib/App/Netdisco/Core/Discover.pm index 109c56a9..a6798730 100644 --- a/Netdisco/lib/App/Netdisco/Core/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Core/Discover.pm @@ -10,7 +10,7 @@ use NetAddr::IP::Lite ':lower'; use List::MoreUtils (); use Encode; use Try::Tiny; -use Net::MAC; +use NetAddr::MAC; use base 'Exporter'; our @EXPORT = (); @@ -713,8 +713,8 @@ sub store_neighbors { $device->ip, $remote_ip, $port, $remote_id; if (!defined $neigh) { - my $mac = Net::MAC->new(mac => $remote_id, 'die' => 0, verbose => 0); - if (not $mac->get_error) { + my $mac = NetAddr::MAC->new(mac => $remote_id); + if (not $mac->errstr) { $neigh = $devices->single({mac => $remote_id}); } } diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Node.pm b/Netdisco/lib/App/Netdisco/DB/Result/Node.pm index 36740d18..2332d332 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Node.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Node.pm @@ -7,7 +7,7 @@ package App::Netdisco::DB::Result::Node; use strict; use warnings; -use Net::MAC; +use NetAddr::MAC; use base 'DBIx::Class::Core'; __PACKAGE__->table("node"); @@ -175,10 +175,10 @@ sub time_last_stamp { return (shift)->get_column('time_last_stamp') } =head2 net_mac -Returns the C column instantiated into a L object. +Returns the C column instantiated into a L object. =cut -sub net_mac { return Net::MAC->new(mac => (shift)->mac) } +sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) } 1; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm b/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm index 504c2f7f..0a3f6a77 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm @@ -7,7 +7,7 @@ package App::Netdisco::DB::Result::NodeIp; use strict; use warnings; -use Net::MAC; +use NetAddr::MAC; use base 'DBIx::Class::Core'; __PACKAGE__->table("node_ip"); @@ -221,10 +221,10 @@ sub time_last_stamp { return (shift)->get_column('time_last_stamp') } =head2 net_mac -Returns the C column instantiated into a L object. +Returns the C column instantiated into a L object. =cut -sub net_mac { return Net::MAC->new(mac => (shift)->mac) } +sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) } 1; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm b/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm index 971ad10a..e8203dc9 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm @@ -7,6 +7,8 @@ package App::Netdisco::DB::Result::NodeNbt; use strict; use warnings; +use NetAddr::MAC; + use base 'DBIx::Class::Core'; __PACKAGE__->table("node_nbt"); __PACKAGE__->add_columns( @@ -176,10 +178,10 @@ sub time_last_stamp { return (shift)->get_column('time_last_stamp') } =head2 net_mac -Returns the C column instantiated into a L object. +Returns the C column instantiated into a L object. =cut -sub net_mac { return Net::MAC->new(mac => (shift)->mac) } +sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) } 1; diff --git a/Netdisco/lib/App/Netdisco/Manual/Developing.pod b/Netdisco/lib/App/Netdisco/Manual/Developing.pod index dea39857..baa5a2f6 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Developing.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Developing.pod @@ -262,8 +262,8 @@ Compared to the current Netdisco, the handler routines are very small. This is because (a) they don't include any HTML - this is delegated to a template, and (b) they don't include an SQL - this is delegated to DBIx::Class. Small routines are more manageable, and easier to maintain. You'll also notice use -of modules such as L and L to simplify and make -more robust the handling of data. +of modules such as L and L to simplify and +make more robust the handling of data. In fact, many sections of the web application have been factored out into separate Plugin modules. For more information see the diff --git a/Netdisco/lib/App/Netdisco/Util/Node.pm b/Netdisco/lib/App/Netdisco/Util/Node.pm index 9555a57d..c138250a 100644 --- a/Netdisco/lib/App/Netdisco/Util/Node.pm +++ b/Netdisco/lib/App/Netdisco/Util/Node.pm @@ -3,7 +3,7 @@ package App::Netdisco::Util::Node; use Dancer qw/:syntax :script/; use Dancer::Plugin::DBIC 'schema'; -use Net::MAC; +use NetAddr::MAC; use App::Netdisco::Util::Permission 'check_acl'; use base 'Exporter'; @@ -66,18 +66,18 @@ MAC address does not belong to an interface on any known Device sub check_mac { my ($device, $node, $port_macs) = @_; - my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0); + my $mac = NetAddr::MAC->new(mac => $node); $port_macs ||= {}; # incomplete MAC addresses (BayRS frame relay DLCI, etc) - if ($mac->get_error) { + if ($mac->errstr) { debug sprintf ' [%s] check_mac - mac [%s] malformed - skipping', $device->ip, $node; return 0; } else { # lower case, hex, colon delimited, 8-bit groups - $node = lc $mac->as_IEEE; + $node = lc $mac->as_microsoft; } # broadcast MAC addresses diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 89e97cfe..c683f574 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -55,6 +55,11 @@ hook 'before' => sub { { name => 'n_archived', label => 'Archived Data', default => '' }, ]); + # not stored in the cookie - global defaults + params->{'age_num'} ||= 3; + params->{'age_unit'} ||= 'months'; + params->{'mac_format'} ||= 'microsoft'; + return unless (request->path eq uri_for('/device')->path or index(request->path, uri_for('/ajax/content/device')->path) == 0); @@ -101,15 +106,10 @@ hook 'before' => sub { if $col->{default} eq 'on'; } - # not stored in the cookie - params->{'age_num'} ||= 3; - params->{'age_unit'} ||= 'months'; - params->{'mac_format'} ||= 'IEEE'; - if (param('reset')) { params->{'age_num'} = 3; params->{'age_unit'} = 'months'; - params->{'mac_format'} = 'IEEE'; + params->{'mac_format'} = 'microsoft'; # nuke the port params cookie cookie('nd_ports-form' => '', expires => '-1 day'); @@ -129,7 +129,21 @@ hook 'before_template' => sub { $tokens->{device_ports}->query_param($key, params->{$key}); } - # for Net::MAC method + # for NetAddr::MAC method + $tokens->{mac_formats} = { + basic => 'Basic', + # bpr => 'BPR', + cisco => 'Cisco', + ieee => 'IEEE', + # ipv6 => 'IPv6 Suffix', + microsoft => 'Microsoft', + singledash => 'Single Dash', + sun => 'Sun', + tokenring => 'Token Ring', + # eui48 => 'EUI48', + # eui64 => 'EUI64', + }; + $tokens->{mac_format_call} = 'as_'. params->{'mac_format'} if params->{'mac_format'}; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm index a6648a6d..327a7010 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -6,7 +6,7 @@ use Dancer::Plugin::DBIC; use Dancer::Plugin::Auth::Extensible; use NetAddr::IP::Lite ':lower'; -use Net::MAC (); +use NetAddr::MAC (); use App::Netdisco::Web::Plugin; use App::Netdisco::Util::Web 'sql_match'; @@ -22,7 +22,7 @@ ajax '/ajax/content/search/node' => require_login sub { my $agenot = param('age_invert') || '0'; my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx; - my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0); + my $mac = NetAddr::MAC->new(mac => $node); my @active = (param('archived') ? () : (-bool => 'active')); my @times = (); @@ -48,7 +48,7 @@ ajax '/ajax/content/search/node' => require_login sub { my @where_mac = ($using_wildcards ? \['me.mac::text ILIKE ?', $likeval] - : ($mac->get_error ? \'0=1' : ('me.mac' => $mac->as_IEEE)) ); + : ($mac->errstr ? \'0=1' : ('me.mac' => $mac->as_microsoft)) ); my $sightings = schema('netdisco')->resultset('Node') ->search({-and => [@where_mac, @active, @times]}, { diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index eb789ae1..0b0e8d8d 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -125,8 +125,9 @@
  • MAC address format:
  • diff --git a/Netdisco/share/views/sidebar/search/node.tt b/Netdisco/share/views/sidebar/search/node.tt index 3a9c8963..3a308799 100644 --- a/Netdisco/share/views/sidebar/search/node.tt +++ b/Netdisco/share/views/sidebar/search/node.tt @@ -55,8 +55,9 @@
    MAC address format: