Skip to content
Open
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
13 changes: 8 additions & 5 deletions examples/astool
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ unless ($inasn) {
}

my $asn = Net::ASN->new($inasn,$asasdot);
print "type : " . $asn->gettype . "\n";
print "asplain16: " . $asn->toasplain16 . "\n";
print "asplain32: " . $asn->toasplain . "\n";
print "asdot : " . $asn->toasdot . "\n";
print "asdotplus: " . $asn->toasdotplus . "\n";
print "type : " . $asn->gettype . "\n";
print "asplain16 : " . $asn->toasplain16 . "\n";
print "asplain32 : " . $asn->toasplain . "\n";
print "asdot : " . $asn->toasdot . "\n";
print "asdotplus : " . $asn->toasdotplus . "\n";
print "isprivate : " . $asn->isprivate . "\n";
print "isreserved : " . $asn->isreserved . "\n";

print "\n";
63 changes: 50 additions & 13 deletions lib/Net/ASN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ BEGIN {
@EXPORT = qw();

%EXPORT_TAGS = (
all => [qw{
all => [qw{
plaintodot plaintodotplus
dottodotplus dottoplain
dottoplain16 dotplustodot
dotplustoplain dotplustoplain16
isprivateasn
isprivateasn isreservedasn
} ],
);

Expand Down Expand Up @@ -69,7 +69,7 @@ sub new {

$self->_parseasn($asn,$asasdot); #Parse the ASN

return $self;
return $self;

}

Expand Down Expand Up @@ -120,7 +120,7 @@ sub _parseasn ($;$) {
my $secondasn = $2;

unless (
($firstasn >= 0 && $firstasn <= AS16_END) &&
($firstasn >= 0 && $firstasn <= AS16_END) &&
($secondasn >= 0 && $secondasn <= AS16_END) &&
(
($firstasn > 0) ||
Expand Down Expand Up @@ -155,7 +155,7 @@ sub _parseasn ($;$) {
}

sub _plaintodot ($) {

my $self = shift;
my $asplain = shift;

Expand Down Expand Up @@ -202,7 +202,7 @@ sub toasdot () {
}

}
elsif ($self->{_informat} eq 'asdotplus') { #User wants asdot and has given us asdotplus, so return asplain if
elsif ($self->{_informat} eq 'asdotplus') { #User wants asdot and has given us asdotplus, so return asplain if
if ($self->{_asdotsedtet1} == 0) { #If first sedtet is 0, return the second only
return ($self->{_asdotsedtet2});
}
Expand Down Expand Up @@ -343,7 +343,20 @@ sub isprivate {
return 1;
}
return 0;
}
}

##RFC 7300 Reservation of Last Autonomous System (AS) Numbers
##RFC 4893 reserves 23456 for AS_TRANS
sub isreserved {
my $self = shift;
my $asn = $self->toasplain;
if ( $asn == AS16_END ||
$asn == AS32_END ||
$asn == AS_TRANS ) {
return 1;
}
return 0;
}

###NON OO Function wrappers
##toasdot
Expand Down Expand Up @@ -416,6 +429,14 @@ sub isprivateasn ($) {
return ($asn->isprivate);
}

##isreserved
sub isreservedasn ($) {
my $inasn = shift;
croak __PACKAGE__, ": No ASN specified" unless ($inasn);
my $asn = Net::ASN->new($inasn) || croak __PACKAGE__, ": Could not create new Net::ASN object";
return ($asn->isreserved);
}

1;
__END__
=pod
Expand Down Expand Up @@ -454,8 +475,8 @@ Net::ASN - Perl extension for manipulating autonomous system numbers

=head1 DESCRIPTION

Net::ASN provides functions for parsing autonomous system numbers
(ASNs) as defined in RFC 1771 and extended by RFC4893, also
Net::ASN provides functions for parsing autonomous system numbers
(ASNs) as defined in RFC 1771 and extended by RFC4893, also
converting between formats discussed in RFC5396.

Both an OO implementation (method based) and non-OO (function based)
Expand Down Expand Up @@ -494,7 +515,7 @@ Returns the ASPLAIN representation of the parsed ASN
Returns the ASPLAIN representation of the parsed ASN if the ASPLAIN
representation is is less than or equal to 65535, else returns AS_TRANS

Use for compabability with 16 bit ASN systems.
Use for compatibility with 16 bit ASN systems.

=item toasdot

Expand All @@ -516,7 +537,15 @@ Returns the ASDOT+ representation of the parsed ASN.

Returns 1 if the number falls within the private reserved ranges according to
RFC6996, 0 otherwise. Will accept any format that L<Net::ASN> can convert to
ASPLAIN
ASPLAIN

=item isreserved

my $isreserved = $asn->isreservedasn;

Returns 1 if the number falls within the reserved ASN numbers according to
RFC7300 and RFC4893, 0 otherwise. Will accept any format that L<Net::ASN> can
convert to ASPLAIN

=back

Expand Down Expand Up @@ -591,7 +620,15 @@ representation is is less than or equal to 65535, else returns AS_TRANS

Returns 1 if the number falls within the private reserved ranges according to
RFC6996, 0 otherwise. Will accept any format that L<Net::ASN> can convert to
ASPLAIN
ASPLAIN

=item isreservedasn

my $isreservedasn = isreservedasn($asn);

Returns 1 if the number falls within the reserved ASN numbers according to
RFC7300 and RFC4893, 0 otherwise. Will accept any format that L<Net::ASN> can
convert to ASPLAIN

=back

Expand All @@ -611,7 +648,7 @@ it under the terms as perl itself.

=head1 REPOSITORY

L<https://github.com/lochiiconnectivity/netasn.git
L<https://github.com/lochiiconnectivity/netasn.git>

perl(1)

Expand Down
13 changes: 12 additions & 1 deletion t/asn.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl
use Net::ASN qw(:all);
use Test::More tests =>74;
use Test::More tests =>83;

##OO tests
print "Starting OO Tests..\n";
Expand Down Expand Up @@ -68,6 +68,13 @@ is( $public_asn16->isprivate , 0 ,'16 bit ASN corre
ok( $public_asn32 = Net::ASN->new(4199999999) , 'public 32 bit ASN' );
is( $public_asn32->isprivate , 0 ,'32 bit ASN corrected marked as private' );

ok( $reserved_asn16 = Net::ASN->new(23456), 'AS_TRANS ASN' );
is( $reserved_asn16->isreserved , 1 ,'AS_TRANS corrected marked as reserved' );
ok( $reserved_asn16 = Net::ASN->new(65535), 'last 16 bit ASN' );
is( $reserved_asn16->isreserved , 1 ,'last 16 bit ASN corrected marked as reserved' );
ok( $reserved_asn32 = Net::ASN->new(4294967295), 'last 32 bit ASN' );
is( $reserved_asn32->isreserved , 1 ,'last 32 bit ASN corrected marked as reserved' );

##Non-OO Tests
print "Starting non-OO tests..\n";

Expand All @@ -92,3 +99,7 @@ is( isprivateasn(64512) , 1, 'isprivateasn reports private for 16 bit ASN' )
is( isprivateasn(4200000000), 1, 'isprivateasn reports private for 32 bit ASN' );
is( isprivateasn(64511) , 0, 'isprivateasn reports public for 16 bit ASN' );
is( isprivateasn(4199999999), 0, 'isprivateasn reports public for 32 bit ASN' );

is( isreservedasn(23456) , 1, 'isreservedasn reports reserved for 16 bit AS_TRANS' );
is( isreservedasn(65535) , 1, 'isreservedasn reports reserved for last 16 bit ASN' );
is( isreservedasn(4294967295), 1, 'isreservedasn reports reserved for last 32 bit ASN' );