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 |
|
|
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"; |
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 |
|
|
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_name => $server::domain_name }); |
111 |
warn "DNS $server::domain_name"; |
warn "DNS $server::domain_name"; |
112 |
|
|
113 |
$ns->main_loop; |
$ns->main_loop; |