From: Francis Dupont Date: Tue, 12 Aug 2025 09:10:05 +0000 (+0200) Subject: [#226] Checkpoint v4 code X-Git-Tag: Kea-3.1.1~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=beec9ae4e6532d6b66834e581cc6b66cfc9baff8;p=thirdparty%2Fkea.git [#226] Checkpoint v4 code --- diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 60928006c4..775759c391 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -4463,9 +4463,26 @@ AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr, } // Get the context appropriate lifetime. - uint32_t valid_lft = (ctx.offer_lft_ ? ctx.offer_lft_ : getValidLft(ctx)); + uint32_t valid_lft = ctx.offer_lft_; + if (!valid_lft) { + bool use_min(false); + auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold(); + if (!threshold.unspecified() && (threshold < 1.0)) { + auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_V4)-> + getOccupancyRate(addr, ctx.query_->getClasses()); + if (occupancy >= threshold) { + use_min = true; + } + } + if (use_min) { + // Log + getMinValidLft(ctx, valid_lft); + } else { + valid_lft = getValidLft(ctx); + } + } - time_t now = time(NULL); + time_t now = time(0); ClientIdPtr client_id; if (ctx.subnet_->getMatchClientId()) { @@ -5161,10 +5178,27 @@ AllocEngine::updateLease4Information(const Lease4Ptr& lease, changed = true; lease->client_id_ = ClientIdPtr(); } - lease->cltt_ = time(NULL); + lease->cltt_ = time(0); // Get the context appropriate valid lifetime. - lease->valid_lft_ = (ctx.offer_lft_ ? ctx.offer_lft_ : getValidLft(ctx)); + lease->valid_lft_ = ctx.offer_lft_; + if (!lease->valid_lft_) { + bool use_min(false); + auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold(); + if (!threshold.unspecified() && (threshold < 1.0)) { + auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_V4)-> + getOccupancyRate(lease->addr_, ctx.query_->getClasses()); + if (occupancy >= threshold) { + use_min = true; + } + } + if (use_min) { + // Log + getMinValidLft(ctx, lease->valid_lft_); + } else { + lease->valid_lft_ = getValidLft(ctx); + } + } // Valid lifetime has changed. if (lease->valid_lft_ != lease->current_valid_lft_) {