Changeset 574 for trunk


Ignore:
Timestamp:
12/21/12 17:39:09 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Tweak initPool(), and calls to initPool(), to properly set rdepth
Also a minor error-reporting cleanup in initPool()

File:
1 edited

Legend:

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

    r573 r574  
    843843        if ($args{type} =~ /^.p$/) {
    844844          $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
    845           my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all");
     845          my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $args{rdepth}+1);
    846846          die $rmsg if $code eq 'FAIL';
    847847        } elsif ($args{type} =~ /^.d$/) {
    848848          $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
    849           my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal");
     849          my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $args{rdepth}+1);
    850850          die $rmsg if $code eq 'FAIL';
    851851        }
     
    856856      }
    857857# end node hack
     858
    858859        $dbh->commit;
    859860      }; # end of eval
     
    920921        if ($args{type} =~ /^.p$/) {
    921922          $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
    922           my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all");
     923          my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $args{rdepth}+1);
    923924          die $rmsg if $code eq 'FAIL';
    924925        } elsif ($args{type} =~ /^.d$/) {
    925926          $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
    926           my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal");
     927          my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $args{rdepth}+1);
    927928          die $rmsg if $code eq 'FAIL';
    928929        }
     
    959960# function and should ONLY EVER get called from allocateBlock()
    960961sub initPool {
    961   my ($dbh,undef,$type,$city,$class) = @_;
     962  my ($dbh,undef,$type,$city,$class,$rdepth) = @_;
    962963  my $pool = new NetAddr::IP $_[1];
     964
     965  # IPv6 does not lend itself to IP pools as supported
     966  return ('FAIL',"Refusing to create IPv6 static IP pool") if $pool->{isv6};
     967  # IPv4 pools don't make much sense beyond even /24.  Allow up to 4096-host footshooting anyway.
     968  # NetAddr::IP won't allow more than a /16 (65k hosts).
     969  return ('FAIL',"Refusing to create oversized static IP pool") if $pool->masklen <= 20;
    963970
    964971##fixme Need to just replace 2nd char of type with i rather than capturing 1st char of type
     
    975982  eval {
    976983    # have to insert all pool IPs into poolips table as "unallocated".
    977     $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,type)".
    978         " values ('$pool', ?, '$defcustid', ?, '$type')");
     984    $sth = $dbh->prepare("INSERT INTO poolips (pool,ip,custid,city,type,rdepth)".
     985        " VALUES ('$pool', ?, '$defcustid', ?, '$type', $rdepth)");
    979986    my @poolip_list = $pool->hostenum;
    980987    if ($class eq 'all') { # (DSL-ish block - *all* IPs available
     
    9941001      }
    9951002    }
     1003    $dbh->commit;
    9961004  };
    9971005  if ($@) {
    998     $msg = $@." '".$sth->errstr."'";
     1006    $msg = $@;
    9991007    eval { $dbh->rollback; };
    10001008    return ('FAIL',$msg);
Note: See TracChangeset for help on using the changeset viewer.