this patch resets all pseudo devices to have no layer3 support but adds a feature to the pseudo devices admin panel to enable layer3 support. it also changes arpnip and arpwalk behaviour to always permit the action if layer3 is available (ignoring the vendor). documentation will need updating to tell users to create pseudo devices with layer3 support when they want to arpnip an unsupported platform. arpnip with ssh/cli against a supported platform (one that can be discovered) will continue to work normally. Squashed commit of the following: commit9dad5be81dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 09:03:53 2019 +0100 allow pseudo with layer 3 to run arpnip commit7d97943fcdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 08:59:10 2019 +0100 allow pseudo devices with layer 2/3 capability commitd1fdf574e3Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 08:55:41 2019 +0100 move pseudo and layer checks to is_able from is_able_now commite0f72ef67dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 08:51:42 2019 +0100 ports defaults to one commit86ba01270cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 08:50:45 2019 +0100 add tooltip for arpnip toggle commitcdd2470228Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 08:34:46 2019 +0100 simplify template commit46236d68eaAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 23:53:56 2019 +0100 a fix up for pseudo devices which need layer 3 commit016d249efcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 20:37:11 2019 +0100 do not wrap buttons commit1ec1402e0cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 20:33:03 2019 +0100 implement user settable layer-three service for pseudo devices commita267efa3d8Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 18:39:22 2019 +0100 only set layer if successful action commitb108be5e23Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 18:32:19 2019 +0100 should defer SNMP against pseudo devices commit897ba3a629Merge:e0ddbaaba7348900Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 1 14:54:36 2019 +0100 Merge branch 'master' into og-pseudo-vs-cli-arpnip commite0ddbaab08Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Aug 26 11:35:13 2019 +0100 as last commit, for discover commit61f9c89040Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 25 23:55:38 2019 +0100 move pseudo and layer checks into is_*able functions commit8b010d4023Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 25 18:38:11 2019 +0100 any device completing macsuck/arpnip must have that layer commita11bce7863Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 25 18:33:27 2019 +0100 clean up device layers commitd2661bff61Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 25 18:18:02 2019 +0100 first make arpnip behave like other jobs towards pseudo devices
129 lines
3.8 KiB
Perl
129 lines
3.8 KiB
Perl
package App::Netdisco::Worker::Plugin::Arpnip::Nodes;
|
|
|
|
use Dancer ':syntax';
|
|
use Dancer::Plugin::DBIC 'schema';
|
|
|
|
use App::Netdisco::Worker::Plugin;
|
|
use aliased 'App::Netdisco::Worker::Status';
|
|
|
|
use App::Netdisco::Transport::SSH ();
|
|
use App::Netdisco::Transport::SNMP ();
|
|
|
|
use App::Netdisco::Util::Node qw/check_mac store_arp/;
|
|
use App::Netdisco::Util::FastResolver 'hostnames_resolve_async';
|
|
|
|
use NetAddr::IP::Lite ':lower';
|
|
use Time::HiRes 'gettimeofday';
|
|
|
|
register_worker({ phase => 'store' }, sub {
|
|
my ($job, $workerconf) = @_;
|
|
my $device = $job->device;
|
|
|
|
# would be possible just to use now() on updated records, but by using this
|
|
# same value for them all, we _can_ if we want add a job at the end to
|
|
# select and do something with the updated set (no reason to yet, though)
|
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
|
|
|
# update node_ip with ARP and Neighbor Cache entries
|
|
|
|
store_arp(\%$_, $now) for @{ vars->{'v4arps'} };
|
|
debug sprintf ' [%s] arpnip - processed %s ARP Cache entries',
|
|
$device->ip, scalar @{ vars->{'v4arps'} };
|
|
|
|
store_arp(\%$_, $now) for @{ vars->{'v6arps'} };
|
|
debug sprintf ' [%s] arpnip - processed %s IPv6 Neighbor Cache entries',
|
|
$device->ip, scalar @{ vars->{'v6arps'} };
|
|
|
|
$device->update({last_arpnip => \$now});
|
|
|
|
my $status = $job->best_status;
|
|
return Status->$status("Ended arpnip for $device");
|
|
});
|
|
|
|
register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|
my ($job, $workerconf) = @_;
|
|
|
|
my $device = $job->device;
|
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
|
or return Status->defer("arpnip failed: could not SNMP connect to $device");
|
|
|
|
# cache v4 arp table
|
|
push @{ vars->{'v4arps'} },
|
|
@{ get_arps_snmp($device, $snmp->at_paddr, $snmp->at_netaddr) };
|
|
|
|
# cache v6 neighbor cache
|
|
push @{ vars->{'v6arps'} },
|
|
@{get_arps_snmp($device, $snmp->ipv6_n2p_mac, $snmp->ipv6_n2p_addr) };
|
|
|
|
$device->update({layers => \[q{overlay(layers placing '1' from 6 for 1)}]});
|
|
return Status->done("Gathered arp caches from $device");
|
|
});
|
|
|
|
# get an arp table (v4 or v6)
|
|
sub get_arps_snmp {
|
|
my ($device, $paddr, $netaddr) = @_;
|
|
my @arps = ();
|
|
|
|
while (my ($arp, $node) = each %$paddr) {
|
|
my $ip = $netaddr->{$arp};
|
|
next unless defined $ip;
|
|
next unless check_mac($node, $device);
|
|
push @arps, {
|
|
node => $node,
|
|
ip => $ip,
|
|
dns => undef,
|
|
};
|
|
}
|
|
|
|
debug sprintf ' resolving %d ARP entries with max %d outstanding requests',
|
|
scalar @arps, $ENV{'PERL_ANYEVENT_MAX_OUTSTANDING_DNS'};
|
|
my $resolved_ips = hostnames_resolve_async(\@arps);
|
|
|
|
return $resolved_ips;
|
|
}
|
|
|
|
register_worker({ phase => 'main', driver => 'cli' }, sub {
|
|
my ($job, $workerconf) = @_;
|
|
|
|
my $device = $job->device;
|
|
my $cli = App::Netdisco::Transport::SSH->session_for($device)
|
|
or return Status->defer("arpnip failed: could not SSH connect to $device");
|
|
|
|
# should be both v4 and v6
|
|
my @arps = @{ get_arps_cli($device, [$cli->arpnip]) };
|
|
|
|
# cache v4 arp table
|
|
push @{ vars->{'v4arps'} },
|
|
grep { NetAddr::IP::Lite->new($_->{ip})->bits == 32 } @arps;
|
|
|
|
# cache v6 neighbor cache
|
|
push @{ vars->{'v6arps'} },
|
|
grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps;
|
|
|
|
$device->update({layers => \[q{overlay(layers placing '1' from 6 for 1)}]});
|
|
return Status->done("Gathered arp caches from $device");
|
|
});
|
|
|
|
sub get_arps_cli {
|
|
my ($device, $entries) = @_;
|
|
my @arps = ();
|
|
$entries ||= [];
|
|
|
|
foreach my $entry (@$entries) {
|
|
next unless check_mac($entry->{mac}, $device);
|
|
push @arps, {
|
|
node => $entry->{mac},
|
|
ip => $entry->{ip},
|
|
dns => $entry->{dns},
|
|
};
|
|
}
|
|
|
|
debug sprintf ' resolving %d ARP entries with max %d outstanding requests',
|
|
scalar @arps, $ENV{'PERL_ANYEVENT_MAX_OUTSTANDING_DNS'};
|
|
my $resolved_ips = hostnames_resolve_async(\@arps);
|
|
|
|
return $resolved_ips;
|
|
}
|
|
|
|
true;
|