[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 44470195c16de08d1d48ae0ca9940596bda21849

Mark Wells mark at 420.am
Mon Jul 23 16:48:07 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  44470195c16de08d1d48ae0ca9940596bda21849 (commit)
      from  ca7ddc7c66dbee1b7413027cbc8841e71449236f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 44470195c16de08d1d48ae0ca9940596bda21849
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jul 23 16:47:07 2012 -0700

    don't enumerate the whole subnet when looking for a free address, #18556

diff --git a/FS/FS/addr_block.pm b/FS/FS/addr_block.pm
index e00f587..686bdbd 100755
--- a/FS/FS/addr_block.pm
+++ b/FS/FS/addr_block.pm
@@ -223,43 +223,45 @@ sub cidr {
   $self->NetAddr->cidr;
 }
 
-=item free_addrs
+=item next_free_addr
 
 Returns a NetAddr::IP object corresponding to the first unassigned address 
 in the block (other than the network, broadcast, or gateway address).  If 
 there are no free addresses, returns nothing.  There are never free addresses
 when manual_flag is true.
 
-=item next_free_addr
-
-Returns a NetAddr::IP object for the first unassigned address in the block,
-or '' if there are none.
+There is no longer a method to return all free addresses in a block.
 
 =cut
 
-sub free_addrs {
+sub next_free_addr {
   my $self = shift;
+  my $selfaddr = $self->NetAddr;
 
   return if $self->manual_flag;
 
   my $conf = new FS::Conf;
   my @excludeaddr = $conf->config('exclude_ip_addr');
-  
+
   my %used = map { $_ => 1 }
   (
+    @excludeaddr,
+    $selfaddr->addr,
+    $selfaddr->network->addr,
+    $selfaddr->broadcast->addr,
     (map { $_->NetAddr->addr }
-      ($self,
-       qsearch('svc_broadband', { blocknum => $self->blocknum }))
+       qsearch('svc_broadband', { blocknum => $self->blocknum })
     ), @excludeaddr
   );
 
-  grep { !$used{$_->addr} } $self->NetAddr->hostenum;
-
-}
+  # just do a linear search of the block
+  my $freeaddr = $selfaddr->network + 1;
+  while ( $freeaddr < $selfaddr->broadcast ) {
+    return $freeaddr unless $used{ $freeaddr->addr };
+    $freeaddr++;
+  }
+  return;
 
-sub next_free_addr {
-  my $self = shift;
-  ($self->free_addrs, '')[0]
 }
 
 =item allocate -- deprecated

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/addr_block.pm |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)




More information about the freeside-commits mailing list