Changeset 696


Ignore:
Timestamp:
02/13/15 17:35:24 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Fix most of the edge cases for initPool() being called on extending a
pool. Callers would be responsible for cleaning up parent_id in the
case of eg "merge pools". See #24.

File:
1 edited

Legend:

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

    r695 r696  
    12401240    }
    12411241
     1242# Dodge an edge case - pool where IPs have been "stolen" and turned into a netblock assignment.
     1243# We can't just "get all the current IPs, and add the missing ones", because some IPs are
     1244# legitimately missing (for stretchy values of "legitimately").
     1245
     1246    my $pdata = getBlockData($dbh, $parent);
     1247    my $pcidr = new NetAddr::IP $pdata->{block};
     1248
     1249    if ($pcidr != $pool) {
     1250      # enumerate the IPs from the *old* pool, flag them as "found", so we can iterate the entire
     1251      # requested pool and still make sure we skip the IPs in the old pool - even if they've been
     1252      # "stolen" by legacy netblocks.
     1253      my @oldips = $pcidr->hostenum;
     1254      # decide whether to start excluding existing IPs at the "gateway" or "gateway+1"
     1255      my $ostart = ($pdata->{type} =~ /^.d$/ ? 1 : 0);
     1256      for (my $i = $ostart;  $i<= $#oldips; $i++) {
     1257        $foundips{$oldips[$i]} = 1;
     1258      }
     1259    }
     1260
    12421261    # enumerate the hosts in the IP range - everything except the first (net) and last (bcast) IP
    12431262    my @poolip_list = $pool->hostenum;
     
    12461265    # (but the set won't be in oooorderrrrr!  <pout>)
    12471266    for (my $i=1; $i<=$#poolip_list; $i++) {
    1248       $sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent) unless $foundips{$poolip_list[$i]};
     1267      my $baseip = $poolip_list[$i]->addr;
     1268      if ($baseip !~ /\.(?:0|255)$/ && !$foundips{$poolip_list[$i]}) {
     1269        $sth->execute($baseip, $pcustid, $city, $type, $parent);
     1270      }
    12491271    }
    12501272
     
    12551277        $sth->execute($pool->addr, $pcustid, $city, $type, $parent) unless $foundips{$pool->addr};
    12561278      }
    1257       $sth->execute($poolip_list[0]->addr, $pcustid, $city, $type, $parent) unless $poolip_list[0];
     1279      $sth->execute($poolip_list[0]->addr, $pcustid, $city, $type, $parent) unless $foundips{$poolip_list[0]};
    12581280      $pool--;
    12591281      if ($pool->addr !~ /\.255$/) {    # .255 can cause weirdness.
Note: See TracChangeset for help on using the changeset viewer.