nanog mailing list archives

Re: CIDR cleanup


From: Tim Jackson <jackson.tim () gmail com>
Date: Thu, 1 Oct 2020 08:44:49 -0500

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use NetAddr::IP qw(Compact);

my @ips = ( '105.170.72.0/24', '105.170.73.0/24', '105.170.74.0/24' );

my @agged = aggregate(\@ips);

sub aggregate {
        my @naddr = map { NetAddr::IP->new($_) } @{$_[0]};
        my @output = Compact(@naddr);
        return @output;
}


On Thu, Oct 1, 2020 at 8:36 AM John Von Essen <john () essenz com> wrote:

Sorry if this is slightly off-topic, but I am writing some code for a
custom GeoDNS routemap. My starting data set is a raw list of /24 subnets,
no prefix aggregation has been done. In other words, its the entire BGP
routing table in /24 prefixes - tagged by Geo region. Each region is its
own txt file with a dump of /24’s. As a result, these lists are HUGE. I
want to aggregate the prefixes as much as possible to create a smaller
routemap.

So right now it looks like:

...
105.170.72.0/24 brs
105.170.73.0/24 brs
105.170.74.0/24 brs
105.170.75.0/24 brs
105.170.76.0/24 brs
105.170.77.0/24 brs
105.170.78.0/24 brs
105.170.79.0/24 brs
105.170.80.0/24 brs
105.170.81.0/24 brs
105.170.82.0/24 brs
105.170.83.0/24 brs
105.170.84.0/24 brs
…

and so on. Obviously, 105.170.72.0/24 thru 105.170.79.0/24 can be
aggregated to 105.170.72.0/21 and so on. I normally use Perl, does anyone
now if there is a perl module that will automatically do this prefix
aggregation? I tried to write my code to do this, and its not trivial, just
lookinh for a shortcurt. I did a breif glance at some CIDR related Perl
cpan modules, and nothing has jumped out.

Thanks
John





Current thread: