Index: /trunk/cgi-bin/IPDB.pm
===================================================================
--- /trunk/cgi-bin/IPDB.pm	(revision 632)
+++ /trunk/cgi-bin/IPDB.pm	(revision 633)
@@ -738,4 +738,14 @@
   my $failmsg = "No suitable free block found\n";
 
+  my @vallist;
+  my $sql;
+
+  # Free pool IPs should be easy.
+  if ($type =~ /^.i$/) {
+    # User may get an IP from the wrong VRF.  User should not be using admin tools to allocate static IPs.
+    $sql = "SELECT id, ip, parent_id FROM poolips WHERE ip = ?";
+    @vallist = ($optargs{gimme});
+  } else {
+
 ## Set up the SQL to find out what freeblock we can (probably) use for an allocation.
 ## Very large systems will require development of a reserve system (possibly an extension
@@ -743,6 +753,6 @@
 ## Also populate a value list for the DBI call.
 
-  my @vallist = ($maskbits);
-  my $sql = "SELECT cidr,rdepth FROM freeblocks WHERE masklen(cidr) <= ?";
+    @vallist = ($maskbits);
+    $sql = "SELECT id,cidr,parent_id FROM freeblocks WHERE masklen(cidr) <= ?";
 
 # cases, strict rules
@@ -765,4 +775,7 @@
 ##fixme:  strict-or-not flag
 
+##fixme:  config or UI flag for "Strict" mode
+# if ($strictmode) {
+if (0) {
   if ($type =~ /^(.)r$/) {
     push @vallist, $1;
@@ -773,35 +786,38 @@
     $sql .= " AND routed = 'r'";
   }
-
-  # for PPP(oE) and container types, the POP city is the one attached to the pool.
-  # individual allocations get listed with the customer city site.
-  ##fixme:  chain cities to align roughly with a full layer-2 node graph
-  $city = $pop if $type !~ /^.[pc]$/;
-  if ($type ne 'rm' && $city) {
-    $sql .= " AND city = ?";
-    push @vallist, $city;
-  }
-  # Allow specifying an arbitrary full block, instead of a master
-  if ($optargs{gimme}) {
-    $sql .= " AND cidr >>= ?";
-    push @vallist, $optargs{gimme};
-  }
-  # if a specific master was requested, allow the requestor to self->shoot(foot)
-  if ($optargs{master} && $optargs{master} ne '-') {
-    $sql .= " AND cidr <<= ?" if $optargs{master} ne '-';
-    push @vallist, $optargs{master};
-  } else {
-    # if a specific master was NOT requested, filter out the RFC 1918 private networks
-    if (!$optargs{allowpriv}) {
-      $sql .= " AND NOT (cidr <<= '192.168.0.0/16' OR cidr <<= '10.0.0.0/8' OR cidr <<= '172.16.0.0/12')";
-    }
-  }
-  # Sorting and limiting, since we don't (currently) care to provide a selection of
-  # blocks to carve up.  This preserves something resembling optimal usage of the IP
-  # space by forcing contiguous allocations and free blocks as much as possible.
-  $sql .= " ORDER BY maskbits DESC,cidr LIMIT 1";
-
-  my ($fbfound,$fbdepth) = $dbh->selectrow_array($sql, undef, @vallist);
-  return $fbfound,$fbdepth;
+}
+
+    # for PPP(oE) and container types, the POP city is the one attached to the pool.
+    # individual allocations get listed with the customer city site.
+    ##fixme:  chain cities to align roughly with a full layer-2 node graph
+    $city = $pop if $type !~ /^.[pc]$/;
+    if ($type ne 'rm' && $city) {
+      $sql .= " AND city = ?";
+      push @vallist, $city;
+    }
+    # Allow specifying an arbitrary full block, instead of a master
+    if ($optargs{gimme}) {
+      $sql .= " AND cidr >>= ?";
+      push @vallist, $optargs{gimme};
+    }
+    # if a specific master was requested, allow the requestor to self->shoot(foot)
+    if ($optargs{master} && $optargs{master} ne '-') {
+      $sql .= " AND master_id = ?";
+# if $optargs{master} ne '-';
+      push @vallist, $optargs{master};
+    } else {
+      # if a specific master was NOT requested, filter out the RFC 1918 private networks
+      if (!$optargs{allowpriv}) {
+        $sql .= " AND NOT (cidr <<= '192.168.0.0/16' OR cidr <<= '10.0.0.0/8' OR cidr <<= '172.16.0.0/12')";
+      }
+    }
+    # Sorting and limiting, since we don't (currently) care to provide a selection of
+    # blocks to carve up.  This preserves something resembling optimal usage of the IP
+    # space by forcing contiguous allocations and free blocks as much as possible.
+    $sql .= " ORDER BY masklen(cidr) DESC,cidr LIMIT 1";
+  } # done setting up SQL for free CIDR block
+
+  my ($fbid,$fbfound,$fbparent) = $dbh->selectrow_array($sql, undef, @vallist);
+  return $fbid,$fbfound,$fbparent;
 } # end findAllocateFrom()
 
