| 1 | package Zonemaster::Engine::Constants; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use v5.16.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use version; our $VERSION = version->declare("v1.2.5"); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use English qw( -no_match_vars ) ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use parent 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Net::IP::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Text::CSV; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use File::ShareDir qw[dist_dir dist_file]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | =head1 NAME | ||||||||||
| 18 | |||||||||||
| 19 | Zonemaster::Engine::Constants - module holding constants used in Test modules | ||||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use Zonemaster::Engine::Constants ':all'; | ||||||||||
| 24 | |||||||||||
| 25 | =head1 EXPORTED GROUPS | ||||||||||
| 26 | |||||||||||
| 27 | =over | ||||||||||
| 28 | |||||||||||
| 29 | =item all | ||||||||||
| 30 | |||||||||||
| 31 | All exportable names. | ||||||||||
| 32 | |||||||||||
| 33 | =item algo | ||||||||||
| 34 | |||||||||||
| 35 | DNSSEC algorithms. | ||||||||||
| 36 | |||||||||||
| 37 | =item cname | ||||||||||
| 38 | |||||||||||
| 39 | CNAME records. | ||||||||||
| 40 | |||||||||||
| 41 | =item name | ||||||||||
| 42 | |||||||||||
| 43 | Label and name lengths. | ||||||||||
| 44 | |||||||||||
| 45 | =item ip | ||||||||||
| 46 | |||||||||||
| 47 | IP version constants. | ||||||||||
| 48 | |||||||||||
| 49 | =item soa | ||||||||||
| 50 | |||||||||||
| 51 | SOA values limits. | ||||||||||
| 52 | |||||||||||
| 53 | =item misc | ||||||||||
| 54 | |||||||||||
| 55 | Other, uncategorized export names, e.g. UDP payload limit and minimum number of name servers per zone. | ||||||||||
| 56 | |||||||||||
| 57 | =item addresses | ||||||||||
| 58 | |||||||||||
| 59 | Address classes for IPv4 and IPv6. | ||||||||||
| 60 | |||||||||||
| 61 | =back | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 1 | our @EXPORT_OK = qw[ | |||||||||
| 66 | $ALGO_STATUS_DEPRECATED | ||||||||||
| 67 | $ALGO_STATUS_PRIVATE | ||||||||||
| 68 | $ALGO_STATUS_RESERVED | ||||||||||
| 69 | $ALGO_STATUS_UNASSIGNED | ||||||||||
| 70 | $ALGO_STATUS_OTHER | ||||||||||
| 71 | $ALGO_STATUS_NOT_RECOMMENDED | ||||||||||
| 72 | $ALGO_STATUS_NOT_ZONE_SIGN | ||||||||||
| 73 | $BLACKLISTING_ENABLED | ||||||||||
| 74 | $CNAME_MAX_CHAIN_LENGTH | ||||||||||
| 75 | $CNAME_MAX_RECORDS | ||||||||||
| 76 | $DURATION_5_MINUTES_IN_SECONDS | ||||||||||
| 77 | $DURATION_1_HOUR_IN_SECONDS | ||||||||||
| 78 | $DURATION_4_HOURS_IN_SECONDS | ||||||||||
| 79 | $DURATION_12_HOURS_IN_SECONDS | ||||||||||
| 80 | $DURATION_1_DAY_IN_SECONDS | ||||||||||
| 81 | $DURATION_1_WEEK_IN_SECONDS | ||||||||||
| 82 | $DURATION_180_DAYS_IN_SECONDS | ||||||||||
| 83 | $FQDN_MAX_LENGTH | ||||||||||
| 84 | $IP_VERSION_4 | ||||||||||
| 85 | $IP_VERSION_6 | ||||||||||
| 86 | $LABEL_MAX_LENGTH | ||||||||||
| 87 | $SERIAL_BITS | ||||||||||
| 88 | $SERIAL_MAX_VARIATION | ||||||||||
| 89 | $MINIMUM_NUMBER_OF_NAMESERVERS | ||||||||||
| 90 | $UDP_PAYLOAD_LIMIT | ||||||||||
| 91 | $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT | ||||||||||
| 92 | $EDNS_UDP_PAYLOAD_DEFAULT | ||||||||||
| 93 | $EDNS_UDP_PAYLOAD_COMMON_LIMIT | ||||||||||
| 94 | @IPV4_SPECIAL_ADDRESSES | ||||||||||
| 95 | @IPV6_SPECIAL_ADDRESSES | ||||||||||
| 96 | ]; | ||||||||||
| 97 | |||||||||||
| 98 | 1 | our %EXPORT_TAGS = ( | |||||||||
| 99 | all => \@EXPORT_OK, | ||||||||||
| 100 | algo => [ | ||||||||||
| 101 | qw($ALGO_STATUS_DEPRECATED $ALGO_STATUS_PRIVATE $ALGO_STATUS_RESERVED $ALGO_STATUS_UNASSIGNED $ALGO_STATUS_OTHER $ALGO_STATUS_NOT_ZONE_SIGN $ALGO_STATUS_NOT_RECOMMENDED) | ||||||||||
| 102 | ], | ||||||||||
| 103 | cname => [ qw($CNAME_MAX_CHAIN_LENGTH $CNAME_MAX_RECORDS) ], | ||||||||||
| 104 | name => [qw($FQDN_MAX_LENGTH $LABEL_MAX_LENGTH)], | ||||||||||
| 105 | ip => [qw($IP_VERSION_4 $IP_VERSION_6)], | ||||||||||
| 106 | soa => [ | ||||||||||
| 107 | qw($DURATION_5_MINUTES_IN_SECONDS $DURATION_1_HOUR_IN_SECONDS $DURATION_4_HOURS_IN_SECONDS $DURATION_12_HOURS_IN_SECONDS $DURATION_1_DAY_IN_SECONDS $DURATION_1_WEEK_IN_SECONDS $DURATION_180_DAYS_IN_SECONDS $SERIAL_BITS $SERIAL_MAX_VARIATION) | ||||||||||
| 108 | ], | ||||||||||
| 109 | misc => [qw($UDP_PAYLOAD_LIMIT $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT $EDNS_UDP_PAYLOAD_DEFAULT $EDNS_UDP_PAYLOAD_COMMON_LIMIT $MINIMUM_NUMBER_OF_NAMESERVERS $BLACKLISTING_ENABLED)] | ||||||||||
| 110 | , # everything in %EXPORT_OK that isn't included in any of the other tags | ||||||||||
| 111 | addresses => [qw(@IPV4_SPECIAL_ADDRESSES @IPV6_SPECIAL_ADDRESSES)], | ||||||||||
| 112 | ); | ||||||||||
| 113 | |||||||||||
| 114 | =head1 EXPORTED NAMES | ||||||||||
| 115 | |||||||||||
| 116 | =over | ||||||||||
| 117 | |||||||||||
| 118 | =item * C<$ALGO_STATUS_DEPRECATED> | ||||||||||
| 119 | |||||||||||
| 120 | =item * C<$ALGO_STATUS_PRIVATE> | ||||||||||
| 121 | |||||||||||
| 122 | =item * C<$ALGO_STATUS_RESERVED> | ||||||||||
| 123 | |||||||||||
| 124 | =item * C<$ALGO_STATUS_UNASSIGNED> | ||||||||||
| 125 | |||||||||||
| 126 | =item * C<$ALGO_STATUS_OTHER> | ||||||||||
| 127 | |||||||||||
| 128 | =item * C<$ALGO_STATUS_NOT_RECOMMENDED> | ||||||||||
| 129 | |||||||||||
| 130 | =item * C<$ALGO_STATUS_NOT_ZONE_SIGN> | ||||||||||
| 131 | |||||||||||
| 132 | =item * C<$BLACKLISTING_ENABLED> | ||||||||||
| 133 | |||||||||||
| 134 | A boolean, used to enable the name server blacklisting mechanism. | ||||||||||
| 135 | |||||||||||
| 136 | =item * C<$CNAME_MAX_CHAIN_LENGTH> | ||||||||||
| 137 | |||||||||||
| 138 | An integer, used to define the maximum length of a CNAME chain when doing consecutive recursive lookups. | ||||||||||
| 139 | |||||||||||
| 140 | =item * C<$CNAME_MAX_RECORDS> | ||||||||||
| 141 | |||||||||||
| 142 | An integer, used to define the maximum number of CNAME records in a response. | ||||||||||
| 143 | |||||||||||
| 144 | =item * C<$DURATION_5_MINUTES_IN_SECONDS> | ||||||||||
| 145 | |||||||||||
| 146 | =item * C<$DURATION_1_HOUR_IN_SECONDS> | ||||||||||
| 147 | |||||||||||
| 148 | =item * C<$DURATION_4_HOURS_IN_SECONDS> | ||||||||||
| 149 | |||||||||||
| 150 | =item * C<$DURATION_12_HOURS_IN_SECONDS> | ||||||||||
| 151 | |||||||||||
| 152 | =item * C<$DURATION_1_DAY_IN_SECONDS> | ||||||||||
| 153 | |||||||||||
| 154 | =item * C<$DURATION_1_WEEK_IN_SECONDS> | ||||||||||
| 155 | |||||||||||
| 156 | =item * C<$DURATION_180_DAYS_IN_SECONDS> | ||||||||||
| 157 | |||||||||||
| 158 | =item * C<$FQDN_MAX_LENGTH> | ||||||||||
| 159 | |||||||||||
| 160 | =item * C<$LABEL_MAX_LENGTH> | ||||||||||
| 161 | |||||||||||
| 162 | =item * C<$IP_VERSION_4> | ||||||||||
| 163 | |||||||||||
| 164 | =item * C<$IP_VERSION_6> | ||||||||||
| 165 | |||||||||||
| 166 | =item * C<$SERIAL_BITS> | ||||||||||
| 167 | |||||||||||
| 168 | An integer, used to define the size of the serial number space, as defined in RFC1982, section 2. | ||||||||||
| 169 | |||||||||||
| 170 | =item * C<$SERIAL_MAX_VARIATION> | ||||||||||
| 171 | |||||||||||
| 172 | =item * C<$MINIMUM_NUMBER_OF_NAMESERVERS> | ||||||||||
| 173 | |||||||||||
| 174 | =item * C<$UDP_PAYLOAD_LIMIT> | ||||||||||
| 175 | |||||||||||
| 176 | =item * C<$EDNS_UDP_PAYLOAD_DEFAULT> | ||||||||||
| 177 | |||||||||||
| 178 | An integer, used to define the EDNS0 UDP packet size in non-DNSSEC EDNS queries. | ||||||||||
| 179 | |||||||||||
| 180 | =item * C<$EDNS_UDP_PAYLOAD_COMMON_LIMIT> | ||||||||||
| 181 | |||||||||||
| 182 | =item * C<$EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT> | ||||||||||
| 183 | |||||||||||
| 184 | An integer, used to define the EDNS0 UDP packet size in DNSSEC queries. | ||||||||||
| 185 | |||||||||||
| 186 | =item * C<@IPV4_SPECIAL_ADDRESSES> | ||||||||||
| 187 | |||||||||||
| 188 | =item * C<@IPV6_SPECIAL_ADDRESSES> | ||||||||||
| 189 | |||||||||||
| 190 | =back | ||||||||||
| 191 | |||||||||||
| 192 | =cut | ||||||||||
| 193 | |||||||||||
| 194 | 1 | Readonly our $ALGO_STATUS_DEPRECATED => 1; | |||||||||
| 195 | 1 | Readonly our $ALGO_STATUS_PRIVATE => 4; | |||||||||
| 196 | 1 | Readonly our $ALGO_STATUS_RESERVED => 2; | |||||||||
| 197 | 1 | Readonly our $ALGO_STATUS_UNASSIGNED => 3; | |||||||||
| 198 | 1 | Readonly our $ALGO_STATUS_OTHER => 5; | |||||||||
| 199 | 1 | Readonly our $ALGO_STATUS_NOT_ZONE_SIGN => 8; | |||||||||
| 200 | 1 | Readonly our $ALGO_STATUS_NOT_RECOMMENDED => 9; | |||||||||
| 201 | |||||||||||
| 202 | 1 | Readonly our $BLACKLISTING_ENABLED => 1; | |||||||||
| 203 | |||||||||||
| 204 | 1 | Readonly our $CNAME_MAX_CHAIN_LENGTH => 10; | |||||||||
| 205 | 1 | Readonly our $CNAME_MAX_RECORDS => 9; | |||||||||
| 206 | |||||||||||
| 207 | 1 | Readonly our $DURATION_5_MINUTES_IN_SECONDS => 5 * 60; | |||||||||
| 208 | 1 | Readonly our $DURATION_1_HOUR_IN_SECONDS => 60 * 60; | |||||||||
| 209 | 1 | Readonly our $DURATION_4_HOURS_IN_SECONDS => 4 * 60 * 60; | |||||||||
| 210 | 1 | Readonly our $DURATION_12_HOURS_IN_SECONDS => 12 * 60 * 60; | |||||||||
| 211 | 1 | Readonly our $DURATION_1_DAY_IN_SECONDS => 24 * 60 * 60; | |||||||||
| 212 | 1 | Readonly our $DURATION_1_WEEK_IN_SECONDS => 7 * 24 * 60 * 60; | |||||||||
| 213 | 1 | Readonly our $DURATION_180_DAYS_IN_SECONDS => 180 * 24 * 60 * 60; | |||||||||
| 214 | |||||||||||
| 215 | # Maximum length of ASCII version of a domain name, with trailing dot. | ||||||||||
| 216 | 1 | Readonly our $FQDN_MAX_LENGTH => 254; | |||||||||
| 217 | 1 | Readonly our $LABEL_MAX_LENGTH => 63; | |||||||||
| 218 | |||||||||||
| 219 | 1 | Readonly our $IP_VERSION_4 => 4; | |||||||||
| 220 | 1 | Readonly our $IP_VERSION_6 => 6; | |||||||||
| 221 | |||||||||||
| 222 | 1 | Readonly our $MINIMUM_NUMBER_OF_NAMESERVERS => 2; | |||||||||
| 223 | |||||||||||
| 224 | 1 | Readonly our $SERIAL_BITS => 32; | |||||||||
| 225 | 1 | Readonly our $SERIAL_MAX_VARIATION => 0; | |||||||||
| 226 | |||||||||||
| 227 | 1 | Readonly our $UDP_PAYLOAD_LIMIT => 512; | |||||||||
| 228 | 1 | Readonly our $EDNS_UDP_PAYLOAD_DEFAULT => 512; | |||||||||
| 229 | 1 | Readonly our $EDNS_UDP_PAYLOAD_COMMON_LIMIT => 4096; | |||||||||
| 230 | 1 | Readonly our $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT => 1232; | |||||||||
| 231 | |||||||||||
| 232 | 1 | Readonly::Array our @IPV4_SPECIAL_ADDRESSES => _extract_iana_ip_blocks($IP_VERSION_4); | |||||||||
| 233 | 1 | Readonly::Array our @IPV6_SPECIAL_ADDRESSES => _extract_iana_ip_blocks($IP_VERSION_6); | |||||||||
| 234 | |||||||||||
| 235 | =head1 METHODS | ||||||||||
| 236 | |||||||||||
| 237 | =over | ||||||||||
| 238 | |||||||||||
| 239 | =item _extract_iana_ip_blocks() | ||||||||||
| 240 | |||||||||||
| 241 | my @array = _extract_iana_ip_blocks( $ip_version ); | ||||||||||
| 242 | |||||||||||
| 243 | Internal method that is used to extract IP blocks details from IANA files for a given IP version (i.e. 4 or 6). | ||||||||||
| 244 | |||||||||||
| 245 | Takes an integer (IP version). | ||||||||||
| 246 | |||||||||||
| 247 | Returns a list of hashes - the keys of which are C<ip> (L<Net::IP::XS> object), C<name> (string), C<reference> (string) | ||||||||||
| 248 | and C<globally_reachable> (string). | ||||||||||
| 249 | |||||||||||
| 250 | =back | ||||||||||
| 251 | |||||||||||
| 252 | =cut | ||||||||||
| 253 | |||||||||||
| 254 | 2 | ▶ | sub _extract_iana_ip_blocks { | ||||||||
|
Subroutine
_extract_iana_ip_blocks: called CC=8 SCAR=20.8
| |||||||||||
| 255 | 2 | my $ip_version = shift; | |||||||||
| 256 | 2 | my @list = (); | |||||||||
| 257 | |||||||||||
| 258 | 2 | my $csv = Text::CSV->new ({ | |||||||||
| 259 | binary => 1, | ||||||||||
| 260 | auto_diag => 1, | ||||||||||
| 261 | sep_char => q{,} | ||||||||||
| 262 | }); | ||||||||||
| 263 | 2 | my @files_details = ( | |||||||||
| 264 | { name => q{iana-ipv4-special-registry.csv}, ip_version => $IP_VERSION_4 }, | ||||||||||
| 265 | { name => q{iana-ipv6-special-registry.csv}, ip_version => $IP_VERSION_6 }, | ||||||||||
| 266 | ); | ||||||||||
| 267 | |||||||||||
| 268 | 2 | foreach my $file_details ( @files_details ) { | |||||||||
| 269 | 4 | my $first_line = 1; | |||||||||
| 270 | 4 | ▶ | next if ${$file_details}{ip_version} != $ip_version; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 271 | 2 | my $makefile_name = 'Zonemaster-Engine'; # This must be the same name as "name" in Makefile.PL | |||||||||
| 272 | 2 | my $data_location = dist_file($makefile_name, ${$file_details}{name}); | |||||||||
| 273 | 1 | ▶ | open(my $data, '<:encoding(utf8)', $data_location) or croak "Cannot open '${data_location}' : ${OS_ERROR}"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 274 | 2 | ▶ | while (my $fields = $csv->getline( $data )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 275 | 51 | ▶ | if ( $first_line ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 276 | 2 | $first_line = 0; | |||||||||
| 277 | 2 | next; | |||||||||
| 278 | } | ||||||||||
| 279 | 49 | my $address_data = $fields->[0]; | |||||||||
| 280 | 49 | $address_data =~ s/[ ]+//smx; | |||||||||
| 281 | 49 | foreach my $address_item ( split /,/smx, $address_data ) { | |||||||||
| 282 | 50 | $address_item =~ s/(\A.+\/\d+).*\z/$1/smx; | |||||||||
| 283 | 50 | push @list, { ip => Net::IP::XS->new( $address_item ), name => $fields->[1], reference => $fields->[2], globally_reachable => $fields->[8] }; | |||||||||
| 284 | } | ||||||||||
| 285 | } | ||||||||||
| 286 | 2 | ▶ | close $data or croak "Cannot close '${data_location}' : ${OS_ERROR}"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 287 | } | ||||||||||
| 288 | |||||||||||
| 289 | 2 | return @list; | |||||||||
| 290 | } ## end sub _extract_iana_ip_blocks | ||||||||||
| 291 | |||||||||||
| 292 | 1 | 1; | |||||||||