summaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2020-11-11 17:43:36 +0100
committerFrancis Dupont <fdupont@isc.org>2021-01-11 16:05:46 +0100
commite78fbe1a4f0288f8df3f27a0ac094ffe7a77e4a4 (patch)
tree9b0e6416a67a0e95707b141aca60c3b06dd25b0b /src/bin
parent[#1418] Removed conditionalExtendLifetime (diff)
downloadkea-e78fbe1a4f0288f8df3f27a0ac094ffe7a77e4a4.tar.xz
kea-e78fbe1a4f0288f8df3f27a0ac094ffe7a77e4a4.zip
[#1418] Checkpoint: preparation code done
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/dhcp4/dhcp4_messages.cc2
-rw-r--r--src/bin/dhcp4/dhcp4_messages.h1
-rw-r--r--src/bin/dhcp4/dhcp4_messages.mes8
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc14
-rw-r--r--src/bin/dhcp6/dhcp6_messages.cc4
-rw-r--r--src/bin/dhcp6/dhcp6_messages.h2
-rw-r--r--src/bin/dhcp6/dhcp6_messages.mes16
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc86
8 files changed, 112 insertions, 21 deletions
diff --git a/src/bin/dhcp4/dhcp4_messages.cc b/src/bin/dhcp4/dhcp4_messages.cc
index df37920301..8124fb9d18 100644
--- a/src/bin/dhcp4/dhcp4_messages.cc
+++ b/src/bin/dhcp4/dhcp4_messages.cc
@@ -84,6 +84,7 @@ extern const isc::log::MessageID DHCP4_INIT_FAIL = "DHCP4_INIT_FAIL";
extern const isc::log::MessageID DHCP4_INIT_REBOOT = "DHCP4_INIT_REBOOT";
extern const isc::log::MessageID DHCP4_LEASE_ADVERT = "DHCP4_LEASE_ADVERT";
extern const isc::log::MessageID DHCP4_LEASE_ALLOC = "DHCP4_LEASE_ALLOC";
+extern const isc::log::MessageID DHCP4_LEASE_REUSE = "DHCP4_LEASE_REUSE";
extern const isc::log::MessageID DHCP4_MULTI_THREADING_INFO = "DHCP4_MULTI_THREADING_INFO";
extern const isc::log::MessageID DHCP4_NCR_CREATE = "DHCP4_NCR_CREATE";
extern const isc::log::MessageID DHCP4_NCR_CREATION_FAILED = "DHCP4_NCR_CREATION_FAILED";
@@ -236,6 +237,7 @@ const char* values[] = {
"DHCP4_INIT_REBOOT", "%1: client is in INIT-REBOOT state and requests address %2",
"DHCP4_LEASE_ADVERT", "%1: lease %2 will be advertised",
"DHCP4_LEASE_ALLOC", "%1: lease %2 has been allocated for %3 seconds",
+ "DHCP4_LEASE_REUSE", "%1: lease %2 has been reused for %3 seconds",
"DHCP4_MULTI_THREADING_INFO", "enabled: %1, number of threads: %2, queue size: %3",
"DHCP4_NCR_CREATE", "%1: DDNS updates enabled, therefore sending name change requests",
"DHCP4_NCR_CREATION_FAILED", "%1: failed to generate name change requests for DNS: %2",
diff --git a/src/bin/dhcp4/dhcp4_messages.h b/src/bin/dhcp4/dhcp4_messages.h
index 70e914145f..8d561bfbab 100644
--- a/src/bin/dhcp4/dhcp4_messages.h
+++ b/src/bin/dhcp4/dhcp4_messages.h
@@ -85,6 +85,7 @@ extern const isc::log::MessageID DHCP4_INIT_FAIL;
extern const isc::log::MessageID DHCP4_INIT_REBOOT;
extern const isc::log::MessageID DHCP4_LEASE_ADVERT;
extern const isc::log::MessageID DHCP4_LEASE_ALLOC;
+extern const isc::log::MessageID DHCP4_LEASE_REUSE;
extern const isc::log::MessageID DHCP4_MULTI_THREADING_INFO;
extern const isc::log::MessageID DHCP4_NCR_CREATE;
extern const isc::log::MessageID DHCP4_NCR_CREATION_FAILED;
diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes
index daaa60dfb2..9749a67908 100644
--- a/src/bin/dhcp4/dhcp4_messages.mes
+++ b/src/bin/dhcp4/dhcp4_messages.mes
@@ -456,6 +456,14 @@ client and the transaction identification information. The second argument
contains the allocated IPv4 address. The third argument is the validity
lifetime.
+% DHCP4_LEASE_REUSE %1: lease %2 has been reused for %3 seconds
+This informational message indicates that the server successfully reused a
+lease in response to client's message. The lease information will
+be sent to the client in the DHCPACK message. The first argument contains the
+client and the transaction identification information. The second argument
+contains the allocated IPv4 address. The third argument is the validity
+lifetime.
+
% DHCP4_MULTI_THREADING_INFO enabled: %1, number of threads: %2, queue size: %3
This is a message listing some information about the multi-threading parameters
with which the server is running.
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 8a59716582..4739e88446 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -1354,7 +1354,7 @@ Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
callout_handle->setArgument("query4", query);
Lease4CollectionPtr new_leases(new Lease4Collection());
- if (ctx->new_lease_) {
+ if (ctx->new_lease_ && (ctx->new_lease_->remaining_valid_lft_ == 0)) {
new_leases->push_back(ctx->new_lease_);
}
callout_handle->setArgument("leases4", new_leases);
@@ -2508,6 +2508,15 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) {
// switched to a different subnet within a shared network.
postAllocateNameUpdate(ctx, lease, query, resp, client_name_changed);
+ // Reuse the lease if possible.
+ if (lease->remaining_valid_lft_ > 0) {
+ lease->valid_lft_ = lease->remaining_valid_lft_;
+ LOG_INFO(lease4_logger, DHCP4_LEASE_REUSE)
+ .arg(query->getLabel())
+ .arg(lease->addr_.toText())
+ .arg(Lease::lifetimeToText(lease->valid_lft_));
+ }
+
// IP Address Lease time (type 51)
OptionPtr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
lease->valid_lft_));
@@ -2592,6 +2601,9 @@ Dhcpv4Srv::postAllocateNameUpdate(const AllocEngine::ClientContext4Ptr& ctx, con
// implementation) and log an error.
try {
if (!ctx->fake_allocation_) {
+ // The lease can't be reused.
+ lease->remaining_valid_lft_ = 0;
+
// The lease update should be safe, because the lease should
// be already in the database. In most cases the exception
// would be thrown if the lease was missing.
diff --git a/src/bin/dhcp6/dhcp6_messages.cc b/src/bin/dhcp6/dhcp6_messages.cc
index 3696558256..db95d640dd 100644
--- a/src/bin/dhcp6/dhcp6_messages.cc
+++ b/src/bin/dhcp6/dhcp6_messages.cc
@@ -86,6 +86,7 @@ extern const isc::log::MessageID DHCP6_LEASE_DATA = "DHCP6_LEASE_DATA";
extern const isc::log::MessageID DHCP6_LEASE_NA_WITHOUT_DUID = "DHCP6_LEASE_NA_WITHOUT_DUID";
extern const isc::log::MessageID DHCP6_LEASE_PD_WITHOUT_DUID = "DHCP6_LEASE_PD_WITHOUT_DUID";
extern const isc::log::MessageID DHCP6_LEASE_RENEW = "DHCP6_LEASE_RENEW";
+extern const isc::log::MessageID DHCP6_LEASE_REUSE = "DHCP6_LEASE_REUSE";
extern const isc::log::MessageID DHCP6_MULTI_THREADING_INFO = "DHCP6_MULTI_THREADING_INFO";
extern const isc::log::MessageID DHCP6_NOT_RUNNING = "DHCP6_NOT_RUNNING";
extern const isc::log::MessageID DHCP6_NO_INTERFACES = "DHCP6_NO_INTERFACES";
@@ -117,6 +118,7 @@ extern const isc::log::MessageID DHCP6_PD_LEASE_ADVERT_FAIL = "DHCP6_PD_LEASE_AD
extern const isc::log::MessageID DHCP6_PD_LEASE_ALLOC = "DHCP6_PD_LEASE_ALLOC";
extern const isc::log::MessageID DHCP6_PD_LEASE_ALLOC_FAIL = "DHCP6_PD_LEASE_ALLOC_FAIL";
extern const isc::log::MessageID DHCP6_PD_LEASE_RENEW = "DHCP6_PD_LEASE_RENEW";
+extern const isc::log::MessageID DHCP6_PD_LEASE_REUSE = "DHCP6_PD_LEASE_REUSE";
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_EXTEND = "DHCP6_PROCESS_IA_NA_EXTEND";
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_RELEASE = "DHCP6_PROCESS_IA_NA_RELEASE";
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_REQUEST = "DHCP6_PROCESS_IA_NA_REQUEST";
@@ -238,6 +240,7 @@ const char* values[] = {
"DHCP6_LEASE_NA_WITHOUT_DUID", "%1: address lease for address %2 does not have a DUID",
"DHCP6_LEASE_PD_WITHOUT_DUID", "%1: lease for prefix %2/%3 does not have a DUID",
"DHCP6_LEASE_RENEW", "%1: lease for address %2 and iaid=%3 has been allocated",
+ "DHCP6_LEASE_REUSE", "%1: lease for address %2 and iaid=%3 has been reused for %4 seconds",
"DHCP6_MULTI_THREADING_INFO", "enabled: %1, number of threads: %2, queue size: %3",
"DHCP6_NOT_RUNNING", "IPv6 DHCP server is not running",
"DHCP6_NO_INTERFACES", "failed to detect any network interfaces",
@@ -269,6 +272,7 @@ const char* values[] = {
"DHCP6_PD_LEASE_ALLOC", "%1: lease for prefix %2/%3 and iaid=%4 has been allocated for %5 seconds",
"DHCP6_PD_LEASE_ALLOC_FAIL", "%1: failed to grant a prefix lease for iaid=%2",
"DHCP6_PD_LEASE_RENEW", "%1: lease for prefix %2/%3 and iaid=%4 has been allocated",
+ "DHCP6_PD_LEASE_REUSE", "%1: lease for prefix %2/%3 and iaid=%4 has been reused for %5 seconds",
"DHCP6_PROCESS_IA_NA_EXTEND", "%1: extending lease lifetime for IA_NA option with iaid=%2",
"DHCP6_PROCESS_IA_NA_RELEASE", "%1: releasing lease for IA_NA option with iaid=%2",
"DHCP6_PROCESS_IA_NA_REQUEST", "%1: server is processing IA_NA option with iaid=%2 and hint=%3",
diff --git a/src/bin/dhcp6/dhcp6_messages.h b/src/bin/dhcp6/dhcp6_messages.h
index e30330bfef..6207fead91 100644
--- a/src/bin/dhcp6/dhcp6_messages.h
+++ b/src/bin/dhcp6/dhcp6_messages.h
@@ -87,6 +87,7 @@ extern const isc::log::MessageID DHCP6_LEASE_DATA;
extern const isc::log::MessageID DHCP6_LEASE_NA_WITHOUT_DUID;
extern const isc::log::MessageID DHCP6_LEASE_PD_WITHOUT_DUID;
extern const isc::log::MessageID DHCP6_LEASE_RENEW;
+extern const isc::log::MessageID DHCP6_LEASE_REUSE;
extern const isc::log::MessageID DHCP6_MULTI_THREADING_INFO;
extern const isc::log::MessageID DHCP6_NOT_RUNNING;
extern const isc::log::MessageID DHCP6_NO_INTERFACES;
@@ -118,6 +119,7 @@ extern const isc::log::MessageID DHCP6_PD_LEASE_ADVERT_FAIL;
extern const isc::log::MessageID DHCP6_PD_LEASE_ALLOC;
extern const isc::log::MessageID DHCP6_PD_LEASE_ALLOC_FAIL;
extern const isc::log::MessageID DHCP6_PD_LEASE_RENEW;
+extern const isc::log::MessageID DHCP6_PD_LEASE_REUSE;
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_EXTEND;
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_RELEASE;
extern const isc::log::MessageID DHCP6_PROCESS_IA_NA_REQUEST;
diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes
index 5ffc80dca2..567ba5dbe2 100644
--- a/src/bin/dhcp6/dhcp6_messages.mes
+++ b/src/bin/dhcp6/dhcp6_messages.mes
@@ -503,6 +503,14 @@ The first argument includes the client and transaction identification
information. The remaining arguments hold the allocated address and
IAID.
+% DHCP6_LEASE_REUSE %1: lease for address %2 and iaid=%3 has been reused for %4 seconds
+This informational message indicates that in response to a client's
+message, the server successfully reused a non-temporary address
+lease. This is a normal behavior and indicates successful operation.
+The first argument includes the client and transaction identification
+information. The remaining arguments hold the allocated address,
+IAID and validity lifetime.
+
% DHCP6_MULTI_THREADING_INFO enabled: %1, number of threads: %2, queue size: %3
This is a message listing some information about the multi-threading parameters
with which the server is running.
@@ -684,6 +692,14 @@ The first argument includes the client and transaction identification
information. The remaining arguments hold the allocated prefix,
prefix length and IAID.
+% DHCP6_PD_LEASE_REUSE %1: lease for prefix %2/%3 and iaid=%4 has been reused for %5 seconds
+This informational message indicates that in response to a client's
+message, the server successfully reused a prefix lease.
+This is a normal behavior and indicates successful operation.
+The first argument includes the client and transaction identification
+information. The remaining arguments hold the allocated prefix,
+prefix length, IAID and validity lifetime.
+
% DHCP6_PROCESS_IA_NA_EXTEND %1: extending lease lifetime for IA_NA option with iaid=%2
This message is logged when the server is starting to extend the lifetime
of the address lease associated with the particular IAID. The first argument
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 38f4687e16..656d291c04 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -1004,8 +1004,11 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
Lease6CollectionPtr new_leases(new Lease6Collection());
if (!ctx.new_leases_.empty()) {
- new_leases->assign(ctx.new_leases_.cbegin(),
- ctx.new_leases_.cend());
+ for (auto new_lease : ctx.new_leases_) {
+ if (new_lease->remaining_valid_lft_ == 0) {
+ new_leases->push_back(new_lease);
+ }
+ }
}
callout_handle->setArgument("leases6", new_leases);
@@ -2062,12 +2065,21 @@ Dhcpv6Srv::assignIA_NA(const Pkt6Ptr& query, const Pkt6Ptr& answer,
.arg(query->getLabel())
.arg(lease->addr_.toText())
.arg(ia->getIAID());
- } else {
+ } else if (lease->remaining_valid_lft_ == 0) {
LOG_INFO(lease6_logger, DHCP6_LEASE_ALLOC)
.arg(query->getLabel())
.arg(lease->addr_.toText())
.arg(ia->getIAID())
.arg(Lease::lifetimeToText(lease->valid_lft_));
+ } else {
+ auto age = lease->valid_lft_ - lease->remaining_valid_lft_;
+ lease->valid_lft_ = lease->remaining_valid_lft_;
+ lease->preferred_lft_ -= age;
+ LOG_INFO(lease6_logger, DHCP6_LEASE_REUSE)
+ .arg(query->getLabel())
+ .arg(lease->addr_.toText())
+ .arg(ia->getIAID())
+ .arg(Lease::lifetimeToText(lease->valid_lft_));
}
LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_LEASE_DATA)
.arg(query->getLabel())
@@ -2170,11 +2182,6 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& /*answer*/,
for (Lease6Collection::iterator l = leases.begin();
l != leases.end(); ++l) {
- // Check for new minimum lease time
- if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
- min_preferred_lft = (*l)->preferred_lft_;
- }
-
// We have a lease! Let's wrap its content into IA_PD option
// with IAADDR suboption.
if (ctx.fake_allocation_) {
@@ -2183,13 +2190,28 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& /*answer*/,
.arg((*l)->addr_.toText())
.arg(static_cast<int>((*l)->prefixlen_))
.arg(ia->getIAID());
- } else {
+ } else if ((*l)->remaining_valid_lft_ == 0) {
LOG_INFO(lease6_logger, DHCP6_PD_LEASE_ALLOC)
.arg(query->getLabel())
.arg((*l)->addr_.toText())
.arg(static_cast<int>((*l)->prefixlen_))
.arg(ia->getIAID())
.arg(Lease::lifetimeToText((*l)->valid_lft_));
+ } else {
+ auto age = (*l)->valid_lft_ - (*l)->remaining_valid_lft_;
+ (*l)->valid_lft_ = (*l)->remaining_valid_lft_;
+ (*l)->preferred_lft_ -= age;
+ LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE)
+ .arg(query->getLabel())
+ .arg((*l)->addr_.toText())
+ .arg(static_cast<int>((*l)->prefixlen_))
+ .arg(ia->getIAID())
+ .arg(Lease::lifetimeToText((*l)->valid_lft_));
+ }
+
+ // Check for new minimum lease time
+ if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
+ min_preferred_lft = (*l)->preferred_lft_;
}
boost::shared_ptr<Option6IAPrefix>
@@ -2329,16 +2351,27 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, const Pkt6Ptr& answer,
(*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_));
ia_rsp->addOption(iaaddr);
+ if ((*l)->remaining_valid_lft_ == 0) {
+ LOG_INFO(lease6_logger, DHCP6_LEASE_RENEW)
+ .arg(query->getLabel())
+ .arg((*l)->addr_.toText())
+ .arg(ia->getIAID());
+ } else {
+ auto age = (*l)->valid_lft_ - (*l)->remaining_valid_lft_;
+ (*l)->valid_lft_ = (*l)->remaining_valid_lft_;
+ (*l)->preferred_lft_ -= age;
+ LOG_INFO(lease6_logger, DHCP6_LEASE_REUSE)
+ .arg(query->getLabel())
+ .arg((*l)->addr_.toText())
+ .arg(ia->getIAID())
+ .arg(Lease::lifetimeToText((*l)->valid_lft_));
+ }
+
// Check for new minimum lease time
if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
min_preferred_lft = (*l)->preferred_lft_;
}
- LOG_INFO(lease6_logger, DHCP6_LEASE_RENEW)
- .arg(query->getLabel())
- .arg((*l)->addr_.toText())
- .arg(ia->getIAID());
-
// Now remove this prefix from the hints list.
AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
@@ -2523,17 +2556,29 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query,
}
}
+ if ((*l)->remaining_valid_lft_ == 0) {
+ LOG_INFO(lease6_logger, DHCP6_PD_LEASE_RENEW)
+ .arg(query->getLabel())
+ .arg((*l)->addr_.toText())
+ .arg(static_cast<int>((*l)->prefixlen_))
+ .arg(ia->getIAID());
+ } else {
+ auto age = (*l)->valid_lft_ - (*l)->remaining_valid_lft_;
+ (*l)->valid_lft_ = (*l)->remaining_valid_lft_;
+ (*l)->preferred_lft_ -= age;
+ LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE)
+ .arg(query->getLabel())
+ .arg((*l)->addr_.toText())
+ .arg(static_cast<int>((*l)->prefixlen_))
+ .arg(ia->getIAID())
+ .arg(Lease::lifetimeToText((*l)->valid_lft_));
+ }
+
// Check for new minimum lease time
if (((*l)->preferred_lft_ > 0) && ((*l)->preferred_lft_ < min_preferred_lft)) {
min_preferred_lft = (*l)->preferred_lft_;
}
- LOG_INFO(lease6_logger, DHCP6_PD_LEASE_RENEW)
- .arg(query->getLabel())
- .arg((*l)->addr_.toText())
- .arg(static_cast<int>((*l)->prefixlen_))
- .arg(ia->getIAID());
-
// Now remove this prefix from the hints list.
AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
@@ -4290,6 +4335,7 @@ Dhcpv6Srv::checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer,
(*l)->hostname_ = ctx.hostname_;
(*l)->fqdn_fwd_ = ctx.fwd_dns_update_;
(*l)->fqdn_rev_ = ctx.rev_dns_update_;
+ (*l)->remaining_valid_lft_ = 0;
LeaseMgrFactory::instance().updateLease6(*l);
}
}