--- lib/PXElator/dnsd.pm 2009/09/08 16:54:35 393 +++ lib/PXElator/dnsd.pm 2009/09/13 09:38:00 426 @@ -9,6 +9,7 @@ use CouchDB; use server; +use client; our $debug = server::debug; my $res = Net::DNS::Resolver->new( @@ -17,13 +18,22 @@ debug => $debug, ); -our $ptr_cache; +our ( $ptr_cache, $a_cache ); sub name_ip { my ( $name, $ip ) = @_; $ptr_cache->{ join('.', reverse split(/\./, $ip)) } = $name; + $a_cache->{$name} = $ip; return $ip; } +name_ip 'server' => $server::ip; + +foreach my $ip ( client::all_ips ) { + if ( my $name = client::conf( $ip => 'hostname' ) ) { + name_ip $name => $ip; + } +} + sub reply_handler { my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; my ($rcode, @ans, @auth, @add); @@ -50,24 +60,29 @@ warn "local[$local] $qname $qtype"; $rcode = "NOERROR"; my $rdata; - if ( $qtype eq "A" && $local eq "server" ) { - $rdata = name_ip( $local, $server::ip ); - $audit->{source} = 'local'; - } else { - $rcode = "NXDOMAIN"; - } - - push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata") if $ttl; - - } elsif ( $qtype eq 'PTR' && $qname =~ m{^([0-9\.]*)\.in-addr\.arpa$} ) { - if ( my $rdata = $ptr_cache->{$1} ) { + if ( $qtype eq "A" ) { + if ( $rdata = $a_cache->{$local} ) { + $audit->{source} = 'local'; + } else { + $rcode = "NXDOMAIN"; +warn "## no $local in ",dump( $a_cache ); + } + } elsif ( $qtype eq 'PTR' ) { + $qname =~ s{\.in-addr\.arpa$}{} || warn "W: can't strip suffix from $qtype $qname"; + if ( my $rdata = $ptr_cache->{$qname} ) { $rdata .= '.' . $server::domain; push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata"); $audit->{source} = 'PTR'; } else { -warn "## ",dump( $ptr_cache ); +warn "## no $qname in ",dump( $ptr_cache ); $rcode = "NXDOMAIN"; } + } else { + $audit->{warn} = "qtype $qtype not supported"; + } + + push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata") if $ttl; + } elsif ( my $packet = $res->query( $qname, $qtype ) ) { $audit->{source} = 'upstream';