Commit 34c51378 authored by Marcin Siodelski's avatar Marcin Siodelski

[5638] Fixed invalid callouts status for the v4 case.

parent 50c6675a
......@@ -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)) {
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment