Kea: ping_check_config.cc Source File

| Kea 3.2.0-git

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
18const data::SimpleKeywords
19 PingCheckConfig::CONFIG_KEYWORDS =
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
28PingCheckConfig::PingCheckConfig() :
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
37PingCheckConfig::parse(data::ConstElementPtr config) {
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.
43 SimpleParser::checkKeywords(CONFIG_KEYWORDS, config);
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
Element::integer
@ integer
Definition data.h:153
Element::boolean
@ boolean
Definition data.h:155
isc::data::SimpleParser::checkKeywords
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
Definition lib/cc/simple_parser.cc:35
isc::dhcp::DhcpConfigError
To be removed. Please use ConfigError instead.
Definition dhcp_config_error.h:58
isc::ping_check::PingCheckConfig::PingCheckConfig
PingCheckConfig()
Constructor.
Definition ping_check_config.cc:28
isc::ping_check::PingCheckConfig::parse
void parse(data::ConstElementPtr config)
Extracts member values from an Element::map.
Definition ping_check_config.cc:37
isc::ping_check::PingCheckConfig::CONFIG_KEYWORDS
static const data::SimpleKeywords CONFIG_KEYWORDS
List of valid parameters and expected types.
Definition ping_check_config.h:21
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::config
Definition command_interpreter.cc:23
isc::data
Definition base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::SimpleKeywords
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Definition lib/cc/simple_parser.h:36
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::ping_check
Definition config_cache.cc:19
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
ping_check_config.h