Changeset 572


Ignore:
Timestamp:
12/21/12 17:33:03 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Get-info-about-freeblocks cleanups

  • Update/tweak getPoolSelect() for rdepth and saner SQL
  • Update findAllocateFrom() for new table logic and structures
File:
1 edited

Legend:

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

    r565 r572  
    587587
    588588  my $plist = $dbh->selectall_arrayref(
    589         "SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool) AS poolcit, ".
    590         "poolips.pool AS poolblock, COUNT(*) AS poolfree FROM poolips,allocations ".
    591         "WHERE poolips.available='y' AND poolips.pool=allocations.cidr ".
    592         "AND allocations.city = ? AND poolips.type LIKE ? ".
    593         "GROUP BY pool", { Slice => {} }, ($pcity, $ptype) );
     589        "SELECT count(*) AS poolfree,p.pool AS poolblock, a.city AS poolcit, a.rdepth AS poolrdepth ".
     590        "FROM poolips p ".
     591        "JOIN allocations a ON p.pool=a.cidr ".
     592        "WHERE p.available='y' AND a.city = ? AND p.type LIKE ? ".
     593        "GROUP BY p.pool,a.city,a.rdepth",
     594        { Slice => {} }, ($pcity, $ptype) );
    594595  return $plist;
    595596} # end getPoolSelect()
     
    620621## Also populate a value list for the DBI call.
    621622
    622   my @vallist = ($maskbits, ($type eq 'rm' ? 'n' : ($type =~ /^(.)r$/ ? "$1" : 'y')) );
    623   my $sql = "SELECT cidr FROM freeblocks WHERE maskbits <= ? AND routed = ?";
     623  my @vallist = ($maskbits);
     624  my $sql = "SELECT cidr,rdepth FROM freeblocks WHERE masklen(cidr) <= ?";
     625
     626# cases, strict rules
     627# .c  ->  container type
     628#   requires a routing container, fbtype r
     629# .d  ->  DHCP/"normal-routing" static pool
     630#   requires a routing container, fbtype r
     631# .e  ->  Dynamic-assignment connectivity
     632#   requires a routing container, fbtype r
     633# .i  ->  error, can't allocate static IPs this way?
     634# mm  ->  error, master block
     635# rm  ->  routed block
     636#   requires master block, fbtype m
     637# .n  ->  Miscellaneous usage
     638#   requires a routing container, fbtype r
     639# .p  ->  PPP(oE) static pool
     640#   requires a routing container, fbtype r
     641# .r  ->  contained type
     642#   requires a matching container, fbtype $1
     643##fixme:  strict-or-not flag
     644
     645  if ($type =~ /^(.)r$/) {
     646    push @vallist, $1;
     647    $sql .= " AND routed = ?";
     648  } elsif ($type eq 'rm') {
     649    $sql .= " AND routed = 'm'";
     650  } else {
     651    $sql .= " AND routed = 'r'";
     652  }
    624653
    625654  # for PPP(oE) and container types, the POP city is the one attached to the pool.
     
    651680  $sql .= " ORDER BY maskbits DESC,cidr LIMIT 1";
    652681
    653   my ($fbfound) = $dbh->selectrow_array($sql, undef, @vallist);
    654   return $fbfound;
     682  my ($fbfound,$fbdepth) = $dbh->selectrow_array($sql, undef, @vallist);
     683  return $fbfound,$fbdepth;
    655684} # end findAllocateFrom()
    656685
Note: See TracChangeset for help on using the changeset viewer.