line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNS::Resolver::Mock; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
208883
|
use strict; |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
85
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.20230216'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
16
|
use base 'Net::DNS::Resolver'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1714
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
287574
|
use Net::DNS::Packet; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
176
|
|
11
|
3
|
|
|
3
|
|
39
|
use Net::DNS::Question; |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
215
|
|
12
|
3
|
|
|
3
|
|
2361
|
use Net::DNS::ZoneFile; |
|
3
|
|
|
|
|
21790
|
|
|
3
|
|
|
|
|
2660
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $die_on = {}; |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my @_debug_output; |
17
|
|
|
|
|
|
|
sub enable_debug { |
18
|
1
|
|
|
1
|
1
|
603
|
my ( $self ) = @_; |
19
|
1
|
|
|
|
|
6
|
$self->{_mock_debug} = 1; |
20
|
1
|
|
|
|
|
6
|
$self->_add_debug( "Net::DNS::Resolver::Mock Debugging enabled" ); |
21
|
1
|
|
|
|
|
3
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
sub disable_debug { |
24
|
1
|
|
|
1
|
0
|
545
|
my ( $self ) = @_; |
25
|
1
|
|
|
|
|
8
|
$self->clear_debug(); |
26
|
1
|
|
|
|
|
3
|
delete $self->{_mock_debug}; |
27
|
1
|
|
|
|
|
3
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
sub _add_debug { |
30
|
4
|
|
|
4
|
|
9
|
my ( $self, $debug ) = @_; |
31
|
4
|
|
|
|
|
9
|
push @_debug_output, $debug; |
32
|
4
|
|
|
|
|
66
|
warn $debug; |
33
|
4
|
|
|
|
|
15
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
sub clear_debug { |
36
|
1
|
|
|
1
|
1
|
4
|
my ( $self ) = @_; |
37
|
1
|
|
|
|
|
4
|
@_debug_output = (); |
38
|
1
|
|
|
|
|
2
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
sub get_debug { |
41
|
5
|
|
|
5
|
1
|
3037
|
my ( $self ) = @_; |
42
|
5
|
|
|
|
|
19
|
return @_debug_output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub die_on { |
47
|
1
|
|
|
1
|
1
|
1090
|
my ( $self, $name, $type, $error ) = @_; |
48
|
1
|
|
|
|
|
6
|
$die_on->{ "$name $type" } = $error; |
49
|
1
|
|
|
|
|
5
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub build_cache { |
53
|
4
|
|
|
4
|
0
|
21
|
my ( $self ) = @_; |
54
|
4
|
|
|
|
|
10
|
my $cache = {}; |
55
|
4
|
|
|
|
|
9
|
my $FakeZone = $self->{ 'zonefile' }; |
56
|
4
|
|
|
|
|
14
|
foreach my $Item ( @$FakeZone ) { |
57
|
9
|
|
|
|
|
38
|
my $itemname = lc $Item->name(); |
58
|
9
|
|
|
|
|
334
|
my $itemtype = lc $Item->type(); |
59
|
9
|
|
|
|
|
89
|
my $key = join( ':', $itemname, $itemtype ); |
60
|
9
|
100
|
|
|
|
27
|
if ( ! exists $cache->{$key} ) { |
61
|
8
|
|
|
|
|
26
|
$cache->{$key} = []; |
62
|
|
|
|
|
|
|
} |
63
|
9
|
|
|
|
|
12
|
push @{ $cache->{$key} }, $Item; |
|
9
|
|
|
|
|
29
|
|
64
|
|
|
|
|
|
|
} |
65
|
4
|
|
|
|
|
29
|
$self->{ 'zonefile_cache' } = $cache; |
66
|
4
|
|
|
|
|
12
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub zonefile_read { |
70
|
1
|
|
|
1
|
1
|
2283
|
my ( $self, $zonefile ) = @_; |
71
|
1
|
|
|
|
|
8
|
$self->{ 'zonefile' } = Net::DNS::ZoneFile->read( $zonefile ); |
72
|
1
|
|
|
|
|
5392
|
$self->build_cache(); |
73
|
1
|
|
|
|
|
3
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub zonefile_parse { |
77
|
3
|
|
|
3
|
1
|
3118
|
my ( $self, $zonefile ) = @_; |
78
|
3
|
|
|
|
|
21
|
$self->{ 'zonefile' } = Net::DNS::ZoneFile->parse( $zonefile ); |
79
|
3
|
|
|
|
|
3977
|
$self->build_cache(); |
80
|
3
|
|
|
|
|
10
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub send { |
84
|
17
|
|
|
17
|
1
|
13157
|
my ( $self, $name, $type ) = @_; |
85
|
|
|
|
|
|
|
|
86
|
17
|
100
|
|
|
|
70
|
$self->_add_debug( "DNS Lookup '$name' '$type'" ) if $self->{_mock_debug}; |
87
|
|
|
|
|
|
|
|
88
|
17
|
100
|
|
|
|
62
|
if ( exists ( $die_on->{ "$name $type" } ) ) { |
89
|
1
|
|
|
|
|
23
|
die $die_on->{ "$name $type" }; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
16
|
100
|
|
|
|
63
|
$name =~ s/\.$// unless $name eq '.'; |
93
|
|
|
|
|
|
|
|
94
|
16
|
|
|
|
|
27
|
my $origname = $name; |
95
|
16
|
100
|
|
|
|
49
|
if ( lc $type eq 'ptr' ) { |
96
|
4
|
100
|
|
|
|
16
|
if ( index( lc $name, '.in-addr.arpa' ) == -1 ) { |
97
|
3
|
100
|
|
|
|
16
|
if ( $name =~ /^\d+\.\d+\.\d+\.\d+$/ ) { |
98
|
2
|
|
|
|
|
11
|
$name = join( '.', reverse( split( /\./, $name ) ) ); |
99
|
2
|
|
|
|
|
5
|
$name .= '.in-addr.arpa'; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
16
|
|
|
|
|
79
|
my $Packet = Net::DNS::Packet->new(); |
104
|
16
|
|
|
|
|
287
|
$Packet->push( 'question' => Net::DNS::Question->new( $origname, $type, 'IN' ) ); |
105
|
16
|
|
|
|
|
1282
|
my $key = join( ':', lc $name, lc $type ); |
106
|
16
|
|
|
|
|
38
|
my $cname_key = join( ':', lc $name, 'cname' ); |
107
|
16
|
100
|
|
|
|
64
|
if ( exists( $self->{ 'zonefile_cache' }->{ $cname_key } ) ) { |
|
|
100
|
|
|
|
|
|
108
|
1
|
|
|
|
|
27
|
$Packet->push( 'answer' => @{ $self->{ 'zonefile_cache' }->{ $cname_key } } ); |
|
1
|
|
|
|
|
6
|
|
109
|
|
|
|
|
|
|
} elsif ( exists( $self->{ 'zonefile_cache' }->{ $key } ) ) { |
110
|
7
|
|
|
|
|
14
|
$Packet->push( 'answer' => @{ $self->{ 'zonefile_cache' }->{ $key } } ); |
|
7
|
|
|
|
|
22
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
16
|
|
|
|
|
127
|
$Packet->{ 'answerfrom' } = '127.0.0.1'; |
114
|
16
|
|
|
|
|
26
|
$Packet->{ 'status' } = 33152; |
115
|
16
|
|
|
|
|
53
|
return $Packet; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |