Changeset 192 for branches/stable/cgi-bin/consistency-check.pl
- Timestamp:
- 03/10/05 14:15:19 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/cgi-bin/consistency-check.pl
r168 r192 17 17 initIPDBGlobals($dbh); 18 18 19 print " First check: All blocks must be within one of the master blocks\n";19 print "Checking master containment...\n"; 20 20 21 21 # First check - make sure ALL routes and allocated blocks are part 22 22 # of one of the master blocks. 23 print " Checking routed blocks:";23 print " Checking routed blocks:"; 24 24 $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 = ''; 27 27 ROUTED: while (@data = $sth->fetchrow_array) { 28 28 $cidr = new NetAddr::IP $data[0]; … … 30 30 if ($master->contains($cidr)) { next ROUTED; } 31 31 } 32 print " $cidr not mastered\n";33 } 34 print " done.\n";32 print "\n $cidr not mastered"; 33 } 34 print "$flag done.\n"; 35 35 36 36 # Next test: All allocations must be part of a master. 37 print " Checking allocations:";37 print " Checking allocations:"; 38 38 $sth = $dbh->prepare("select cidr from allocations"); 39 39 $sth->execute; 40 $flag = ''; 40 41 ALLOCATED: while (@data = $sth->fetchrow_array) { 41 42 $cidr = new NetAddr::IP $data[0]; … … 43 44 if ($master->contains($cidr)) { next ALLOCATED; } 44 45 } 45 print "$cidr not mastered\n"; 46 } 47 print " done.\n"; 46 print "\n $cidr not mastered"; 47 $flag = "\n "; 48 } 49 print "$flag done.\n"; 48 50 49 51 # Next: free blocks 50 print " Checking freeblocks:";52 print " Checking freeblocks:"; 51 53 $sth = $dbh->prepare("select cidr from freeblocks order by cidr"); 52 54 $sth->execute; 55 $flag = ''; 53 56 FREEBLOCK: while (@data = $sth->fetchrow_array) { 54 57 $cidr = new NetAddr::IP $data[0]; … … 56 59 if ($master->contains($cidr)) { next FREEBLOCK; } 57 60 } 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 } 64 print "$flag done.\n"; 65 66 print "Done checking master containment.\n\n"; 67 68 print "Checking pool containment...\n"; 63 69 64 70 $sth = $dbh->prepare("select pool,ip from poolips order by ip"); … … 67 73 $pool = new NetAddr::IP $data[0]; 68 74 $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" 70 76 if !$pool->contains($ip); 71 77 } … … 75 81 $sth2 = $dbh->prepare("select cidr from allocations where cidr='$data[0]'"); 76 82 $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" 78 84 if (($sth2->fetchrow_array)[0] eq ''); 79 85 } 80 86 81 print "Done checking pool containment.\n\nChecking block-alignment consistency:\n"; 87 print "Done checking pool containment.\n\n"; 88 89 print "Checking block-alignment consistency...\n"; 82 90 83 91 # Block alignment consistency: All allocated+free blocks within a master … … 95 103 96 104 foreach $master (@masterblocks) { 97 print " Master $master:\n";105 print " Master $master:\n"; 98 106 $prev = $master; 99 107 $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"); 103 111 $sth->execute; 104 112 … … 109 117 # check if cur starts with master 110 118 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"; 112 120 } 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"; 114 122 } 115 123 } else { 116 124 if ($cur->numeric < ($prev->numeric + 1)) { 117 print " Block ".$prev->network." overlaps block $cur\n";125 print " Block ".$prev->network." overlaps block $cur\n"; 118 126 } 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"; 120 128 } 121 129 } … … 129 137 $master--; 130 138 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 144 print "Done checking block alignment.\n\n"; 145 146 print "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; 153 while (@data = $sth->fetchrow_array) { 154 $containers[$i++] = new NetAddr::IP $data[0]; 155 } 156 print " Checking general containment:"; 157 $sth = $dbh->prepare("select cidr from allocations where type like '_r' order by cidr"); 158 $sth->execute; 159 $flag = ''; 160 CONTAINED: 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 } 168 print "$flag done.\n"; 169 print " Checking alignment:\n"; 170 foreach $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 } 210 print " done container alignment.\n"; 211 print "Done checking container containment.\n\n"; 212 213 print "Checking for correctness on 'defined' CustIDs:\n"; 137 214 # New check: Make sure "defined" CustIDs are correct. 138 215 $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.