--- lib/PXElator/dnsd.pm 2009/08/05 13:25:19 148 +++ lib/PXElator/dnsd.pm 2009/08/05 14:01:59 150 @@ -16,25 +16,48 @@ debug => $debug, ); +our $ptr_cache; +sub name_ip { + my ( $name, $ip ) = @_; + $ptr_cache->{ join('.', reverse split(/\./, $ip)) } = $name; + return $ip; +} + sub reply_handler { my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; my ($rcode, @ans, @auth, @add); server->refresh; + $debug = server::debug; + + print "$qname $qclass $qtype $peerhost to ". $conn->{"sockhost"}. "\n"; + $query->print if $debug; - print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n"; - $query->print; + my $local = $1 if $qname =~ m{^(.+)\.\Q$server::domain_name\E$}; + $local = $qname if $qname !~ m{\.}; - if ( $qname =~ s{\Q$server::domain_name\E$}{} ) { - warn "local $qname $qtype"; - if ( $qtype eq "A" && $qname eq "pxelator." ) { - my ($ttl, $rdata) = (3600, "172.16.10.1"); - push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata"); - $rcode = "NOERROR"; + my $ttl = 3600; + + if ( $local ) { + warn "local[$local] $qname $qtype"; + $rcode = "NOERROR"; + my $rdata; + if ( $qtype eq "A" && $local eq "server" ) { + $rdata = name_ip( $local, '172.16.10.1' ); } 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} ) { + $rdata .= '.' . $server::domain_name; + push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata"); + } else { +warn "## ",dump( $ptr_cache ); + $rcode = "NXDOMAIN"; + } } elsif ( my $packet = $res->query( $qname, $qtype ) ) { $packet->print;