/[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 211 by dpavlin, Thu Aug 13 12:00:51 2009 UTC revision 393 by dpavlin, Tue Sep 8 16:54:35 2009 UTC
# Line 28  sub reply_handler { Line 28  sub reply_handler {
28          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
29          my ($rcode, @ans, @auth, @add);          my ($rcode, @ans, @auth, @add);
30    
         server->refresh;  
31          $debug = server::debug;          $debug = server::debug;
32    
33          CouchDB::audit( 'request', {          my $audit = {
34                  qname => $qname,                  qname => $qname,
35                  qclass => $qclass,                  qclass => $qclass,
36                  qtype => $qtype,                  qtype => $qtype,
37                  peerhost =>  $peerhost,                  peerhost =>  $peerhost,
38                  sockhost => $conn->{"sockhost"}                  sockhost => $conn->{"sockhost"},
39          });                  source => 'unknown',
40            };
41    
42          $query->print if $debug;          $query->print if $debug;
43    
44          my $local = $1     if $qname =~ m{^(.+)\.\Q$server::domain_name\E$};          my $local = $1     if $qname =~ m{^(.+)\.\Q$server::domain\E$};
45             $local = $qname if $qname !~ m{\.};             $local = $qname if $qname !~ m{\.};
46    
47          my $ttl = 3600;          my $ttl = 3600;
48    
         my $audit = { source => 'unknown' };  
   
49          if ( $local ) {          if ( $local ) {
50                  warn "local[$local] $qname $qtype";                  warn "local[$local] $qname $qtype";
51                  $rcode = "NOERROR";                  $rcode = "NOERROR";
# Line 63  sub reply_handler { Line 61  sub reply_handler {
61    
62          } elsif ( $qtype eq 'PTR' && $qname =~ m{^([0-9\.]*)\.in-addr\.arpa$} ) {          } elsif ( $qtype eq 'PTR' && $qname =~ m{^([0-9\.]*)\.in-addr\.arpa$} ) {
63                          if ( my $rdata = $ptr_cache->{$1} ) {                          if ( my $rdata = $ptr_cache->{$1} ) {
64                                  $rdata .= '.' . $server::domain_name;                                  $rdata .= '.' . $server::domain;
65                                  push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");                                  push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
66                                  $audit->{source} = 'PTR';                                  $audit->{source} = 'PTR';
67                          } else {                          } else {
# Line 85  warn "## ",dump( $ptr_cache ); Line 83  warn "## ",dump( $ptr_cache );
83          warn "rcode: $rcode ",dump( @ans );          warn "rcode: $rcode ",dump( @ans );
84    
85          $audit->{rcode} = $rcode;          $audit->{rcode} = $rcode;
86          $audit->{ans} = [ @ans ];          $audit->{ans} = [ map {
87                    my $data;
88                    foreach my $n ( keys %$_ ) {
89                            $data->{$n} = $_->{$n};
90                    }
91                    $data;
92            } @ans ];
93    
94          CouchDB::audit( 'response', $audit );          CouchDB::audit( 'response', $audit );
95    
# Line 96  warn "## ",dump( $ptr_cache ); Line 100  warn "## ",dump( $ptr_cache );
100  sub start {  sub start {
101          my $ns = Net::DNS::Nameserver->new(          my $ns = Net::DNS::Nameserver->new(
102                  LocalPort    => 53,                  LocalPort    => 53,
103                  ReplyHandler => \&reply_handler,                  ReplyHandler => sub {
104                            server->refresh;
105                            reply_handler(@_);
106                    },
107                  Verbose      => $debug,                  Verbose      => $debug,
108          ) || die "couldn't create nameserver object\n";          ) || die "couldn't create nameserver object\n";
109    
110          CouchDB::audit('start', { listen => { port => 53, domain_name => $server::domain_name } });          CouchDB::audit('start', { port => 53, domain => $server::domain });
111          warn "DNS $server::domain_name";          warn "DNS $server::domain";
112    
113          $ns->main_loop;          $ns->main_loop;
114  }  }

Legend:
Removed from v.211  
changed lines
  Added in v.393

  ViewVC Help
Powered by ViewVC 1.1.26