Skip to content
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

PoC: Send queries with EDNS option NSID set and retrieve the value if available #1133

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lib/Zonemaster/Engine/Nameserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use overload

has 'name' => ( is => 'ro' );
has 'address' => ( is => 'ro' );
has 'nsid' => ( is => 'rw' );

has 'dns' => ( is => 'ro' );
has 'cache' => ( is => 'ro' );
Expand Down Expand Up @@ -340,6 +341,10 @@ sub query {

Zonemaster::Engine->logger->add( CACHED_RETURN => { packet => ( $p ? $p->string : 'undef' ) } );

if ( Zonemaster::Engine::Profile->effective->get( q{nsid} ) ) {
eval { $self->{nsid} = $p->get_nsid(); };
}

return $p;
} ## end sub query

Expand Down Expand Up @@ -455,37 +460,40 @@ sub _query {
);
}
else {
my $pkt = Zonemaster::LDNS::Packet->new("$name", $type, $href->{class} );
if ( $edns_special_case ) {
my $pkt = Zonemaster::LDNS::Packet->new("$name", $type, $href->{class} );
if ( defined $href->{edns_details} and defined $href->{edns_details}{version} and $href->{edns_details}{version} != 0 ) {
$pkt->set_edns_present();
$pkt->edns_version($href->{edns_details}{version});
}
if ( defined $href->{edns_details} and defined $href->{edns_details}{z} ) {
if ( defined $href->{edns_details} and defined $href->{edns_details}{z} ) {
$pkt->set_edns_present();
$pkt->edns_z($href->{edns_details}{z});
}
if ( defined $href->{edns_details} and defined $href->{edns_details}{do} ) {
if ( defined $href->{edns_details} and defined $href->{edns_details}{do} ) {
$pkt->set_edns_present();
$pkt->do($href->{edns_details}{do});
}
if ( defined $href->{edns_details} and defined $href->{edns_details}{udp_size} ) {
if ( defined $href->{edns_details} and defined $href->{edns_details}{udp_size} ) {
$pkt->set_edns_present();
$pkt->edns_size($href->{edns_details}{udp_size});
}
if ( defined $href->{edns_details} and defined $href->{edns_details}{extended_rcode} ) {
if ( defined $href->{edns_details} and defined $href->{edns_details}{extended_rcode} ) {
$pkt->set_edns_present();
$pkt->edns_rcode($href->{edns_details}{extended_rcode});
}
if ( defined $href->{edns_details} and defined $href->{edns_details}{data} ) {
$pkt->set_edns_present();
$pkt->edns_data($href->{edns_details}{data});
}
$res = eval { $self->dns->query_with_pkt( $pkt ) };
}
else {
$res = eval { $self->dns->query( "$name", $type, $href->{class} ) };

if ( Zonemaster::Engine::Profile->effective->get( q{nsid} ) ) {
eval { $pkt->nsid; };
}

$res = eval { $self->dns->query_with_pkt( $pkt ) };

if ( $@ ) {
my $msg = "$@";
my $trailing_info = " at ".__FILE__;
Expand Down Expand Up @@ -530,6 +538,9 @@ sub _query {
sub string {
my ( $self ) = @_;

if ( defined $self->nsid ) {
return $self->name->string . q{/} . $self->address->short . q{/} . $self->nsid;
}
return $self->name->string . q{/} . $self->address->short;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Zonemaster/Engine/Packet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ has 'packet' => (
rcode
aa
ra
tc
tc
question
answer
authority
Expand All @@ -39,6 +39,7 @@ has 'packet' => (
querytime
do
opcode
get_nsid
)
]
);
Expand Down
7 changes: 7 additions & 0 deletions lib/Zonemaster/Engine/Profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ my %profile_properties_details = (
q{no_network} => {
type => q{Bool}
},
q{nsid} => {
type => q{Bool}
},
q{asnroots} => {
type => q{ArrayRef},
test => sub {
Expand Down Expand Up @@ -647,6 +650,10 @@ A boolean. If true, network traffic is forbidden. Default false.
Use when you want to be sure that any data is only taken from a preloaded
cache.

=head2 nsid

A boolean. If true, sets the EDNS option NSID in queries. Default false.

=head2 asnroots (DEPRECATED)

An arrayref of domain names. Default C<["asnlookup.zonemaster.net",
Expand Down
1 change: 1 addition & 0 deletions lib/Zonemaster/Engine/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ BEGIN {
sub _log_versions {
info( GLOBAL_VERSION => { version => Zonemaster::Engine->VERSION } );

info( DEPENDENCY_VERSION => { name => 'libldns', version => Zonemaster::LDNS::lib_version() } );
info( DEPENDENCY_VERSION => { name => 'Zonemaster::LDNS', version => $Zonemaster::LDNS::VERSION } );
info( DEPENDENCY_VERSION => { name => 'IO::Socket::INET6', version => $IO::Socket::INET6::VERSION } );
info( DEPENDENCY_VERSION => { name => 'Moose', version => $Moose::VERSION } );
Expand Down
1 change: 1 addition & 0 deletions share/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ipv6" : true
},
"no_network" : false,
"nsid": true,
"resolver" : {
"defaults" : {
"debug" : false,
Expand Down