From 61f9c89040912391ac94a67e1c2ab93c8fb207a9 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 25 Aug 2019 23:55:38 +0100 Subject: [PATCH] move pseudo and layer checks into is_*able functions --- lib/App/Netdisco/Util/Device.pm | 26 +++++++++++++++++------ lib/App/Netdisco/Worker/Plugin/Arpnip.pm | 6 ------ lib/App/Netdisco/Worker/Plugin/Macsuck.pm | 6 ------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index e0fbd2114..9ca6361bd 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -241,9 +241,10 @@ sub is_arpnipable { =head2 is_arpnipable_now( $ip ) -Same as C, but also checks the last_arpnip field if the -device is in storage, and returns false if that host has been too recently -arpnipped. +Same as C, but also compares the C field +of the C to the C configuration. Also checks +for pseudo devices and for devices not supporting layer 3, with some +exceptions. Returns false if the host is not permitted to arpnip the target device. @@ -253,6 +254,12 @@ sub is_arpnipable_now { my ($ip) = @_; my $device = get_device($ip) or return 0; + return _bail_msg("is_arpnipable: $device is pseudo-device") + if $device->is_pseudo; + + return _bail_msg("is_arpnipable: $device has no layer 3 capability") + unless $device->has_layer(3); + if ($device->in_storage and $device->since_last_arpnip and setting('arpnip_min_age') and $device->since_last_arpnip < setting('arpnip_min_age')) { @@ -290,9 +297,10 @@ sub is_macsuckable { =head2 is_macsuckable_now( $ip ) -Same as C, but also checks the last_macsuck field if the -device is in storage, and returns false if that host has been too recently -macsucked. +Same as C, but also compares the C field +of the C to the C configuration. Also checks +for pseudo devices and for devices not supporting layer 2, with some +exceptions. Returns false if the host is not permitted to macsuck the target device. @@ -302,6 +310,12 @@ sub is_macsuckable_now { my ($ip) = @_; my $device = get_device($ip) or return 0; + return _bail_msg("is_macsuckable: $device is pseudo-device") + if $device->is_pseudo; + + return _bail_msg("is_macsuckable: $device has no layer 2 capability") + unless $device->has_layer(2); + if ($device->in_storage and $device->since_last_macsuck and setting('macsuck_min_age') and $device->since_last_macsuck < setting('macsuck_min_age')) { diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip.pm index caff485a9..1637b5dff 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip.pm @@ -16,12 +16,6 @@ register_worker({ phase => 'check' }, sub { return Status->error("arpnip skipped: $device not yet discovered") unless $device->in_storage; - return Status->info("macsuck skipped: $device is pseudo-device") - if $device->is_pseudo; - - return Status->info("arpnip skipped: $device has no layer 3 capability") - unless $device->has_layer(3); - return Status->info("arpnip skipped: $device is not arpnipable") unless is_arpnipable_now($device); diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck.pm index 8f90fdf02..13b610652 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck.pm @@ -16,12 +16,6 @@ register_worker({ phase => 'check' }, sub { return Status->error("macsuck skipped: $device not yet discovered") unless $device->in_storage; - return Status->info("macsuck skipped: $device is pseudo-device") - if $device->is_pseudo; - - return Status->info("macsuck skipped: $device has no layer 2 capability") - unless $device->has_layer(2); - return Status->info("macsuck skipped: $device is not macsuckable") unless is_macsuckable_now($device);