2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 22:15:23 +00:00

[#2612] addressed review comments

This commit is contained in:
Razvan Becheriu
2023-01-16 13:57:26 +02:00
parent f16ef6a673
commit 2d5fdeb15d
2 changed files with 24 additions and 16 deletions

View File

@@ -20,9 +20,9 @@ namespace dhcp {
Pool::Pool(Lease::Type type, const isc::asiolink::IOAddress& first,
const isc::asiolink::IOAddress& last)
:id_(getNextID()), first_(first), last_(last), type_(type),
capacity_(0), cfg_option_(new CfgOption()), client_class_(""),
permutation_() {
: id_(getNextID()), first_(first), last_(last), type_(type),
capacity_(0), cfg_option_(new CfgOption()), client_class_(""),
permutation_() {
}
bool Pool::inRange(const isc::asiolink::IOAddress& addr) const {
@@ -47,7 +47,7 @@ Pool::toText() const {
Pool4::Pool4(const isc::asiolink::IOAddress& first,
const isc::asiolink::IOAddress& last)
:Pool(Lease::TYPE_V4, first, last) {
: Pool(Lease::TYPE_V4, first, last) {
// check if specified address boundaries are sane
if (!first.isV4() || !last.isV4()) {
isc_throw(BadValue, "Invalid Pool4 address boundaries: not IPv4");
@@ -64,8 +64,8 @@ Pool4::Pool4(const isc::asiolink::IOAddress& first,
capacity_ = addrsInRange(first, last);
}
Pool4::Pool4( const isc::asiolink::IOAddress& prefix, uint8_t prefix_len)
:Pool(Lease::TYPE_V4, prefix, IOAddress("0.0.0.0")) {
Pool4::Pool4(const isc::asiolink::IOAddress& prefix, uint8_t prefix_len)
: Pool(Lease::TYPE_V4, prefix, IOAddress("0.0.0.0")) {
// check if the prefix is sane
if (!prefix.isV4()) {
@@ -77,6 +77,13 @@ Pool4::Pool4( const isc::asiolink::IOAddress& prefix, uint8_t prefix_len)
isc_throw(BadValue, "Invalid prefix length");
}
IOAddress first_address = firstAddrInPrefix(prefix, prefix_len);
if (first_address != prefix) {
isc_throw(BadValue, "Invalid Pool4 address boundaries: " << prefix
<< " is not the first address in prefix: " << first_address
<< "/" << static_cast<uint32_t>(prefix_len));
}
// Let's now calculate the last address in defined pool
last_ = lastAddrInPrefix(prefix, prefix_len);
@@ -160,8 +167,8 @@ Pool6::Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
isc_throw(BadValue, "Invalid Pool6 address boundaries: not IPv6");
}
if ( (type != Lease::TYPE_NA) && (type != Lease::TYPE_TA) &&
(type != Lease::TYPE_PD)) {
if ((type != Lease::TYPE_NA) && (type != Lease::TYPE_TA) &&
(type != Lease::TYPE_PD)) {
isc_throw(BadValue, "Invalid Pool6 type: " << static_cast<int>(type)
<< ", must be TYPE_IA, TYPE_TA or TYPE_PD");
}
@@ -241,7 +248,7 @@ Pool6::Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
if (excluded_prefix_len <= prefix_len_) {
isc_throw(BadValue, "excluded prefix length "
<< static_cast<unsigned>(excluded_prefix_len)
<< " must be lower than the delegated prefix length "
<< " must be longer than the delegated prefix length "
<< static_cast<unsigned>(prefix_len_));
}
@@ -312,6 +319,13 @@ Pool6::init(const Lease::Type& type,
<< static_cast<int>(delegated_len) << ")");
}
IOAddress first_address = firstAddrInPrefix(prefix, prefix_len);
if (first_address != prefix) {
isc_throw(BadValue, "Invalid Pool6 address boundaries: " << prefix
<< " is not the first address in prefix: " << first_address
<< "/" << static_cast<uint32_t>(prefix_len));
}
/// @todo: We should probably implement checks against weird addresses
/// here, like ::, starting with fe80, starting with ff etc. .
@@ -323,12 +337,6 @@ Pool6::init(const Lease::Type& type,
// much faster to do calculations on prefix lengths.
capacity_ = prefixesInRange(prefix_len, delegated_len);
if (prefixLengthFromRange(prefix, last_) < 0) {
// The pool is bad: give up
isc_throw(BadValue, "invalid prefix range "
<< prefix.toText() << "-" << last_.toText());
}
// If user specified an excluded prefix, create an option that will
// be sent to clients obtaining prefixes from this pool.
if (excluded_prefix_len > 0) {

View File

@@ -466,7 +466,7 @@ TEST(Subnet4Test, pool4Checks) {
ASSERT_THROW(subnet->addPool(pool2), BadValue);
// this one is totally out of blue
Pool4Ptr pool3(new Pool4(IOAddress("1.2.3.4"), 16));
Pool4Ptr pool3(new Pool4(IOAddress("1.2.0.0"), 16));
ASSERT_THROW(subnet->addPool(pool3), BadValue);
// This pool should be added just fine.