Kea 3.1.1
ping_check_config.cc
Go to the documentation of this file.
1// Copyright (C) 2023-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#include <config.h>
8
9#include <ping_check_config.h>
10
11using namespace isc;
12using namespace isc::data;
13using namespace isc::dhcp;
14
15namespace isc {
16namespace ping_check {
17
20{
21 { "enable-ping-check", Element::boolean },
22 { "min-ping-requests", Element::integer },
23 { "reply-timeout", Element::integer },
24 { "ping-cltt-secs", Element::integer},
25 { "ping-channel-threads", Element::integer}
26};
27
29 enable_ping_check_(true),
30 min_ping_requests_(1),
31 reply_timeout_(100),
32 ping_cltt_secs_(60),
33 ping_channel_threads_(0) {
34}
35
36void
38 // Use a local instance to collect values. This way we
39 // avoid corrupting current values if there are any errors.
40 PingCheckConfig local;
41
42 // Note checkKeywords() will throw DhcpConfigError if there is a problem.
44 ConstElementPtr value = config->get("enable-ping-check");
45 if (value) {
46 local.setEnablePingCheck(value->boolValue());
47 }
48
49 value = config->get("min-ping-requests");
50 if (value) {
51 int64_t val = value->intValue();
52 if (val <= 0) {
53 isc_throw(DhcpConfigError, "invalid min-ping-requests: '"
54 << val << "', must be greater than 0");
55 }
56
57 local.setMinPingRequests(static_cast<size_t>(val));
58 }
59
60 value = config->get("reply-timeout");
61 if (value) {
62 int64_t val = value->intValue();
63 if (val <= 0) {
64 isc_throw(DhcpConfigError, "invalid reply-timeout: '"
65 << val << "', must be greater than 0");
66 }
67
68 local.setReplyTimeout(static_cast<size_t>(val));
69 }
70
71 value = config->get("ping-cltt-secs");
72 if (value) {
73 int64_t val = value->intValue();
74 if (val < 0) {
75 isc_throw(DhcpConfigError, "invalid ping-cltt-secs: '"
76 << val << "', cannot be less than 0");
77 }
78
79 local.setPingClttSecs(static_cast<size_t>(val));
80 }
81
82 value = config->get("ping-channel-threads");
83 if (value) {
84 int64_t val = value->intValue();
85 if (val < 0) {
86 isc_throw(DhcpConfigError, "invalid ping-channel-threads: '"
87 << val << "', cannot be less than 0");
88 }
89
90 local.setPingChannelThreads(static_cast<size_t>(val));
91 }
92
93 // All values good, copy from local instance.
94 *this = local;
95}
96
97} // end of namespace ping_check
98} // end of namespace isc
@ integer
Definition data.h:140
@ boolean
Definition data.h:142
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
To be removed. Please use ConfigError instead.
void parse(data::ConstElementPtr config)
Extracts member values from an Element::map.
static const data::SimpleKeywords CONFIG_KEYWORDS
List of valid parameters and expected types.
#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::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Defines the logger used by the top-level component of kea-lfc.