Skip to content

Commit 92c8682

Browse files
committed
[#1415] Improve AddressRange and PrefixRange
Switch order of tests in AddressRange and added a comment. Changes suggested in review.
1 parent b6bf526 commit 92c8682

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib/dhcpsrv/ip_range.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ namespace dhcp {
1717

1818
AddressRange::AddressRange(const IOAddress& start, const IOAddress& end)
1919
: start_(start), end_(end) {
20-
// The start must be lower or equal the end.
21-
if (end_ < start_) {
22-
isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
23-
}
2420
// Two IPv4 or two IPv6 addresses are expected as range boundaries.
2521
if (start_.getFamily() != end_.getFamily()) {
2622
isc_throw(BadValue, "address range boundaries must have the same type: " << start_
2723
<< ":" << end_);
2824
}
25+
// The start must be lower or equal the end.
26+
if (end_ < start_) {
27+
isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
28+
}
2929
}
3030

3131
PrefixRange::PrefixRange(const asiolink::IOAddress& prefix, const uint8_t length, const uint8_t delegated)
@@ -44,6 +44,7 @@ PrefixRange::PrefixRange(const asiolink::IOAddress& prefix, const uint8_t length
4444
<< " and prefix length " << static_cast<int>(length)
4545
<< " must not be greater than 128");
4646
}
47+
// Now calculate the last prefix in the range.
4748
auto prefixes_num = prefixesInRange(prefix_length_, delegated_length_);
4849
uint64_t addrs_in_prefix = static_cast<uint64_t>(1) << (128 - delegated_length_);
4950
end_ = offsetAddress(prefix, (prefixes_num - 1) * addrs_in_prefix);

0 commit comments

Comments
 (0)