2024-01-29 10:17:26 +01:00
|
|
|
// Copyright (C) 2021-2024 Internet Systems Consortium, Inc. ("ISC")
|
2020-12-18 18:53:18 +01:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <dhcpsrv/cfg_globals.h>
|
|
|
|
|
|
|
|
using namespace isc::data;
|
|
|
|
|
|
|
|
namespace isc {
|
|
|
|
namespace dhcp {
|
|
|
|
|
|
|
|
const std::map<std::string, int>
|
|
|
|
CfgGlobals::nameToIndex = {
|
|
|
|
// Common parameters.
|
|
|
|
{ "valid-lifetime", VALID_LIFETIME },
|
|
|
|
{ "min-valid-lifetime", MIN_VALID_LIFETIME },
|
|
|
|
{ "max-valid-lifetime", MAX_VALID_LIFETIME },
|
|
|
|
{ "renew-timer", RENEW_TIMER },
|
|
|
|
{ "rebind-timer", REBIND_TIMER },
|
|
|
|
{ "decline-probation-period", DECLINE_PROBATION_PERIOD },
|
|
|
|
{ "dhcp4o6-port", DHCP4O6_PORT },
|
|
|
|
{ "comment", COMMENT },
|
|
|
|
{ "server-tag", SERVER_TAG },
|
|
|
|
{ "reservations-global", RESERVATIONS_GLOBAL },
|
|
|
|
{ "reservations-in-subnet", RESERVATIONS_IN_SUBNET },
|
|
|
|
{ "reservations-out-of-pool", RESERVATIONS_OUT_OF_POOL },
|
|
|
|
{ "calculate-tee-times", CALCULATE_TEE_TIMES },
|
|
|
|
{ "t1-percent", T1_PERCENT },
|
|
|
|
{ "t2-percent", T2_PERCENT },
|
|
|
|
{ "hostname-char-set", HOSTNAME_CHAR_SET },
|
|
|
|
{ "hostname-char-replacement", HOSTNAME_CHAR_REPLACEMENT },
|
|
|
|
{ "ddns-send-updates", DDNS_SEND_UPDATES },
|
|
|
|
{ "ddns-override-no-update", DDNS_OVERRIDE_NO_UPDATE },
|
|
|
|
{ "ddns-override-client-update", DDNS_OVERRIDE_CLIENT_UPDATE },
|
|
|
|
{ "ddns-replace-client-name", DDNS_REPLACE_CLIENT_NAME },
|
|
|
|
{ "ddns-generated-prefix", DDNS_GENERATED_PREFIX },
|
|
|
|
{ "ddns-qualifying-suffix", DDNS_QUALIFYING_SUFFIX },
|
|
|
|
{ "store-extended-info", STORE_EXTENDED_INFO },
|
|
|
|
{ "statistic-default-sample-count", STATISTIC_DEFAULT_SAMPLE_COUNT },
|
|
|
|
{ "statistic-default-sample-age", STATISTIC_DEFAULT_SAMPLE_AGE },
|
|
|
|
{ "cache-threshold", CACHE_THRESHOLD },
|
|
|
|
{ "cache-max-age", CACHE_MAX_AGE },
|
2022-02-04 21:34:10 +01:00
|
|
|
{ "early-global-reservations-lookup", EARLY_GLOBAL_RESERVATIONS_LOOKUP },
|
2020-12-18 18:53:18 +01:00
|
|
|
{ "ip-reservations-unique", IP_RESERVATIONS_UNIQUE },
|
2022-02-03 19:41:17 +02:00
|
|
|
{ "reservations-lookup-first", RESERVATIONS_LOOKUP_FIRST },
|
2020-12-18 18:53:18 +01:00
|
|
|
{ "ddns-update-on-renew", DDNS_UPDATE_ON_RENEW },
|
2021-11-26 15:31:35 +01:00
|
|
|
{ "parked-packet-limit", PARKED_PACKET_LIMIT },
|
2022-11-21 12:13:01 +01:00
|
|
|
{ "allocator", ALLOCATOR },
|
2023-03-21 11:53:32 -04:00
|
|
|
{ "ddns-ttl-percent", DDNS_TTL_PERCENT },
|
2023-05-31 13:51:19 -04:00
|
|
|
{ "ddns-conflict-resolution-mode", DDNS_CONFLICT_RESOLUTION_MODE },
|
2024-01-17 18:52:05 +02:00
|
|
|
{ "compatibility", COMPATIBILITY },
|
|
|
|
{ "dhcp-ddns", DHCP_DDNS },
|
|
|
|
{ "expired-leases-processing", EXPIRED_LEASES_PROCESSING },
|
|
|
|
{ "multi-threading", MULTI_THREADING },
|
|
|
|
{ "sanity-checks", SANITY_CHECKS },
|
|
|
|
{ "dhcp-queue-control", DHCP_QUEUE_CONTROL },
|
2020-12-18 18:53:18 +01:00
|
|
|
|
|
|
|
// DHCPv4 specific parameters.
|
|
|
|
{ "echo-client-id", ECHO_CLIENT_ID },
|
|
|
|
{ "match-client-id", MATCH_CLIENT_ID },
|
|
|
|
{ "authoritative", AUTHORITATIVE },
|
|
|
|
{ "next-server", NEXT_SERVER },
|
|
|
|
{ "server-hostname", SERVER_HOSTNAME },
|
|
|
|
{ "boot-file-name", BOOT_FILE_NAME },
|
2023-03-06 10:25:24 -05:00
|
|
|
{ "offer-lifetime", OFFER_LIFETIME },
|
2024-03-30 10:23:23 +01:00
|
|
|
{ "stash-agent-options", STASH_AGENT_OPTIONS },
|
2020-12-18 18:53:18 +01:00
|
|
|
|
|
|
|
// DHCPv6 specific parameters.
|
|
|
|
{ "data-directory", DATA_DIRECTORY },
|
|
|
|
{ "preferred-lifetime", PREFERRED_LIFETIME },
|
|
|
|
{ "min-preferred-lifetime", MIN_PREFERRED_LIFETIME },
|
2022-11-21 12:13:01 +01:00
|
|
|
{ "max-preferred-lifetime", MAX_PREFERRED_LIFETIME },
|
2024-01-17 18:52:05 +02:00
|
|
|
{ "pd-allocator", PD_ALLOCATOR },
|
|
|
|
{ "server-id", SERVER_ID }
|
2020-12-18 18:53:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Load time sanity check.
|
|
|
|
namespace {
|
|
|
|
struct CfgGlobalsChecks {
|
|
|
|
CfgGlobalsChecks() {
|
|
|
|
// Check the size for missing entries.
|
|
|
|
if (CfgGlobals::nameToIndex.size() != CfgGlobals::SIZE) {
|
|
|
|
isc_throw(Unexpected, "CfgGlobals::nameToIndex has "
|
|
|
|
<< CfgGlobals::nameToIndex.size()
|
|
|
|
<< " elements (expected " << CfgGlobals::SIZE << ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the name vector.
|
|
|
|
std::vector<std::string> names;
|
|
|
|
names.resize(CfgGlobals::SIZE);
|
2024-01-12 16:31:50 +02:00
|
|
|
for (auto const& it : CfgGlobals::nameToIndex) {
|
|
|
|
int idx = it.second;
|
2022-01-04 11:02:02 +02:00
|
|
|
if ((idx < 0) || (idx >= CfgGlobals::SIZE)) {
|
2020-12-18 18:53:18 +01:00
|
|
|
isc_throw(Unexpected, "invalid index " << idx
|
2024-01-12 16:31:50 +02:00
|
|
|
<< " for name " << it.first);
|
2020-12-18 18:53:18 +01:00
|
|
|
}
|
|
|
|
if (!names[idx].empty()) {
|
|
|
|
isc_throw(Unexpected, "duplicated names for " << idx
|
|
|
|
<< " got " << names[idx]);
|
|
|
|
}
|
2024-01-12 16:31:50 +02:00
|
|
|
names[idx] = it.first;
|
2020-12-18 18:53:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// No name should be empty.
|
2022-01-04 11:02:02 +02:00
|
|
|
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
|
2020-12-18 18:53:18 +01:00
|
|
|
if (names[idx].empty()) {
|
|
|
|
isc_throw(Unexpected, "missing name for " << idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CfgGlobalsChecks check;
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
CfgGlobals::CfgGlobals() : values_(SIZE) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstElementPtr
|
|
|
|
CfgGlobals::get(const std::string& name) const {
|
|
|
|
auto const& it = nameToIndex.find(name);
|
|
|
|
if (it == nameToIndex.cend()) {
|
|
|
|
isc_throw(NotFound, "invalid global parameter name '" << name << "'");
|
|
|
|
}
|
|
|
|
return (get(it->second));
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstElementPtr
|
|
|
|
CfgGlobals::get(int index) const {
|
2022-01-04 11:02:02 +02:00
|
|
|
if ((index < 0) || (index >= CfgGlobals::SIZE)) {
|
2020-12-18 18:53:18 +01:00
|
|
|
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
|
|
|
}
|
|
|
|
return (values_[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CfgGlobals::set(const std::string& name, ConstElementPtr value) {
|
|
|
|
auto const& it = nameToIndex.find(name);
|
|
|
|
if (it == nameToIndex.cend()) {
|
|
|
|
isc_throw(NotFound, "invalid global parameter name '" << name << "'");
|
|
|
|
}
|
2023-06-05 10:51:40 -04:00
|
|
|
|
2020-12-18 18:53:18 +01:00
|
|
|
set(it->second, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CfgGlobals::set(int index, ConstElementPtr value) {
|
2022-01-04 11:02:02 +02:00
|
|
|
if ((index < 0) || (index >= CfgGlobals::SIZE)) {
|
2020-12-18 18:53:18 +01:00
|
|
|
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
|
|
|
}
|
|
|
|
values_[index] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CfgGlobals::clear() {
|
2022-01-04 11:02:02 +02:00
|
|
|
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
|
2020-12-18 18:53:18 +01:00
|
|
|
if (values_[idx]) {
|
|
|
|
values_[idx] = ConstElementPtr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 23:55:26 +01:00
|
|
|
const CfgGlobals::MapType
|
|
|
|
CfgGlobals::valuesMap() const {
|
|
|
|
MapType map;
|
2024-01-12 16:31:50 +02:00
|
|
|
for (auto const& it : nameToIndex) {
|
|
|
|
int idx = it.second;
|
2020-12-18 23:55:26 +01:00
|
|
|
ConstElementPtr value = values_[idx];
|
|
|
|
if (value) {
|
2024-01-12 16:31:50 +02:00
|
|
|
map.insert(make_pair(it.first, value));
|
2020-12-18 23:55:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (map);
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:53:18 +01:00
|
|
|
ElementPtr
|
|
|
|
CfgGlobals::toElement() const {
|
|
|
|
ElementPtr result = Element::createMap();
|
2024-01-12 16:31:50 +02:00
|
|
|
for (auto const& it : nameToIndex) {
|
|
|
|
int idx = it.second;
|
2020-12-18 18:53:18 +01:00
|
|
|
ConstElementPtr value = values_[idx];
|
|
|
|
if (value) {
|
2024-01-12 16:31:50 +02:00
|
|
|
result->set(it.first, value);
|
2020-12-18 18:53:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace isc::dhcp
|
|
|
|
} // namespace isc
|