From: Thomas Markwalder Date: Tue, 3 Mar 2020 16:04:00 +0000 (-0500) Subject: [#1124] Reversed order for v6 also X-Git-Tag: Kea-1.7.6~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d955b3dda27285df74de739bf92cc3300a572487;p=thirdparty%2Fkea.git [#1124] Reversed order for v6 also modified: alloc_engine.cc --- diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index fe806faae1..352fe8fc41 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -1031,17 +1031,6 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { ctx.query_->getClasses(), ctx.duid_, hint); - - /// In-pool reservations: Check if this address is reserved for someone - /// else. There is no need to check for whom it is reserved, because if - /// it has been reserved for us we would have already allocated a lease. - if (hr_mode == Network::HR_ALL && - HostMgr::instance().get6(subnet->getID(), candidate)) { - - // Don't allocate. - continue; - } - // The first step is to find out prefix length. It is 128 for // non-PD leases. uint8_t prefix_len = 128; @@ -1055,9 +1044,21 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { } } + // Look for an existing lease for the candidate. Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(ctx.currentIA().type_, candidate); + if (!existing) { + /// In-pool reservations: Check if this address is reserved for someone + /// else. There is no need to check for whom it is reserved, because if + /// it has been reserved for us we would have already allocated a lease. + if (hr_mode == Network::HR_ALL && + HostMgr::instance().get6(subnet->getID(), candidate)) { + + // Don't allocate. + continue; + } + // there's no existing lease for selected candidate, so it is // free. Let's allocate it. @@ -1083,6 +1084,13 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { // allocation attempts. } else { if (existing->expired()) { + // Make sure it's not reserved. + if (hr_mode == Network::HR_ALL && + HostMgr::instance().get6(subnet->getID(), candidate)) { + // Don't allocate. + continue; + } + // Copy an existing, expired lease so as it can be returned // to the caller. Lease6Ptr old_lease(new Lease6(*existing));