Kea: sanity_checks_parser.cc Source File

| Kea 3.2.0-git

sanity_checks_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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#include <dhcpsrv/parsers/sanity_checks_parser.h>
9#include <dhcpsrv/cfg_consistency.h>
10#include <cc/data.h>
11
12using namespace isc::data;
13
14namespace isc {
15namespace dhcp {
16
17void
18SanityChecksParser::parse(SrvConfig& cfg, const ConstElementPtr& sanity_checks) {
19
20 if (!sanity_checks) {
21 return;
22 }
23 if (sanity_checks->getType() != Element::map) {
24 isc_throw(DhcpConfigError, "sanity-checks is supposed to be a map");
25 }
26
27 // Subnet-id lease checker.
28 ConstElementPtr checks = sanity_checks->get("lease-checks");
29 if (checks) {
30 if (checks->getType() != Element::string) {
31 isc_throw(DhcpConfigError, "lease-checks must be a string");
32 }
33 std::string lc = checks->stringValue();
34 CfgConsistency::LeaseSanity check;
35 if (lc == "none") {
36 check = CfgConsistency::LEASE_CHECK_NONE;
37 } else if (lc == "warn") {
38 check = CfgConsistency::LEASE_CHECK_WARN;
39 } else if (lc == "fix") {
40 check = CfgConsistency::LEASE_CHECK_FIX;
41 } else if (lc == "fix-del") {
42 check = CfgConsistency::LEASE_CHECK_FIX_DEL;
43 } else if (lc == "del") {
44 check = CfgConsistency::LEASE_CHECK_DEL;
45 } else {
46 isc_throw(DhcpConfigError, "Unsupported lease-checks value: " << lc
47 << ", supported values are: none, warn, fix, fix-del, del");
48 }
49 cfg.getConsistency()->setLeaseSanityCheck(check);
50 }
51
52 // Extended info lease checker.
53 checks = sanity_checks->get("extended-info-checks");
54 if (checks) {
55 if (checks->getType() != Element::string) {
56 isc_throw(DhcpConfigError, "extended-info-checks must be a string");
57 }
58 std::string exc = checks->stringValue();
59 CfgConsistency::ExtendedInfoSanity check;
60 if (exc == "none") {
61 check = CfgConsistency::EXTENDED_INFO_CHECK_NONE;
62 } else if (exc == "fix") {
63 check = CfgConsistency::EXTENDED_INFO_CHECK_FIX;
64 } else if (exc == "strict") {
65 check = CfgConsistency::EXTENDED_INFO_CHECK_STRICT;
66 } else if (exc == "pedantic") {
67 check = CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC;
68 } else {
69 isc_throw(DhcpConfigError,
70 "Unsupported extended-info-checks value: " << exc
71 << ", supported values are: none, fix, strict, pedantic");
72 }
73 cfg.getConsistency()->setExtendedInfoSanityCheck(check);
74 }
75
76 // Additional sanity check fields will come in later here.
77}
78
79}
80}
cfg_consistency.h
isc::data::Element::map
@ map
Definition data.h:160
isc::data::Element::string
@ string
Definition data.h:157
isc::dhcp::CfgConsistency::LeaseSanity
LeaseSanity
Values for subnet-id sanity checks done for leases.
Definition cfg_consistency.h:24
isc::dhcp::CfgConsistency::LEASE_CHECK_FIX
@ LEASE_CHECK_FIX
Definition cfg_consistency.h:27
isc::dhcp::CfgConsistency::LEASE_CHECK_DEL
@ LEASE_CHECK_DEL
Definition cfg_consistency.h:32
isc::dhcp::CfgConsistency::LEASE_CHECK_FIX_DEL
@ LEASE_CHECK_FIX_DEL
Definition cfg_consistency.h:30
isc::dhcp::CfgConsistency::LEASE_CHECK_WARN
@ LEASE_CHECK_WARN
Definition cfg_consistency.h:26
isc::dhcp::CfgConsistency::LEASE_CHECK_NONE
@ LEASE_CHECK_NONE
Definition cfg_consistency.h:25
isc::dhcp::CfgConsistency::ExtendedInfoSanity
ExtendedInfoSanity
Values for extended info sanity checks done for leases.
Definition cfg_consistency.h:36
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_STRICT
@ EXTENDED_INFO_CHECK_STRICT
Definition cfg_consistency.h:39
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC
@ EXTENDED_INFO_CHECK_PEDANTIC
Definition cfg_consistency.h:41
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_FIX
@ EXTENDED_INFO_CHECK_FIX
Definition cfg_consistency.h:38
isc::dhcp::CfgConsistency::EXTENDED_INFO_CHECK_NONE
@ EXTENDED_INFO_CHECK_NONE
Definition cfg_consistency.h:37
isc::dhcp::DhcpConfigError
To be removed. Please use ConfigError instead.
Definition dhcp_config_error.h:58
isc::dhcp::SanityChecksParser::parse
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure
Definition sanity_checks_parser.cc:18
isc::dhcp::SrvConfig
Specifies current DHCP configuration.
Definition srv_config.h:50
isc::dhcp::SrvConfig::getConsistency
CfgConsistencyPtr getConsistency()
Returns non-const pointer to object holding sanity checks flags.
Definition srv_config.h:370
data.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data
Definition base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
sanity_checks_parser.h