X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Faddr_range.pm;h=3cf746f7d4491a099cd7d4593939701cdc423377;hb=b7c25d5e38e6459efe5d1c2f09f437b79798038e;hp=18ae1e2ea9432ef2da82dcaa7e5cb5c6ecb81abf;hpb=7cc8431906315822e8107143920bbca85e5b53ce;p=freeside.git diff --git a/FS/FS/addr_range.pm b/FS/FS/addr_range.pm index 18ae1e2ea..3cf746f7d 100644 --- a/FS/FS/addr_range.pm +++ b/FS/FS/addr_range.pm @@ -149,7 +149,10 @@ sub end { $self->set('start', $end); ($end, $start) = ($start, $end); } - $self->set('length', $end - $start + 1); + # bigints are PROBABLY not needed here...but if someone wants to exclude + # all the address space not assigned to them, for example, that could be + # a pretty large part of IPv4. + $self->set('length', $end->bigint - $start->bigint + 1); return $end->addr; } my $end = $start + $self->get('length') - 1; @@ -165,13 +168,13 @@ Checks whether IPADDR (a dotted-quad IPv4 address) is within the range. sub contains { my $self = shift; my $addr = shift; - $addr = NetAddr::IP->new($addr, 0) - unless ref($addr) and UNIVERSAL::isa($addr, 'NetAddr::IP'); + $addr = NetAddr::IP->new($addr, 0); return 0 unless $addr; my $start = NetAddr::IP->new($self->start, 0); - return ($addr >= $start and $addr - $start < $self->length) ? 1 : 0; + return ($addr >= $start and $addr->bigint - $start->bigint < $self->length) + ? 1 : 0; } =item as_string @@ -242,10 +245,14 @@ sub any_contains { =head1 DEVELOPER NOTE -L objects have netmasks. When using them to represent -range endpoints, be sure to set the netmask to I 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.) +L objects have netmasks. They also have overloaded operators +for addition and subtraction, but those have range limitations when comparing +addresses. (An IPv4 address is effectively a uint32; the difference +between two IPv4 addresses is the same range, but signed.) Therefore, +the distance between two addresses should be calculated using the +C method ($addr2->bigint - $addr1->bigint), which returns the +address as a L object, and also conveniently discards the +netmask. =head1 BUGS