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