2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-04 16:05:17 +00:00

[#1147] Checkpoint: cleaned up alloc code

This commit is contained in:
Francis Dupont
2020-05-11 11:07:01 +02:00
parent be8c8f76eb
commit 8a69ac46be

View File

@@ -866,10 +866,9 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
CalloutHandle::CalloutNextStep callout_status = CalloutHandle::NEXT_STEP_CONTINUE; CalloutHandle::CalloutNextStep callout_status = CalloutHandle::NEXT_STEP_CONTINUE;
while (subnet) { for (; subnet; subnet = subnet->getNextSubnet(original_subnet)) {
if (!subnet->clientSupported(ctx.query_->getClasses())) { if (!subnet->clientSupported(ctx.query_->getClasses())) {
subnet = subnet->getNextSubnet(original_subnet);
continue; continue;
} }
@@ -882,12 +881,10 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
hint)); hint));
// check if the pool is allowed // check if the pool is allowed
if (pool && !pool->clientSupported(ctx.query_->getClasses())) { if (!pool || !pool->clientSupported(ctx.query_->getClasses())) {
pool.reset(); continue;
} }
if (pool) {
// Check which host reservation mode is supported in this subnet. // Check which host reservation mode is supported in this subnet.
Network::HRMode hr_mode = subnet->getHostReservationMode(); Network::HRMode hr_mode = subnet->getHostReservationMode();
@@ -931,11 +928,9 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
.arg(hint.toText()); .arg(hint.toText());
} }
} else { } else if (lease->expired()) {
// If the lease is expired, we may likely reuse it, but... // If the lease is expired, we may likely reuse it, but...
if (lease->expired()) {
ConstHostPtr host; ConstHostPtr host;
if (hr_mode != Network::HR_DISABLED) { if (hr_mode != Network::HR_DISABLED) {
host = HostMgr::instance().get6(subnet->getID(), hint); host = HostMgr::instance().get6(subnet->getID(), hint);
@@ -965,10 +960,6 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
} }
} }
} }
}
subnet = subnet->getNextSubnet(original_subnet);
}
uint64_t total_attempts = 0; uint64_t total_attempts = 0;
@@ -994,10 +985,9 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
ctx.subnet_ = subnet = original_subnet; ctx.subnet_ = subnet = original_subnet;
while (subnet) { for (; subnet; subnet = subnet->getNextSubnet(original_subnet)) {
if (!subnet->clientSupported(ctx.query_->getClasses())) { if (!subnet->clientSupported(ctx.query_->getClasses())) {
subnet = subnet->getNextSubnet(original_subnet);
continue; continue;
} }
@@ -1012,7 +1002,6 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
ctx.query_->getClasses()); ctx.query_->getClasses());
// Try next subnet if there is no chance to get something // Try next subnet if there is no chance to get something
if (possible_attempts == 0) { if (possible_attempts == 0) {
subnet = subnet->getNextSubnet(original_subnet);
continue; continue;
} }
uint64_t max_attempts = (attempts_ > 0 ? attempts_ : possible_attempts); uint64_t max_attempts = (attempts_ > 0 ? attempts_ : possible_attempts);
@@ -1084,8 +1073,7 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
// Although the address was free just microseconds ago, it may have // Although the address was free just microseconds ago, it may have
// been taken just now. If the lease insertion fails, we continue // been taken just now. If the lease insertion fails, we continue
// allocation attempts. // allocation attempts.
} else { } else if (existing->expired()) {
if (existing->expired()) {
// Make sure it's not reserved. // Make sure it's not reserved.
if (hr_mode == Network::HR_ALL && if (hr_mode == Network::HR_ALL &&
HostMgr::instance().get6(subnet->getID(), candidate)) { HostMgr::instance().get6(subnet->getID(), candidate)) {
@@ -1108,9 +1096,6 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
} }
} }
subnet = subnet->getNextSubnet(original_subnet);
}
// Unable to allocate an address, return an empty lease. // Unable to allocate an address, return an empty lease.
LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V6_ALLOC_FAIL) LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V6_ALLOC_FAIL)
.arg(ctx.query_->getLabel()) .arg(ctx.query_->getLabel())
@@ -1201,16 +1186,14 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
// There is no lease for a reservation in this IA. So, let's now iterate // There is no lease for a reservation in this IA. So, let's now iterate
// over reservations specified and try to allocate one of them for the IA. // over reservations specified and try to allocate one of them for the IA.
Subnet6Ptr subnet = ctx.subnet_; for (Subnet6Ptr subnet = ctx.subnet_; subnet;
subnet = subnet->getNextSubnet(ctx.subnet_)) {
while (subnet) {
SubnetID subnet_id = subnet->getID(); SubnetID subnet_id = subnet->getID();
// No hosts for this subnet or the subnet not supported. // No hosts for this subnet or the subnet not supported.
if (!subnet->clientSupported(ctx.query_->getClasses()) || if (!subnet->clientSupported(ctx.query_->getClasses()) ||
ctx.hosts_.count(subnet_id) == 0) { ctx.hosts_.count(subnet_id) == 0) {
subnet = subnet->getNextSubnet(ctx.subnet_);
continue; continue;
} }
@@ -1289,10 +1272,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
// would work for any number of reservations. // would work for any number of reservations.
return; return;
} }
} }
subnet = subnet->getNextSubnet(ctx.subnet_);
} }
} }
@@ -4018,6 +3998,9 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
CalloutHandle::CalloutNextStep callout_status = CalloutHandle::NEXT_STEP_CONTINUE; CalloutHandle::CalloutNextStep callout_status = CalloutHandle::NEXT_STEP_CONTINUE;
for (uint64_t i = 0; i < max_attempts; ++i) { for (uint64_t i = 0; i < max_attempts; ++i) {
++total_attempts;
IOAddress candidate = allocator->pickAddress(subnet, IOAddress candidate = allocator->pickAddress(subnet,
ctx.query_->getClasses(), ctx.query_->getClasses(),
client_id, client_id,
@@ -4048,8 +4031,6 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
subnet.reset(); subnet.reset();
break; break;
} }
++total_attempts;
} }
// This pointer may be set to NULL if hooks set SKIP status. // This pointer may be set to NULL if hooks set SKIP status.