Ignore:
Timestamp:
03/10/05 14:15:19 (19 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge updates and changes (and bugfixes to same) from /trunk
r186,187 and r189-191

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/cgi-bin/consistency-check.pl

    r168 r192  
    1717initIPDBGlobals($dbh);
    1818
    19 print "First check:  All blocks must be within one of the master blocks\n";
     19print "Checking master containment...\n";
    2020
    2121# First check - make sure ALL routes and allocated blocks are part
    2222# of one of the master blocks.
    23 print "Checking routed blocks: ";
     23print "  Checking routed blocks:";
    2424$sth = $dbh->prepare("select cidr from routed");
    25 # union select cidr from allocations union select cidr from freeblocks");
    26 $sth->execute;
     25$sth->execute;
     26$flag = '';
    2727ROUTED: while (@data = $sth->fetchrow_array) {
    2828  $cidr = new NetAddr::IP $data[0];
     
    3030    if ($master->contains($cidr)) { next ROUTED; }
    3131  }
    32   print "$cidr not mastered\n";
    33 }
    34 print " done.\n";
     32  print "\n    $cidr not mastered";
     33}
     34print "$flag done.\n";
    3535
    3636# Next test:  All allocations must be part of a master.
    37 print "Checking allocations: ";
     37print "  Checking allocations:";
    3838$sth = $dbh->prepare("select cidr from allocations");
    3939$sth->execute;
     40$flag = '';
    4041ALLOCATED: while (@data = $sth->fetchrow_array) {
    4142  $cidr = new NetAddr::IP $data[0];
     
    4344    if ($master->contains($cidr)) { next ALLOCATED; }
    4445  }
    45   print "$cidr not mastered\n";
    46 }
    47 print " done.\n";
     46  print "\n    $cidr not mastered";
     47  $flag = "\n ";
     48}
     49print "$flag done.\n";
    4850
    4951# Next:  free blocks
    50 print "Checking freeblocks: ";
     52print "  Checking freeblocks:";
    5153$sth = $dbh->prepare("select cidr from freeblocks order by cidr");
    5254$sth->execute;
     55$flag = '';
    5356FREEBLOCK: while (@data = $sth->fetchrow_array) {
    5457  $cidr = new NetAddr::IP $data[0];
     
    5659    if ($master->contains($cidr)) { next FREEBLOCK; }
    5760  }
    58   print "$cidr not mastered\n";
    59 }
    60 print " done.\n";
    61 
    62 print "Done checking master containment.\n\nChecking pool containment:\n";
     61  print "\n    $cidr not mastered";
     62  $flag = "\n ";
     63}
     64print "$flag done.\n";
     65
     66print "Done checking master containment.\n\n";
     67
     68print "Checking pool containment...\n";
    6369
    6470$sth = $dbh->prepare("select pool,ip from poolips order by ip");
     
    6773  $pool = new NetAddr::IP $data[0];
    6874  $ip = new NetAddr::IP $data[1];
    69   print "IP $ip listed with incorrect pool $pool\n"
     75  print "  IP $ip listed with incorrect pool $pool\n"
    7076    if !$pool->contains($ip);
    7177}
     
    7581  $sth2 = $dbh->prepare("select cidr from allocations where cidr='$data[0]'");
    7682  $sth2->execute;
    77   print "Pool $data[0] does not exist in allocations table\n"
     83  print "  Pool $data[0] does not exist in allocations table\n"
    7884    if (($sth2->fetchrow_array)[0] eq '');
    7985}
    8086
    81 print "Done checking pool containment.\n\nChecking block-alignment consistency:\n";
     87print "Done checking pool containment.\n\n";
     88
     89print "Checking block-alignment consistency...\n";
    8290
    8391# Block alignment consistency:  All allocated+free blocks within a master
     
    95103
    96104foreach $master (@masterblocks) {
    97   print "Master $master:\n";
     105  print "  Master $master:\n";
    98106  $prev = $master;
    99107  $sth = $dbh->prepare("(select network(cidr) as net, broadcast(cidr) as bcast ".
    100         " from allocations where cidr <<= '$master') union ".
    101         "(select network(cidr) as net, broadcast(cidr) as bcast ".
    102         "from freeblocks where cidr <<= '$master') order by net");
     108        "from allocations where cidr <<= '$master' and type not like '_c') ".
     109        "union (select network(cidr) as net, broadcast(cidr) as bcast ".
     110        "from freeblocks where cidr <<= '$master' and not (routed='c')) order by net");
    103111  $sth->execute;
    104112
     
    109117      # check if cur starts with master
    110118      if ($cur->numeric > $prev->numeric) {
    111         print " Gap from start of master $master to first block $cur\n";
     119        print "    Gap from start of master $master to first block $cur\n";
    112120      } elsif ($cur->numeric < $prev->numeric) {
    113         print " BIG problem!  Current block $cur begins before master $master!\n";
     121        print "    BIG problem!  Current block $cur begins before master $master!\n";
    114122      }
    115123    } else {
    116124      if ($cur->numeric < ($prev->numeric + 1)) {
    117         print " Block ".$prev->network." overlaps block $cur\n";
     125        print "    Block ".$prev->network." overlaps block $cur\n";
    118126      } elsif ($cur->numeric > ($prev->numeric + 1)) {
    119         print " Gap between end of block ".$prev->network." and block $cur\n";
     127        print "    Gap between end of block ".$prev->network." and block $cur\n";
    120128      }
    121129    }
     
    129137  $master--;
    130138  if ($cur->numeric ne $master->numeric) {
    131     print " Gap from $cur to end of master at $master\n";
    132   }
    133   print "done $master.\n";
    134 }
    135 
    136 print "Done checking block alignment.\n\nChecking for correctness on 'defined' CustIDs:\n";
     139    print "    Gap from $cur to end of master at $master\n";
     140  }
     141  print "  done $master.\n";
     142}
     143
     144print "Done checking block alignment.\n\n";
     145
     146print "Checking containment on container blocks...\n";
     147# First, we need a list of containers.
     148# Then, we check all of the contained blocks to see if they're within
     149# the proper container.
     150$sth = $dbh->prepare("select cidr from allocations where type like '_c' order by cidr");
     151$sth->execute;
     152$i=0;
     153while (@data = $sth->fetchrow_array) {
     154  $containers[$i++] = new NetAddr::IP $data[0];
     155}
     156print "  Checking general containment:";
     157$sth = $dbh->prepare("select cidr from allocations where type like '_r' order by cidr");
     158$sth->execute;
     159$flag = '';
     160CONTAINED: while (@data = $sth->fetchrow_array) {
     161  $cidr = new NetAddr::IP $data[0];
     162  foreach $container (@containers) {
     163    next CONTAINED if $container->contains($cidr);
     164  }
     165  print "\n    $cidr not contained";
     166  $flag = "\n ";
     167}
     168print "$flag done.\n";
     169print "  Checking alignment:\n";
     170foreach $container (@containers) {
     171  print "    Container $container:\n";
     172  $prev = $container;
     173  $sth = $dbh->prepare("(select network(cidr) as net, broadcast(cidr) as bcast ".
     174        "from allocations where cidr <<= '$container' and type like '_r') ".
     175        "union (select network(cidr) as net, broadcast(cidr) as bcast ".
     176        "from freeblocks where cidr <<= '$container' and routed='w') order by net");
     177    $sth->execute;
     178
     179  while (@data = $sth->fetchrow_array) {
     180    $cur = new NetAddr::IP $data[0];
     181
     182    if ($container->numeric == $prev->numeric) {
     183      # check if cur starts with master
     184      if ($cur->numeric > $prev->numeric) {
     185        print "      Gap from start of container $container to first block $cur\n";
     186      } elsif ($cur->numeric < $prev->numeric) {
     187        print "      BIG problem!  Current block $cur begins before container $container!\n";
     188      }
     189    } else {
     190      if ($cur->numeric < ($prev->numeric + 1)) {
     191        print "      Block ".$prev->network." overlaps block $cur\n";
     192      } elsif ($cur->numeric > ($prev->numeric + 1)) {
     193        print "      Gap between end of block ".$prev->network." and block $cur\n";
     194      }
     195    }
     196
     197    $prev = $cur;
     198    $prev--;
     199
     200  } # while (@data...)
     201
     202  $cur--;
     203  $container--;
     204  if ($cur->numeric ne $container->numeric) {
     205    print "      Gap from $cur to end of container at $container\n";
     206  }
     207  print "    done $container.\n";
     208
     209}
     210print "  done container alignment.\n";
     211print "Done checking container containment.\n\n";
     212
     213print "Checking for correctness on 'defined' CustIDs:\n";
    137214# New check:  Make sure "defined" CustIDs are correct.
    138215$sth = $dbh->prepare("select cidr,type,custid from allocations where not type='cn' order by cidr");
Note: See TracChangeset for help on using the changeset viewer.