2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-22 09:57:41 +00:00
kea/src/lib/dhcpsrv/cfg_globals.cc

194 lines
6.3 KiB
C++
Raw Normal View History

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 },
{ "reservations-lookup-first", RESERVATIONS_LOOKUP_FIRST },
2020-12-18 18:53:18 +01:00
{ "ddns-update-on-renew", DDNS_UPDATE_ON_RENEW },
{ "parked-packet-limit", PARKED_PACKET_LIMIT },
2022-11-21 12:13:01 +01:00
{ "allocator", ALLOCATOR },
{ "ddns-ttl-percent", DDNS_TTL_PERCENT },
[#2276] Initial impl ddns-resolution-conflict-mode New Files: src/bin/d2/check_exists_add.cc src/bin/d2/check_exists_add.h src/bin/d2/check_exists_remove.cc src/bin/d2/check_exists_remove.h src/bin/d2/simple_add_without_dhcid.cc src/bin/d2/simple_add_without_dhcid.h src/bin/d2/simple_remove_without_dhcid.cc src/bin/d2/simple_remove_without_dhcid.h src/bin/d2/tests/check_exists_add_unittests.cc src/bin/d2/tests/check_exists_remove_unittests.cc src/bin/d2/tests/simple_add_without_dhcid_unittests.cc src/bin/d2/tests/simple_remove_without_dhcid_unittests.cc Modified: doc/examples/kea4/all-keys.json doc/examples/kea4/with-ddns.json doc/examples/kea6/all-keys.json doc/examples/kea6/with-ddns.json src/bin/d2/Makefile.am src/bin/d2/check_exists_add.cc src/bin/d2/check_exists_add.h src/bin/d2/check_exists_remove.cc src/bin/d2/check_exists_remove.h src/bin/d2/d2_update_mgr.cc src/bin/d2/simple_add_without_dhcid.cc src/bin/d2/simple_add_without_dhcid.h src/bin/d2/simple_remove_without_dhcid.cc src/bin/d2/simple_remove_without_dhcid.h src/bin/d2/tests/Makefile.am src/bin/d2/tests/check_exists_add_unittests.cc src/bin/d2/tests/check_exists_remove_unittests.cc src/bin/d2/tests/d2_process_unittests.cc src/bin/d2/tests/d2_queue_mgr_unittests.cc src/bin/d2/tests/d2_update_mgr_unittests.cc src/bin/d2/tests/nc_add_unittests.cc src/bin/d2/tests/nc_remove_unittests.cc src/bin/d2/tests/simple_add_unittests.cc src/bin/d2/tests/simple_add_without_dhcid_unittests.cc src/bin/d2/tests/simple_remove_unittests.cc src/bin/d2/tests/simple_remove_without_dhcid_unittests.cc src/bin/dhcp4/dhcp4_lexer.cc src/bin/dhcp4/dhcp4_lexer.ll src/bin/dhcp4/dhcp4_parser.cc src/bin/dhcp4/dhcp4_parser.h src/bin/dhcp4/dhcp4_parser.yy src/bin/dhcp4/json_config_parser.cc src/bin/dhcp4/location.hh src/bin/dhcp4/parser_context.h src/bin/dhcp4/tests/config_parser_unittest.cc src/bin/dhcp4/tests/d2_unittest.cc src/bin/dhcp4/tests/fqdn_unittest.cc src/bin/dhcp4/tests/get_config_unittest.cc src/bin/dhcp6/dhcp6_lexer.cc src/bin/dhcp6/dhcp6_lexer.ll src/bin/dhcp6/dhcp6_parser.cc src/bin/dhcp6/dhcp6_parser.h src/bin/dhcp6/dhcp6_parser.yy src/bin/dhcp6/dhcp6_srv.cc src/bin/dhcp6/json_config_parser.cc src/bin/dhcp6/location.hh src/bin/dhcp6/parser_context.h src/bin/dhcp6/tests/config_parser_unittest.cc src/bin/dhcp6/tests/d2_unittest.cc src/bin/dhcp6/tests/fqdn_unittest.cc src/bin/dhcp6/tests/get_config_unittest.cc src/lib/d2srv/testutils/nc_test_utils.cc src/lib/d2srv/testutils/nc_test_utils.h src/lib/dhcp_ddns/ncr_msg.cc src/lib/dhcp_ddns/ncr_msg.h src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc src/lib/dhcp_ddns/tests/ncr_unittests.cc src/lib/dhcpsrv/cfg_globals.cc src/lib/dhcpsrv/cfg_globals.h src/lib/dhcpsrv/ncr_generator.cc src/lib/dhcpsrv/network.cc src/lib/dhcpsrv/network.h src/lib/dhcpsrv/parsers/base_network_parser.cc src/lib/dhcpsrv/parsers/base_network_parser.h src/lib/dhcpsrv/parsers/simple_parser4.cc src/lib/dhcpsrv/parsers/simple_parser6.cc src/lib/dhcpsrv/srv_config.cc src/lib/dhcpsrv/srv_config.h src/lib/dhcpsrv/tests/d2_udp_unittest.cc src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc src/lib/dhcpsrv/tests/ncr_generator_unittest.cc src/lib/dhcpsrv/tests/network_unittest.cc src/lib/dhcpsrv/tests/srv_config_unittest.cc
2023-05-31 13:51:19 -04:00
{ "ddns-conflict-resolution-mode", DDNS_CONFLICT_RESOLUTION_MODE },
{ "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 },
{ "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 },
{ "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);
for (auto const& it : CfgGlobals::nameToIndex) {
int idx = it.second;
if ((idx < 0) || (idx >= CfgGlobals::SIZE)) {
2020-12-18 18:53:18 +01:00
isc_throw(Unexpected, "invalid index " << idx
<< " 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]);
}
names[idx] = it.first;
2020-12-18 18:53:18 +01:00
}
// No name should be empty.
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 {
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 << "'");
}
2020-12-18 18:53:18 +01:00
set(it->second, value);
}
void
CfgGlobals::set(int index, ConstElementPtr value) {
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() {
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
2020-12-18 18:53:18 +01:00
if (values_[idx]) {
values_[idx] = ConstElementPtr();
}
}
}
const CfgGlobals::MapType
CfgGlobals::valuesMap() const {
MapType map;
for (auto const& it : nameToIndex) {
int idx = it.second;
ConstElementPtr value = values_[idx];
if (value) {
map.insert(make_pair(it.first, value));
}
}
return (map);
}
2020-12-18 18:53:18 +01:00
ElementPtr
CfgGlobals::toElement() const {
ElementPtr result = Element::createMap();
for (auto const& it : nameToIndex) {
int idx = it.second;
2020-12-18 18:53:18 +01:00
ConstElementPtr value = values_[idx];
if (value) {
result->set(it.first, value);
2020-12-18 18:53:18 +01:00
}
}
return (result);
}
} // namespace isc::dhcp
} // namespace isc