/[pxelator]/lib/PXElator/dnsd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/dnsd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 148 by dpavlin, Wed Aug 5 13:25:19 2009 UTC revision 150 by dpavlin, Wed Aug 5 14:01:59 2009 UTC
# Line 16  my $res = Net::DNS::Resolver->new( Line 16  my $res = Net::DNS::Resolver->new(
16          debug => $debug,          debug => $debug,
17  );  );
18    
19    our $ptr_cache;
20    sub name_ip {
21            my ( $name, $ip ) = @_;
22            $ptr_cache->{ join('.', reverse split(/\./, $ip)) } = $name;
23            return $ip;
24    }
25    
26  sub reply_handler {  sub reply_handler {
27          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
28          my ($rcode, @ans, @auth, @add);          my ($rcode, @ans, @auth, @add);
29    
30          server->refresh;          server->refresh;
31            $debug = server::debug;
32    
33            print "$qname $qclass $qtype $peerhost to ". $conn->{"sockhost"}. "\n";
34            $query->print if $debug;
35    
36          print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n";          my $local = $1     if $qname =~ m{^(.+)\.\Q$server::domain_name\E$};
37          $query->print;             $local = $qname if $qname !~ m{\.};
38    
39          if ( $qname =~ s{\Q$server::domain_name\E$}{} ) {          my $ttl = 3600;
40                  warn "local $qname $qtype";  
41                  if ( $qtype eq "A" && $qname eq "pxelator." ) {          if ( $local ) {
42                          my ($ttl, $rdata) = (3600, "172.16.10.1");                  warn "local[$local] $qname $qtype";
43                          push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");                  $rcode = "NOERROR";
44                          $rcode = "NOERROR";                  my $rdata;
45                    if ( $qtype eq "A" && $local eq "server" ) {
46                            $rdata = name_ip( $local, '172.16.10.1' );
47                  } else {                  } else {
48                          $rcode = "NXDOMAIN";                          $rcode = "NXDOMAIN";
49                  }                  }
50    
51                    push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata") if $ttl;
52    
53            } elsif ( $qtype eq 'PTR' && $qname =~ m{^([0-9\.]*)\.in-addr\.arpa$} ) {
54                            if ( my $rdata = $ptr_cache->{$1} ) {
55                                    $rdata .= '.' . $server::domain_name;
56                                    push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
57                            } else {
58    warn "## ",dump( $ptr_cache );
59                                    $rcode = "NXDOMAIN";
60                            }
61          } elsif ( my $packet = $res->query( $qname, $qtype ) ) {          } elsif ( my $packet = $res->query( $qname, $qtype ) ) {
62    
63                  $packet->print;                  $packet->print;

Legend:
Removed from v.148  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26