-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathNameserver.pm
1814 lines (1463 loc) · 57.8 KB
/
Nameserver.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package Zonemaster::Engine::Test::Nameserver;
use 5.014002;
use strict;
use warnings;
use version; our $VERSION = version->declare( "v1.1.0" );
use List::MoreUtils qw[uniq none];
use Locale::TextDomain qw[Zonemaster-Engine];
use Readonly;
use JSON::PP;
use Net::IP::XS;
use Zonemaster::Engine::Profile;
use Zonemaster::Engine::Constants qw[:ip];
use Zonemaster::Engine::Test::Address;
use Zonemaster::Engine::Util;
use Zonemaster::Engine::TestMethods;
=head1 NAME
Zonemaster::Engine::Test::Nameserver - Module implementing tests focused on the properties of a name server
=head1 SYNOPSIS
my @results = Zonemaster::Engine::Test::Nameserver->all( $zone );
=cut
Readonly my @NONEXISTENT_NAMES => qw{
xn--nameservertest.iis.se
xn--nameservertest.icann.org
xn--nameservertest.ripe.net
};
=head1 METHODS
=over
=item all()
my @logentry_array = all( $zone );
Runs the default set of tests for that module, i.e. L<fourteen tests|/TESTS>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub all {
my ( $class, $zone ) = @_;
my @results;
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver01} ) ) {
push @results, $class->nameserver01( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver02} ) ) {
push @results, $class->nameserver02( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver03} ) ) {
push @results, $class->nameserver03( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver04} ) ) {
push @results, $class->nameserver04( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver05} ) ) {
push @results, $class->nameserver05( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver06} ) ) {
push @results, $class->nameserver06( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver07} ) ) {
push @results, $class->nameserver07( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver08} ) ) {
push @results, $class->nameserver08( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver09} ) ) {
push @results, $class->nameserver09( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver10} ) ) {
push @results, $class->nameserver10( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver11} ) ) {
push @results, $class->nameserver11( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver12} ) ) {
push @results, $class->nameserver12( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver13} ) ) {
push @results, $class->nameserver13( $zone );
}
if ( Zonemaster::Engine::Util::should_run_test( q{nameserver15} ) ) {
push @results, $class->nameserver15( $zone );
}
return @results;
} ## end sub all
=over
=item metadata()
my $hash_ref = metadata();
Returns a reference to a hash, the keys of which are the names of all Test Cases in the module, and the corresponding values are references to
an array containing all the message tags that the Test Case can use in L<log entries|Zonemaster::Engine::Logger::Entry>.
=back
=cut
sub metadata {
my ( $class ) = @_;
return {
nameserver01 => [
qw(
IS_A_RECURSOR
NO_RECURSOR
NO_RESPONSE
TEST_CASE_END
TEST_CASE_START
)
],
nameserver02 => [
qw(
BREAKS_ON_EDNS
EDNS_RESPONSE_WITHOUT_EDNS
EDNS_VERSION_ERROR
EDNS0_SUPPORT
NO_EDNS_SUPPORT
NO_RESPONSE
NS_ERROR
TEST_CASE_END
TEST_CASE_START
)
],
nameserver03 => [
qw(
AXFR_FAILURE
AXFR_AVAILABLE
TEST_CASE_END
TEST_CASE_START
)
],
nameserver04 => [
qw(
DIFFERENT_SOURCE_IP
SAME_SOURCE_IP
TEST_CASE_END
TEST_CASE_START
)
],
nameserver05 => [
qw(
AAAA_BAD_RDATA
AAAA_QUERY_DROPPED
AAAA_UNEXPECTED_RCODE
AAAA_WELL_PROCESSED
A_UNEXPECTED_RCODE
NO_RESPONSE
IPV4_DISABLED
IPV6_DISABLED
TEST_CASE_END
TEST_CASE_START
)
],
nameserver06 => [
qw(
CAN_NOT_BE_RESOLVED
CAN_BE_RESOLVED
NO_RESOLUTION
TEST_CASE_END
TEST_CASE_START
)
],
nameserver07 => [
qw(
UPWARD_REFERRAL_IRRELEVANT
UPWARD_REFERRAL
NO_UPWARD_REFERRAL
TEST_CASE_END
TEST_CASE_START
)
],
nameserver08 => [
qw(
QNAME_CASE_INSENSITIVE
QNAME_CASE_SENSITIVE
TEST_CASE_END
TEST_CASE_START
)
],
nameserver09 => [
qw(
CASE_QUERY_SAME_ANSWER
CASE_QUERY_DIFFERENT_ANSWER
CASE_QUERY_SAME_RC
CASE_QUERY_DIFFERENT_RC
CASE_QUERY_NO_ANSWER
CASE_QUERIES_RESULTS_OK
CASE_QUERIES_RESULTS_DIFFER
TEST_CASE_END
TEST_CASE_START
)
],
nameserver10 => [
qw(
N10_NO_RESPONSE_EDNS1_QUERY
N10_UNEXPECTED_RCODE
N10_EDNS_RESPONSE_ERROR
TEST_CASE_END
TEST_CASE_START
)
],
nameserver11 => [
qw(
N11_NO_EDNS
N11_NO_RESPONSE
N11_RETURNS_UNKNOWN_OPTION_CODE
N11_UNEXPECTED_ANSWER_SECTION
N11_UNEXPECTED_RCODE
N11_UNSET_AA
TEST_CASE_END
TEST_CASE_START
)
],
nameserver12 => [
qw(
NO_RESPONSE
NO_EDNS_SUPPORT
Z_FLAGS_NOTCLEAR
NS_ERROR
TEST_CASE_END
TEST_CASE_START
)
],
nameserver13 => [
qw(
NO_RESPONSE
NO_EDNS_SUPPORT
NS_ERROR
MISSING_OPT_IN_TRUNCATED
TEST_CASE_END
TEST_CASE_START
)
],
nameserver15 => [
qw(
N15_ERROR_ON_VERSION_QUERY
N15_NO_VERSION_REVEALED
N15_SOFTWARE_VERSION
N15_WRONG_CLASS
)
],
};
} ## end sub metadata
Readonly my %TAG_DESCRIPTIONS => (
NAMESERVER01 => sub {
__x # NAMESERVER:NAMESERVER01
'A name server should not be a recursor';
},
NAMESERVER02 => sub {
__x # NAMESERVER:NAMESERVER02
'Test of EDNS0 support';
},
NAMESERVER03 => sub {
__x # NAMESERVER:NAMESERVER03
'Test availability of zone transfer (AXFR)';
},
NAMESERVER04 => sub {
__x # NAMESERVER:NAMESERVER04
'Same source address';
},
NAMESERVER05 => sub {
__x # NAMESERVER:NAMESERVER05
'Behaviour against AAAA query';
},
NAMESERVER06 => sub {
__x # NAMESERVER:NAMESERVER06
'NS can be resolved';
},
NAMESERVER07 => sub {
__x # NAMESERVER:NAMESERVER07
'To check whether authoritative name servers return an upward referral';
},
NAMESERVER08 => sub {
__x # NAMESERVER:NAMESERVER08
'Testing QNAME case insensitivity';
},
NAMESERVER09 => sub {
__x # NAMESERVER:NAMESERVER09
'Testing QNAME case sensitivity';
},
NAMESERVER10 => sub {
__x # NAMESERVER:NAMESERVER10
'Test for undefined EDNS version';
},
NAMESERVER11 => sub {
__x # NAMESERVER:NAMESERVER11
'Test for unknown EDNS OPTION-CODE';
},
NAMESERVER12 => sub {
__x # NAMESERVER:NAMESERVER12
'Test for unknown EDNS flags';
},
NAMESERVER13 => sub {
__x # NAMESERVER:NAMESERVER13
'Test for truncated response on EDNS query';
},
NAMESERVER14 => sub {
__x # NAMESERVER:NAMESERVER14
'Test for unknown version with unknown OPTION-CODE';
},
NAMESERVER15 => sub {
__x # NAMESERVER:NAMESERVER15
'Checking for revealed software version';
},
AAAA_BAD_RDATA => sub {
__x # NAMESERVER:AAAA_BAD_RDATA
'Nameserver {ns} answered AAAA query with an unexpected RDATA length ({length} instead of 16).', @_;
},
AAAA_QUERY_DROPPED => sub {
__x # NAMESERVER:AAAA_QUERY_DROPPED
'Nameserver {ns} dropped AAAA query.', @_;
},
AAAA_UNEXPECTED_RCODE => sub {
__x # NAMESERVER:AAAA_UNEXPECTED_RCODE
'Nameserver {ns} answered AAAA query with an unexpected rcode ({rcode}).', @_;
},
AAAA_WELL_PROCESSED => sub {
__x # NAMESERVER:AAAA_WELL_PROCESSED
'The following nameservers answer AAAA queries without problems : {ns_list}.', @_;
},
A_UNEXPECTED_RCODE => sub {
__x # NAMESERVER:A_UNEXPECTED_RCODE
'Nameserver {ns} answered A query with an unexpected rcode ({rcode}).', @_;
},
AXFR_AVAILABLE => sub {
__x # NAMESERVER:AXFR_AVAILABLE
'Nameserver {ns} allow zone transfer using AXFR.', @_;
},
AXFR_FAILURE => sub {
__x # NAMESERVER:AXFR_FAILURE
'AXFR not available on nameserver {ns}.', @_;
},
BREAKS_ON_EDNS => sub {
__x # NAMESERVER:BREAKS_ON_EDNS
'No response from {ns} when EDNS is used in query asking for {domain}.', @_;
},
CAN_BE_RESOLVED => sub {
__x # NAMESERVER:CAN_BE_RESOLVED
'All nameservers succeeded to resolve to an IP address.', @_;
},
CAN_NOT_BE_RESOLVED => sub {
__x # NAMESERVER:CAN_NOT_BE_RESOLVED
'The following nameservers failed to resolve to an IP address : {nsname_list}.', @_;
},
CASE_QUERIES_RESULTS_DIFFER => sub {
__x # NAMESERVER:CASE_QUERIES_RESULTS_DIFFER
'When asked for {type} records on "{domain}" with different cases, all servers do not reply consistently.', @_;
},
CASE_QUERIES_RESULTS_OK => sub {
__x # NAMESERVER:CASE_QUERIES_RESULTS_OK
'When asked for {type} records on "{domain}" with different cases, all servers reply consistently.', @_;
},
CASE_QUERY_DIFFERENT_ANSWER => sub {
__x # NAMESERVER:CASE_QUERY_DIFFERENT_ANSWER
'When asked for {type} records on "{query1}" and "{query2}", '
. 'nameserver {ns} returns different answers.',
@_;
},
CASE_QUERY_DIFFERENT_RC => sub {
__x # NAMESERVER:CASE_QUERY_DIFFERENT_RC
'When asked for {type} records on "{query1}" and "{query2}", '
. 'nameserver {ns} returns different RCODE ("{rcode1}" vs "{rcode2}").',
@_;
},
CASE_QUERY_NO_ANSWER => sub {
__x # NAMESERVER:CASE_QUERY_NO_ANSWER
'When asked for {type} records on "{domain}", nameserver {ns} returns nothing.', @_;
},
CASE_QUERY_SAME_ANSWER => sub {
__x # NAMESERVER:CASE_QUERY_SAME_ANSWER
'When asked for {type} records on "{query1}" and "{query2}", nameserver {ns} returns same answers.',
@_;
},
CASE_QUERY_SAME_RC => sub {
__x # NAMESERVER:CASE_QUERY_SAME_RC
'When asked for {type} records on "{query1}" and "{query2}", '
. 'nameserver {ns} returns same RCODE "{rcode}".',
@_;
},
DIFFERENT_SOURCE_IP => sub {
__x # NAMESERVER:DIFFERENT_SOURCE_IP
'Nameserver {ns} replies on a SOA query with a different source address ({source}).', @_;
},
EDNS_RESPONSE_WITHOUT_EDNS => sub {
__x # NAMESERVER:EDNS_RESPONSE_WITHOUT_EDNS
'Response without EDNS from {ns} on query with EDNS0 asking for {domain}.', @_;
},
EDNS_VERSION_ERROR => sub {
__x # NAMESERVER:EDNS_VERSION_ERROR
'Incorrect version of EDNS (expected 0) in response from {ns} '
. 'on query with EDNS (version 0) asking for {domain}.',
@_;
},
EDNS0_SUPPORT => sub {
__x # NAMESERVER:EDNS0_SUPPORT
'The following nameservers support EDNS0 : {ns_list}.', @_;
},
IPV4_DISABLED => sub {
__x # NAMESERVER:IPV4_DISABLED
'IPv4 is disabled, not sending "{rrtype}" query to {ns}.', @_;
},
IPV6_DISABLED => sub {
__x # NAMESERVER:IPV6_DISABLED
'IPv6 is disabled, not sending "{rrtype}" query to {ns}.', @_;
},
IS_A_RECURSOR => sub {
__x # NAMESERVER:IS_A_RECURSOR
'Nameserver {ns} is a recursor.', @_;
},
MISSING_OPT_IN_TRUNCATED => sub {
__x # NAMESERVER:MISSING_OPT_IN_TRUNCATED
'Nameserver {ns} replies on an EDNS query with a truncated response without EDNS.', @_;
},
NO_EDNS_SUPPORT => sub {
__x # NAMESERVER:NO_EDNS_SUPPORT
'Nameserver {ns} does not support EDNS0 (replies with FORMERR).', @_;
},
NO_RECURSOR => sub {
__x # NAMESERVER:NO_RECURSOR
'Nameserver {ns} is not a recursor.', @_;
},
NO_RESOLUTION => sub {
__x # NAMESERVER:NO_RESOLUTION
"No nameserver was successfully resolved to an IP address.", @_;
},
NO_RESPONSE => sub {
__x # NAMESERVER:NO_RESPONSE
'No response from {ns} asking for {domain}.', @_;
},
NO_UPWARD_REFERRAL => sub {
__x # NAMESERVER:NO_UPWARD_REFERRAL
'None of the following nameservers returns an upward referral : {nsname_list}.', @_;
},
NS_ERROR => sub {
__x # NAMESERVER:NS_ERROR
'Erroneous response from nameserver {ns}.', @_;
},
N10_EDNS_RESPONSE_ERROR => sub {
__x # NAMESERVER:N10_EDNS_RESPONSE_ERROR
'Expected RCODE but received erroneous response to an EDNS version 1 query. Fetched from the nameservers with IP addresses {ns_ip_list}', @_;
},
N10_NO_RESPONSE_EDNS1_QUERY => sub {
__x # NAMESERVER:N10_NO_RESPONSE_EDNS1_QUERY
'No response to an EDNS version 1 query. Fetched from the nameservers with IP addresses {ns_ip_list}', @_;
},
N10_UNEXPECTED_RCODE => sub {
__x # NAMESERVER:N10_UNEXPECTED_RCODE
'Erroneous RCODE ("{rcode}") in response to an EDNS version 1 query. Fetched from the nameservers with IP addresses {ns_ip_list}', @_;
},
N11_NO_EDNS => sub {
__x # NAMESERVER:N11_N11_NO_EDNS
'The DNS response, on query with unknown EDNS option-code, does not contain any EDNS from name servers "{ns_ip_list}".', @_;
},
N11_NO_RESPONSE => sub {
__x # NAMESERVER:N11_NO_RESPONSE
'There is no response on query with unknown EDNS option-code from name servers "{ns_ip_list}".', @_;
},
N11_RETURNS_UNKNOWN_OPTION_CODE => sub {
__x # NAMESERVER:N11_RETURNS_UNKNOWN_OPTION_CODE
'The DNS response contains an unknown EDNS option-code. Returned from name servers "{ns_ip_list}".', @_;
},
N11_UNEXPECTED_ANSWER_SECTION => sub {
__x # NAMESERVER:N11_UNEXPECTED_ANSWER_SECTION
'The DNS response, on query with unknown EDNS option-code, does not contain the expected SOA record in the answer section from name servers "{ns_ip_list}".', @_;
},
N11_UNEXPECTED_RCODE => sub {
__x # NAMESERVER:N11_UNEXPECTED_RCODE
'The DNS response, on query with unknown EDNS option-code, has unexpected RCODE name "{rcode}" from name servers "{ns_ip_list}".', @_;
},
N11_UNSET_AA => sub {
__x # NAMESERVER:N11_UNSET_AA
'The DNS response, on query with unknown EDNS option-code, is unexpectedly not authoritative from name servers "{ns_ip_list}".', @_;
},
N15_ERROR_ON_VERSION_QUERY => sub {
__x # NAMESERVER:N15_ERROR_ON_VERSION_QUERY
'The following name server(s) do not respond or respond with SERVFAIL to software version query "{query_name}". Returned from name servers: "{ns_list}"', @_;
},
N15_NO_VERSION_REVEALED => sub {
__x # NAMESERVER:N15_NO_VERSION_REVEALED
'The following name server(s) do not reveal the software version. Returned from name servers: "{ns_list}"', @_;
},
N15_SOFTWARE_VERSION => sub {
__x # NAMESERVER:N15_SOFTWARE_VERSION
'The following name server(s) respond to software version query "{query_name}" with string "{string}". Returned from name servers: "{ns_list}"', @_;
},
N15_WRONG_CLASS => sub {
__x # NAMESERVER:N15_WRONG_CLASS
'The following name server(s) do not return CH class record(s) on CH class query. Returned from name servers: "{ns_list}"', @_;
},
QNAME_CASE_INSENSITIVE => sub {
__x # NAMESERVER:QNAME_CASE_INSENSITIVE
'Nameserver {ns} does not preserve original case of the queried name ({domain}).', @_;
},
QNAME_CASE_SENSITIVE => sub {
__x # NAMESERVER:QNAME_CASE_SENSITIVE
"Nameserver {ns} preserves original case of queried names ({domain}).", @_;
},
SAME_SOURCE_IP => sub {
__x # NAMESERVER:SAME_SOURCE_IP
'All nameservers reply with same IP used to query them.', @_;
},
TEST_CASE_END => sub {
__x # NAMESERVER:TEST_CASE_END
'TEST_CASE_END {testcase}.', @_;
},
TEST_CASE_START => sub {
__x # NAMESERVER:TEST_CASE_START
'TEST_CASE_START {testcase}.', @_;
},
UPWARD_REFERRAL => sub {
__x # NAMESERVER:UPWARD_REFERRAL
'Nameserver {ns} returns an upward referral.', @_;
},
UPWARD_REFERRAL_IRRELEVANT => sub {
__x # NAMESERVER:UPWARD_REFERRAL_IRRELEVANT
'Upward referral tests skipped for root zone.', @_;
},
Z_FLAGS_NOTCLEAR => sub {
__x # NAMESERVER:Z_FLAGS_NOTCLEAR
'Nameserver {ns} has one or more unknown EDNS Z flag bits set.', @_;
},
);
=over
=item tag_descriptions()
my $hash_ref = tag_descriptions();
Used by the L<built-in translation system|Zonemaster::Engine::Translator>.
Returns a reference to a hash, the keys of which are the message tags and the corresponding values are strings (message IDs).
=back
=cut
sub tag_descriptions {
return \%TAG_DESCRIPTIONS;
}
=over
=item version()
my $version_string = version();
Returns a string containing the version of the current module.
=back
=cut
sub version {
return "$Zonemaster::Engine::Test::Nameserver::VERSION";
}
=head1 INTERNAL METHODS
=over
=item _emit_log()
my $log_entry = _emit_log( $message_tag_string, $hash_ref );
Adds a message to the L<logger|Zonemaster::Engine::Logger> for this module.
See L<Zonemaster::Engine::Logger::Entry/add($tag, $argref, $module, $testcase)> for more details.
Takes a string (message tag) and a reference to a hash (arguments).
Returns a L<Zonemaster::Engine::Logger::Entry> object.
=back
=cut
sub _emit_log { my ( $tag, $argref ) = @_; return Zonemaster::Engine->logger->add( $tag, $argref, 'Nameserver' ); }
=over
=item _ip_disabled_message()
my $bool = _ip_disabled_message( $logentry_array_ref, $ns, @query_type_array );
Checks if the IP version of a given name server is allowed to be queried. If not, it adds a logging message and returns true. Else, it returns false.
Takes a reference to an array of L<Zonemaster::Engine::Logger::Entry> objects, a L<Zonemaster::Engine::Nameserver> object and an array of strings (query type).
Returns a boolean.
=back
=cut
sub _ip_disabled_message {
my ( $results_array, $ns, @rrtypes ) = @_;
if ( not Zonemaster::Engine::Profile->effective->get(q{net.ipv6}) and $ns->address->version == $IP_VERSION_6 ) {
push @$results_array, map {
_emit_log(
IPV6_DISABLED => {
ns => $ns->string,
rrtype => $_
}
)
} @rrtypes;
return 1;
}
if ( not Zonemaster::Engine::Profile->effective->get(q{net.ipv4}) and $ns->address->version == $IP_VERSION_4 ) {
push @$results_array, map {
_emit_log(
IPV4_DISABLED => {
ns => $ns->string,
rrtype => $_,
}
)
} @rrtypes;
return 1;
}
return 0;
}
=head1 TESTS
=over
=item nameserver01()
my @logentry_array = nameserver01( $zone );
Runs the L<Nameserver01 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Nameserver-TP/nameserver01.md>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub nameserver01 {
my ( $class, $zone ) = @_;
local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Nameserver01';
push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
my @nss = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
for my $ns ( @nss ) {
next if ( _ip_disabled_message( \@results, $ns, q{A} ) );
my $response_count = 0;
my $nxdomain_count = 0;
my $is_no_recursor = 1;
my $has_seen_ra = 0;
for my $nonexistent_name ( @NONEXISTENT_NAMES ) {
my $p = $ns->query( $nonexistent_name, q{A}, { blacklisting_disabled => 1 } );
if ( !$p ) {
push @results,
_emit_log(
NO_RESPONSE => {
ns => $ns->string,
domain => $nonexistent_name,
}
);
$is_no_recursor = 0;
}
else {
$response_count++;
if ( $p->ra ) {
$has_seen_ra = 1;
}
if ( $p->rcode eq q{NXDOMAIN} ) {
$nxdomain_count++;
}
}
} ## end for my $nonexistent_name...
if ( $has_seen_ra || ( $response_count > 0 && $nxdomain_count == $response_count ) ) {
push @results, _emit_log( IS_A_RECURSOR => { ns => $ns->string } );
$is_no_recursor = 0;
}
if ( $is_no_recursor ) {
push @results, _emit_log( NO_RECURSOR => { ns => $ns->string } );
}
} ## end for my $ns ( @nss )
return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
} ## end sub nameserver01
=over
=item nameserver02()
my @logentry_array = nameserver02( $zone );
Runs the L<Nameserver02 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Nameserver-TP/nameserver02.md>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub nameserver02 {
my ( $class, $zone ) = @_;
local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Nameserver02';
push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
my %nsnames_and_ip;
my $n_error = 0;
my @nss = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
foreach my $local_ns ( @nss ) {
next if ( _ip_disabled_message( \@results, $local_ns, q{SOA} ) );
next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
my $p = $local_ns->query( $zone->name, q{SOA}, { edns_details => { version => 0 } } );
if ( $p ) {
if ( $p->rcode eq q{FORMERR} and not $p->has_edns) {
push @results, _emit_log( NO_EDNS_SUPPORT => { ns => $local_ns->string } );
$n_error++;
}
elsif ( $p->rcode eq q{NOERROR} and not $p->edns_rcode and $p->get_records( q{SOA}, q{answer} ) and $p->edns_version == 0 ) {
$nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
next;
}
elsif ( $p->rcode eq q{NOERROR} and not $p->has_edns ) {
push @results,
_emit_log(
EDNS_RESPONSE_WITHOUT_EDNS => {
ns => $local_ns->string,
domain => $zone->name,
}
);
$n_error++;
}
elsif ( $p->rcode eq q{NOERROR} and $p->has_edns and $p->edns_version != 0 ) {
push @results,
_emit_log(
EDNS_VERSION_ERROR => {
ns => $local_ns->string,
domain => $zone->name,
}
);
$n_error++;
}
else {
push @results, _emit_log( NS_ERROR => { ns => $local_ns->string } );
$n_error++;
}
}
else {
my $p2 = $local_ns->query( $zone->name, q{SOA} );
if ( $p2 ) {
push @results,
_emit_log(
BREAKS_ON_EDNS => {
ns => $local_ns->string,
domain => $zone->name,
}
);
$n_error++;
}
else {
push @results,
_emit_log(
NO_RESPONSE => {
ns => $local_ns->string,
domain => $zone->name,
}
);
$n_error++;
}
}
$nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
} ## end foreach my $local_ns ( @{ Zonemaster::Engine::TestMethods...})
if ( scalar keys %nsnames_and_ip and not $n_error ) {
push @results,
_emit_log(
EDNS0_SUPPORT => {
ns_list => join( q{;}, keys %nsnames_and_ip ),
}
);
}
return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
} ## end sub nameserver02
=over
=item nameserver03()
my @logentry_array = nameserver03( $zone );
Runs the L<Nameserver03 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Nameserver-TP/nameserver03.md>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub nameserver03 {
my ( $class, $zone ) = @_;
local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Nameserver03';
push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
my %nsnames_and_ip;
my @nss = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
foreach my $local_ns ( @nss ) {
next if ( _ip_disabled_message( \@results, $local_ns, q{AXFR} ) );
next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
my $first_rr;
eval {
$local_ns->axfr( $zone->name, sub { ( $first_rr ) = @_; return 0; } );
1;
} or do {
push @results, _emit_log( AXFR_FAILURE => { ns => $local_ns->string } );
};
if ( $first_rr and $first_rr->type eq q{SOA} ) {
push @results, _emit_log( AXFR_AVAILABLE => { ns => $local_ns->string } );
}
$nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
} ## end foreach my $local_ns ( @{ Zonemaster::Engine::TestMethods...})
return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
} ## end sub nameserver03
=over
=item nameserver04()
my @logentry_array = nameserver04( $zone );
Runs the L<Nameserver04 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Nameserver-TP/nameserver04.md>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub nameserver04 {
my ( $class, $zone ) = @_;
local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Nameserver04';
push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
my %nsnames_and_ip;
my $n_error = 0;
my @nss = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
foreach my $local_ns ( @nss ) {
next if ( _ip_disabled_message( \@results, $local_ns, q{SOA} ) );
next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
my $p = $local_ns->query( $zone->name, q{SOA} );
if ( $p ) {
if ( $p->answerfrom and ( $local_ns->address->short ne Net::IP::XS->new( $p->answerfrom )->short ) ) {
push @results,
_emit_log(
DIFFERENT_SOURCE_IP => {
ns => $local_ns->string,
source => $p->answerfrom,
}
);
$n_error++;
}
}
$nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
} ## end foreach my $local_ns ( @{ Zonemaster::Engine::TestMethods...})
if ( scalar keys %nsnames_and_ip and not $n_error) {
push @results,
_emit_log(
SAME_SOURCE_IP => {
names => join( q{,}, keys %nsnames_and_ip ),
}
);
}
return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
} ## end sub nameserver04
=over
=item nameserver05()
my @logentry_array = nameserver05( $zone );
Runs the L<Nameserver05 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Nameserver-TP/nameserver05.md>.
Takes a L<Zonemaster::Engine::Zone> object.
Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
=back
=cut
sub nameserver05 {
my ( $class, $zone ) = @_;
local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Nameserver05';
push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
my %nsnames_and_ip;
my $aaaa_issue = 0;
my @aaaa_ok;
my @nss = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
foreach my $ns ( @nss ) {
next if ( _ip_disabled_message( \@results, $ns, q{A} ) );
next if $nsnames_and_ip{ $ns->name->string . q{/} . $ns->address->short };
$nsnames_and_ip{ $ns->name->string . q{/} . $ns->address->short }++;
my $p = $ns->query( $zone->name, q{A}, { usevc => 0 } );
if ( not $p ) {
push @results,
_emit_log(
NO_RESPONSE => {
ns => $ns->string,
domain => $zone->name,
}
);
}
elsif ( $p->rcode ne q{NOERROR} ) {
push @results,
_emit_log(
A_UNEXPECTED_RCODE => {
ns => $ns->string,
rcode => $p->rcode,
}
);
}
else {
$p = $ns->query( $zone->name, q{AAAA}, { usevc => 0 } );
if ( not $p ) {
push @results,
_emit_log( AAAA_QUERY_DROPPED => { ns => $ns->string } );
$aaaa_issue++;
}
elsif ( $p->rcode ne q{NOERROR} ) {
push @results,
_emit_log(
AAAA_UNEXPECTED_RCODE => {
ns => $ns->string,