/[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 152 by dpavlin, Wed Aug 5 19:49:19 2009 UTC revision 207 by dpavlin, Wed Aug 12 22:56:45 2009 UTC
# Line 6  use strict; Line 6  use strict;
6  use Net::DNS::Nameserver;  use Net::DNS::Nameserver;
7  use Net::DNS::Resolver;  use Net::DNS::Resolver;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    use CouchDB;
10    
11  use server;  use server;
12  our $debug = server::debug;  our $debug = server::debug;
# Line 30  sub reply_handler { Line 31  sub reply_handler {
31          server->refresh;          server->refresh;
32          $debug = server::debug;          $debug = server::debug;
33    
34          print "$qname $qclass $qtype $peerhost to ". $conn->{"sockhost"}. "\n";          CouchDB::audit( 'request', {
35                    qname => $qname,
36                    qclass => $qclass,
37                    qtype => $qtype,
38                    peerhost =>  $peerhost,
39                    sockhost => $conn->{"sockhost"}
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_name\E$};
# Line 44  sub reply_handler { Line 52  sub reply_handler {
52                  my $rdata;                  my $rdata;
53                  if ( $qtype eq "A" && $local eq "server" ) {                  if ( $qtype eq "A" && $local eq "server" ) {
54                          $rdata = name_ip( $local, $server::ip );                          $rdata = name_ip( $local, $server::ip );
55                            CouchDB::audit('local', $rdata);
56                  } else {                  } else {
57                          $rcode = "NXDOMAIN";                          $rcode = "NXDOMAIN";
58                  }                  }
# Line 54  sub reply_handler { Line 63  sub reply_handler {
63                          if ( my $rdata = $ptr_cache->{$1} ) {                          if ( my $rdata = $ptr_cache->{$1} ) {
64                                  $rdata .= '.' . $server::domain_name;                                  $rdata .= '.' . $server::domain_name;
65                                  push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");                                  push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
66                                    CouchDB::audit('ptr', $rdata );
67                          } else {                          } else {
68  warn "## ",dump( $ptr_cache );  warn "## ",dump( $ptr_cache );
69                                  $rcode = "NXDOMAIN";                                  $rcode = "NXDOMAIN";
70                          }                          }
71          } elsif ( my $packet = $res->query( $qname, $qtype ) ) {          } elsif ( my $packet = $res->query( $qname, $qtype ) ) {
72    
73                    CouchDB::audit( 'upstream', $packet );
74                  $packet->print;                  $packet->print;
75                  push @ans, $_ foreach $packet->answer;                  push @ans, $_ foreach $packet->answer;
76                  $rcode = "NOERROR";                  $rcode = "NOERROR";
# Line 71  warn "## ",dump( $ptr_cache ); Line 82  warn "## ",dump( $ptr_cache );
82    
83          warn "rcode: $rcode ",dump( @ans );          warn "rcode: $rcode ",dump( @ans );
84    
85            CouchDB::audit('response', { rcode => $rcode, ans => [ @ans ], auth => [ @auth ], add => [ @add ] });
86    
87          # mark the answer as authoritive (by setting the 'aa' flag          # mark the answer as authoritive (by setting the 'aa' flag
88          return ($rcode, \@ans, \@auth, \@add, { aa => 1 });          return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
89  }  }
# Line 82  sub start { Line 95  sub start {
95                  Verbose      => $debug,                  Verbose      => $debug,
96          ) || die "couldn't create nameserver object\n";          ) || die "couldn't create nameserver object\n";
97    
98            CouchDB::audit('start', { listen => { port => 53, domain_name => $server::domain_name } });
99          warn "DNS $server::domain_name";          warn "DNS $server::domain_name";
100    
101          $ns->main_loop;          $ns->main_loop;

Legend:
Removed from v.152  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC 1.1.26