Changeset 349


Ignore:
Timestamp:
10/06/06 12:20:42 (18 years ago)
Author:
Kris Deugau
Message:

/trunk

Backport bugfixery from /branches/stable r336

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r320 r349  
    193193  my $sth;
    194194
     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
    195200  # To contain the error message, if any.
    196201  my $msg = "Unknown error allocating $cidr as '$type'";
     
    344349
    345350          # 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...
    348359          $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    349360                " values (?, ?, (select city from routed where cidr >>= '$cidr'),'".
    350                 (($type =~ /^(.)r$/) ? "$1" : 'y')."')");
     361                ( ( ($alloc_from_type =~ /^(p)$/) || ($type =~ /^(.)r$/) ) ? "$1" : 'y')."')");
    351362          foreach my $block (@newfreeblocks) {
    352363            $sth->execute("$block", $block->masklen);
     
    463474  my $sth;
    464475
     476  # Magic variables used for odd allocation cases.
     477  my $container;
     478  my $con_type;
     479
    465480  # To contain the error message, if any.
    466481  my $msg = "Unknown error deallocating $type $cidr";
     
    529544      } else { # end alloctype routing case
    530545
     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
    531552        # Delete all allocations within the block being deleted.  This is
    532553        # deliberate and correct, and removes the need to special-case
     
    543564
    544565        # 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 <<= ".
    546574                "(select cidr from routed where cidr >>= '$cidr') ".
    547575                " and maskbits<=".$cidr->masklen.
    548576                " and routed='".(($type =~ /^(.)r$/) ? '$1' : 'y').
    549577                "' order by maskbits desc");
     578        }
    550579
    551580      } # end alloctype general case
     
    588617                " values ('$cidr',".$cidr->masklen.",'<NULL>')");
    589618      } 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
    590623        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    591624                " values ('$cidr',".$cidr->masklen.
Note: See TracChangeset for help on using the changeset viewer.