diff --git a/Netdisco/Changes b/Netdisco/Changes index 83fbd737..9289ba88 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -16,7 +16,6 @@ * 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 222610e7..b6329673 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 'NetAddr::MAC' => 0.82; +requires 'Net::MAC' => 2.103622; 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 a6798730..109c56a9 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 NetAddr::MAC; +use Net::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 = NetAddr::MAC->new(mac => $remote_id); - if (not $mac->errstr) { + my $mac = Net::MAC->new(mac => $remote_id, 'die' => 0, verbose => 0); + if (not $mac->get_error) { $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 2332d332..36740d18 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 NetAddr::MAC; +use Net::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 NetAddr::MAC->new(mac => (shift)->mac) } +sub net_mac { return Net::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 0a3f6a77..504c2f7f 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 NetAddr::MAC; +use Net::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 NetAddr::MAC->new(mac => (shift)->mac) } +sub net_mac { return Net::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 e8203dc9..971ad10a 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/NodeNbt.pm @@ -7,8 +7,6 @@ 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( @@ -178,10 +176,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 NetAddr::MAC->new(mac => (shift)->mac) } +sub net_mac { return Net::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 baa5a2f6..dea39857 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 c138250a..9555a57d 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 NetAddr::MAC; +use Net::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 = NetAddr::MAC->new(mac => $node); + my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0); $port_macs ||= {}; # incomplete MAC addresses (BayRS frame relay DLCI, etc) - if ($mac->errstr) { + if ($mac->get_error) { 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_microsoft; + $node = lc $mac->as_IEEE; } # broadcast MAC addresses diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index c683f574..89e97cfe 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -55,11 +55,6 @@ 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); @@ -106,10 +101,15 @@ 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'} = 'microsoft'; + params->{'mac_format'} = 'IEEE'; # nuke the port params cookie cookie('nd_ports-form' => '', expires => '-1 day'); @@ -129,21 +129,7 @@ hook 'before_template' => sub { $tokens->{device_ports}->query_param($key, params->{$key}); } - # 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', - }; - + # for Net::MAC method $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 327a7010..a6648a6d 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 NetAddr::MAC (); +use Net::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 = NetAddr::MAC->new(mac => $node); + my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0); 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->errstr ? \'0=1' : ('me.mac' => $mac->as_microsoft)) ); + : ($mac->get_error ? \'0=1' : ('me.mac' => $mac->as_IEEE)) ); 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 0b0e8d8d..eb789ae1 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -125,9 +125,8 @@
  • MAC address format:
  • diff --git a/Netdisco/share/views/sidebar/search/node.tt b/Netdisco/share/views/sidebar/search/node.tt index 3a308799..3a9c8963 100644 --- a/Netdisco/share/views/sidebar/search/node.tt +++ b/Netdisco/share/views/sidebar/search/node.tt @@ -55,9 +55,8 @@
    MAC address format: