mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 23:45:27 +00:00
[295-min-max-lease-time-configuration-options] checkpoint
This commit is contained in:
@@ -15,23 +15,88 @@ using namespace isc::util;
|
||||
namespace isc {
|
||||
namespace dhcp {
|
||||
|
||||
const Triplet<uint32_t>
|
||||
BaseNetworkParser::parseLifetime(const ConstElementPtr& scope,
|
||||
const std::string& name) {
|
||||
uint32_t value;
|
||||
bool has_value = false;
|
||||
uint32_t min_value;
|
||||
bool has_min = false;
|
||||
uint32_t max_value;
|
||||
bool has_max = false;
|
||||
if (scope->contains(name)) {
|
||||
value = getInteger(scope, name);
|
||||
has_value = true;
|
||||
}
|
||||
if (scope->contains("default-" + name)) {
|
||||
if (has_value) {
|
||||
isc_throw(DhcpConfigError, "have both " << name << " and default-"
|
||||
<< name << " in " << scope->getPosition());
|
||||
}
|
||||
value = getInteger(scope, "default-" + name);
|
||||
has_value = true;
|
||||
}
|
||||
if (scope->contains("min-" + name)) {
|
||||
min_value = getInteger(scope, "min-" + name);
|
||||
has_min = true;
|
||||
}
|
||||
if (scope->contains("max-" + name)) {
|
||||
max_value = getInteger(scope, "max-" + name);
|
||||
has_max = true;
|
||||
}
|
||||
if (!has_value && !has_min && !has_max) {
|
||||
return (Triplet<uint32_t>());
|
||||
}
|
||||
if (has_value) {
|
||||
if (!has_min && !has_max) {
|
||||
// default only.
|
||||
min_value = value;
|
||||
max_value = value;
|
||||
} else if (!has_min) {
|
||||
// default and max.
|
||||
min_value = value;
|
||||
} else if (!has_max) {
|
||||
// default and min.
|
||||
max_value = value;
|
||||
}
|
||||
} else if (has_min) {
|
||||
// min only.
|
||||
if (!has_max) {
|
||||
value = min_value;
|
||||
max_value = min_value;
|
||||
} else {
|
||||
// min and max.
|
||||
isc_throw(DhcpConfigError, "have min-" << name << " and max-"
|
||||
<< name << " but no default-" << name << " nor "
|
||||
<< name << " in " << scope->getPosition());
|
||||
}
|
||||
} else {
|
||||
// max only.
|
||||
min_value = max_value;
|
||||
value = max_value;
|
||||
}
|
||||
// Check that value is between min and max.
|
||||
if ((value < min_value) || (value > max_value)) {
|
||||
isc_throw(DhcpConfigError, "the value of default-" << name << " ("
|
||||
<< value << ") is not between min-" << name << " ("
|
||||
<< min_value << ") and max-" << name << " ("
|
||||
<< max_value << ")");
|
||||
}
|
||||
return (Triplet<uint32_t>(min_value, value, max_value));
|
||||
}
|
||||
|
||||
void
|
||||
BaseNetworkParser::parseCommonTimers(const ConstElementPtr& network_data,
|
||||
NetworkPtr& network) {
|
||||
Triplet<uint32_t> t1;
|
||||
if (network_data->contains("renew-timer")) {
|
||||
network->setT1(getInteger(network_data, "renew-timer"));
|
||||
}
|
||||
|
||||
Triplet<uint32_t> t2;
|
||||
if (network_data->contains("rebind-timer")) {
|
||||
network->setT2(getInteger(network_data, "rebind-timer"));
|
||||
}
|
||||
|
||||
Triplet<uint32_t> valid;
|
||||
if (network_data->contains("valid-lifetime")) {
|
||||
network->setValid(getInteger(network_data, "valid-lifetime"));
|
||||
}
|
||||
network->setValid(parseLifetime(network_data, "valid-lifetime"));
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user