line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zonemaster::Engine::Packet; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
203
|
use version; our $VERSION = version->declare("v1.0.4"); |
|
26
|
|
|
|
|
50
|
|
|
26
|
|
|
|
|
220
|
|
4
|
|
|
|
|
|
|
|
5
|
26
|
|
|
26
|
|
3088
|
use 5.014002; |
|
26
|
|
|
|
|
105
|
|
6
|
26
|
|
|
26
|
|
131
|
use warnings; |
|
26
|
|
|
|
|
48
|
|
|
26
|
|
|
|
|
790
|
|
7
|
|
|
|
|
|
|
|
8
|
26
|
|
|
26
|
|
128
|
use Moose; |
|
26
|
|
|
|
|
46
|
|
|
26
|
|
|
|
|
179
|
|
9
|
26
|
|
|
26
|
|
166682
|
use Zonemaster::Engine::Util; |
|
26
|
|
|
|
|
78
|
|
|
26
|
|
|
|
|
15429
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'packet' => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => 'Zonemaster::LDNS::Packet', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
handles => [ |
16
|
|
|
|
|
|
|
qw( |
17
|
|
|
|
|
|
|
data |
18
|
|
|
|
|
|
|
rcode |
19
|
|
|
|
|
|
|
aa |
20
|
|
|
|
|
|
|
question |
21
|
|
|
|
|
|
|
answer |
22
|
|
|
|
|
|
|
authority |
23
|
|
|
|
|
|
|
additional |
24
|
|
|
|
|
|
|
print |
25
|
|
|
|
|
|
|
string |
26
|
|
|
|
|
|
|
answersize |
27
|
|
|
|
|
|
|
unique_push |
28
|
|
|
|
|
|
|
timestamp |
29
|
|
|
|
|
|
|
type |
30
|
|
|
|
|
|
|
edns_size |
31
|
|
|
|
|
|
|
edns_rcode |
32
|
|
|
|
|
|
|
has_edns |
33
|
|
|
|
|
|
|
id |
34
|
|
|
|
|
|
|
querytime |
35
|
|
|
|
|
|
|
do |
36
|
|
|
|
|
|
|
opcode |
37
|
|
|
|
|
|
|
) |
38
|
|
|
|
|
|
|
] |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub no_such_record { |
42
|
19283
|
|
|
19283
|
1
|
57910
|
my ( $self ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
19283
|
100
|
|
|
|
102468
|
if ( $self->type eq 'nodata' ) { |
45
|
602
|
|
|
|
|
15552
|
my ( $q ) = $self->question; |
46
|
602
|
|
|
|
|
11690
|
Zonemaster::Engine::Util::info( NO_SUCH_RECORD => { name => Zonemaster::Engine::Util::name( $q->name ), type => $q->type } ); |
47
|
|
|
|
|
|
|
|
48
|
602
|
|
|
|
|
4921
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
18681
|
|
|
|
|
486622
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub no_such_name { |
56
|
21669
|
|
|
21669
|
1
|
55925
|
my ( $self ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
21669
|
100
|
|
|
|
65097
|
if ( $self->type eq 'nxdomain' ) { |
59
|
32
|
|
|
|
|
394
|
my ( $q ) = $self->question; |
60
|
32
|
|
|
|
|
604
|
info( NO_SUCH_NAME => { name => name( $q->name ), type => $q->type } ); |
61
|
|
|
|
|
|
|
|
62
|
32
|
|
|
|
|
243
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
21637
|
|
|
|
|
377695
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub is_redirect { |
70
|
13332
|
|
|
13332
|
1
|
41391
|
my ( $self ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
13332
|
100
|
|
|
|
41879
|
if ( $self->type eq 'referral' ) { |
73
|
12922
|
|
|
|
|
290326
|
my ( $q ) = $self->question; |
74
|
12922
|
|
|
|
|
254828
|
my ( $a ) = $self->authority; |
75
|
12922
|
|
|
|
|
371300
|
Zonemaster::Engine::Util::info( |
76
|
|
|
|
|
|
|
IS_REDIRECT => { |
77
|
|
|
|
|
|
|
name => Zonemaster::Engine::Util::name( $q->name ), |
78
|
|
|
|
|
|
|
type => $q->type, |
79
|
|
|
|
|
|
|
to => Zonemaster::Engine::Util::name( $a->name ) |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
12922
|
|
|
|
|
111857
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
410
|
|
|
|
|
4874
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} ## end sub is_redirect |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_records { |
91
|
65647
|
|
|
65647
|
1
|
172843
|
my ( $self, $type, @section ) = @_; |
92
|
65647
|
|
|
|
|
132908
|
my %sec = map { lc( $_ ) => 1 } @section; |
|
485
|
|
|
|
|
2118
|
|
93
|
65647
|
|
|
|
|
93073
|
my @raw; |
94
|
|
|
|
|
|
|
|
95
|
65647
|
100
|
|
|
|
153899
|
if ( !@section ) { |
96
|
65162
|
|
|
|
|
1725956
|
@raw = ( $self->packet->answer, $self->packet->authority, $self->packet->additional ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
65647
|
100
|
|
|
|
183118
|
if ( $sec{'answer'} ) { |
100
|
461
|
|
|
|
|
12464
|
push @raw, $self->packet->answer; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
65647
|
100
|
|
|
|
136905
|
if ( $sec{'authority'} ) { |
104
|
24
|
|
|
|
|
696
|
push @raw, $self->packet->authority; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
65647
|
50
|
|
|
|
148116
|
if ( $sec{'additional'} ) { |
108
|
0
|
|
|
|
|
0
|
push @raw, $self->packet->additional; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
65647
|
|
|
|
|
140493
|
@raw = grep { $_->type eq uc( $type ) } @raw; |
|
1116297
|
|
|
|
|
3094433
|
|
112
|
|
|
|
|
|
|
|
113
|
65647
|
|
|
|
|
323203
|
return @raw; |
114
|
|
|
|
|
|
|
} ## end sub get_records |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub get_records_for_name { |
117
|
7583
|
|
|
7583
|
1
|
20099
|
my ( $self, $type, $name ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
7583
|
|
|
|
|
18757
|
return grep { name( $_->name ) eq name( $name ) } $self->get_records( $type ); |
|
5947
|
|
|
|
|
18197
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub has_rrs_of_type_for_name { |
123
|
93
|
|
|
93
|
1
|
241
|
my ( $self, $type, $name ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
93
|
|
|
|
|
259
|
return ( grep { name( $_->name ) eq name( $name ) } $self->get_records( $type ) ) > 0; |
|
80
|
|
|
|
|
264
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub answerfrom { |
129
|
12949
|
|
|
12949
|
1
|
43870
|
my ( $self, @args ) = @_; |
130
|
|
|
|
|
|
|
|
131
|
12949
|
50
|
|
|
|
47098
|
if ( @args ) { |
132
|
0
|
|
|
|
|
0
|
$self->packet->answerfrom( @args ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
12949
|
|
50
|
|
|
375683
|
my $from = $self->packet->answerfrom // '<unknown>'; |
136
|
|
|
|
|
|
|
|
137
|
12949
|
|
|
|
|
64371
|
return $from; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub TO_JSON { |
141
|
237
|
|
|
237
|
1
|
86875
|
my ( $self ) = @_; |
142
|
|
|
|
|
|
|
|
143
|
237
|
|
|
|
|
6615
|
return { 'Zonemaster::Engine::Packet' => $self->packet }; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
26
|
|
|
26
|
|
244
|
no Moose; |
|
26
|
|
|
|
|
66
|
|
|
26
|
|
|
|
|
224
|
|
147
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 NAME |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Zonemaster::Engine::Packet - wrapping object for L<Zonemaster::LDNS::Packet> objects |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SYNOPSIS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $packet = $ns->query('iis.se', 'NS'); |
158
|
|
|
|
|
|
|
my @rrs = $packet->get_records('ns'); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item packet |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Holds the L<Zonemaster::LDNS::Packet> the object is wrapping. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 METHODS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item no_such_record |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns true if the packet represents an existing DNS node lacking any records of the requested type. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item no_such_name |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns true if the packet represents a non-existent DNS node. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item is_redirect |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Returns true if the packet is a redirect to another set of nameservers. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item get_records($type[, $section]) |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Returns the L<Zonemaster::LDNS::RR> objects of the requested type in the packet. If the optional C<$section> argument is given, and is one of C<answer>, |
189
|
|
|
|
|
|
|
C<authority> and C<additional>, only RRs from that section are returned. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item get_records_for_name($type, $name) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns all L<Zonemaster::LDNS::RR> objects for the given name in the packet. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item has_rrs_of_type_for_name($type, $name) |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns true if the packet holds any RRs of the specified type for the given name. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item answerfrom |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Wrapper for the underlying packet method, that replaces udnefined values with the string C<E<lt>unknownE<gt>>. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item TO_JSON |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Support method for L<JSON> to be able to serialize these objects. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=back |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 METHODS PASSED THROUGH |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
These methods are passed through transparently to the underlying L<Zonemaster::LDNS::Packet> object. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
data |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
rcode |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
aa |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item * |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
question |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
answer |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item * |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
authority |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item * |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
additional |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item * |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
print |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item * |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
string |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item * |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
answersize |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
unique_push |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item * |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
timestamp |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
type |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
edns_size |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
edns_rcode |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
has_edns |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item * |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
id |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item * |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
querytime |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item * |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
do |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item * |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
opcode |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=back |