X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FIP_Mixin.pm;h=07fa9e7760aa41e2702be6d6d34db0e824c88797;hb=2ee7f0c27233d800254d5244fc5913d881b48800;hp=beb41d290de4950deb892efc74b44dd643c67091;hpb=459bd7aac2b4ca34b61fa58123f5c86c5ac9d537;p=freeside.git diff --git a/FS/FS/IP_Mixin.pm b/FS/FS/IP_Mixin.pm index beb41d290..07fa9e776 100644 --- a/FS/FS/IP_Mixin.pm +++ b/FS/FS/IP_Mixin.pm @@ -94,6 +94,10 @@ sub ip_check { $self->ip_addr(''); } + # Will strip extraneous leading zeros from ip adddresses + # e.g. 10.0.022.220 corrected to 10.0.22.220 + $self->ut_ip46n('ip_addr'); + if ( $self->ip_addr and !$self->router and $self->conf->exists('auto_router') ) { @@ -130,6 +134,10 @@ sub assign_ip_addr { my $self = shift; my %opt = @_; + #otherwise we'll get the same assignment for concurrent identical calls + # this will serialize them + $_->lock_table foreach @subclasses; + my @blocks; my $na = $self->NetAddr; @@ -262,9 +270,10 @@ sub router { =item used_addresses [ BLOCK ] -Returns a list of all addresses (in BLOCK, or in all blocks) -that are in use. If called as an instance method, excludes -that instance from the search. +Returns a list of all addresses that are in use by a service. If called as an +instance method, excludes that instance from the search. + +Does not filter by block, will return ALL used addresses. ref:f197bdbaa1 =cut @@ -279,6 +288,27 @@ sub _used_addresses { die "$class->_used_addresses not implemented"; } +=item used_addresses_in_block [ FS::addr_block ] + +Returns a list of all addresses in use within the given L + +=cut + +sub used_addresses_in_block { + my ($self, $block) = @_; + + ( + $block->ip_gateway ? $block->ip_gateway : (), + $block->NetAddr->broadcast->addr, + map { $_->_used_addresses_in_block($block, $self ) } @subclasses + ); +} + +sub _used_addresses_in_block { + my $class = shift; + die "$class->_used_addresses_in_block not implemented"; +} + =item is_used ADDRESS Returns a string describing what object is using ADDRESS, or