From: Marcin Siodelski Date: Mon, 8 May 2023 16:01:50 +0000 (+0200) Subject: [#2843] Fix in initializing subnet states X-Git-Tag: Kea-2.3.8~148 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64b902366f767aef8639ccdd7a5733018394afa6;p=thirdparty%2Fkea.git [#2843] Fix in initializing subnet states --- diff --git a/src/lib/dhcpsrv/subnet.cc b/src/lib/dhcpsrv/subnet.cc index e6038bb932..ef37ca52fb 100644 --- a/src/lib/dhcpsrv/subnet.cc +++ b/src/lib/dhcpsrv/subnet.cc @@ -768,6 +768,8 @@ Subnet4::createAllocators() { setAllocator(Lease::TYPE_V4, boost::make_shared (Lease::TYPE_V4, shared_from_this())); + setAllocationState(Lease::TYPE_V4, SubnetAllocationStatePtr()); + for (auto pool : pools_) { pool->setAllocationState(PoolFreeLeaseQueueAllocationState::create(pool)); } @@ -776,6 +778,9 @@ Subnet4::createAllocators() { setAllocator(Lease::TYPE_V4, boost::make_shared (Lease::TYPE_V4, shared_from_this())); + setAllocationState(Lease::TYPE_V4, + SubnetIterativeAllocationState::create(shared_from_this())); + for (auto pool : pools_) { pool->setAllocationState(PoolIterativeAllocationState::create(pool)); } diff --git a/src/lib/dhcpsrv/tests/subnet_unittest.cc b/src/lib/dhcpsrv/tests/subnet_unittest.cc index 304ca88ba9..b4151b5277 100644 --- a/src/lib/dhcpsrv/tests/subnet_unittest.cc +++ b/src/lib/dhcpsrv/tests/subnet_unittest.cc @@ -807,6 +807,8 @@ TEST(Subnet4Test, createAllocatorsRandom) { // Expect random allocator. EXPECT_TRUE(boost::dynamic_pointer_cast (subnet->getAllocator(Lease::TYPE_V4))); + // Expect null subnet allocation state. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_V4)); // Expect random allocation state for the pool. EXPECT_TRUE(boost::dynamic_pointer_cast (pool->getAllocationState())); @@ -828,6 +830,8 @@ TEST(Subnet4Test, createAllocatorsFreeLeaseQueue) { // Expect FLQ allocator. EXPECT_TRUE(boost::dynamic_pointer_cast (subnet->getAllocator(Lease::TYPE_V4))); + // Expect null subnet allocation state. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_V4)); // Expect FLQ allocation state for the pool. EXPECT_TRUE(boost::dynamic_pointer_cast (pool->getAllocationState())); @@ -1846,6 +1850,12 @@ TEST(Subnet6Test, createAllocatorsRandom) { // Expect random allocator for PD. EXPECT_TRUE(boost::dynamic_pointer_cast (subnet->getAllocator(Lease::TYPE_PD))); + // Expect null subnet allocation state for NA. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_NA)); + // Expect null subnet allocation state for TA. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_TA)); + // Expect null subnet allocation state for PD. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_PD)); // Expect random allocation state for the NA pool. EXPECT_TRUE(boost::dynamic_pointer_cast (pool->getAllocationState())); @@ -1887,6 +1897,12 @@ TEST(Subnet6Test, createAllocatorsFreeLeaseQueue) { // Expect FLQ allocator for PD. EXPECT_TRUE(boost::dynamic_pointer_cast (subnet->getAllocator(Lease::TYPE_PD))); + // Expect null subnet allocation state for NA. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_NA)); + // Expect null subnet allocation state for TA. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_TA)); + // Expect null subnet allocation state for PD. + EXPECT_FALSE(subnet->getAllocationState(Lease::TYPE_PD)); // Expect random allocation state for the NA pool. EXPECT_TRUE(boost::dynamic_pointer_cast (pool->getAllocationState()));