Changeset 533 for trunk/cgi-bin/IPDB.pm
- Timestamp:
- 10/31/12 15:47:53 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r532 r533 28 28 &addMaster 29 29 &listSummary &listMaster &listRBlock &listFree &listPool 30 &getTypeList &getPoolSelect 30 &getTypeList &getPoolSelect &findAllocateFrom 31 31 &getParent &getRoutedCity 32 32 &allocateBlock &updateBlock &deleteBlock &getBlockData … … 42 42 &addMaster 43 43 &listSummary &listMaster &listRBlock &listFree &listPool 44 &getTypeList &getPoolSelect 44 &getTypeList &getPoolSelect &findAllocateFrom 45 45 &getParent &getRoutedCity 46 46 &allocateBlock &updateBlock &deleteBlock &getBlockData … … 501 501 ## IPDB::getPoolSelect() 502 502 # Get a list of pools matching the passed city and type that have 1 or more free IPs 503 # Returns an arrayref to a list of hashrefs 503 504 sub getPoolSelect { 504 505 my $dbh = shift; … … 518 519 return $plist; 519 520 } # end getPoolSelect() 521 522 523 ## IPDB::findAllocateFrom() 524 # Find free block to add a new allocation from. (CIDR block version of pool select above, more or less) 525 # Takes 526 # - mask length 527 # - allocation type 528 # - POP city "parent" 529 # - optional master-block restriction 530 # - optional flag to allow automatic pick-from-private-network-ranges 531 # Returns a string with the first CIDR block matching the criteria, if any 532 sub findAllocateFrom { 533 my $dbh = shift; 534 my $maskbits = shift; 535 my $type = shift; 536 my $city = shift; 537 my $pop = shift; 538 my %optargs = @_; 539 540 my $failmsg = "No suitable free block found\n"; 541 542 ## Set up the SQL to find out what freeblock we can (probably) use for an allocation. 543 ## Very large systems will require development of a reserve system (possibly an extension 544 ## of the reserve-for-expansion concept in https://secure.deepnet.cx/trac/ipdb/ticket/24?) 545 ## Also populate a value list for the DBI call. 546 547 my @vallist = ($maskbits, ($type eq 'rm' ? 'n' : ($type =~ /^(.)r$/ ? "$1" : 'y')) ); 548 my $sql = "SELECT cidr FROM freeblocks WHERE maskbits <= ? AND routed = ?"; 549 550 # for PPP(oE) and container types, the POP city is the one attached to the pool. 551 # individual allocations get listed with the customer city site. 552 ##fixme: chain cities to align roughly with a full layer-2 node graph 553 $city = $pop if $type !~ /^.[pc]$/; 554 if ($type ne 'rm') { 555 $sql .= " AND city = ?"; 556 push @vallist, $city; 557 } 558 # if a specific master was requested, allow the requestor to self->shoot(foot) 559 if ($optargs{master} && $optargs{master} ne '-') { 560 $sql .= " AND cidr <<= ?" if $optargs{master} ne '-'; 561 push @vallist, $optargs{master}; 562 } else { 563 # if a specific master was NOT requested, filter out the RFC 1918 private networks 564 if (!$optargs{allowpriv}) { 565 $sql .= " AND NOT (cidr <<= '192.168.0.0/16' OR cidr <<= '10.0.0.0/8' OR cidr <<= '172.16.0.0/12')"; 566 } 567 } 568 # Sorting and limiting, since we don't (currently) care to provide a selection of 569 # blocks to carve up. This preserves something resembling optimal usage of the IP 570 # space by forcing contiguous allocations and free blocks as much as possible. 571 $sql .= " ORDER BY maskbits DESC,cidr LIMIT 1"; 572 573 my ($fbfound) = $dbh->selectrow_array($sql, undef, @vallist); 574 return $fbfound; 575 } # end findAllocateFrom() 520 576 521 577
Note:
See TracChangeset
for help on using the changeset viewer.