|
@@ -289,10 +289,45 @@ AllocEngine::AllocatorPtr AllocEngine::getAllocator(Lease::Type type) {
|
|
return (alloc->second);
|
|
return (alloc->second);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+} // end of isc::dhcp namespace
|
|
|
|
+} // end of isc namespace
|
|
|
|
+
|
|
|
|
+namespace {
|
|
|
|
+
|
|
|
|
+/// @brief Extends the lease lifetime.
|
|
|
|
+///
|
|
|
|
+/// This function is called to conditionally extend the lifetime of
|
|
|
|
+/// the DHCPv4 or DHCPv6 lease. It is envisaged that this function will
|
|
|
|
+/// make a decision if the lease lifetime should be extended, using
|
|
|
|
+/// a preconfigured threshold, which would indicate how many percent
|
|
|
|
+/// of the valid lifetime should have passed for the lease lifetime
|
|
|
|
+/// to be extended. The lease lifetime would not be extended if
|
|
|
|
+/// the threshold hasn't been reached.
|
|
|
|
+///
|
|
|
|
+/// @todo Currently this function always extends the lease lifetime.
|
|
|
|
+/// In the future, it will take the threshold value into account,
|
|
|
|
+/// once the threshold is configurable.
|
|
|
|
+///
|
|
|
|
+/// @param [out] lease A lease for which the lifetime should be
|
|
|
|
+/// extended.
|
|
|
|
+///
|
|
|
|
+/// @return true if the lease lifetime has been extended, false
|
|
|
|
+/// otherwise.
|
|
|
|
+bool
|
|
|
|
+conditionalExtendLifetime(Lease& lease) {
|
|
|
|
+ lease.cltt_ = time(NULL);
|
|
|
|
+ return (true);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+} // end of anonymous namespace
|
|
|
|
+
|
|
// ##########################################################################
|
|
// ##########################################################################
|
|
// # DHCPv6 lease allocation code starts here.
|
|
// # DHCPv6 lease allocation code starts here.
|
|
// ##########################################################################
|
|
// ##########################################################################
|
|
|
|
|
|
|
|
+namespace isc {
|
|
|
|
+namespace dhcp {
|
|
|
|
+
|
|
AllocEngine::ClientContext6::ClientContext6()
|
|
AllocEngine::ClientContext6::ClientContext6()
|
|
: subnet_(), duid_(), iaid_(0), type_(Lease::TYPE_NA), hwaddr_(),
|
|
: subnet_(), duid_(), iaid_(0), type_(Lease::TYPE_NA), hwaddr_(),
|
|
hints_(), fwd_dns_update_(false), rev_dns_update_(false), hostname_(""),
|
|
hints_(), fwd_dns_update_(false), rev_dns_update_(false), hostname_(""),
|
|
@@ -422,7 +457,7 @@ AllocEngine::allocateLeases6(ClientContext6& ctx) {
|
|
|
|
|
|
if (!leases.empty()) {
|
|
if (!leases.empty()) {
|
|
// Return old leases so the server can see what has changed.
|
|
// Return old leases so the server can see what has changed.
|
|
- return (updateFqdnData(ctx, leases));
|
|
|
|
|
|
+ return (updateLeaseData(ctx, leases));
|
|
}
|
|
}
|
|
|
|
|
|
// If leases are empty at this stage, it means that we used to have
|
|
// If leases are empty at this stage, it means that we used to have
|
|
@@ -719,7 +754,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, Lease6Collection& exis
|
|
uint8_t prefix_len = resv->second.getPrefixLen();
|
|
uint8_t prefix_len = resv->second.getPrefixLen();
|
|
|
|
|
|
// Check if already have this lease on the existing_leases list.
|
|
// Check if already have this lease on the existing_leases list.
|
|
- for (Lease6Collection::const_iterator l = existing_leases.begin();
|
|
|
|
|
|
+ for (Lease6Collection::iterator l = existing_leases.begin();
|
|
l != existing_leases.end(); ++l) {
|
|
l != existing_leases.end(); ++l) {
|
|
|
|
|
|
// Ok, we already have a lease for this reservation and it's usable
|
|
// Ok, we already have a lease for this reservation and it's usable
|
|
@@ -729,6 +764,13 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, Lease6Collection& exis
|
|
.arg(ctx.query_->getLabel())
|
|
.arg(ctx.query_->getLabel())
|
|
.arg((*l)->typeToText((*l)->type_))
|
|
.arg((*l)->typeToText((*l)->type_))
|
|
.arg((*l)->addr_.toText());
|
|
.arg((*l)->addr_.toText());
|
|
|
|
+
|
|
|
|
+ // If this is a real allocation, we may need to extend the lease
|
|
|
|
+ // lifetime.
|
|
|
|
+ if (!ctx.fake_allocation_ && conditionalExtendLifetime(**l)) {
|
|
|
|
+ LeaseMgrFactory::instance().updateLease6(*l);
|
|
|
|
+ }
|
|
|
|
+
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1186,12 +1228,14 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
|
|
lease->valid_lft_ = ctx.subnet_->getValid();
|
|
lease->valid_lft_ = ctx.subnet_->getValid();
|
|
lease->t1_ = ctx.subnet_->getT1();
|
|
lease->t1_ = ctx.subnet_->getT1();
|
|
lease->t2_ = ctx.subnet_->getT2();
|
|
lease->t2_ = ctx.subnet_->getT2();
|
|
- lease->cltt_ = time(NULL);
|
|
|
|
lease->hostname_ = ctx.hostname_;
|
|
lease->hostname_ = ctx.hostname_;
|
|
lease->fqdn_fwd_ = ctx.fwd_dns_update_;
|
|
lease->fqdn_fwd_ = ctx.fwd_dns_update_;
|
|
lease->fqdn_rev_ = ctx.rev_dns_update_;
|
|
lease->fqdn_rev_ = ctx.rev_dns_update_;
|
|
lease->hwaddr_ = ctx.hwaddr_;
|
|
lease->hwaddr_ = ctx.hwaddr_;
|
|
|
|
|
|
|
|
+ // Extend lease lifetime if it is time to extend it.
|
|
|
|
+ conditionalExtendLifetime(*lease);
|
|
|
|
+
|
|
LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE_DETAIL_DATA,
|
|
LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE_DETAIL_DATA,
|
|
ALLOC_ENGINE_V6_EXTEND_NEW_LEASE_DATA)
|
|
ALLOC_ENGINE_V6_EXTEND_NEW_LEASE_DATA)
|
|
.arg(ctx.query_->getLabel())
|
|
.arg(ctx.query_->getLabel())
|
|
@@ -1246,7 +1290,7 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
|
|
}
|
|
}
|
|
|
|
|
|
Lease6Collection
|
|
Lease6Collection
|
|
-AllocEngine::updateFqdnData(ClientContext6& ctx, const Lease6Collection& leases) {
|
|
|
|
|
|
+AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases) {
|
|
Lease6Collection updated_leases;
|
|
Lease6Collection updated_leases;
|
|
for (Lease6Collection::const_iterator lease_it = leases.begin();
|
|
for (Lease6Collection::const_iterator lease_it = leases.begin();
|
|
lease_it != leases.end(); ++lease_it) {
|
|
lease_it != leases.end(); ++lease_it) {
|
|
@@ -1255,7 +1299,8 @@ AllocEngine::updateFqdnData(ClientContext6& ctx, const Lease6Collection& leases)
|
|
lease->fqdn_rev_ = ctx.rev_dns_update_;
|
|
lease->fqdn_rev_ = ctx.rev_dns_update_;
|
|
lease->hostname_ = ctx.hostname_;
|
|
lease->hostname_ = ctx.hostname_;
|
|
if (!ctx.fake_allocation_ &&
|
|
if (!ctx.fake_allocation_ &&
|
|
- ((lease->fqdn_fwd_ != (*lease_it)->fqdn_fwd_) ||
|
|
|
|
|
|
+ (conditionalExtendLifetime(*lease) ||
|
|
|
|
+ (lease->fqdn_fwd_ != (*lease_it)->fqdn_fwd_) ||
|
|
(lease->fqdn_rev_ != (*lease_it)->fqdn_rev_) ||
|
|
(lease->fqdn_rev_ != (*lease_it)->fqdn_rev_) ||
|
|
(lease->hostname_ != (*lease_it)->hostname_))) {
|
|
(lease->hostname_ != (*lease_it)->hostname_))) {
|
|
ctx.changed_leases_.push_back(*lease_it);
|
|
ctx.changed_leases_.push_back(*lease_it);
|