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/IPDB.pm

    r185 r192  
    234234      eval {
    235235        $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'";
    236         if ($type eq 'rr') {
     236        if ($type eq 'rm') {
    237237          $sth = $dbh->prepare("update freeblocks set routed='y',city='$city'".
    238238            " where cidr='$cidr'");
     
    243243        } else {
    244244          # common stuff for end-use, dialup, dynDSL, pools, etc, etc.
    245           $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'");
    246           $sth->execute;
    247 
     245
     246          # special case - block is a container/"reserve" block
     247          if ($type =~ /^(.)c$/) {
     248            $sth = $dbh->prepare("update freeblocks set routed='$1' where cidr='$cidr'");
     249            $sth->execute;
     250          } else {
     251            # "normal" case
     252            $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'");
     253            $sth->execute;
     254          }
    248255          $sth = $dbh->prepare("insert into allocations".
    249256                " (cidr,custid,type,city,description,notes,maskbits,circuitid)".
     
    305312
    306313        # now we have to do some magic for routing blocks
    307         if ($type eq 'rr') {
     314        if ($type eq 'rm') {
    308315
    309316          # Insert the new freeblocks entries
     
    325332          $sth->execute;
    326333
    327         } else { # done with alloctype == rr
     334        } else { # done with alloctype == rm
    328335
    329336          # Insert the new freeblocks entries
     337          # Along with some more HairyPerl(TM) in case we're inserting a
     338          # subblock (.r) allocation
    330339          $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    331                 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'y')");
     340                " values (?, ?, (select city from routed where cidr >>= '$cidr'),'".
     341                (($type =~ /^(.)r$/) ? "$1" : 'y')."')");
    332342          foreach my $block (@newfreeblocks) {
    333343            $sth->execute("$block", $block->masklen);
    334344          }
    335 
     345          # Special-case for reserve/"container" blocks - generate
     346          # the "extra" freeblocks entry for the container
     347          if ($type =~ /^(.)c$/) {
     348            $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
     349                " values ('$cidr',".$cidr->masklen.",'$city','$1')");
     350            $sth->execute;
     351          }
    336352          # Insert the allocations entry
    337353          $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,".
     
    354370          }
    355371
    356         } # done with netblock alloctype != rr
     372        } # done with netblock alloctype != rm
    357373
    358374        $dbh->commit;
     
    485501    eval {
    486502
    487       if ($type eq 'rr') {
     503      if ($type eq 'rm') {
    488504        $msg = "Unable to remove routing allocation $cidr";
    489505        $sth = $dbh->prepare("delete from routed where cidr='$cidr'");
     
    499515      } else { # end alloctype routing case
    500516
    501         $sth = $dbh->prepare("delete from allocations where cidr='$cidr'");
     517        # Delete all allocations within the block being deleted.  This is
     518        # deliberate and correct, and removes the need to special-case
     519        # removal of "container" blocks.
     520        $sth = $dbh->prepare("delete from allocations where cidr <<='$cidr'");
    502521        $sth->execute;
     522
    503523        # Special case - delete pool IPs
    504524        if ($type =~ /^.[pd]$/) {
     
    511531        $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ".
    512532                "(select cidr from routed where cidr >>= '$cidr') ".
    513                 " and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc");
     533                " and maskbits<=".$cidr->masklen.
     534                " and routed='".(($type =~ /^(.)r$/) ? '$1' : 'y').
     535                "' order by maskbits desc");
    514536
    515537      } # end alloctype general case
     
    562584      }
    563585
    564       # Clear old freeblocks entries - if any.  $i==0 if not.
    565       if ($i>0) {
    566         $sth = $dbh->prepare("delete from freeblocks where cidr=?");
    567         foreach my $block (@combinelist) {
    568           $sth->execute("$block");
    569         }
    570       }
     586      # Clear old freeblocks entries - if any.  They should all be within
     587      # the $cidr determined above.
     588      $sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'");
     589      $sth->execute;
    571590
    572591      # insert "new" freeblocks entry
    573       if ($type eq 'rr') {
     592      if ($type eq 'rm') {
    574593        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)".
    575594                " values ('$cidr',".$cidr->masklen.",'<NULL>')");
     
    577596        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    578597                " values ('$cidr',".$cidr->masklen.
    579                 ",(select city from routed where cidr >>= '$cidr'),'y')");
     598                ",(select city from routed where cidr >>= '$cidr'),'".
     599                (($type =~ /^(.)r$/) ? "$1" : 'y')."')");
    580600      }
    581601      $sth->execute;
Note: See TracChangeset for help on using the changeset viewer.