Changeset 186 for trunk/cgi-bin/IPDB.pm


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

/trunk

First round of changes for "clean" handling of subblock allocations.
Note that the code will likely malfunction in a number of corner
and not-so-corner cases. Fixing those will require rethinking of
the allocation types.

File:
1 edited

Legend:

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

    r184 r186  
    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 - alloctype begins with 'r'
     247          if ($type =~ /^r.$/) {
     248            $sth = $dbh->prepare("update freeblocks set routed='r' 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)".
     
    328335
    329336          # Insert the new freeblocks entries
     337          # Along with some more HairyPerl(TM) in case we're inserting a
     338          # subblock (l.) 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 =~ /^l.$/) ? 'r' : 'y')."')");
    332342          foreach my $block (@newfreeblocks) {
    333343            $sth->execute("$block", $block->masklen);
    334344          }
    335 
     345          # special-case for reserve/"container" blocks
     346          if ($type =~ /^r.$/) {
     347            $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
     348                " values ('$cidr',".$cidr->masklen.",'$city','r')");
     349            $sth->execute;
     350          }
    336351          # Insert the allocations entry
    337352          $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,".
     
    499514      } else { # end alloctype routing case
    500515
    501         $sth = $dbh->prepare("delete from allocations where cidr='$cidr'");
     516        # Delete all allocations within the block being deleted.  This is
     517        # deliberate and correct, and removes the need to special-case
     518        # removal of "container" blocks.
     519        $sth = $dbh->prepare("delete from allocations where cidr <<='$cidr'");
    502520        $sth->execute;
     521
    503522        # Special case - delete pool IPs
    504523        if ($type =~ /^.[pd]$/) {
     
    511530        $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ".
    512531                "(select cidr from routed where cidr >>= '$cidr') ".
    513                 " and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc");
     532                " and maskbits<=".$cidr->masklen.
     533                " and routed='".(($type =~ /^l.$/) ? 'r' : 'y').
     534                "' order by maskbits desc");
    514535
    515536      } # end alloctype general case
     
    542563      }
    543564
    544       # Clear old freeblocks entries - if any.  $i==0 if not.
    545       if ($i>0) {
    546         $sth = $dbh->prepare("delete from freeblocks where cidr=?");
    547         foreach my $block (@combinelist) {
    548           $sth->execute("$block");
    549         }
    550       }
     565      # Clear old freeblocks entries - if any.  They should all be within
     566      # the $cidr determined above.
     567      $sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'");
     568      $sth->execute;
    551569
    552570      # insert "new" freeblocks entry
     
    557575        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    558576                " values ('$cidr',".$cidr->masklen.
    559                 ",(select city from routed where cidr >>= '$cidr'),'y')");
     577                ",(select city from routed where cidr >>= '$cidr'),'".
     578                (($type =~ /^l.$/) ? 'r' : 'y')."')");
    560579      }
    561580      $sth->execute;
Note: See TracChangeset for help on using the changeset viewer.