Skip to content

Commit

Permalink
move pseudo and layer checks into is_*able functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ollyg committed Aug 25, 2019
1 parent 8b010d4 commit 61f9c89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
26 changes: 20 additions & 6 deletions lib/App/Netdisco/Util/Device.pm
Expand Up @@ -241,9 +241,10 @@ sub is_arpnipable {

=head2 is_arpnipable_now( $ip )
Same as C<is_arpnipable>, 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<is_arpnipable>, but also compares the C<last_arpnip> field
of the C<device> to the C<arpnip_min_age> 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.
Expand All @@ -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')) {
Expand Down Expand Up @@ -290,9 +297,10 @@ sub is_macsuckable {

=head2 is_macsuckable_now( $ip )
Same as C<is_macsuckable>, 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<is_macsuckable>, but also compares the C<last_macsuck> field
of the C<device> to the C<macsuck_min_age> 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.
Expand All @@ -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')) {
Expand Down
6 changes: 0 additions & 6 deletions lib/App/Netdisco/Worker/Plugin/Arpnip.pm
Expand Up @@ -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);

Expand Down
6 changes: 0 additions & 6 deletions lib/App/Netdisco/Worker/Plugin/Macsuck.pm
Expand Up @@ -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);

Expand Down

0 comments on commit 61f9c89

Please sign in to comment.