-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix default settings of queries #1397
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
92080b1
Fix default settings of queries
tgreenx d9cf0e7
Add maximum value check for edns_size parameter in Zonemaster::Engine…
tgreenx c9bcc37
Add minimum value check for edns_size parameter in Zonemaster::Engine…
tgreenx 80a4261
Update unit tests
tgreenx a2d6e64
Update unit tests and unit tests data
tgreenx f8f826d
Update after review
tgreenx e116d4d
Minor updates in unit test for clearer output
tgreenx 50287a1
Fix conflict on unit test data
tgreenx 4ef9276
Update unit test data
tgreenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -166,7 +166,7 @@ sub _build_dns { | |||||||||
|
||||||||||
$res->recurse( 0 ); | ||||||||||
$res->dnssec( 0 ); | ||||||||||
$res->edns_size( $UDP_EDNS_QUERY_DEFAULT ); | ||||||||||
$res->edns_size( 0 ); | ||||||||||
|
||||||||||
$res->retry( Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.retry} ) ); | ||||||||||
$res->retrans( Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.retrans} ) ); | ||||||||||
|
@@ -225,7 +225,12 @@ sub query { | |||||||||
my $dnssec = $href->{dnssec} // 0; | ||||||||||
my $usevc = $href->{usevc} // Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.usevc} ); | ||||||||||
my $recurse = $href->{recurse} // Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.recurse} ); | ||||||||||
my $edns_size = $href->{edns_size} // $UDP_EDNS_QUERY_DEFAULT; | ||||||||||
|
||||||||||
if ( exists $href->{edns_details} and exists $href->{edns_details}{do} ) { | ||||||||||
$dnssec = $href->{edns_details}{do}; | ||||||||||
} | ||||||||||
|
||||||||||
my $edns_size = $href->{edns_size} // ( $dnssec ? $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT : 0 ); | ||||||||||
|
||||||||||
# Fake a DS answer | ||||||||||
if ( $type eq 'DS' and $class eq 'IN' and $self->fake_ds->{ lc( $name ) } ) { | ||||||||||
|
@@ -285,14 +290,7 @@ sub query { | |||||||||
$md5->add( q{NAME} , $name ); | ||||||||||
$md5->add( q{TYPE} , "\U$type" ); | ||||||||||
$md5->add( q{CLASS} , "\U$class" ); | ||||||||||
|
||||||||||
if ( exists $href->{edns_details} and exists $href->{edns_details}{do} ) { | ||||||||||
$md5->add( q{DNSSEC} , $href->{edns_details}{do} ); | ||||||||||
} | ||||||||||
else { | ||||||||||
$md5->add( q{DNSSEC} , $dnssec ); | ||||||||||
} | ||||||||||
|
||||||||||
$md5->add( q{DNSSEC} , $dnssec ); | ||||||||||
$md5->add( q{USEVC} , $usevc ); | ||||||||||
$md5->add( q{RECURSE} , $recurse ); | ||||||||||
|
||||||||||
|
@@ -301,12 +299,13 @@ sub query { | |||||||||
$md5->add( q{EDNS_Z} , $href->{edns_details}{z} // 0 ); | ||||||||||
$md5->add( q{EDNS_EXTENDED_RCODE} , $href->{edns_details}{rcode} // 0 ); | ||||||||||
$md5->add( q{EDNS_DATA} , $href->{edns_details}{data} // q{} ); | ||||||||||
$md5->add( q{EDNS_UDP_SIZE} , $href->{edns_details}{size} // $edns_size ); | ||||||||||
} | ||||||||||
else { | ||||||||||
$md5->add( q{EDNS_UDP_SIZE} , 0); | ||||||||||
$edns_size = $href->{edns_details}{size} // ( $href->{edns_size} // ( $dnssec ? $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT : $EDNS_UDP_PAYLOAD_DEFAULT ) ); | ||||||||||
} | ||||||||||
|
||||||||||
croak "edns_size (or edns_details->size) parameter must be a value between 0 and 65535" if $edns_size > 65535 or $edns_size < 0; | ||||||||||
|
||||||||||
$md5->add( q{EDNS_UDP_SIZE} , $edns_size ); | ||||||||||
|
||||||||||
my $idx = $md5->b64digest(); | ||||||||||
|
||||||||||
my ( $in_cache, $p) = $self->cache->get_key( $idx ); | ||||||||||
|
@@ -406,11 +405,13 @@ sub _query { | |||||||||
$flags{q{fallback}} = $href->{q{fallback}} // Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.fallback} ); | ||||||||||
$flags{q{recurse}} = $href->{q{recurse}} // Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.recurse} ); | ||||||||||
$flags{q{timeout}} = $href->{q{timeout}} // Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.timeout} ); | ||||||||||
$flags{q{edns_size}} = $href->{q{edns_size}} // $UDP_EDNS_QUERY_DEFAULT; | ||||||||||
|
||||||||||
if ( exists $href->{edns_details} ) { | ||||||||||
$flags{q{dnssec}} = $href->{edns_details}{do} // $flags{q{dnssec}}; | ||||||||||
$flags{q{edns_size}} = $href->{edns_details}{size} // $flags{q{edns_size}}; | ||||||||||
$flags{q{edns_size}} = $href->{edns_details}{size} // ( $href->{q{edns_size}} // ( $flags{q{dnssec}} ? $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT : $EDNS_UDP_PAYLOAD_DEFAULT ) ); | ||||||||||
} | ||||||||||
else { | ||||||||||
$flags{q{edns_size}} = $href->{q{edns_size}} // ( $flags{q{dnssec}} ? $EDNS_UDP_PAYLOAD_DNSSEC_DEFAULT : 0 ); | ||||||||||
} | ||||||||||
|
||||||||||
# Set flags for this query | ||||||||||
|
@@ -447,6 +448,9 @@ sub _query { | |||||||||
if ( exists $href->{edns_details}{do} ) { | ||||||||||
$pkt->do($href->{edns_details}{do}); | ||||||||||
} | ||||||||||
elsif ( $flags{q{dnssec}} ) { | ||||||||||
$pkt->do($flags{q{dnssec}}); | ||||||||||
} | ||||||||||
if ( exists $href->{edns_details}{size} ) { | ||||||||||
$pkt->edns_size($href->{edns_details}{size}); | ||||||||||
} | ||||||||||
|
@@ -478,20 +482,13 @@ sub _query { | |||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
push @{ $self->times }, ( time() - $before ); | ||||||||||
|
||||||||||
# Reset to defaults | ||||||||||
foreach my $flag ( keys %flags ) { | ||||||||||
# Except for any flag that is not configurable in the profile | ||||||||||
unless ( grep( /^$flag$/, ( 'dnssec', 'edns_size' ) ) ) { | ||||||||||
$self->dns->$flag( Zonemaster::Engine::Profile->effective->get( q{resolver.defaults.}.$flag ) ); | ||||||||||
} | ||||||||||
} | ||||||||||
push @{ $self->times }, ( time() - $before ); | ||||||||||
|
||||||||||
if ( $res ) { | ||||||||||
my $p = Zonemaster::Engine::Packet->new( { packet => $res } ); | ||||||||||
my $size = length( $p->data ); | ||||||||||
if ( $size > $UDP_COMMON_EDNS_LIMIT ) { | ||||||||||
if ( $size > $EDNS_UDP_PAYLOAD_COMMON_LIMIT ) { | ||||||||||
my $command = sprintf q{dig @%s %s%s %s}, $self->address->short, $flags{dnssec} ? q{+dnssec } : q{}, | ||||||||||
"$name", $type; | ||||||||||
Zonemaster::Engine->logger->add( | ||||||||||
|
@@ -773,7 +770,7 @@ Remove all cached nameserver objects and queries. | |||||||||
|
||||||||||
Send a DNS query to the nameserver the object represents. C<$name> and C<$type> are the name and type that will be queried for (C<$type> defaults | ||||||||||
to 'A' if it's left undefined). C<$flagref> is a reference to a hash, the keys of which are flags and the values are their corresponding values. | ||||||||||
The available flags are as follows. All but 'class' and 'edns_details' directly correspond to methods in the L<Zonemaster::LDNS::Resolver> object. | ||||||||||
The available flags are as follows. All but 'class' and 'edns_details' directly correspond to methods in the L<Zonemaster::LDNS> object. | ||||||||||
|
||||||||||
=over | ||||||||||
|
||||||||||
|
@@ -794,7 +791,7 @@ The retransmission interval. | |||||||||
Set the DO flag in the query. Defaults to false. | ||||||||||
|
||||||||||
If set to true, it becomes an EDNS query. | ||||||||||
Value overridden by 'edns_details->do' (if also given). More details in 'edns_details' below. | ||||||||||
Value overridden by C<edns_details{do}> (if also given). More details in L<edns_details> below. | ||||||||||
|
||||||||||
=item debug | ||||||||||
|
||||||||||
|
@@ -826,22 +823,23 @@ If set to true, prevents a server to be black-listed on a query in case there is | |||||||||
|
||||||||||
=item edns_size | ||||||||||
|
||||||||||
Set the EDNS0 UDP maximum size. Defaults to 512. | ||||||||||
Set the EDNS0 UDP maximum size. The value must be comprised between 0 and 65535. | ||||||||||
Defaults to 0, or 512 if the query is a non-DNSSEC EDNS query, or 1232 if the query is a DNSSEC query. | ||||||||||
Comment on lines
+826
to
+827
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
Used only when the query is an EDNS query. Does not enable on its own the query to be an EDNS query. | ||||||||||
Value overridden by 'edns_details->size' (if also given). More details in 'edns_details' below. | ||||||||||
Setting a value other than 0 will also implicitly enable EDNS for the query. | ||||||||||
Value overridden by C<edns_details-E<gt>{size}> (if also given). More details in L<edns_details> below. | ||||||||||
|
||||||||||
=item edns_details | ||||||||||
|
||||||||||
A hash. An empty hash or a hash with any keys below will enable the query to be an EDNS query. | ||||||||||
A hash. An empty hash or a hash with any keys below will enable EDNS for the query. | ||||||||||
|
||||||||||
The currently supported keys are 'version', 'z', 'do', 'rcode', 'size' and 'data'. | ||||||||||
See L<Zonemaster::LDNS::Packet> for more details (key names prefixed with 'edns_'). | ||||||||||
|
||||||||||
Note that flag 'edns_size' also exists (see above) and has the same effect as 'edns_details->size', although the value of the | ||||||||||
Note that flag L<edns_size> also exists (see above) and has the same effect as C<edns_details-E<gt>{size}>, although the value of the | ||||||||||
latter will take precedence if both are given. | ||||||||||
|
||||||||||
Similarly, note that flag 'dnssec' also exists (see above) and has the same effect as 'edns_details->do', although the value of the | ||||||||||
Similarly, note that flag L<dnssec> also exists (see above) and has the same effect as C<edns_details-E<gt>{do}>, although the value of the | ||||||||||
latter will take precedence if both are given. | ||||||||||
|
||||||||||
=back | ||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today we have no use cases for values 1-511. Any such value would today be a mistake and it would be better to catch those. For EDNS 0-511 is defined to mean the same thing as 512. If we ever want to check for servers handling small values we could always change the logic.
One could also argue that high values would never be used. We have today no use cases for high values. From that perspective it could be argued that the code should set a limit to catch mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it is really needed to have such "subjective" checks. These are still "valid" values in the sense that the underlying library (LDNS) will accept them. I don't think we should impose those to us, or to any other user of Zonemaster-Engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.