Kea 3.3.4
cfg_globals.cc
Go to the documentation of this file.
1// Copyright (C) 2021-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
9
10using namespace isc::data;
11
12namespace isc {
13namespace dhcp {
14
15const std::map<std::string, int>
17 // Common parameters.
18 { "valid-lifetime", VALID_LIFETIME },
19 { "min-valid-lifetime", MIN_VALID_LIFETIME },
20 { "max-valid-lifetime", MAX_VALID_LIFETIME },
21 { "renew-timer", RENEW_TIMER },
22 { "rebind-timer", REBIND_TIMER },
23 { "decline-probation-period", DECLINE_PROBATION_PERIOD },
24 { "dhcp4o6-port", DHCP4O6_PORT },
25 { "comment", COMMENT },
26 { "server-tag", SERVER_TAG },
27 { "reservations-global", RESERVATIONS_GLOBAL },
28 { "reservations-in-subnet", RESERVATIONS_IN_SUBNET },
29 { "reservations-out-of-pool", RESERVATIONS_OUT_OF_POOL },
30 { "calculate-tee-times", CALCULATE_TEE_TIMES },
31 { "t1-percent", T1_PERCENT },
32 { "t2-percent", T2_PERCENT },
33 { "hostname-char-set", HOSTNAME_CHAR_SET },
34 { "hostname-char-replacement", HOSTNAME_CHAR_REPLACEMENT },
35 { "ddns-send-updates", DDNS_SEND_UPDATES },
36 { "ddns-override-no-update", DDNS_OVERRIDE_NO_UPDATE },
37 { "ddns-override-client-update", DDNS_OVERRIDE_CLIENT_UPDATE },
38 { "ddns-replace-client-name", DDNS_REPLACE_CLIENT_NAME },
39 { "ddns-generated-prefix", DDNS_GENERATED_PREFIX },
40 { "ddns-qualifying-suffix", DDNS_QUALIFYING_SUFFIX },
41 { "ddns-reverse-zone", DDNS_REVERSE_ZONE },
42 { "store-extended-info", STORE_EXTENDED_INFO },
43 { "statistic-default-sample-count", STATISTIC_DEFAULT_SAMPLE_COUNT },
44 { "statistic-default-sample-age", STATISTIC_DEFAULT_SAMPLE_AGE },
45 { "cache-threshold", CACHE_THRESHOLD },
46 { "cache-max-age", CACHE_MAX_AGE },
47 { "early-global-reservations-lookup", EARLY_GLOBAL_RESERVATIONS_LOOKUP },
48 { "ip-reservations-unique", IP_RESERVATIONS_UNIQUE },
49 { "reservations-lookup-first", RESERVATIONS_LOOKUP_FIRST },
50 { "ddns-update-on-renew", DDNS_UPDATE_ON_RENEW },
51 { "parked-packet-limit", PARKED_PACKET_LIMIT },
52 { "allocator", ALLOCATOR },
53 { "ddns-ttl-percent", DDNS_TTL_PERCENT },
54 { "ddns-conflict-resolution-mode", DDNS_CONFLICT_RESOLUTION_MODE },
55 { "compatibility", COMPATIBILITY },
56 { "dhcp-ddns", DHCP_DDNS },
57 { "expired-leases-processing", EXPIRED_LEASES_PROCESSING },
58 { "multi-threading", MULTI_THREADING },
59 { "sanity-checks", SANITY_CHECKS },
60 { "dhcp-queue-control", DHCP_QUEUE_CONTROL },
61 { "ddns-ttl", DDNS_TTL },
62 { "ddns-ttl-min", DDNS_TTL_MIN },
63 { "ddns-ttl-max", DDNS_TTL_MAX },
64 { "host-reservation-identifiers", HOST_RESERVATION_IDENTIFIERS },
65 { "adaptive-lease-time-threshold", ADAPTIVE_LEASE_TIME_THRESHOLD },
66
67 // DHCPv4 specific parameters.
68 { "echo-client-id", ECHO_CLIENT_ID },
69 { "match-client-id", MATCH_CLIENT_ID },
70 { "authoritative", AUTHORITATIVE },
71 { "next-server", NEXT_SERVER },
72 { "server-hostname", SERVER_HOSTNAME },
73 { "boot-file-name", BOOT_FILE_NAME },
74 { "offer-lifetime", OFFER_LIFETIME },
75 { "stash-agent-options", STASH_AGENT_OPTIONS },
76
77 // DHCPv6 specific parameters.
78 { "data-directory", DATA_DIRECTORY },
79 { "preferred-lifetime", PREFERRED_LIFETIME },
80 { "min-preferred-lifetime", MIN_PREFERRED_LIFETIME },
81 { "max-preferred-lifetime", MAX_PREFERRED_LIFETIME },
82 { "pd-allocator", PD_ALLOCATOR },
83 { "server-id", SERVER_ID },
84 { "allow-address-registration", ALLOW_ADDRESS_REGISTRATION },
85};
86
87// Load time sanity check.
88namespace {
89struct CfgGlobalsChecks {
90 CfgGlobalsChecks() {
91 // Check the size for missing entries.
93 isc_throw(Unexpected, "CfgGlobals::nameToIndex has "
95 << " elements (expected " << CfgGlobals::SIZE << ")");
96 }
97
98 // Build the name vector.
99 std::vector<std::string> names;
100 names.resize(CfgGlobals::SIZE);
101 for (auto const& it : CfgGlobals::nameToIndex) {
102 int idx = it.second;
103 if ((idx < 0) || (idx >= CfgGlobals::SIZE)) {
104 isc_throw(Unexpected, "invalid index " << idx
105 << " for name " << it.first);
106 }
107 if (!names[idx].empty()) {
108 isc_throw(Unexpected, "duplicated names for " << idx
109 << " got " << names[idx]);
110 }
111 names[idx] = it.first;
112 }
113
114 // No name should be empty.
115 for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
116 if (names[idx].empty()) {
117 isc_throw(Unexpected, "missing name for " << idx);
118 }
119 }
120 }
121};
122
123CfgGlobalsChecks check;
124} // end of anonymous namespace
125
128
130CfgGlobals::get(const std::string& name) const {
131 auto const& it = nameToIndex.find(name);
132 if (it == nameToIndex.cend()) {
133 isc_throw(NotFound, "invalid global parameter name '" << name << "'");
134 }
135 return (get(it->second));
136}
137
139CfgGlobals::get(int index) const {
140 if ((index < 0) || (index >= CfgGlobals::SIZE)) {
141 isc_throw(OutOfRange, "invalid global parameter index " << index);
142 }
143 return (values_[index]);
144}
145
146void
147CfgGlobals::set(const std::string& name, ConstElementPtr value) {
148 auto const& it = nameToIndex.find(name);
149 if (it == nameToIndex.cend()) {
150 isc_throw(NotFound, "invalid global parameter name '" << name << "'");
151 }
152
153 set(it->second, value);
154}
155
156void
158 if ((index < 0) || (index >= CfgGlobals::SIZE)) {
159 isc_throw(OutOfRange, "invalid global parameter index " << index);
160 }
161 values_[index] = value;
162}
163
164void
166 for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
167 if (values_[idx]) {
168 values_[idx] = ConstElementPtr();
169 }
170 }
171}
172
175 MapType map;
176 for (auto const& it : nameToIndex) {
177 int idx = it.second;
178 ConstElementPtr value = values_[idx];
179 if (value) {
180 map.insert(make_pair(it.first, value));
181 }
182 }
183 return (map);
184}
185
189 for (auto const& it : nameToIndex) {
190 int idx = it.second;
191 ConstElementPtr value = values_[idx];
192 if (value) {
193 result->set(it.first, value);
194 }
195 }
196 return (result);
197}
198
199} // namespace isc::dhcp
200} // namespace isc
A generic exception that is thrown when an object can not be found.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:355
void clear()
Clear configured parameter values.
void set(const std::string &name, isc::data::ConstElementPtr value)
Set a configured parameter value by name.
const MapType valuesMap() const
Returns configured parameters as a map.
CfgGlobals()
Instance members.
static const std::map< std::string, int > nameToIndex
Name to index map.
std::map< std::string, isc::data::ConstElementPtr > MapType
Type of name and value map.
isc::data::ElementPtr toElement() const
Unparse configured global parameters.
isc::data::ConstElementPtr get(const std::string &name) const
Get a configured parameter value by name.
std::vector< isc::data::ConstElementPtr > values_
Vectors of values.
#define COMMENT
Definition d2_lexer.cc:1274
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
Defines the logger used by the top-level component of kea-lfc.