actually make auto-assignment avoid forbidden ranges, #25530
authorMark Wells <mark@freeside.biz>
Wed, 11 Dec 2013 04:44:01 +0000 (20:44 -0800)
committerMark Wells <mark@freeside.biz>
Wed, 11 Dec 2013 04:44:01 +0000 (20:44 -0800)
FS/FS/addr_block.pm
FS/FS/addr_range.pm

index 6a62777..1f4000b 100755 (executable)
@@ -256,7 +256,17 @@ sub next_free_addr {
   # just do a linear search of the block
   my $freeaddr = $selfaddr->network + 1;
   while ( $freeaddr < $selfaddr->broadcast ) {
-    return $freeaddr unless $used{ $freeaddr->addr };
+    # also make sure it's not blocked from assignment by an address range
+    if ( !$used{$freeaddr->addr } ) {
+      my ($range) = grep { !$_->allow_use }
+                  FS::addr_range->any_contains($freeaddr);
+      if ( !$range ) {
+        # then we've found a free address
+        return $freeaddr;
+      }
+      # otherwise, skip to the end of the range
+      $freeaddr = NetAddr::IP->new($range->end, $self->ip_netmask);
+    }
     $freeaddr++;
   }
   return;
index 5faa443..18ae1e2 100644 (file)
@@ -219,11 +219,6 @@ sub desc {
   $status_desc{ $self->status };
 }
 
-sub allow_auto {
-  my $self = shift;
-  $status_allow_auto{ $self->status };
-}
-
 sub allow_use {
   my $self = shift;
   $status_allow_use{ $self->status };
@@ -250,7 +245,7 @@ sub any_contains {
 L<NetAddr::IP> objects have netmasks.  When using them to represent 
 range endpoints, be sure to set the netmask to I<zero> so that math on 
 the address doesn't stop at the subnet boundary.  (The default is /32, 
-which doesn't work very well.  Address ranges ignore subnet boundaries.
+which doesn't work very well.  Address ranges ignore subnet boundaries.)
 
 =head1 BUGS