RT# 30783 Add network block enumerating utils
[freeside.git] / FS / FS / addr_block.pm
index b8486fe..a39e1f1 100755 (executable)
@@ -6,6 +6,7 @@ use FS::Record qw( qsearchs qsearch dbh );
 use FS::router;
 use FS::addr_range;
 use FS::svc_broadband;
+use FS::svc_acct;
 use FS::Conf;
 use FS::IP_Mixin;
 use NetAddr::IP;
@@ -237,6 +238,23 @@ sub cidr {
   $self->NetAddr->cidr;
 }
 
+=item free_addrs
+
+Returns a sorted list of free addresses in the block.
+
+=cut
+
+sub free_addrs {
+  my $self = shift;
+
+  my %used_addr_map =
+    map {$_ => 1}
+    FS::IP_Mixin->used_addresses_in_block($self),
+    FS::Conf->new()->config('exclude_ip_addr');
+
+  grep { !exists $used_addr_map{$_} } map { $_->addr } $self->NetAddr->hostenum;
+}
+
 =item next_free_addr
 
 Returns a NetAddr::IP object corresponding to the first unassigned address 
@@ -432,4 +450,3 @@ now because that's the smallest block that makes any sense at all.
 =cut
 
 1;
-