[306] | 1 | #!/usr/bin/perl
|
---|
| 2 | # ipdb/cgi-bin/combineblocks.pl
|
---|
| 3 | # Quick hack to clean up mangled deallocations
|
---|
| 4 | ###
|
---|
| 5 | # Revision info
|
---|
| 6 | # $Date: 2013-05-14 22:10:22 +0000 (Tue, 14 May 2013) $
|
---|
| 7 | # SVN revision $Rev: 593 $
|
---|
| 8 | # Last update by $Author: kdeugau $
|
---|
| 9 | ###
|
---|
| 10 |
|
---|
| 11 | use strict;
|
---|
| 12 | use warnings;
|
---|
| 13 | #use CGI::Carp qw(fatalsToBrowser);
|
---|
| 14 | use DBI;
|
---|
| 15 | #use POSIX qw(ceil);
|
---|
| 16 | use NetAddr::IP;
|
---|
| 17 |
|
---|
[445] | 18 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
| 19 | ##uselib##
|
---|
[306] | 20 |
|
---|
[445] | 21 | use MyIPDB;
|
---|
| 22 |
|
---|
[306] | 23 | my $null = new NetAddr::IP "255.255.255.255/32";
|
---|
| 24 |
|
---|
| 25 | my @fbtypes;
|
---|
| 26 |
|
---|
| 27 | my ($dbh,$ret) = connectDB_My;
|
---|
| 28 | initIPDBGlobals($dbh);
|
---|
| 29 | my $sth;
|
---|
| 30 |
|
---|
| 31 | # Get the types of freeblocks
|
---|
| 32 | $sth = $dbh->prepare("select distinct routed from freeblocks");
|
---|
| 33 | $sth->execute;
|
---|
| 34 | while (my @data = $sth->fetchrow_array) {
|
---|
| 35 | push @fbtypes, @data;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | foreach my $type (@fbtypes) {
|
---|
| 39 |
|
---|
| 40 | my $i=0;
|
---|
| 41 | my @compacted;
|
---|
| 42 |
|
---|
| 43 | my $sth = $dbh->prepare("select cidr from freeblocks where routed='$type'");
|
---|
| 44 | $sth->execute;
|
---|
| 45 | while (my @data = $sth->fetchrow_array) {
|
---|
| 46 | my $temp = new NetAddr::IP $data[0];
|
---|
| 47 | @compacted = $temp->compact(@compacted);
|
---|
| 48 | $i++;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | #print $compacted[0];
|
---|
| 52 | my $numcomp = @compacted;
|
---|
| 53 | #print " $numcomp";
|
---|
| 54 |
|
---|
| 55 | if ($i == $numcomp) {
|
---|
| 56 | print "No compactable blocks for type $type ($i free)\n";
|
---|
| 57 | next;
|
---|
| 58 | }
|
---|
| 59 | print "Type $type: $i free blocks to start, $numcomp to finish\n";
|
---|
| 60 |
|
---|
| 61 | $sth = $dbh->prepare("select cidr from freeblocks where cidr << ?");
|
---|
| 62 | foreach my $cip (@compacted) {
|
---|
| 63 | $sth->execute("$cip");
|
---|
| 64 | if ($sth->rows > 0) {
|
---|
| 65 | print " $cip combines from:\n";
|
---|
| 66 | while (my @data = $sth->fetchrow_array) {
|
---|
| 67 | print " $data[0]\n";
|
---|
| 68 | }
|
---|
| 69 | # } else {
|
---|
| 70 | # print " $cip does not compact\n";
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | } # each @fbtype
|
---|
| 75 |
|
---|
| 76 | finish($dbh);
|
---|