Kea 2.7.7
base_network_parser.h
Go to the documentation of this file.
1// Copyright (C) 2019-2025 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#ifndef BASE_NETWORK_PARSER_H
8#define BASE_NETWORK_PARSER_H
9
10#include <cc/data.h>
11#include <cc/simple_parser.h>
12#include <dhcpsrv/cfg_globals.h>
13#include <dhcpsrv/network.h>
14
15namespace isc {
16namespace dhcp {
17
21protected:
22
38 void parseCommon(const data::ConstElementPtr& network_data,
39 NetworkPtr& network);
40
55 void parseTeePercents(const data::ConstElementPtr& network_data,
56 NetworkPtr& network);
57
71 void parseCacheParams(const data::ConstElementPtr& network_data,
72 NetworkPtr& network);
73
92 void parseDdnsParams(const data::ConstElementPtr& network_data,
93 NetworkPtr& network);
94
104 void parseAllocatorParams(const data::ConstElementPtr& network_data,
105 NetworkPtr& network);
106
117 void parsePdAllocatorParams(const data::ConstElementPtr& network_data,
118 Network6Ptr& network);
119
127 void parseOfferLft(const data::ConstElementPtr& network_data,
128 Network4Ptr& network);
129public:
130 typedef std::function<void(const isc::dhcp::ClientClass&)> ClassAdderFunc;
131
139 ClassAdderFunc adder_func);
140
148 ClassAdderFunc adder_func);
149
175 template<typename DdnsOwnerTypePtr>
177 DdnsOwnerTypePtr owner) {
178
179 if (config->contains("ddns-send-updates")) {
180 owner->setDdnsSendUpdates(getBoolean(config, "ddns-send-updates"));
181 }
182
183 if (config->contains("ddns-override-no-update")) {
184 owner->setDdnsOverrideNoUpdate(getBoolean(config, "ddns-override-no-update"));
185 }
186
187 if (config->contains("ddns-override-client-update")) {
188 owner->setDdnsOverrideClientUpdate(getBoolean(config, "ddns-override-client-update"));
189 }
190
191 if (config->contains("ddns-replace-client-name")) {
192 owner->setDdnsReplaceClientNameMode(getAndConvert<D2ClientConfig::ReplaceClientNameMode,
194 (config, "ddns-replace-client-name",
195 "ReplaceClientName mode"));
196 }
197
198 if (config->contains("ddns-generated-prefix")) {
199 owner->setDdnsGeneratedPrefix(getString(config, "ddns-generated-prefix"));
200 }
201
202 if (config->contains("ddns-qualifying-suffix")) {
203 owner->setDdnsQualifyingSuffix(getString(config, "ddns-qualifying-suffix"));
204 }
205
206 std::string hostname_char_set;
207 if (config->contains("hostname-char-set")) {
208 hostname_char_set = getString(config, "hostname-char-set");
209 owner->setHostnameCharSet(hostname_char_set);
210 }
211
212 std::string hostname_char_replacement;
213 if (config->contains("hostname-char-replacement")) {
214 hostname_char_replacement = getString(config, "hostname-char-replacement");
215 owner->setHostnameCharReplacement(hostname_char_replacement);
216 }
217
218 // We need to validate sanitizer values here so we can detect problems and
219 // cause a configuration. We don't retain the compilation because it's not
220 // something we can inherit.
221 if (!hostname_char_set.empty()) {
222 try {
224 new util::str::StringSanitizer(hostname_char_set,
225 hostname_char_replacement));
226 } catch (const std::exception& ex) {
227 isc_throw(BadValue, "hostname-char-set '" << hostname_char_set
228 << "' is not a valid regular expression");
229 }
230 }
231
232 if (config->contains("ddns-update-on-renew")) {
233 owner->setDdnsUpdateOnRenew(getBoolean(config, "ddns-update-on-renew"));
234 }
235
236 bool has_ddns_ttl = false;
237 uint32_t ddns_ttl = 0;
238 if (config->contains("ddns-ttl")) {
239 ddns_ttl = getInteger(config, "ddns-ttl");
240 owner->setDdnsTtl(ddns_ttl);
241 has_ddns_ttl = true;
242 }
243
244 if (config->contains("ddns-ttl-percent")) {
245 if (has_ddns_ttl) {
246 isc_throw(BadValue, "cannot specify both ddns-ttl-percent and ddns-ttl");
247 }
248
249 owner->setDdnsTtlPercent(getDouble(config, "ddns-ttl-percent"));
250 }
251
252 uint32_t ddns_ttl_min = 0;
253 if (config->contains("ddns-ttl-min")) {
254 if (has_ddns_ttl) {
255 isc_throw(BadValue, "cannot specify both ddns-ttl-min and ddns-ttl");
256 }
257
258 ddns_ttl_min = getInteger(config, "ddns-ttl-min");
259 owner->setDdnsTtlMin(ddns_ttl_min);
260 }
261
262 if (config->contains("ddns-ttl-max")) {
263 if (has_ddns_ttl) {
264 isc_throw(BadValue, "cannot specify both ddns-ttl-max and ddns-ttl");
265 }
266
267 uint32_t ddns_ttl_max = getInteger(config, "ddns-ttl-max");
268 if (ddns_ttl_max < ddns_ttl_min) {
269 isc_throw(BadValue, "ddns-ttl-max: " << ddns_ttl_max
270 << " must be greater than ddns-ttl-min: " << ddns_ttl_min);
271 }
272
273 owner->setDdnsTtlMax(ddns_ttl_max);
274 }
275
276 // For backward compatibility, ddns-conflict-resolution-mode is optional.
277 if (config->contains("ddns-conflict-resolution-mode")) {
278 owner->setDdnsConflictResolutionMode(getString(config,
279 "ddns-conflict-resolution-mode"));
280 }
281 }
282};
283
284} // end of namespace isc::dhcp
285} // end of namespace isc
286
287#endif
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
target_type getAndConvert(isc::data::ConstElementPtr scope, const std::string &name, const std::string &type_name)
Returns a converted value from a scope.
static double getDouble(const ConstElementPtr &scope, const std::string &name)
Returns a floating point parameter from a scope.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
Common configuration parser for shared networks and subnets.
void parseCacheParams(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters related to lease cache settings.
void parseAllocatorParams(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters pertaining to allocator selection.
static void getClientClassesElem(data::ConstElementPtr params, ClassAdderFunc adder_func)
Fetches the element for either 'client-classes' or deprecated 'client-class'.
void parseDdnsParams(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters pertaining to DDNS behavior.
void parseCommon(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses common parameters.
std::function< void(const isc::dhcp::ClientClass &)> ClassAdderFunc
void parseDdnsParameters(const data::ConstElementPtr &config, DdnsOwnerTypePtr owner)
Parses parameters pertaining to DDNS behavior.
static void getAdditionalClassesElem(data::ConstElementPtr params, ClassAdderFunc adder_func)
Fetches the element for either 'evaluate-additional-classes' or deprecated 'require-client-classes'.
void parseTeePercents(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters related to "percent" timers settings.
void parsePdAllocatorParams(const data::ConstElementPtr &network_data, Network6Ptr &network)
Parses parameters pertaining to prefix delegation allocator selection.
void parseOfferLft(const data::ConstElementPtr &network_data, Network4Ptr &network)
Parses offer-lifetime parameter (v4 only)
static ReplaceClientNameMode stringToReplaceClientNameMode(const std::string &mode_str)
Converts labels to ReplaceClientNameMode enum values.
ReplaceClientNameMode
Defines the client name replacement modes.
Implements a regular expression based string scrubber.
Definition str.h:222
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
std::string ClientClass
Defines a single class name.
Definition classify.h:43
boost::shared_ptr< Network4 > Network4Ptr
Pointer to the Network4 object.
Definition network.h:1478
boost::shared_ptr< Network6 > Network6Ptr
Pointer to the Network6 object.
Definition network.h:1483
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
Definition network.h:73
std::unique_ptr< StringSanitizer > StringSanitizerPtr
Type representing the pointer to the StringSanitizer.
Definition str.h:263
Defines the logger used by the top-level component of kea-lfc.