@@ -872,5 +888,4 @@
 
   $args{cidr} = new NetAddr::IP $args{cidr};
-  $args{alloc_from} = new NetAddr::IP $args{alloc_from};
 
   $args{desc} = '' if !$args{desc};
@@ -883,8 +898,9 @@
   my $sth;
 
-  # Snag the "type" of the freeblock (alloc_from) "just in case"
-  $sth = $dbh->prepare("select routed from freeblocks where cidr='$args{alloc_from}'");
-  $sth->execute;
-  my ($alloc_from_type) = $sth->fetchrow_array;
+  # Snag the "type" of the freeblock and its CIDR
+  my ($alloc_from_type, $alloc_from, $fbparent, $fcity, $fbmaster) =
+	$dbh->selectrow_array("SELECT routed,cidr,parent_id,city,master_id FROM freeblocks WHERE id = ?",
+	undef, $args{fbid});
+  $alloc_from = new NetAddr::IP $alloc_from;
 
   # To contain the error message, if any.
@@ -908,7 +924,10 @@
 		undef, ($args{alloc_from}) );
       }
-      $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=?,vrf=?,rdns=? ".
-	"WHERE ip=?", undef, ($args{custid}, $args{city}, $args{desc}, $args{notes}, $args{circid},
-		$args{privdata}, $args{vrf}, $args{rdns}, $args{cidr}) );
+      $dbh->do("UPDATE poolips SET custid = ?, city = ?,available='n', description = ?, notes = ?, ".
+	"circuitid = ?, privdata = ?, vrf = ?, rdns = ? ".
+	"WHERE ip = ? AND parent_id = ?", undef,
+		($args{custid}, $args{city}, $args{desc}, $args{notes},
+		$args{circid}, $args{privdata}, $args{vrf}, $args{rdns},
+		$args{cidr}, $args{parent}) );
 
 # node hack
