Skip to content

Commit

Permalink
Make ASNLookup.pm use standard recursive DNS lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreenx committed Jul 18, 2023
1 parent 76b9dd9 commit 253b4da
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 355 deletions.
9 changes: 5 additions & 4 deletions lib/Zonemaster/Engine/ASNLookup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use warnings;
use version; our $VERSION = version->declare( "v1.0.11" );

use Zonemaster::Engine;
use Zonemaster::Engine::Util qw( name );
use Zonemaster::Engine::Nameserver;
use Zonemaster::Engine::Profile;

Expand Down Expand Up @@ -37,7 +38,7 @@ sub get_with_prefix {
else {
$db_style = Zonemaster::Engine::Profile->effective->get( q{asn_db.style} );
my %db_sources = %{ Zonemaster::Engine::Profile->effective->get( q{asn_db.sources} ) };
@db_sources = map { Zonemaster::Engine->zone( $_ ) } @{ $db_sources{ $db_style } };
@db_sources = map { name( $_ ) } @{ $db_sources{ $db_style } };
}
}

Expand Down Expand Up @@ -79,15 +80,15 @@ sub _cymru_asn_lookup {
my $reverse = $ip->reverse_ip;
my $db_source_nb = 0;
foreach my $db_source ( @db_sources ) {
my $domain = $db_source->name->string;
my $domain = $db_source->string;
my $pair = {
'in-addr.arpa.' => "origin.$domain",
'ip6.arpa.' => "origin6.$domain",
};
$db_source_nb++;
foreach my $root ( keys %{$pair} ) {
if ( $reverse =~ s/$root/$pair->{$root}/ix ) {
my $p = $db_source->query_persistent( $reverse, 'TXT' );
my $p = Zonemaster::Engine->recurse( $reverse, 'TXT' );
my @rr;
if ( $p ) {
@rr = $p->get_records( 'TXT' );
Expand Down Expand Up @@ -143,7 +144,7 @@ sub _ripe_asn_lookup {
my $db_source_nb = 0;
foreach my $db_source ( @db_sources ) {
$db_source_nb++;
my $socket = IO::Socket::INET->new( PeerAddr => $db_source->name->string,
my $socket = IO::Socket::INET->new( PeerAddr => $db_source->string,
PeerPort => q{43},
Proto => q{tcp} );
unless ( $socket ) {
Expand Down
125 changes: 62 additions & 63 deletions t/Test-connectivity.data

Large diffs are not rendered by default.

233 changes: 93 additions & 140 deletions t/Test-connectivity03.data

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions t/Test-connectivity03.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ $profile_test = Zonemaster::Engine::Profile->from_json( $json );
Zonemaster::Engine::Profile->effective->merge( $profile_test );

###
my $zone = Zonemaster::Engine->zone( q{001.tf} );
my $zone = Zonemaster::Engine->zone( q{zonemaster.net} );

zone_gives( $testcase, $zone, [qw{IPV4_ONE_ASN IPV6_ONE_ASN}] );
zone_gives_not( $testcase, $zone, [qw{EMPTY_ASN_SET ERROR_ASN_DATABASE IPV4_DIFFERENT_ASN IPV4_SAME_ASN IPV6_DIFFERENT_ASN IPV6_SAME_ASN}] );
zone_gives( $testcase, $zone, [qw{IPV4_DIFFERENT_ASN IPV6_DIFFERENT_ASN}] );
zone_gives_not( $testcase, $zone, [qw{EMPTY_ASN_SET ERROR_ASN_DATABASE IPV4_SAME_ASN IPV6_SAME_ASN IPV4_ONE_ASN IPV6_ONE_ASN}] );

$zone = Zonemaster::Engine->zone( q{zut-root.rd.nic.fr} );
zone_gives( $testcase, $zone, [qw{IPV4_ONE_ASN}] );
zone_gives_not( $testcase, $zone, [qw{EMPTY_ASN_SET ERROR_ASN_DATABASE IPV4_DIFFERENT_ASN IPV4_SAME_ASN IPV6_DIFFERENT_ASN IPV6_ONE_ASN IPV6_SAME_ASN}] );

TODO: {
my @missing = qw( EMPTY_ASN_SET ERROR_ASN_DATABASE IPV4_DIFFERENT_ASN IPV4_SAME_ASN IPV6_DIFFERENT_ASN IPV6_SAME_ASN );
my @missing = qw( EMPTY_ASN_SET ERROR_ASN_DATABASE IPV4_SAME_ASN IPV6_SAME_ASN IPV6_ONE_ASN);
local $TODO = "Need to find/create zones with those errors: ";
warn $TODO, "\n\t", join("\n\t", @missing), "\n";
}
Expand Down
Loading

0 comments on commit 253b4da

Please sign in to comment.