/[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 122 by dpavlin, Mon Aug 3 08:57:59 2009 UTC revision 148 by dpavlin, Wed Aug 5 13:25:19 2009 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use Net::DNS::Nameserver;  use Net::DNS::Nameserver;
7    use Net::DNS::Resolver;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    
10    use server;
11    our $debug = server::debug;
12    
13    my $res = Net::DNS::Resolver->new(
14    #       nameserver => [ '10.60.0.1' ],
15            recurse => 1,
16            debug => $debug,
17    );
18    
19  sub reply_handler {  sub reply_handler {
20          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;          my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
21          my ($rcode, @ans, @auth, @add);          my ($rcode, @ans, @auth, @add);
22    
23            server->refresh;
24    
25          print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n";          print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n";
26          $query->print;          $query->print;
27    
28                    if ( $qname =~ s{\Q$server::domain_name\E$}{} ) {
29          if ($qtype eq "A" && $qname eq "foo.example.com" ) {                  warn "local $qname $qtype";
30                  my ($ttl, $rdata) = (3600, "10.1.2.3");                  if ( $qtype eq "A" && $qname eq "pxelator." ) {
31                  push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");                          my ($ttl, $rdata) = (3600, "172.16.10.1");
32                  $rcode = "NOERROR";                          push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
33          }elsif( $qname eq "foo.example.com" ) {                          $rcode = "NOERROR";
34                    } else {
35                            $rcode = "NXDOMAIN";
36                    }
37    
38            } elsif ( my $packet = $res->query( $qname, $qtype ) ) {
39    
40                    $packet->print;
41                    push @ans, $_ foreach $packet->answer;
42                  $rcode = "NOERROR";                  $rcode = "NOERROR";
43    
44          }else{          } else {
45                   $rcode = "NXDOMAIN";                  # not found
46                    $rcode = "NXDOMAIN";
47          }          }
48    
49            warn "rcode: $rcode ",dump( @ans );
50    
51          # mark the answer as authoritive (by setting the 'aa' flag          # mark the answer as authoritive (by setting the 'aa' flag
52          return ($rcode, \@ans, \@auth, \@add, { aa => 1 });          return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
53  }  }
# Line 33  sub start { Line 56  sub start {
56          my $ns = Net::DNS::Nameserver->new(          my $ns = Net::DNS::Nameserver->new(
57                  LocalPort    => 53,                  LocalPort    => 53,
58                  ReplyHandler => \&reply_handler,                  ReplyHandler => \&reply_handler,
59                  Verbose      => 1,                  Verbose      => $debug,
60          ) || die "couldn't create nameserver object\n";          ) || die "couldn't create nameserver object\n";
61    
62          warn dump( $ns );          warn "DNS $server::domain_name";
63    
64          $ns->main_loop;          $ns->main_loop;
65  }  }
66    
67  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26