#767 also respect dns->no configuration in ip_from_hostname()

This commit is contained in:
Oliver Gorwits
2021-07-14 12:25:01 +01:00
parent 485cfd24fa
commit 74b9583fae
2 changed files with 8 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
* #784 empty device_skip table when also emptying job queue
* #788 use device.name instead of device.dns for pseudo devices
* #783 fix FQDN discovery in node monitor emails
* #767 also respect dns->no configuration in ip_from_hostname()
2.047005 - 2021-02-24

View File

@@ -7,6 +7,8 @@ use Dancer ':script';
use Net::DNS;
use NetAddr::IP::Lite ':lower';
use App::Netdisco::Util::Permission 'check_acl_no';
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/hostname_from_ip ipv4_from_hostname/;
@@ -29,6 +31,8 @@ subroutines.
Given an IP address (either IPv4 or IPv6), return the canonical hostname.
Will respect the excluded IPs in L<DNS no> configuration.
C<< %opts >> can override the various timeouts available in
L<Net::DNS::Resolver>:
@@ -51,8 +55,11 @@ Returns C<undef> if no PTR record exists for the IP.
sub hostname_from_ip {
my ($ip, $opts) = @_;
return unless $ip;
my $skip = setting('dns')->{'no'};
my $ETCHOSTS = setting('dns')->{'ETCHOSTS'};
return if check_acl_no($ip, $skip);
# check /etc/hosts file and short-circuit if found
foreach my $name (reverse sort keys %$ETCHOSTS) {
if ($ETCHOSTS->{$name}->[0]->[0] eq $ip) {