2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 14:35:29 +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;
while (subnet) {
for (; subnet; subnet = subnet->getNextSubnet(original_subnet)) {
if (!subnet->clientSupported(ctx.query_->getClasses())) {
subnet = subnet->getNextSubnet(original_subnet);
continue;
}
@@ -882,12 +881,10 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
hint));
// check if the pool is allowed
if (pool && !pool->clientSupported(ctx.query_->getClasses())) {
pool.reset();
if (!pool || !pool->clientSupported(ctx.query_->getClasses())) {
continue;
}
if (pool) {
// Check which host reservation mode is supported in this subnet.
Network::HRMode hr_mode = subnet->getHostReservationMode();
@@ -931,11 +928,9 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
.arg(hint.toText());
}
} else {
} else if (lease->expired()) {
// If the lease is expired, we may likely reuse it, but...
if (lease->expired()) {
ConstHostPtr host;
if (hr_mode != Network::HR_DISABLED) {
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;
@@ -994,10 +985,9 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
ctx.subnet_ = subnet = original_subnet;
while (subnet) {
for (; subnet; subnet = subnet->getNextSubnet(original_subnet)) {
if (!subnet->clientSupported(ctx.query_->getClasses())) {
subnet = subnet->getNextSubnet(original_subnet);
continue;
}
@@ -1012,7 +1002,6 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
ctx.query_->getClasses());
// Try next subnet if there is no chance to get something
if (possible_attempts == 0) {
subnet = subnet->getNextSubnet(original_subnet);
continue;
}
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
// been taken just now. If the lease insertion fails, we continue
// allocation attempts.
} else {
if (existing->expired()) {
} else if (existing->expired()) {
// Make sure it's not reserved.
if (hr_mode == Network::HR_ALL &&
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.
LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V6_ALLOC_FAIL)
.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
// over reservations specified and try to allocate one of them for the IA.
Subnet6Ptr subnet = ctx.subnet_;
while (subnet) {
for (Subnet6Ptr subnet = ctx.subnet_; subnet;
subnet = subnet->getNextSubnet(ctx.subnet_)) {
SubnetID subnet_id = subnet->getID();
// No hosts for this subnet or the subnet not supported.
if (!subnet->clientSupported(ctx.query_->getClasses()) ||
ctx.hosts_.count(subnet_id) == 0) {
subnet = subnet->getNextSubnet(ctx.subnet_);
continue;
}
@@ -1289,10 +1272,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
// would work for any number of reservations.
return;
}
}
subnet = subnet->getNextSubnet(ctx.subnet_);
}
}
@@ -4018,6 +3998,9 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
CalloutHandle::CalloutNextStep callout_status = CalloutHandle::NEXT_STEP_CONTINUE;
for (uint64_t i = 0; i < max_attempts; ++i) {
++total_attempts;
IOAddress candidate = allocator->pickAddress(subnet,
ctx.query_->getClasses(),
client_id,
@@ -4048,8 +4031,6 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
subnet.reset();
break;
}
++total_attempts;
}
// This pointer may be set to NULL if hooks set SKIP status.