AllKnowingDNS
view release on metacpan or search on metacpan
lib/App/AllKnowingDNS/Handler.pm view on Meta::CPAN
my $resolver = Net::DNS::Resolver->new(
nameservers => [ $zone->upstream_dns ],
recurse => 0,
);
my $result = $resolver->query($qname . '.upstream', 'PTR');
# If the upstream query was successful, relay the response, otherwise
# generate a reply.
if (defined($result) && $result->header->rcode eq 'NOERROR') {
if ($querylog) {
say strftime('%x %X %z', localtime) . " - Relaying upstream answer for $qname";
}
my @answer = $result->answer;
for my $answer (@answer) {
my $name = $answer->name;
$name =~ s/\.upstream$//;
$answer->name($name);
}
return ('NOERROR', [ $result->answer ], [], [], { aa => 1 });
}
}
lib/App/AllKnowingDNS/Handler.pm view on Meta::CPAN
Returns DNS RRs for PTR and AAAA queries of zones which are configured in
C<$config>.
=cut
sub reply_handler {
my ($config, $querylog, $qname, $qclass, $qtype, $peerhost) = @_;
if ($querylog) {
say strftime('%x %X %z', localtime) . " - $peerhost - query for $qname ($qtype)";
}
if ($qtype eq 'PTR' &&
defined(my $zone = $config->zone_for_ptr($qname))) {
return handle_ptr_query($querylog, $zone, $qname, $qclass, $qtype);
}
if (defined(my $zone = $config->zone_for_aaaa($qname))) {
return handle_aaaa_query($zone, $qname, $qclass, $qtype);
}
lib/App/AllKnowingDNS/Util.pm view on Meta::CPAN
# Ignore comments.
next if substr($line, 0, 1) eq '#';
# Skip empty lines
next if length($line) == 0;
# If we are not currently parsing a zone, only the 'network' keyword is
# appropriate.
if (!defined($current_zone) &&
!($line =~ /^network/i) && !($line =~ /^listen/i)) {
say STDERR qq|all-knowing-dns: CONFIG: Expected 'network' or 'listen' keyword in line "$line"|;
next;
}
if (my ($address) = ($line =~ /^listen (.*)/i)) {
$config->add_listen_address(lc $address);
next;
}
if (my ($network) = ($line =~ /^network (.*)/i)) {
# The current zone is done now, if any.
lib/App/AllKnowingDNS/Util.pm view on Meta::CPAN
return $config;
}
=head2 netmask_to_ptrzone($netmask)
Converts the given netmask to a PTR zone.
Example:
my $ptrzone = netmask_to_ptrzone('2001:4d88:100e:ccc0::/64');
say $ptrzone; # 0.c.c.c.e.0.0.1.8.8.d.4.1.0.0.2.ip6.arpa
=cut
sub netmask_to_ptrzone {
my ($netmask) = @_;
my ($address, $mask) = ($netmask =~ m,^([^/]+)/([0-9]+),);
if (($mask % 16) != 0) {
say STDERR "all-knowing-dns: ERROR: Only netmasks which " .
"are dividable by 16 are supported!";
exit 1;
}
my @components = unpack("n8", ipv6_aton($address));
# A nibble is a 4-bit aggregation, that is, one "hex digit".
my @nibbles = map { ((($_ & 0xF000) >> 12),
(($_ & 0x0F00) >> 8),
(($_ & 0x00F0) >> 4),
(($_ & 0x000F) >> 0)) } @components;
script/all-knowing-dns view on Meta::CPAN
our $VERSION = '1.7';
my $configfile = '/etc/all-knowing-dns.conf';
my $querylog = 0;
GetOptions(
'configfile=s' => \$configfile,
'querylog!' => \$querylog,
'version' => sub {
say "AllKnowingDNS v$VERSION " .
"© 2012 Michael Stapelberg and contributors";
exit 0;
},
'help' => sub {
say "all-knowing-dns [--configfile <path>] [--querylog]";
say "";
say "\t--configfile <path>\tSpecifies an alternate configfile location.";
say "\t\t\t\tThe default is /etc/all-knowing-dns.conf";
say "\t--querylog\t\tLogs every query to stdout (for debugging).";
say "";
exit 0;
},
);
openlog('all-knowing-dns', 'pid', 'daemon');
syslog('info', "AllKnowingDNS v$VERSION starting");
my $input;
my $fh;
if (!open($fh, '<', $configfile)) {
( run in 1.583 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )