| 1 | package Zonemaster::Recursor v1.0.1; | ||||||||||||||||||||||||||||||||
| 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 JSON::PP; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Zonemaster::Util; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::IP::XS; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Zonemaster; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | my $seed_data; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | our %recurse_cache; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||||||
| 15 | 1 | local $/; | |||||||||||||||||||||||||||||||
| 16 | 1 | my $json = <DATA>; | |||||||||||||||||||||||||||||||
| 17 | 1 | $seed_data = decode_json $json; | |||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | sub recurse { | ||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my ( $self, $name, $type, $class ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
recurse: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 22 | 0 | $name = name( $name ); | |||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $type //= 'A'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$type //= "A"
MC/DC0%0/1
$type //= "A"
$type
Truth table0%0/2
A
A= $type
| |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $class //= 'IN'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$class //= "IN"
MC/DC0%0/1
$class //= "IN"
$class
Truth table0%0/2
A
A= $class
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | Zonemaster->logger->add( RECURSE => { name => $name, type => $type, class => $class } ); | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( exists $recurse_cache{$name}{$type}{$class} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 0 | return $recurse_cache{$name}{$type}{$class}; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | my ( $p, $state ) = | |||||||||||||||||||||||||||||||
| 33 | $self->_recurse( $name, $type, $class, | ||||||||||||||||||||||||||||||||
| 34 | { ns => [ root_servers() ], count => 0, common => 0, seen => {}, glue => {} } ); | ||||||||||||||||||||||||||||||||
| 35 | 0 | $recurse_cache{$name}{$type}{$class} = $p; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 0 | return $p; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | sub parent { | ||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my ( $self, $name ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
parent: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 0 | $name = name( $name ); | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | my ( $p, $state ) = | |||||||||||||||||||||||||||||||
| 45 | $self->_recurse( $name, 'SOA', 'IN', | ||||||||||||||||||||||||||||||||
| 46 | { ns => [ root_servers() ], count => 0, common => 0, seen => {}, glue => {} } ); | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | my $pname; | |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( name( $state->{trace}[0][0] ) eq name( $name ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 0 | $pname = name( $state->{trace}[1][0] ); | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||||||
| 53 | 0 | $pname = name( $state->{trace}[0][0] ); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | # Extra check that parent really is parent. | ||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($name->next_higher ne $pname) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 0 | my $source_ns = $state->{trace}[0][1]; | |||||||||||||||||||||||||||||||
| 59 | 0 | my $source_ip = $state->{trace}[0][2]; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | # No $source_ns means we're looking at root taken from priming | ||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($source_ns) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | my $pp; | |||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($source_ns->can('query')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 0 | $pp = $source_ns->query($name->next_higher->string, 'SOA'); | |||||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||||||
| 67 | 0 | my $n = ns($source_ns, $source_ip); | |||||||||||||||||||||||||||||||
| 68 | 0 | $pp = $n->query($name->next_higher->string, 'SOA'); | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($pp) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 0 | my ($rr) = $pp->get_records('SOA', 'answer'); | |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($rr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $pname = name($rr->owner); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( wantarray() ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 0 | return ( $pname, $p ); | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||
| 83 | 0 | return $pname; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | } ## end sub parent | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | sub _recurse { | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my ( $self, $name, $type, $class, $state ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_recurse: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||
| 89 | 0 | $name = '' . name( $name ); | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $state->{in_progress}{$name}{$type} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 0 | return; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | 0 | $state->{in_progress}{$name}{$type} = 1; | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | while ( my $ns = pop @{ $state->{ns} } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 0 | Zonemaster->logger->add( RECURSE_QUERY => { ns => "$ns", name => $name, type => $type, class => $class } ); | |||||||||||||||||||||||||||||||
| 98 | 0 | my $p = $self->_do_query( $ns, $name, $type, { class => $class }, $state ); | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | next if not $p; # Ask next server if no response | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( $p->rcode eq 'REFUSED' or $p->rcode eq 'SERVFAIL' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p->rcode eq "REFUSED" or $p->rcode eq "SERVFAIL"
MC/DC0%0/2
$p->rcode eq "REFUSED" or $p->rcode eq "SERVFAIL"
$p->rcode eq "REFUSED"
$p->rcode eq "SERVFAIL"
Truth table0%0/3
A or B
A= $p->rcode eq "REFUSED"B= $p->rcode eq "SERVFAIL"
| |||||||||||||||||||||||||||||||||
| 103 | # Respond with these if we can't get a better response | ||||||||||||||||||||||||||||||||
| 104 | 0 | $state->{candidate} = $p; | |||||||||||||||||||||||||||||||
| 105 | 0 | next; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( $p->no_such_record ) { # Node exists, but not record | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 0 | return ( $p, $state ); | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $p->no_such_name ) { # Node does not exist | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 0 | return ( $p, $state ); | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( $self->_is_answer( $p ) ) { # Return answer | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | return ( $p, $state ); | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | # So it's not an error, not an empty response and not an answer | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $p->is_redirect ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my $zname = name( lc( ( $p->get_records( 'ns' ) )[0]->name ) ); | |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | next if $zname eq '.'; # Redirect to root is never right. | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | next if $state->{seen}{$zname}; # We followed this redirect before | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | $state->{seen}{$zname} = 1; | |||||||||||||||||||||||||||||||
| 130 | 0 | my $common = name( $zname )->common( name( $state->{qname} ) ); | |||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | next | ||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if $common < $state->{common}; # Redirect going up the hierarchy is not OK | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 0 | $state->{common} = $common; | |||||||||||||||||||||||||||||||
| 136 | 0 | $state->{ns} = $self->get_ns_from( $p, $state ); # Follow redirect | |||||||||||||||||||||||||||||||
| 137 | 0 | $state->{count} += 1; | |||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return ( undef, $state ) if $state->{count} > 20; # Loop protection | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | 0 | unshift @{ $state->{trace} }, [$zname, $ns, $p->answerfrom]; | |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 0 | next; | |||||||||||||||||||||||||||||||
| 142 | } ## end if ( $p->is_redirect ) | ||||||||||||||||||||||||||||||||
| 143 | } ## end while ( my $ns = pop @{ $state...}) | ||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return ( $state->{candidate}, $state ) if $state->{candidate}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | return ( undef, $state ); | |||||||||||||||||||||||||||||||
| 147 | } ## end sub _recurse | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | sub _do_query { | ||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my ( $self, $ns, $name, $type, $opts, $state ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_do_query: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( ref( $ns ) and $ns->can( 'query' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $ns and $ns->can("query")
MC/DC0%0/2
ref $ns and $ns->can("query")
ref $ns
$ns->can("query")
Truth table0%0/3
A and B
A= ref $nsB= $ns->can("query")
| |||||||||||||||||||||||||||||||||
| 153 | 0 | my $p = $ns->query( $name, $type, $opts ); | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ( $p ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | for my $rr ( grep { $_->type eq 'A' or $_->type eq 'AAAA' } $p->answer, $p->additional ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | 0 | $state->{glue}{ lc( name( $rr->name ) ) }{ $rr->address } = 1; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | 0 | return $p; | |||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | elsif ( my $href = $state->{glue}{ lc( name( $ns ) ) } ) { | ||||||||||||||||||||||||||||||||
| 163 | 0 | foreach my $addr ( keys %$href ) { | |||||||||||||||||||||||||||||||
| 164 | 0 | my $realns = ns( $ns, $addr ); | |||||||||||||||||||||||||||||||
| 165 | 0 | my $p = $self->_do_query( $realns, $name, $type, $opts, $state ); | |||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ( $p ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | 0 | return $p; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||
| 172 | 0 | $state->{glue}{ lc( name( $ns ) ) } = {}; | |||||||||||||||||||||||||||||||
| 173 | 0 | my @addr = $self->get_addresses_for( $ns, $state ); | |||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( @addr > 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 175 | 0 | foreach my $addr ( @addr ) { | |||||||||||||||||||||||||||||||
| 176 | 0 | $state->{glue}{ lc( name( $ns ) ) }{ $addr->short } = 1; | |||||||||||||||||||||||||||||||
| 177 | 0 | my $new = ns( $ns, $addr->short ); | |||||||||||||||||||||||||||||||
| 178 | 0 | my $p = $new->query( $name, $type, $opts ); | |||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $p if $p; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | else { | ||||||||||||||||||||||||||||||||
| 183 | 0 | return; | |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | } ## end sub _do_query | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | sub get_ns_from { | ||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my ( $self, $p, $state ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_ns_from: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 190 | 0 | my ( @new, @extra ); | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 0 | my @names = sort map { name( lc( $_->nsdname ) ) } $p->get_records( 'ns' ); | |||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | $state->{glue}{ lc( name( $_->name ) ) }{ $_->address } = 1 | ||||||||||||||||||||||||||||||||
| 195 | 0 | for ( $p->get_records( 'a' ), $p->get_records( 'aaaa' ) ); | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 0 | foreach my $name ( @names ) { | |||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( exists $state->{glue}{ lc( name( $name ) ) } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | 0 | for my $addr ( keys %{ $state->{glue}{ lc( name( $name ) ) } } ) { | |||||||||||||||||||||||||||||||
| 200 | 0 | push @new, ns( $name, $addr ); | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||
| 204 | 0 | push @extra, $name; | |||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | @new = sort { $a->name cmp $b->name or $a->address->ip cmp $b->address->ip } @new; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | 0 | @extra = sort { $a cmp $b } @extra; | |||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 0 | return [ @new, @extra ]; | |||||||||||||||||||||||||||||||
| 212 | } ## end sub get_ns_from | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | sub get_addresses_for { | ||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my ( $self, $name, $state ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_addresses_for: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 216 | 0 | my @res; | |||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $state //= | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$state //= {"ns", [root_servers()], "count", 0, "common", 0, "seen", {}}
MC/DC0%0/1
$state //= {"ns", [root_servers()], "count", 0, "common", 0, "seen", {}}
$state
Truth table0%0/2
A
A= $state
| |||||||||||||||||||||||||||||||||
| 218 | { ns => [ root_servers() ], count => 0, common => 0, seen => {} }; | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | my ( $pa ) = $self->_recurse( | ||||||||||||||||||||||||||||||||
| 221 | "$name", 'A', 'IN', | ||||||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||||||
| 223 | ns => [ root_servers() ], | ||||||||||||||||||||||||||||||||
| 224 | count => $state->{count}, | ||||||||||||||||||||||||||||||||
| 225 | common => 0, | ||||||||||||||||||||||||||||||||
| 226 | in_progress => $state->{in_progress}, | ||||||||||||||||||||||||||||||||
| 227 | glue => $state->{glue} | ||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | 0 | ); | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | # Name does not exist, just stop | ||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ( $pa and $pa->no_such_name ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pa and $pa->no_such_name
MC/DC0%0/2
$pa and $pa->no_such_name
$pa
$pa->no_such_name
Truth table0%0/3
A and B
A= $paB= $pa->no_such_name
| |||||||||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | my ( $paaaa ) = $self->_recurse( | ||||||||||||||||||||||||||||||||
| 237 | "$name", 'AAAA', 'IN', | ||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||
| 239 | ns => [ root_servers() ], | ||||||||||||||||||||||||||||||||
| 240 | count => $state->{count}, | ||||||||||||||||||||||||||||||||
| 241 | common => 0, | ||||||||||||||||||||||||||||||||
| 242 | in_progress => $state->{in_progress}, | ||||||||||||||||||||||||||||||||
| 243 | glue => $state->{glue} | ||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | 0 | ); | |||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | 0 | my @rrs; | |||||||||||||||||||||||||||||||
| 248 | my %cname; | ||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($pa) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 0 | push @rrs, $pa->get_records( 'a' ); | |||||||||||||||||||||||||||||||
| 251 | 0 | $cname{$_->cname} = 1 for $pa->get_records_for_name('CNAME', $name); | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($paaaa) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 254 | 0 | push @rrs, $paaaa->get_records( 'aaaa' ); | |||||||||||||||||||||||||||||||
| 255 | 0 | $cname{$_->cname} = 1 for $paaaa->get_records_for_name('CNAME', $name); | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | foreach my $rr ( sort { $a->address cmp $b->address } @rrs ) | |||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (name($rr->name) eq $name or $cname{$rr->name}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
name($rr->name) eq $name or $cname{$rr->name}
MC/DC0%0/2
name($rr->name) eq $name or $cname{$rr->name}
name($rr->name) eq $name
$cname{$rr->name}
Truth table0%0/3
A or B
A= name($rr->name) eq $nameB= $cname{$rr->name}
| |||||||||||||||||||||||||||||||||
| 261 | 0 | push @res, Net::IP::XS->new( $rr->address ); | |||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | 0 | return @res; | |||||||||||||||||||||||||||||||
| 266 | } ## end sub get_addresses_for | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | sub _is_answer { | ||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my ( $self, $packet ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_is_answer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 0 | return ( $packet->type eq 'answer' ); | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | sub clear_cache { | ||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | %recurse_cache = (); | ||||||||||||||||||||||||||||||
|
Subroutine
clear_cache: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | sub root_servers { | ||||||||||||||||||||||||||||||||
| 279 | 0 | return map { Zonemaster::Util::ns( $_->{name}, $_->{address} ) } | |||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sort { $a->{name} cmp $b->{name} } @{ $seed_data->{'.'} }; | ||||||||||||||||||||||||||||||
|
Subroutine
root_servers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 284 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | 1 | 1; | |||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | Zonemaster::Recursor - recursive resolver for Zonemaster | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | my $packet = Zonemaster::Recursor->recurse($name, $type, $class); | ||||||||||||||||||||||||||||||||
| 295 | my $pname = Zonemaster::Recursor->parent('example.org'); | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | =over | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | =item recurse($name, $type, $class) | ||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | Does a recursive resolution from the root servers down for the given triplet. | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | =item parent($name) | ||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | Does a recursive resolution from the root down for the given name (using type C<SOA> and class C<IN>). If the resolution is successful, it returns | ||||||||||||||||||||||||||||||||
| 308 | the domain name of the second-to-last step. If the resolution is unsuccessful, it returns the domain name of the last step. | ||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | =item get_ns_from($packet, $state) | ||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | Internal method. Takes a packet and a recursion state and returns a list of ns objects. Used to follow redirections. | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | =item get_addresses_for($name[, $state]) | ||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | Takes a name and returns a (possibly empty) list of IP addresses for | ||||||||||||||||||||||||||||||||
| 317 | that name (in the form of L<Net::IP::XS> objects). When used | ||||||||||||||||||||||||||||||||
| 318 | internally by the recursor it's passed a recursion state as its second | ||||||||||||||||||||||||||||||||
| 319 | argument. | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | =item clear_cache() | ||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | Class method to empty the cache of responses to recursive queries. | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | =item root_servers() | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | Returns a list of ns objects representing the root servers. The list of root servers is hardcoded into this module. | ||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||
| 329 | =back | ||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | =cut | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | __DATA__ | ||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||
| 335 | "." : [ | ||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||
| 337 | "name" : "m.root-servers.net", | ||||||||||||||||||||||||||||||||
| 338 | "address" : "202.12.27.33" | ||||||||||||||||||||||||||||||||
| 339 | }, | ||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||
| 341 | "name" : "m.root-servers.net", | ||||||||||||||||||||||||||||||||
| 342 | "address" : "2001:dc3:0:0:0:0:0:35" | ||||||||||||||||||||||||||||||||
| 343 | }, | ||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||
| 345 | "name" : "e.root-servers.net", | ||||||||||||||||||||||||||||||||
| 346 | "address" : "192.203.230.10" | ||||||||||||||||||||||||||||||||
| 347 | }, | ||||||||||||||||||||||||||||||||
| 348 | { | ||||||||||||||||||||||||||||||||
| 349 | "address" : "199.7.83.42", | ||||||||||||||||||||||||||||||||
| 350 | "name" : "l.root-servers.net" | ||||||||||||||||||||||||||||||||
| 351 | }, | ||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||
| 353 | "address" : "2001:500:3:0:0:0:0:42", | ||||||||||||||||||||||||||||||||
| 354 | "name" : "l.root-servers.net" | ||||||||||||||||||||||||||||||||
| 355 | }, | ||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||
| 357 | "address" : "198.41.0.4", | ||||||||||||||||||||||||||||||||
| 358 | "name" : "a.root-servers.net" | ||||||||||||||||||||||||||||||||
| 359 | }, | ||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||
| 361 | "address" : "2001:503:ba3e:0:0:0:2:30", | ||||||||||||||||||||||||||||||||
| 362 | "name" : "a.root-servers.net" | ||||||||||||||||||||||||||||||||
| 363 | }, | ||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||
| 365 | "address" : "192.5.5.241", | ||||||||||||||||||||||||||||||||
| 366 | "name" : "f.root-servers.net" | ||||||||||||||||||||||||||||||||
| 367 | }, | ||||||||||||||||||||||||||||||||
| 368 | { | ||||||||||||||||||||||||||||||||
| 369 | "address" : "2001:500:2f:0:0:0:0:f", | ||||||||||||||||||||||||||||||||
| 370 | "name" : "f.root-servers.net" | ||||||||||||||||||||||||||||||||
| 371 | }, | ||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||
| 373 | "address" : "199.7.91.13", | ||||||||||||||||||||||||||||||||
| 374 | "name" : "d.root-servers.net" | ||||||||||||||||||||||||||||||||
| 375 | }, | ||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||
| 377 | "address" : "2001:500:2d:0:0:0:0:d", | ||||||||||||||||||||||||||||||||
| 378 | "name" : "d.root-servers.net" | ||||||||||||||||||||||||||||||||
| 379 | }, | ||||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||||
| 381 | "address" : "192.58.128.30", | ||||||||||||||||||||||||||||||||
| 382 | "name" : "j.root-servers.net" | ||||||||||||||||||||||||||||||||
| 383 | }, | ||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||
| 385 | "address" : "2001:503:c27:0:0:0:2:30", | ||||||||||||||||||||||||||||||||
| 386 | "name" : "j.root-servers.net" | ||||||||||||||||||||||||||||||||
| 387 | }, | ||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||
| 389 | "address" : "128.63.2.53", | ||||||||||||||||||||||||||||||||
| 390 | "name" : "h.root-servers.net" | ||||||||||||||||||||||||||||||||
| 391 | }, | ||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||
| 393 | "name" : "h.root-servers.net", | ||||||||||||||||||||||||||||||||
| 394 | "address" : "2001:500:1:0:0:0:803f:235" | ||||||||||||||||||||||||||||||||
| 395 | }, | ||||||||||||||||||||||||||||||||
| 396 | { | ||||||||||||||||||||||||||||||||
| 397 | "name" : "g.root-servers.net", | ||||||||||||||||||||||||||||||||
| 398 | "address" : "192.112.36.4" | ||||||||||||||||||||||||||||||||
| 399 | }, | ||||||||||||||||||||||||||||||||
| 400 | { | ||||||||||||||||||||||||||||||||
| 401 | "name" : "k.root-servers.net", | ||||||||||||||||||||||||||||||||
| 402 | "address" : "193.0.14.129" | ||||||||||||||||||||||||||||||||
| 403 | }, | ||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||
| 405 | "address" : "2001:7fd:0:0:0:0:0:1", | ||||||||||||||||||||||||||||||||
| 406 | "name" : "k.root-servers.net" | ||||||||||||||||||||||||||||||||
| 407 | }, | ||||||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||||||
| 409 | "name" : "b.root-servers.net", | ||||||||||||||||||||||||||||||||
| 410 | "address" : "192.228.79.201" | ||||||||||||||||||||||||||||||||
| 411 | }, | ||||||||||||||||||||||||||||||||
| 412 | { | ||||||||||||||||||||||||||||||||
| 413 | "address" : "192.33.4.12", | ||||||||||||||||||||||||||||||||
| 414 | "name" : "c.root-servers.net" | ||||||||||||||||||||||||||||||||
| 415 | }, | ||||||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||||||
| 417 | "name" : "i.root-servers.net", | ||||||||||||||||||||||||||||||||
| 418 | "address" : "192.36.148.17" | ||||||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||
| 421 | "name" : "i.root-servers.net", | ||||||||||||||||||||||||||||||||
| 422 | "address" : "2001:7fe:0:0:0:0:0:53" | ||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||
| 424 | ] | ||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||