]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5638] Fixed invalid callouts status for the v4 case.
authorMarcin Siodelski <marcin@isc.org>
Mon, 4 Jun 2018 11:38:25 +0000 (13:38 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 4 Jun 2018 11:38:25 +0000 (13:38 +0200)
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc

index 2be4a8fd17293156ebfe19fb995287b78d733406..476a893dcdc76bbe2bc668a20288b325adf912fa 100644 (file)
@@ -3544,6 +3544,13 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
             max_attempts = 0;
         }
 
+        // Set the default status code in case the lease4_select callouts
+        // do not exist and the callout handle has a status returned by
+        // any of the callouts already invoked for this packet.
+        if (ctx.callout_handle_) {
+            ctx.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
+        }
+
         for (uint64_t i = 0; i < max_attempts; ++i) {
             IOAddress candidate = allocator->pickAddress(subnet,
                                                          ctx.query_->getClasses(),
@@ -3551,12 +3558,14 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
                                                          ctx.requested_address_);
             // If address is not reserved for another client, try to allocate it.
             if (!addressReserved(candidate, ctx)) {
+
                 // The call below will return the non-NULL pointer if we
                 // successfully allocate this lease. This means that the
                 // address is not in use by another client.
                 new_lease = allocateOrReuseLease4(candidate, ctx);
                 if (new_lease) {
                     return (new_lease);
+
                 } else if (ctx.callout_handle_ &&
                            (ctx.callout_handle_->getStatus() !=
                             CalloutHandle::NEXT_STEP_CONTINUE)) {
index 64b7b842bd6803a9f5c7a72eda40270ad36cc246..f46ca30c05221e28ea2559d4cd540bf29a611d9e 100644 (file)
@@ -9,6 +9,8 @@
 #include <dhcpsrv/shared_network.h>
 #include <dhcpsrv/tests/alloc_engine_utils.h>
 #include <dhcpsrv/tests/test_utils.h>
+#include <hooks/hooks_manager.h>
+#include <hooks/callout_handle.h>
 #include <stats/stats_mgr.h>
 
 using namespace std;
@@ -78,6 +80,32 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
 
     // Assigned addresses should have incremented.
     EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
+
+    uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
+    HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
+    AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"),
+                                     false, true, "anotherhost.example.com.",
+                                     false);
+    ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
+
+    ctx2.callout_handle_ = HooksManager::createCalloutHandle();
+    ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP);
+
+    pool_->resetLastAllocated();
+
+    lease = engine->allocateLease4(ctx2);
+    // The new lease has been allocated, so the old lease should not exist.
+    EXPECT_FALSE(ctx2.old_lease_);
+
+    // Check that we got a lease
+    ASSERT_TRUE(lease);
+
+    // Check that the lease is indeed in LeaseMgr
+    from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
+    ASSERT_TRUE(from_mgr);
+
+    // Now check that the lease in LeaseMgr has the same parameters
+    detailCompareLease(lease, from_mgr);
 }
 
 // This test checks if the fake allocation (for DHCPDISCOVER) can succeed