1 | #!/usr/bin/perl
|
---|
2 | # ipdb/cgi-bin/combineblocks.pl
|
---|
3 | # Quick hack to clean up mangled deallocations
|
---|
4 | ###
|
---|
5 | # Revision info
|
---|
6 | # $Date: 2017-08-15 17:53:23 +0000 (Tue, 15 Aug 2017) $
|
---|
7 | # SVN revision $Rev: 906 $
|
---|
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 |
|
---|
18 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
19 | ##uselib##
|
---|
20 |
|
---|
21 | # push "the directory the script is in" into @INC
|
---|
22 | use FindBin;
|
---|
23 | use lib "$FindBin::RealBin/";
|
---|
24 |
|
---|
25 | use MyIPDB;
|
---|
26 |
|
---|
27 | my $null = new NetAddr::IP "255.255.255.255/32";
|
---|
28 |
|
---|
29 | my @fbtypes;
|
---|
30 |
|
---|
31 | my ($dbh,$ret) = connectDB_My;
|
---|
32 | initIPDBGlobals($dbh);
|
---|
33 | my $sth;
|
---|
34 |
|
---|
35 | # Get the types of freeblocks
|
---|
36 | $sth = $dbh->prepare("select distinct routed from freeblocks");
|
---|
37 | $sth->execute;
|
---|
38 | while (my @data = $sth->fetchrow_array) {
|
---|
39 | push @fbtypes, @data;
|
---|
40 | }
|
---|
41 |
|
---|
42 | foreach my $type (@fbtypes) {
|
---|
43 |
|
---|
44 | my $i=0;
|
---|
45 | my @compacted;
|
---|
46 |
|
---|
47 | my $sth = $dbh->prepare("select cidr from freeblocks where routed='$type'");
|
---|
48 | $sth->execute;
|
---|
49 | while (my @data = $sth->fetchrow_array) {
|
---|
50 | my $temp = new NetAddr::IP $data[0];
|
---|
51 | @compacted = $temp->compact(@compacted);
|
---|
52 | $i++;
|
---|
53 | }
|
---|
54 |
|
---|
55 | #print $compacted[0];
|
---|
56 | my $numcomp = @compacted;
|
---|
57 | #print " $numcomp";
|
---|
58 |
|
---|
59 | if ($i == $numcomp) {
|
---|
60 | print "No compactable blocks for type $type ($i free)\n";
|
---|
61 | next;
|
---|
62 | }
|
---|
63 | print "Type $type: $i free blocks to start, $numcomp to finish\n";
|
---|
64 |
|
---|
65 | $sth = $dbh->prepare("select cidr from freeblocks where cidr << ?");
|
---|
66 | foreach my $cip (@compacted) {
|
---|
67 | $sth->execute("$cip");
|
---|
68 | if ($sth->rows > 0) {
|
---|
69 | print " $cip combines from:\n";
|
---|
70 | while (my @data = $sth->fetchrow_array) {
|
---|
71 | print " $data[0]\n";
|
---|
72 | }
|
---|
73 | # } else {
|
---|
74 | # print " $cip does not compact\n";
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | } # each @fbtype
|
---|
79 |
|
---|
80 | finish($dbh);
|
---|