| 1 | package Zonemaster::Test::Connectivity v1.0.1; | ||
| 2 | |||
| 3 | use 5.14.2; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use Zonemaster; | ||
| 8 | use Zonemaster::Util; | ||
| 9 | use Zonemaster::TestMethods; | ||
| 10 | use Zonemaster::Constants qw[:ip]; | ||
| 11 | use Zonemaster::ASNLookup; | ||
| 12 | use Carp; | ||
| 13 | |||
| 14 | use List::MoreUtils qw[uniq]; | ||
| 15 | |||
| 16 | ### | ||
| 17 | ### Entry Points | ||
| 18 | ### | ||
| 19 | |||
| 20 | sub all { | ||
| 21 | my ( $class, $zone ) = @_; | ||
| 22 | my @results; | ||
| 23 | |||
| 24 | push @results, $class->connectivity01( $zone ) if Zonemaster->config->should_run('connectivity01'); | ||
| 25 | push @results, $class->connectivity02( $zone ) if Zonemaster->config->should_run('connectivity02'); | ||
| 26 | push @results, $class->connectivity03( $zone ) if Zonemaster->config->should_run('connectivity03'); | ||
| 27 | |||
| 28 | return @results; | ||
| 29 | } | ||
| 30 | |||
| 31 | ### | ||
| 32 | ### Metadata Exposure | ||
| 33 | ### | ||
| 34 | |||
| 35 | sub metadata { | ||
| 36 | my ( $class ) = @_; | ||
| 37 | |||
| 38 | return { | ||
| 39 | connectivity01 => [ | ||
| 40 | qw( | ||
| 41 | NAMESERVER_HAS_UDP_53 | ||
| 42 | NAMESERVER_NO_UDP_53 | ||
| 43 | IPV4_DISABLED | ||
| 44 | IPV6_DISABLED | ||
| 45 | ) | ||
| 46 | ], | ||
| 47 | connectivity02 => [ | ||
| 48 | qw( | ||
| 49 | NAMESERVER_HAS_TCP_53 | ||
| 50 | NAMESERVER_NO_TCP_53 | ||
| 51 | IPV4_DISABLED | ||
| 52 | IPV6_DISABLED | ||
| 53 | ) | ||
| 54 | ], | ||
| 55 | connectivity03 => [ | ||
| 56 | qw( | ||
| 57 | NAMESERVERS_IPV4_NO_AS | ||
| 58 | NAMESERVERS_IPV4_WITH_MULTIPLE_AS | ||
| 59 | NAMESERVERS_IPV4_WITH_UNIQ_AS | ||
| 60 | NAMESERVERS_IPV6_NO_AS | ||
| 61 | NAMESERVERS_IPV6_WITH_MULTIPLE_AS | ||
| 62 | NAMESERVERS_IPV6_WITH_UNIQ_AS | ||
| 63 | NAMESERVERS_NO_AS | ||
| 64 | NAMESERVERS_WITH_MULTIPLE_AS | ||
| 65 | NAMESERVERS_WITH_UNIQ_AS | ||
| 66 | IPV4_ASN | ||
| 67 | IPV6_ASN | ||
| 68 | ) | ||
| 69 | ], | ||
| 70 | }; | ||
| 71 | } ## end sub metadata | ||
| 72 | |||
| 73 | sub translation { | ||
| 74 | return { | ||
| 75 | 'NAMESERVERS_IPV4_WITH_UNIQ_AS' => 'All nameservers IPv4 addresses are in the same AS ({asn}).', | ||
| 76 | 'NAMESERVERS_IPV6_WITH_UNIQ_AS' => 'All nameservers IPv6 addresses are in the same AS ({asn}).', | ||
| 77 | 'NAMESERVERS_WITH_MULTIPLE_AS' => 'Domain\'s authoritative nameservers do not belong to the same AS.', | ||
| 78 | 'NAMESERVERS_WITH_UNIQ_AS' => 'All nameservers are in the same AS ({asn}).', | ||
| 79 | 'NAMESERVERS_IPV4_NO_AS' => 'No IPv4 nameserver address is in an AS.', | ||
| 80 | 'NAMESERVERS_IPV4_WITH_MULTIPLE_AS' => 'Authoritative IPv4 nameservers are in more than one AS.', | ||
| 81 | 'NAMESERVERS_IPV6_NO_AS' => 'No IPv6 nameserver address is in an AS.', | ||
| 82 | 'NAMESERVERS_IPV6_WITH_MULTIPLE_AS' => 'Authoritative IPv6 nameservers are in more than one AS.', | ||
| 83 | 'NAMESERVERS_NO_AS' => 'No nameserver address is in an AS.', | ||
| 84 | 'NAMESERVER_HAS_TCP_53' => 'Nameserver {ns}/{address} accessible over TCP on port 53.', | ||
| 85 | 'NAMESERVER_HAS_UDP_53' => 'Nameserver {ns}/{address} accessible over UDP on port 53.', | ||
| 86 | 'NAMESERVER_NO_TCP_53' => 'Nameserver {ns}/{address} not accessible over TCP on port 53.', | ||
| 87 | 'NAMESERVER_NO_UDP_53' => 'Nameserver {ns}/{address} not accessible over UDP on port 53.', | ||
| 88 | 'IPV4_DISABLED' => 'IPv4 is disabled, not sending "{type}" query to {ns}.', | ||
| 89 | 'IPV6_DISABLED' => 'IPv6 is disabled, not sending "{type}" query to {ns}.', | ||
| 90 | 'IPV4_ASN' => 'Name servers have IPv4 addresses in the following ASs: {asn}.', | ||
| 91 | 'IPV6_ASN' => 'Name servers have IPv6 addresses in the following ASs: {asn}.', | ||
| 92 | }; | ||
| 93 | } ## end sub translation | ||
| 94 | |||
| 95 | sub version { | ||
| 96 | return "$Zonemaster::Test::Connectivity::VERSION"; | ||
| 97 | } | ||
| 98 | |||
| 99 | ### | ||
| 100 | ### Tests | ||
| 101 | ### | ||
| 102 | |||
| 103 | sub connectivity01 { | ||
| 104 | my ( $class, $zone ) = @_; | ||
| 105 | my @results; | ||
| 106 | |||
| 107 | my %ips; | ||
| 108 | |||
| 109 | foreach | ||
| 110 | my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } ) | ||
| 111 | { | ||
| 112 | |||
| 113 | if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) { | ||
| 114 | push @results, | ||
| 115 | info( | ||
| 116 | IPV6_DISABLED => { | ||
| 117 | ns => "$local_ns", | ||
| 118 | type => q{SOA}, | ||
| 119 | } | ||
| 120 | ); | ||
| 121 | next; | ||
| 122 | } | ||
| 123 | |||
| 124 | if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) { | ||
| 125 | push @results, | ||
| 126 | info( | ||
| 127 | IPV4_DISABLED => { | ||
| 128 | ns => "$local_ns", | ||
| 129 | type => q{SOA}, | ||
| 130 | } | ||
| 131 | ); | ||
| 132 | next; | ||
| 133 | } | ||
| 134 | |||
| 135 | next if $ips{ $local_ns->address->short }; | ||
| 136 | |||
| 137 | my $p = $local_ns->query( $zone->name, q{SOA}, { usevc => 0 } ); | ||
| 138 | |||
| 139 | if ( $p and $p->rcode eq q{NOERROR} ) { | ||
| 140 | push @results, | ||
| 141 | info( | ||
| 142 | NAMESERVER_HAS_UDP_53 => { | ||
| 143 | ns => $local_ns->name->string, | ||
| 144 | address => $local_ns->address->short, | ||
| 145 | } | ||
| 146 | ); | ||
| 147 | } | ||
| 148 | else { | ||
| 149 | push @results, | ||
| 150 | info( | ||
| 151 | NAMESERVER_NO_UDP_53 => { | ||
| 152 | ns => $local_ns->name->string, | ||
| 153 | address => $local_ns->address->short, | ||
| 154 | } | ||
| 155 | ); | ||
| 156 | } | ||
| 157 | |||
| 158 | $ips{ $local_ns->address->short }++; | ||
| 159 | |||
| 160 | } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...}) | ||
| 161 | |||
| 162 | return @results; | ||
| 163 | } ## end sub connectivity01 | ||
| 164 | |||
| 165 | sub connectivity02 { | ||
| 166 | my ( $class, $zone ) = @_; | ||
| 167 | my @results; | ||
| 168 | my %ips; | ||
| 169 | |||
| 170 | foreach | ||
| 171 | my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } ) | ||
| 172 | { | ||
| 173 | |||
| 174 | if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) { | ||
| 175 | push @results, | ||
| 176 | info( | ||
| 177 | IPV6_DISABLED => { | ||
| 178 | ns => "$local_ns", | ||
| 179 | type => q{SOA}, | ||
| 180 | } | ||
| 181 | ); | ||
| 182 | next; | ||
| 183 | } | ||
| 184 | |||
| 185 | if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) { | ||
| 186 | push @results, | ||
| 187 | info( | ||
| 188 | IPV4_DISABLED => { | ||
| 189 | ns => "$local_ns", | ||
| 190 | type => q{SOA}, | ||
| 191 | } | ||
| 192 | ); | ||
| 193 | next; | ||
| 194 | } | ||
| 195 | |||
| 196 | next if $ips{ $local_ns->address->short }; | ||
| 197 | |||
| 198 | my $p = $local_ns->query( $zone->name, q{SOA}, { usevc => 1 } ); | ||
| 199 | |||
| 200 | if ( $p and $p->rcode eq q{NOERROR} ) { | ||
| 201 | push @results, | ||
| 202 | info( | ||
| 203 | NAMESERVER_HAS_TCP_53 => { | ||
| 204 | ns => $local_ns->name->string, | ||
| 205 | address => $local_ns->address->short, | ||
| 206 | } | ||
| 207 | ); | ||
| 208 | } | ||
| 209 | else { | ||
| 210 | push @results, | ||
| 211 | info( | ||
| 212 | NAMESERVER_NO_TCP_53 => { | ||
| 213 | ns => $local_ns->name->string, | ||
| 214 | address => $local_ns->address->short, | ||
| 215 | } | ||
| 216 | ); | ||
| 217 | } | ||
| 218 | |||
| 219 | $ips{ $local_ns->address->short }++; | ||
| 220 | |||
| 221 | } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...}) | ||
| 222 | |||
| 223 | return @results; | ||
| 224 | } ## end sub connectivity02 | ||
| 225 | |||
| 226 | sub connectivity03 { | ||
| 227 | my ( $class, $zone ) = @_; | ||
| 228 | my @results; | ||
| 229 | |||
| 230 | my %ips = ( 4 => {}, 6 => {} ); | ||
| 231 | |||
| 232 | foreach my $ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } ) { | ||
| 233 | my $addr = $ns->address; | ||
| 234 | $ips{ $addr->version }{ $addr->ip } = $addr; | ||
| 235 | } | ||
| 236 | |||
| 237 | my @v4ips = values %{ $ips{4} }; | ||
| 238 | my @v6ips = values %{ $ips{6} }; | ||
| 239 | |||
| 240 | my @v4asns = uniq grep { $_ } map { Zonemaster::ASNLookup->get( $_ ) } @v4ips; | ||
| 241 | my @v6asns = uniq grep { $_ } map { Zonemaster::ASNLookup->get( $_ ) } @v6ips; | ||
| 242 | my @all_asns = uniq( @v4asns, @v6asns ); | ||
| 243 | |||
| 244 | push @results, info( IPV4_ASN => { asn => join( ',', @v4asns ) } ); | ||
| 245 | push @results, info( IPV6_ASN => { asn => join( ',', @v6asns ) } ); | ||
| 246 | |||
| 247 | if ( @v4asns == 1 ) { | ||
| 248 | push @results, info( NAMESERVERS_IPV4_WITH_UNIQ_AS => { asn => $v4asns[0] } ); | ||
| 249 | } | ||
| 250 | elsif ( @v4asns > 1 ) { | ||
| 251 | push @results, info( NAMESERVERS_IPV4_WITH_MULTIPLE_AS => { asn => join( ';', @v4asns ) } ); | ||
| 252 | } | ||
| 253 | else { | ||
| 254 | push @results, info( NAMESERVERS_IPV4_NO_AS => {} ); | ||
| 255 | } | ||
| 256 | |||
| 257 | if ( @v6asns == 1 ) { | ||
| 258 | push @results, info( NAMESERVERS_IPV6_WITH_UNIQ_AS => { asn => $v6asns[0] } ); | ||
| 259 | } | ||
| 260 | elsif ( @v6asns > 1 ) { | ||
| 261 | push @results, info( NAMESERVERS_IPV6_WITH_MULTIPLE_AS => { asn => join( ';', @v6asns ) } ); | ||
| 262 | } | ||
| 263 | else { | ||
| 264 | push @results, info( NAMESERVERS_IPV6_NO_AS => {} ); | ||
| 265 | } | ||
| 266 | |||
| 267 | if ( @all_asns == 1 ) { | ||
| 268 | push @results, info( NAMESERVERS_WITH_UNIQ_AS => { asn => $all_asns[0] } ); | ||
| 269 | } | ||
| 270 | elsif ( @all_asns > 1 ) { | ||
| 271 | push @results, info( NAMESERVERS_WITH_MULTIPLE_AS => { asn => join( ';', @all_asns ) } ); | ||
| 272 | } | ||
| 273 | else { | ||
| 274 | push @results, info( NAMESERVERS_NO_AS => {} ); # Shouldn't pass Basic | ||
| 275 | } | ||
| 276 | |||
| 277 | return @results; | ||
| 278 | } ## end sub connectivity03 | ||
| 279 | |||
| 280 | 1; | ||
| 281 | |||
| 282 | =head1 NAME | ||
| 283 | |||
| 284 | Zonemaster::Test::Connectivity - module implementing tests of nameservers reachability | ||
| 285 | |||
| 286 | =head1 SYNOPSIS | ||
| 287 | |||
| 288 | my @results = Zonemaster::Test::Connectivity->all($zone); | ||
| 289 | |||
| 290 | =head1 METHODS | ||
| 291 | |||
| 292 | =over | ||
| 293 | |||
| 294 | =item all($zone) | ||
| 295 | |||
| 296 | Runs the default set of tests and returns a list of log entries made by the tests | ||
| 297 | |||
| 298 | =item metadata() | ||
| 299 | |||
| 300 | Returns a reference to a hash, the keys of which are the names of all test methods in the module, and the corresponding values are references to | ||
| 301 | lists with all the tags that the method can use in log entries. | ||
| 302 | |||
| 303 | =item translation() | ||
| 304 | |||
| 305 | Returns a refernce to a hash with translation data. Used by the builtin translation system. | ||
| 306 | |||
| 307 | =item version() | ||
| 308 | |||
| 309 | Returns a version string for the module. | ||
| 310 | |||
| 311 | =back | ||
| 312 | |||
| 313 | =head1 TESTS | ||
| 314 | |||
| 315 | =over | ||
| 316 | |||
| 317 | =item connectivity01($zone) | ||
| 318 | |||
| 319 | Verify nameservers UDP port 53 reachability. | ||
| 320 | |||
| 321 | =item connectivity02($zone) | ||
| 322 | |||
| 323 | Verify nameservers TCP port 53 reachability. | ||
| 324 | |||
| 325 | =item connectivity03($zone) | ||
| 326 | |||
| 327 | Verify that all nameservers do not belong to the same AS. | ||
| 328 | |||
| 329 | =back | ||
| 330 | |||
| 331 | =cut |