clean up check_mac() interface (ml-cms)

This commit is contained in:
Oliver Gorwits
2018-04-18 19:23:43 +01:00
parent e0d75c3cba
commit 2caae8a642
7 changed files with 20 additions and 13 deletions

View File

@@ -1,3 +1,9 @@
2.039022 - 2018-04-
[BUG FIXES]
* clean up check_mac() interface (ml-cms)
2.039021 - 2018-04-10
[BUG FIXES]

View File

@@ -143,7 +143,7 @@ sub store_arpentries {
foreach my $arpentry ( @$arpentries ) {
# skip broadcast/vrrp/hsrp and other wierdos
next unless check_mac( undef, $arpentry->{mac} );
next unless check_mac( $arpentry->{mac} );
debug sprintf ' arpnip - stored entry: %s / %s',
$arpentry->{mac}, $arpentry->{ip};

View File

@@ -116,7 +116,7 @@ sub _filter_nbname {
my $mac = $node_status->{'mac_address'} || '';
unless ( check_mac( $ip, $mac ) ) {
unless ( check_mac( $mac, $ip ) ) {
# Just assume it's the last MAC we saw this IP at.
my $node_ip = schema('netdisco')->resultset('NodeIp')

View File

@@ -28,11 +28,10 @@ subroutines.
=head1 EXPORT_OK
=head2 check_mac( $device, $node, $port_macs? )
=head2 check_mac( $node, $device?, $port_macs? )
Given a Device database object and a MAC address, perform various sanity
checks which need to be done before writing an ARP/Neighbor entry to the
database storage.
Given a MAC address, perform various sanity checks which need to be done
before writing an ARP/Neighbor entry to the database storage.
Returns false, and might log a debug level message, if the checks fail.
@@ -50,6 +49,8 @@ MAC address is not all-zero, broadcast, CLIP, VRRP or HSRP
=back
Optionally pass a Device instance or IP to use in logging.
Optionally pass a cached set of Device port MAC addresses as the third
argument, in which case an additional check is added:
@@ -64,11 +65,11 @@ MAC address does not belong to an interface on any known Device
=cut
sub check_mac {
my ($device, $node, $port_macs) = @_;
return 0 if !$device or !$node;
my ($node, $port_macs, $device) = @_;
return 0 if !$node;
my $mac = NetAddr::MAC->new(mac => $node);
my $devip = (ref $device ? $device->ip : '');
my $devip = ($device ? (ref $device ? $device->ip : $device) : '');
$port_macs ||= {};
# incomplete MAC addresses (BayRS frame relay DLCI, etc)

View File

@@ -15,9 +15,9 @@ register_admin_task({
sub _sanity_ok {
return 0 unless param('mac')
and check_mac(undef, param('mac'));
and check_mac(param('mac'));
params->{mac} = check_mac(undef, param('mac'));
params->{mac} = check_mac(param('mac'));
return 1;
}

View File

@@ -48,7 +48,7 @@ sub get_arps {
while (my ($arp, $node) = each %$paddr) {
my $ip = $netaddr->{$arp};
next unless defined $ip;
next unless check_mac($device, $node);
next unless check_mac($node, $device);
push @arps, {
node => $node,
ip => $ip,

View File

@@ -281,7 +281,7 @@ sub walk_fwtable {
while (my ($idx, $mac) = each %$fw_mac) {
my $bp_id = $fw_port->{$idx};
next unless check_mac($device, $mac);
next unless check_mac($mac, $device);
unless (defined $bp_id) {
debug sprintf