diff --git a/Netdisco/Changes b/Netdisco/Changes index ed16b0c8..05b3c0a0 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -7,6 +7,7 @@ [ENHANCEMENTS] * [#82] Check /etc/hosts before DNS when doing arp entry name lookup + * [#59] Arpnip tries to resolve link local IPv6 addresses [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod index 43fac9f9..634a8324 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod @@ -761,12 +761,18 @@ Value: Settings Tree. Default: dns: max_outstanding: 250 + no: ['fe80::/64','169.254.0.0/16'] -Sets the maximum number of outstanding requests for asynchronous DNS -resolution used during arpnip and device alias discovery. +Controls the asynchronous DNS resolver used to resolve IP addresses to +names during arpnip and discovery of device aliases. -This setting overrides the C environment -value and the C library default of 10. +C sets the maximum number of outstanding requests for +asynchronous DNS resolution. This setting overrides the +C environment value and the C +library default of 10. + +C is a list of IP addresses or CIDR ranges to excluded from DNS +resolution. Link local addresses are excluded by default. =head3 C diff --git a/Netdisco/lib/App/Netdisco/Util/DNS.pm b/Netdisco/lib/App/Netdisco/Util/DNS.pm index 7acacbb9..38dda178 100644 --- a/Netdisco/lib/App/Netdisco/Util/DNS.pm +++ b/Netdisco/lib/App/Netdisco/Util/DNS.pm @@ -3,9 +3,11 @@ package App::Netdisco::Util::DNS; use strict; use warnings FATAL => 'all'; +use Dancer ':script'; use Net::DNS; use AnyEvent::DNS::EtcHosts; use AnyEvent::DNS; +use NetAddr::IP::Lite ':lower'; use base 'Exporter'; our @EXPORT = (); @@ -104,6 +106,7 @@ sub hostnames_resolve_async { foreach my $hash_ref (@$ips) { my $ip = $hash_ref->{'ip'} || $hash_ref->{'alias'}; + next if no_resolve($ip); $done->begin; AnyEvent::DNS::reverse_verify $ip, sub { $hash_ref->{'dns'} = shift; $done->end; }; @@ -118,5 +121,30 @@ sub hostnames_resolve_async { return $ips; } +=head2 no_resolve( $ip ) + +Given an IP address, returns true if excluded from DNS resolution by the +C configuration directive, otherwise returns false. + +=cut + +sub no_resolve { + my $ip = shift; + + my $config = setting('dns')->{no} || []; + return 0 if not scalar @$config; + + my $addr = NetAddr::IP::Lite->new($ip); + + foreach my $item (@$config) { + my $c_ip = NetAddr::IP::Lite->new($item) + or next; + next unless $c_ip->bits == $addr->bits; + + return 1 if ($c_ip->contains($addr)); + } + return 0; +} + 1; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index d7a2a8f0..3f1f8dcf 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -158,6 +158,7 @@ workers: dns: max_outstanding: 250 + no: ['fe80::/64','169.254.0.0/16'] #housekeeping: # discoverall: