clean up check_mac() interface (ml-cms)
This commit is contained in:
		| @@ -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') | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user