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