Changeset 349 for trunk/cgi-bin
- Timestamp:
- 10/06/06 12:20:42 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r320 r349 193 193 my $sth; 194 194 195 # Snag the "type" of the freeblock (alloc_from) "just in case" 196 $sth = $dbh->prepare("select routed from freeblocks where cidr='$alloc_from'"); 197 $sth->execute; 198 my ($alloc_from_type) = $sth->fetchrow_array; 199 195 200 # To contain the error message, if any. 196 201 my $msg = "Unknown error allocating $cidr as '$type'"; … … 344 349 345 350 # Insert the new freeblocks entries 346 # Along with some more HairyPerl(TM) in case we're inserting a 347 # subblock (.r) allocation 351 # Along with some more HairyPerl(TM): 352 # if $alloc_type_from is p 353 # OR 354 # $type matches /^(.)r$/ 355 # inserted value for routed column should match. 356 # This solves the case of inserting an arbitrary block into a 357 # "Reserve-for-routed-DSL" block. Which you really shouldn't 358 # do in the first place, but anyway... 348 359 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 349 360 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'". 350 ( ($type =~ /^(.)r$/) ? "$1" : 'y')."')");361 ( ( ($alloc_from_type =~ /^(p)$/) || ($type =~ /^(.)r$/) ) ? "$1" : 'y')."')"); 351 362 foreach my $block (@newfreeblocks) { 352 363 $sth->execute("$block", $block->masklen); … … 463 474 my $sth; 464 475 476 # Magic variables used for odd allocation cases. 477 my $container; 478 my $con_type; 479 465 480 # To contain the error message, if any. 466 481 my $msg = "Unknown error deallocating $type $cidr"; … … 529 544 } else { # end alloctype routing case 530 545 546 # Magic. We need to get information about the containing block (if any) 547 # so as to make sure that the freeblocks we insert get the correct "type". 548 $sth = $dbh->prepare("select cidr,type from allocations where cidr >> '$cidr'"); 549 $sth->execute; 550 ($container, $con_type) = $sth->fetchrow_array; 551 531 552 # Delete all allocations within the block being deleted. This is 532 553 # deliberate and correct, and removes the need to special-case … … 543 564 544 565 # Set up query for compacting free blocks. 545 $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ". 566 if ($con_type && $con_type eq 'pc') { 567 # Clean up after "bad" allocations (blocks that are not formally 568 # contained which have nevertheless been allocated from a container block) 569 # We want to make certain that the freeblocks are properly "labelled" 570 $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= '$container'"); 571 } else { 572 # Standard deallocation. 573 $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ". 546 574 "(select cidr from routed where cidr >>= '$cidr') ". 547 575 " and maskbits<=".$cidr->masklen. 548 576 " and routed='".(($type =~ /^(.)r$/) ? '$1' : 'y'). 549 577 "' order by maskbits desc"); 578 } 550 579 551 580 } # end alloctype general case … … 588 617 " values ('$cidr',".$cidr->masklen.",'<NULL>')"); 589 618 } else { 619 # Magic hackery to insert "correct" data for deallocation of 620 # non-contained blocks allocated from within a container. 621 $type = 'pr' if $con_type && $con_type eq 'pc'; 622 590 623 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 591 624 " values ('$cidr',".$cidr->masklen.
Note:
See TracChangeset
for help on using the changeset viewer.