@@ -931,5 +950,5 @@
   } else { # end IP-from-pool allocation
 
-    if ($args{cidr} == $args{alloc_from}) {
+    if ($args{cidr} == $alloc_from) {
       # Easiest case- insert in one table, delete in the other, and go home.  More or less.
       # insert into allocations values (cidr,custid,type,city,desc) and
@@ -940,7 +959,11 @@
 	$msg = "Unable to allocate $args{cidr} as '$disp_alloctypes{$args{type}}'";
 
-	# Get old freeblocks parent/depth/routed for new entries... before we delete it.
-	my ($fparent) = $dbh->selectrow_array("SELECT parent FROM freeblocks WHERE cidr=? AND rdepth=?",
-		undef, ($args{alloc_from}, $args{rdepth}) );
+	# Insert the allocations entry
+	$dbh->do("INSERT INTO allocations ".
+		"(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
+		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
+		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
+		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
+	my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
 
 	# Munge freeblocks
@@ -948,17 +971,10 @@
 	  # special case - block is a routed or container/"reserve" block
 	  my $rtype = $1;
-	  $dbh->do("UPDATE freeblocks SET routed=?,rdepth=rdepth+1,city=?,parent=? WHERE cidr=? AND rdepth=?",
-		undef, ($rtype, $args{city}, $args{cidr}, $args{cidr}, $args{rdepth}) );
+	  $dbh->do("UPDATE freeblocks SET routed = ?,city = ?,parent_id = ? WHERE id = ?",
+		undef, ($rtype, $args{city}, $bid, $args{fbid}) );
 	} else {
 	  # "normal" case
-	  $dbh->do("DELETE FROM freeblocks WHERE cidr=? AND rdepth=?", undef, ($args{cidr}, $args{rdepth}));
+	  $dbh->do("DELETE FROM freeblocks WHERE id = ?", undef, ($args{fbid}) );
 	}
-
-	# Insert the allocations entry
-	$dbh->do("INSERT INTO allocations ".
-		"(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata,rdns)".
-		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
-		($args{cidr}, $fparent, $args{vrf}, $args{rdepth}, $args{custid}, $args{type}, $args{city},
-		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
 
 	# And initialize the pool, if necessary
@@ -967,9 +983,9 @@
 	if ($args{type} =~ /^.p$/) {
 	  $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
-	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $args{rdepth}+1);
+	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $bid);
 	  die $rmsg if $code eq 'FAIL';
 	} elsif ($args{type} =~ /^.d$/) {
 	  $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
-	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $args{rdepth}+1);
+	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $bid);
 	  die $rmsg if $code eq 'FAIL';
 	}
@@ -992,6 +1008,10 @@
 
       # Hard case.  Allocation is smaller than free block.
+
+      # make sure new allocation is in fact within freeblock.  *sigh*
+      return ('FAIL',"Requested allocation $args{cidr} is not within $alloc_from")
+	if !$alloc_from->contains($args{cidr});
       my $wantmaskbits = $args{cidr}->masklen;
-      my $maskbits = $args{alloc_from}->masklen;
+      my $maskbits = $alloc_from->masklen;
 
       my @newfreeblocks;	# Holds free blocks generated from splitting the source freeblock.
@@ -1001,5 +1021,5 @@
       # block is in, and repeat until the wanted block is equal to one of the halves.
       my $i=0;
-      my $tmp_from = $args{alloc_from};	# So we don't munge $args{alloc_from}
+      my $tmp_from = $alloc_from;	# So we don't munge $args{alloc_from}
       while ($maskbits++ < $wantmaskbits) {
 	my @subblocks = $tmp_from->split($maskbits);
@@ -1012,29 +1032,26 @@
 	$msg = "Unable to allocate $args{cidr} as '$disp_alloctypes{$args{type}}'";
 
-	# Get old freeblocks parent/depth/routed for new entries
-	my ($fparent,$fcity,$wasrouted) = $dbh->selectrow_array("SELECT parent,city,routed FROM freeblocks".
-		" WHERE cidr=? AND rdepth=?", undef, ($args{alloc_from}, $args{rdepth}) );
-
 	# Delete old freeblocks entry
-	$dbh->do("DELETE FROM freeblocks WHERE cidr=? AND rdepth=?", undef, ($args{alloc_from}, $args{rdepth}) );
+	$dbh->do("DELETE FROM freeblocks WHERE id = ?", undef, ($args{fbid}) );
 
 	# Insert new list of smaller free blocks left over
-	$sth = $dbh->prepare("INSERT INTO freeblocks (cidr,city,routed,vrf,parent,rdepth) VALUES (?,?,?,?,?,?)");
+	$sth = $dbh->prepare("INSERT INTO freeblocks (cidr,city,routed,vrf,parent_id,master_id) VALUES (?,?,?,?,?,?)");
 	foreach my $block (@newfreeblocks) {
-	  $sth->execute($block, $fcity, $wasrouted, $args{vrf}, $fparent, $args{rdepth});
+	  $sth->execute($block, $fcity, $alloc_from_type, $args{vrf}, $fbparent, $fbmaster);
 	}
+
+	# Insert the allocations entry
+	$dbh->do("INSERT INTO allocations ".
+		"(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
+		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
+		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
+		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
+	my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
 
 	# For routed/container types, add a freeblock within the allocated block so we can subdivide it further
 	if ($args{type} =~ /(.)[mc]/) { # rm and .c types - containers
 	  my $rtype = $1;
-	  $sth->execute($args{cidr}, $args{city}, $rtype, $args{vrf}, $args{cidr}, $args{rdepth}+1);
+	  $sth->execute($args{cidr}, $args{city}, $rtype, $args{vrf}, $bid, $fbmaster);
 	}
-
-	# Insert the allocations entry
-	$dbh->do("INSERT INTO allocations ".
-		"(cidr,parent,vrf,rdepth,custid,type,city,description,notes,circuitid,privdata,rdns)".
-		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
-		($args{cidr}, $fparent, $args{vrf}, $args{rdepth}, $args{custid}, $args{type}, $args{city},
-		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
 
 	# And initialize the pool, if necessary
@@ -1043,9 +1060,9 @@
 	if ($args{type} =~ /^.p$/) {
 	  $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
-	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $args{rdepth}+1);
+	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "all", $bid);
 	  die $rmsg if $code eq 'FAIL';
 	} elsif ($args{type} =~ /^.d$/) {
 	  $msg = "Could not initialize IPs in new $disp_alloctypes{$args{type}} $args{cidr}";
-	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $args{rdepth}+1);
+	  my ($code,$rmsg) = initPool($dbh, $args{cidr}, $args{type}, $args{city}, "normal", $bid);
 	  die $rmsg if $code eq 'FAIL';
 	}
@@ -1086,5 +1103,5 @@
 # function and should ONLY EVER get called from allocateBlock()
 sub initPool {
-  my ($dbh,undef,$type,$city,$class,$rdepth) = @_;
+  my ($dbh,undef,$type,$city,$class,$parent) = @_;
   my $pool = new NetAddr::IP $_[1];
 
@@ -1095,5 +1112,5 @@
   return ('FAIL',"Refusing to create oversized static IP pool") if $pool->masklen <= 20;
 
-##fixme Need to just replace 2nd char of type with i rather than capturing 1st char of type
+  my ($pcustid) = $dbh->selectrow_array("SELECT def_custid FROM alloctypes WHERE type=?", undef, ($type) );
   $type =~ s/[pd]$/i/;
   my $sth;
@@ -1108,28 +1125,29 @@
   eval {
     # have to insert all pool IPs into poolips table as "unallocated".
-    $sth = $dbh->prepare("INSERT INTO poolips (pool,ip,custid,city,type,rdepth)".
-	" VALUES ('$pool', ?, '$defcustid', ?, '$type', $rdepth)");
+    $sth = $dbh->prepare("INSERT INTO poolips (ip,custid,city,type,parent_id) VALUES (?,?,?,?,?)");
     my @poolip_list = $pool->hostenum;
     if ($class eq 'all') { # (DSL-ish block - *all* IPs available
       if ($pool->addr !~ /\.0$/) {	# .0 causes weirdness.
-	$sth->execute($pool->addr, $city);
+	$sth->execute($pool->addr, $pcustid, $city, $type, $parent);
       }
       for (my $i=0; $i<=$#poolip_list; $i++) {
-	$sth->execute($poolip_list[$i]->addr, $city);
+	$sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent);
       }
       $pool--;
       if ($pool->addr !~ /\.255$/) {	# .255 can cause weirdness.
-	$sth->execute($pool->addr, $city);
+	$sth->execute($pool->addr, $pcustid, $city, $type, $parent);
       }
     } else { # (real netblock)
       for (my $i=1; $i<=$#poolip_list; $i++) {
-	$sth->execute($poolip_list[$i]->addr, $city);
-      }
-    }
-    $dbh->commit;
+	$sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent);
+      }
+    }
+# don't commit here!  the caller may not be done.
+#    $dbh->commit;
   };
   if ($@) {
     $msg = $@;
-    eval { $dbh->rollback; };
+# Don't roll back!  It's up to the caller to handle this.
+#    eval { $dbh->rollback; };
     return ('FAIL',$msg);
   } else {
Index: /trunk/cgi-bin/main.cgi
===================================================================
--- /trunk/cgi-bin/main.cgi	(revision 632)
+++ /trunk/cgi-bin/main.cgi	(revision 633)
@@ -300,4 +300,5 @@
 
   # hack pthbttt eww
+  $webvar{parent} = 0 if !$webvar{parent};
   $webvar{block} = '' if !$webvar{block};
 
@@ -307,22 +308,24 @@
   $page->param(allocfrom => $webvar{block});	# fb-assign flag, if block is set, we're in fb-assign
 
-  if ($webvar{block} ne '') {
+  if ($webvar{fbid} || $webvar{fbtype}) {
 
     # Common case, according to reported usage.  Block to assign is specified.
     my $block = new NetAddr::IP $webvar{block};
-    $page->param(rdepth => $webvar{rdepth});
-
-    my $rdns = getBlockRDNS($ip_dbh, $webvar{block}, $webvar{rdepth}, vrf => $webvar{vrf}, user => $authuser);
+
+    my $rdns = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
     $page->param(rdns => $rdns) if $rdns;
+    $page->param(parent => $webvar{parent});
+    $page->param(fbid => $webvar{fbid});
 
     $webvar{fbtype} = '' if !$webvar{fbtype};
     if ($webvar{fbtype} eq 'i') {
-      my $ipinfo = getBlockData($ip_dbh, $block);
+      my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
+      my $pinfo = getBlockData($ip_dbh, $webvar{parent});
       $page->param(
 	fbip => 1,
-	block => $block,
+	block => $ipinfo->{block},
 	fbdisptype => $list_alloctypes{$ipinfo->{type}},
 	type => $ipinfo->{type},
-	allocfrom => $ipinfo->{pool},
+	allocfrom => $pinfo->{block},
 	);
     } else {
@@ -340,5 +343,5 @@
 
     my @pops;
-    foreach my $pop (@poplist) {
+    foreach my $pop (@citylist) {
       my %row = (pop => $pop);
       push (@pops, \%row);
@@ -378,4 +381,6 @@
   my $cidr;
   my $alloc_from;
+  my $fbid = $webvar{fbid};
+  my $p_id = $webvar{parent};
 
   # Going to manually validate some items.
@@ -428,6 +433,6 @@
 
 ## fixme:  add rdepth?
-      ($cidr,$webvar{rdepth}) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city},
-	$webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
+      ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
+	$webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
       if (!$cidr) {
 	$page->param(err => $failmsg);
@@ -464,5 +469,6 @@
   $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
   $page->param(alloc_from => $alloc_from);
-  $page->param(rdepth => $webvar{rdepth});
+  $page->param(parent => $p_id);
+  $page->param(fbid => $fbid);
   $page->param(cidr => $cidr);
   $page->param(rdns => $webvar{rdns});
@@ -514,6 +520,6 @@
   # IP, or the error message if an error occurred.
 
-  my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, alloc_from => $webvar{alloc_from},
-	rdepth => $webvar{rdepth}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city}, 
+  my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, fbid => $webvar{fbid},
+	parent => $webvar{parent}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city}, 
 	desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
 	privdata => $webvar{privdata}, nodeid => $webvar{node}, rdns => $webvar{rdns}, user => $authuser);
@@ -524,5 +530,5 @@
       $page->param(staticip => $msg);
       $page->param(custid => $webvar{custid});
-      $page->param(parent => $webvar{alloc_from}, rdepth => $webvar{rdepth}-1);
+      $page->param(parent => $webvar{parent}, pool => $webvar{alloc_from});
       $page->param(billinguser => $webvar{billinguser});
       mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
@@ -535,6 +541,7 @@
       $page->param(custid => $webvar{custid});
       # breadcrumbs lite!  provide at least a link to the parent of the block we just allocated.
-      my $binfo = getBlockData($ip_dbh, $webvar{fullcidr}, $webvar{rdepth});
-      $page->param(parent => $binfo->{parent}, rdepth => $binfo->{rdepth});
+      my $binfo = getBlockData($ip_dbh, $webvar{parent});
+      $page->param(parentid => $webvar{parent});
+      $page->param(parentblock => $binfo->{block});
       if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
 	$page->param(billinguser => $webvar{billinguser});
Index: /trunk/templates/assign.tmpl
===================================================================
--- /trunk/templates/assign.tmpl	(revision 632)
+++ /trunk/templates/assign.tmpl	(revision 633)
@@ -16,5 +16,6 @@
 </TMPL_IF>
 <td><TMPL_VAR NAME=allocfrom><input type="hidden" name="allocfrom" value="<TMPL_VAR NAME=allocfrom>">
-<input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
+<input type="hidden" name="parent" value="<TMPL_VAR NAME=parent>">
+<input type="hidden" name="fbid" value="<TMPL_VAR NAME=fbid>">
 </td>
 </tr>
@@ -81,5 +82,5 @@
 
 <tr class="<TMPL_VAR NAME=rowa>">
-<td>Wifi tower/Fibre demarc</td>
+<td>Layer-2/demarc node</td>
 <td>
 <select name="node">
@@ -88,5 +89,5 @@
 	<option value="<TMPL_VAR NAME=node_id>"><TMPL_VAR NAME=node_name></option></TMPL_LOOP>
 </select>
-&nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new demarc/tower</a>
+&nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new demarc node</a>
 </td>
 </tr>
@@ -94,5 +95,5 @@
 <TMPL_UNLESS allocfrom>
 <tr class="<TMPL_VAR NAME=rowb>">
-<td>Route from/through:</td>
+<td>Limit to blocks in this location:</td>
 <td>
 <select name="pop">
@@ -105,10 +106,10 @@
 
 <tr class="<TMPL_VAR NAME=rowa>">
-<td>Route/allocate from this master:&nbsp;</td>
+<td>Limit to blocks in this master:&nbsp;</td>
 <td>
 <select name="allocfrom">
 	<option selected="selected">-</option>
 <TMPL_LOOP NAME=masterlist>
-	<option><TMPL_VAR NAME=master></option></TMPL_LOOP>
+	<option value=<TMPL_VAR NAME=id>><TMPL_VAR NAME=master><TMPL_IF vrf> (<TMPL_VAR NAME=vrf>)</TMPL_IF></option></TMPL_LOOP>
 </select>
 Allow automatic allocation from private IP ranges:<input type="checkbox" name="allowpriv"></td>
Index: /trunk/templates/confirm.tmpl
===================================================================
--- /trunk/templates/confirm.tmpl	(revision 632)
+++ /trunk/templates/confirm.tmpl	(revision 633)
@@ -44,5 +44,5 @@
 
 <tr class="row0">
-<td>Demarc switch/wifi tower:</td>
+<td>Layer-2/demarc node:</td>
 <td><TMPL_VAR NAME=nodename></td>
 </tr>
@@ -84,5 +84,6 @@
 <td class="center" colspan="2">
 <TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS>
-<input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
+<input type="hidden" name="parent" value="<TMPL_VAR NAME=parent>">
+<input type="hidden" name="fbid" value="<TMPL_VAR NAME=fbid>">
 <input type="hidden" name="fullcidr" value="<TMPL_VAR NAME=cidr>">
 <input type="hidden" name="rdns" value="<TMPL_VAR NAME=rdns>">
Index: /trunk/templates/insert.tmpl
===================================================================
--- /trunk/templates/insert.tmpl	(revision 632)
+++ /trunk/templates/insert.tmpl	(revision 633)
@@ -12,5 +12,6 @@
 </TMPL_IF>
 </div>
-<div class="center">IPs in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=listpool&amp;pool=<TMPL_VAR NAME=parent>&amp;rdepth=<TMPL_VAR NAME=rdepth>"><TMPL_VAR NAME=parent></a></div>
+<div class="center">IPs in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=listpool&amp;pool=<TMPL_VAR 
+NAME=parent>"><TMPL_VAR NAME=pool></a></div>
 <TMPL_ELSE>
 <div class="center">
@@ -20,5 +21,5 @@
 </TMPL_IF>
 </div>
-<div class="center">Allocations in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=showsubs&amp;block=<TMPL_VAR NAME=parent>&amp;rdepth=<TMPL_VAR NAME=rdepth>"><TMPL_VAR NAME=parent></a></div>
+<div class="center">Allocations in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=showsubs&amp;parent=<TMPL_VAR NAME=parentid>"><TMPL_VAR NAME=parentblock></a></div>
 </TMPL_IF>
 </TMPL_IF>
