CIDR cleanup

Jon Meek meekjt at gmail.com
Thu Oct 1 13:55:20 UTC 2020


The Perl Net::Netmask module is also worth checking out. It may not be
better at aggregation but it does have other functions that could be
helpful. I use the shortest match address lookup functions of Net::Netmask
very heavily and have reproduced them in a R / C++ package.

Jon

On Thu, Oct 1, 2020 at 9:47 AM Tim Jackson <jackson.tim at gmail.com> wrote:

> #!/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 at 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
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nanog.org/pipermail/nanog/attachments/20201001/59188c48/attachment.html>


More information about the NANOG mailing list