Kea 3.3.4
base_network_parser.h
Go to the documentation of this file.
1// Copyright (C) 2019-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#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
132 void parseAdaptiveLeaseTimeParam(const data::ConstElementPtr& network_data,
133 NetworkPtr& network);
134
142 void parseOfferLft(const data::ConstElementPtr& network_data,
143 Network4Ptr& network);
144public:
145 typedef std::function<void(const isc::dhcp::ClientClass&)> ClassAdderFunc;
146
153 ClassAdderFunc adder_func);
154
161 ClassAdderFunc adder_func);
162
189 template<typename DdnsOwnerTypePtr>
191 DdnsOwnerTypePtr owner) {
192
193 if (config->contains("ddns-send-updates")) {
194 owner->setDdnsSendUpdates(getBoolean(config, "ddns-send-updates"));
195 }
196
197 if (config->contains("ddns-override-no-update")) {
198 owner->setDdnsOverrideNoUpdate(getBoolean(config, "ddns-override-no-update"));
199 }
200
201 if (config->contains("ddns-override-client-update")) {
202 owner->setDdnsOverrideClientUpdate(getBoolean(config, "ddns-override-client-update"));
203 }
204
205 if (config->contains("ddns-replace-client-name")) {
206 owner->setDdnsReplaceClientNameMode(getAndConvert<D2ClientConfig::ReplaceClientNameMode,
208 (config, "ddns-replace-client-name",
209 "ReplaceClientName mode"));
210 }
211
212 if (config->contains("ddns-generated-prefix")) {
213 owner->setDdnsGeneratedPrefix(getString(config, "ddns-generated-prefix"));
214 }
215
216 if (config->contains("ddns-qualifying-suffix")) {
217 owner->setDdnsQualifyingSuffix(getString(config, "ddns-qualifying-suffix"));
218 }
219
220 if (config->contains("ddns-reverse-zone")) {
221 owner->setDdnsReverseZone(getString(config, "ddns-reverse-zone"));
222 }
223
224 std::string hostname_char_set;
225 if (config->contains("hostname-char-set")) {
226 hostname_char_set = getString(config, "hostname-char-set");
227 owner->setHostnameCharSet(hostname_char_set);
228 }
229
230 std::string hostname_char_replacement;
231 if (config->contains("hostname-char-replacement")) {
232 hostname_char_replacement = getString(config, "hostname-char-replacement");
233 owner->setHostnameCharReplacement(hostname_char_replacement);
234 }
235
236 // We need to validate sanitizer values here so we can detect problems and
237 // cause a configuration. We don't retain the compilation because it's not
238 // something we can inherit.
239 if (!hostname_char_set.empty()) {
240 try {
242 new util::str::StringSanitizer(hostname_char_set,
243 hostname_char_replacement));
244 } catch (const std::exception& ex) {
245 isc_throw(BadValue, "hostname-char-set '" << hostname_char_set
246 << "' is not a valid regular expression");
247 }
248 }
249
250 if (config->contains("ddns-update-on-renew")) {
251 owner->setDdnsUpdateOnRenew(getBoolean(config, "ddns-update-on-renew"));
252 }
253
254 bool has_ddns_ttl = false;
255 uint32_t ddns_ttl = 0;
256 if (config->contains("ddns-ttl")) {
257 ddns_ttl = getInteger(config, "ddns-ttl");
258 owner->setDdnsTtl(ddns_ttl);
259 has_ddns_ttl = true;
260 }
261
262 if (config->contains("ddns-ttl-percent")) {
263 if (has_ddns_ttl) {
264 isc_throw(BadValue, "cannot specify both ddns-ttl-percent and ddns-ttl");
265 }
266
267 owner->setDdnsTtlPercent(getDouble(config, "ddns-ttl-percent"));
268 }
269
270 uint32_t ddns_ttl_min = 0;
271 if (config->contains("ddns-ttl-min")) {
272 if (has_ddns_ttl) {
273 isc_throw(BadValue, "cannot specify both ddns-ttl-min and ddns-ttl");
274 }
275
276 ddns_ttl_min = getInteger(config, "ddns-ttl-min");
277 owner->setDdnsTtlMin(ddns_ttl_min);
278 }
279
280 if (config->contains("ddns-ttl-max")) {
281 if (has_ddns_ttl) {
282 isc_throw(BadValue, "cannot specify both ddns-ttl-max and ddns-ttl");
283 }
284
285 uint32_t ddns_ttl_max = getInteger(config, "ddns-ttl-max");
286 if (ddns_ttl_max < ddns_ttl_min) {
287 isc_throw(BadValue, "ddns-ttl-max: " << ddns_ttl_max
288 << " must be greater than ddns-ttl-min: " << ddns_ttl_min);
289 }
290
291 owner->setDdnsTtlMax(ddns_ttl_max);
292 }
293
294 // For backward compatibility, ddns-conflict-resolution-mode is optional.
295 if (config->contains("ddns-conflict-resolution-mode")) {
296 owner->setDdnsConflictResolutionMode(getString(config,
297 "ddns-conflict-resolution-mode"));
298 }
299 }
300};
301
302} // end of namespace isc::dhcp
303} // end of namespace isc
304
305#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 'client-classes'.
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.
void parseAdaptiveLeaseTimeParam(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameter related to adaptive lease time.
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 'evaluate-additional-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:30
std::string ClientClass
Defines a single class name.
Definition classify.h:45
boost::shared_ptr< Network4 > Network4Ptr
Pointer to the Network4 object.
Definition network.h:1522
boost::shared_ptr< Network6 > Network6Ptr
Pointer to the Network6 object.
Definition network.h:1527
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.