line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zonemaster v1.0.1; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17612
|
use 5.014002; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
216
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Zonemaster::Nameserver; |
7
|
|
|
|
|
|
|
use Zonemaster::Logger; |
8
|
|
|
|
|
|
|
use Zonemaster::Config; |
9
|
|
|
|
|
|
|
use Zonemaster::Zone; |
10
|
|
|
|
|
|
|
use Zonemaster::Test; |
11
|
|
|
|
|
|
|
use Zonemaster::Recursor; |
12
|
|
|
|
|
|
|
use Zonemaster::ASNLookup; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $logger; |
15
|
|
|
|
|
|
|
our $config; |
16
|
|
|
|
|
|
|
our $recursor = Zonemaster::Recursor->new; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub logger { |
19
|
|
|
|
|
|
|
return $logger //= Zonemaster::Logger->new; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub config { |
23
|
|
|
|
|
|
|
if ( not defined $config ) { |
24
|
|
|
|
|
|
|
$config = Zonemaster::Config->new; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return $config; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub ns { |
31
|
|
|
|
|
|
|
my ( $class, $name, $address ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return Zonemaster::Nameserver->new( { name => $name, address => $address } ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub zone { |
37
|
|
|
|
|
|
|
my ( $class, $name ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return Zonemaster::Zone->new( { name => $name } ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub test_zone { |
43
|
|
|
|
|
|
|
my ( $class, $zname ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return Zonemaster::Test->run_all_for( $class->zone( $zname ) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub test_module { |
49
|
|
|
|
|
|
|
my ( $class, $module, $zname ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return Zonemaster::Test->run_module( $module, $class->zone( $zname ) ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub test_method { |
55
|
|
|
|
|
|
|
my ( $class, $module, $method, @arguments ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return Zonemaster::Test->run_one( $module, $method, @arguments ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub all_tags { |
61
|
|
|
|
|
|
|
my ( $class ) = @_; |
62
|
|
|
|
|
|
|
my @res; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
foreach my $module ( 'Basic', sort { $a cmp $b } Zonemaster::Test->modules ) { |
65
|
|
|
|
|
|
|
my $full = "Zonemaster::Test::$module"; |
66
|
|
|
|
|
|
|
my $ref = $full->metadata; |
67
|
|
|
|
|
|
|
foreach my $list ( values %$ref ) { |
68
|
|
|
|
|
|
|
push @res, map { uc( $module ) . ':' . $_ } sort { $a cmp $b } @$list; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return @res; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub all_methods { |
76
|
|
|
|
|
|
|
my ( $class ) = @_; |
77
|
|
|
|
|
|
|
my %res; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
foreach my $module ( 'Basic', Zonemaster::Test->modules ) { |
80
|
|
|
|
|
|
|
my $full = "Zonemaster::Test::$module"; |
81
|
|
|
|
|
|
|
my $ref = $full->metadata; |
82
|
|
|
|
|
|
|
foreach my $method ( sort { $a cmp $b } keys %$ref ) { |
83
|
|
|
|
|
|
|
push @{ $res{$module} }, $method; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return %res; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub recurse { |
91
|
|
|
|
|
|
|
my ( $class, $qname, $qtype, $qclass ) = @_; |
92
|
|
|
|
|
|
|
$qtype //= 'A'; |
93
|
|
|
|
|
|
|
$qclass //= 'IN'; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return $recursor->recurse( $qname, $qtype, $qclass ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub add_fake_delegation { |
99
|
|
|
|
|
|
|
my ( $class, $domain, $href ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $parent = $class->zone( $recursor->parent( $domain ) ); |
102
|
|
|
|
|
|
|
foreach my $ns ( @{ $parent->ns } ) { |
103
|
|
|
|
|
|
|
$ns->add_fake_delegation( $domain => $href ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub add_fake_ds { |
110
|
|
|
|
|
|
|
my ( $class, $domain, $aref ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $parent = $class->zone( scalar( $recursor->parent( $domain ) ) ); |
113
|
|
|
|
|
|
|
if ( not $parent ) { |
114
|
|
|
|
|
|
|
die "Failed to find parent for $domain"; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
foreach my $ns ( @{ $parent->ns } ) { |
118
|
|
|
|
|
|
|
$ns->add_fake_ds( $domain => $aref ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub save_cache { |
125
|
|
|
|
|
|
|
my ( $class, $filename ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
return Zonemaster::Nameserver->save( $filename ); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub preload_cache { |
131
|
|
|
|
|
|
|
my ( $class, $filename ) = @_; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return Zonemaster::Nameserver->restore( $filename ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub asn_lookup { |
137
|
|
|
|
|
|
|
my ( undef, $ip ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return Zonemaster::ASNLookup->get( $ip ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub modules { |
143
|
|
|
|
|
|
|
return Zonemaster::Test->modules; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub start_time_now { |
147
|
|
|
|
|
|
|
Zonemaster::Logger->start_time_now(); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub reset { |
151
|
|
|
|
|
|
|
Zonemaster::Logger->start_time_now(); |
152
|
|
|
|
|
|
|
Zonemaster::Nameserver->empty_cache(); |
153
|
|
|
|
|
|
|
$logger->clear_history(); |
154
|
|
|
|
|
|
|
Zonemaster::Recursor->clear_cache(); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 NAME |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Zonemaster - A tool to check the quality of a DNS zone |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SYNOPSIS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my @results = Zonemaster->test_zone('iis.se') |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item test_zone($name) |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Runs all available tests and returns a list of L<Zonemaster::Logger::Entry> objects. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item test_module($module, $name) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Runs all available tests for the zone with the given name in the specified module. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item test_method($module, $method, @arguments) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Run one particular test method in one particular module. The requested module must be in the list of active loaded modules (that is, not the Basic |
182
|
|
|
|
|
|
|
module and not a module disabled by the current policy), and the method must be listed in the metadata the module exports. If those requirements |
183
|
|
|
|
|
|
|
are fulfilled, the method will be called with the provided arguments. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item zone($name) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns a L<Zonemaster::Zone> object for the given name. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item ns($name, $address) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns a L<Zonemaster::Nameserver> object for the given name and address. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item config() |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Returns the global L<Zonemaster::Config> object. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item logger() |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns the global L<Zonemaster::Logger> object. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item all_tags() |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Returns a list of all the tags that can be logged for all avilable test modules. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item all_methods() |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Returns a hash, where the keys are test module names and the values are lists with the names of the test methods in that module. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item recurse($name, $type, $class) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Does a recursive lookup for the given name, type and class, and returns the resulting packet (if any). Simply calls |
212
|
|
|
|
|
|
|
L<Zonemaster::Recursor::recurse()> on a globally stored object. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item save_cache($filename) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
After running the tests, save the accumulated cache to a file with the given name. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item preload_cache($filename) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Before running the tests, load the cache with information from a file with the given name. This file must have the same format as is produced by |
221
|
|
|
|
|
|
|
L<save_cache()>. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item asn_lookup($ip) |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Takes a single IP address and returns one of three things: |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Nothing, if the IP address is not in any AS. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
If called in list context, a list of AS number and a L<Net::IP::XS> object representing the prefix it's in. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
If called in scalar context, only the AS number. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item modules() |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Returns a list of the loaded test modules. Exactly the same as L<Zonemaster::Test::modules>. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item add_fake_delegation($domain, $data) |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This method adds some fake delegation information to the system. The arguments are a domain name, and a reference to a hash with delegation |
250
|
|
|
|
|
|
|
information. The keys in the hash must be nameserver names, and the values references to lists of IP addresses for the corresponding nameserver. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Example: |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Zonemaster->add_fake_delegation( |
255
|
|
|
|
|
|
|
'lysator.liu.se' => { |
256
|
|
|
|
|
|
|
'ns.nic.se' => [ '212.247.7.228', '2a00:801:f0:53::53' ], |
257
|
|
|
|
|
|
|
'i.ns.se' => [ '194.146.106.22', '2001:67c:1010:5::53' ], |
258
|
|
|
|
|
|
|
'ns3.nic.se' => [ '212.247.8.152', '2a00:801:f0:211::152' ] |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item add_fake_ds($domain, $data) |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
This method adds fake DS records to the system. The arguments are a domain |
265
|
|
|
|
|
|
|
name, and a reference to a list of references to hashes. The hashes in turn |
266
|
|
|
|
|
|
|
must have the keys C<keytag>, C<algorithm>, C<type> and C<digest>, with the |
267
|
|
|
|
|
|
|
values holding the corresponding data. The digest data should be a single |
268
|
|
|
|
|
|
|
unbroken string of hexadecimal digits. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Example: |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Zonemaster->add_fake_ds( |
273
|
|
|
|
|
|
|
'nic.se' => [ |
274
|
|
|
|
|
|
|
{ keytag => 16696, algorithm => 5, type => 2, digest => '40079DDF8D09E7F10BB248A69B6630478A28EF969DDE399F95BC3B39F8CBACD7' }, |
275
|
|
|
|
|
|
|
{ keytag => 16696, algorithm => 5, type => 1, digest => 'EF5D421412A5EAF1230071AFFD4F585E3B2B1A60' }, |
276
|
|
|
|
|
|
|
] |
277
|
|
|
|
|
|
|
); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item start_time_now() |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Set the logger's start time to the current time. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item reset() |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Reset logger start time to current time, empty the list of log messages, clear |
286
|
|
|
|
|
|
|
nameserver object cache and recursor cache. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=back |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 AUTHOR |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Calle Dybedahl, C<< <calle at init.se> >> |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
no Moose; |
297
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
1; |