]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2843] Fix in initializing subnet states
authorMarcin Siodelski <marcin@isc.org>
Mon, 8 May 2023 16:01:50 +0000 (18:01 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 12 May 2023 11:02:03 +0000 (13:02 +0200)
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc

index e6038bb9320a25ef611cb7b7672c154658bb0897..ef37ca52fbfb7f3e8610a6a460e2f76a1d579ee8 100644 (file)
@@ -768,6 +768,8 @@ Subnet4::createAllocators() {
         setAllocator(Lease::TYPE_V4,
                      boost::make_shared<FreeLeaseQueueAllocator>
                      (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<IterativeAllocator>
                      (Lease::TYPE_V4, shared_from_this()));
+        setAllocationState(Lease::TYPE_V4,
+                           SubnetIterativeAllocationState::create(shared_from_this()));
+
         for (auto pool : pools_) {
             pool->setAllocationState(PoolIterativeAllocationState::create(pool));
         }
index 304ca88ba9d561422237cc2038aa6b2be90d840f..b4151b52777b89d5a642dee9a5ff8b4bedd68ba9 100644 (file)
@@ -807,6 +807,8 @@ TEST(Subnet4Test, createAllocatorsRandom) {
     // Expect random allocator.
     EXPECT_TRUE(boost::dynamic_pointer_cast<RandomAllocator>
                 (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<PoolRandomAllocationState>
                 (pool->getAllocationState()));
@@ -828,6 +830,8 @@ TEST(Subnet4Test, createAllocatorsFreeLeaseQueue) {
     // Expect FLQ allocator.
     EXPECT_TRUE(boost::dynamic_pointer_cast<FreeLeaseQueueAllocator>
                 (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<PoolFreeLeaseQueueAllocationState>
                 (pool->getAllocationState()));
@@ -1846,6 +1850,12 @@ TEST(Subnet6Test, createAllocatorsRandom) {
     // Expect random allocator for PD.
     EXPECT_TRUE(boost::dynamic_pointer_cast<RandomAllocator>
                 (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<PoolRandomAllocationState>
                 (pool->getAllocationState()));
@@ -1887,6 +1897,12 @@ TEST(Subnet6Test, createAllocatorsFreeLeaseQueue) {
     // Expect FLQ allocator for PD.
     EXPECT_TRUE(boost::dynamic_pointer_cast<FreeLeaseQueueAllocator>
                 (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<PoolRandomAllocationState>
                 (pool->getAllocationState()));