summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/parsers/sanity_checks_parser.cc
blob: 6210857a919377244be1b1fd53fdea4b7e3d1283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>
#include <dhcpsrv/parsers/sanity_checks_parser.h>
#include <dhcpsrv/cfg_consistency.h>
#include <cc/data.h>

using namespace isc::data;

namespace isc {
namespace dhcp {

void
SanityChecksParser::parse(SrvConfig& cfg, const ConstElementPtr& sanity_checks) {

    if (!sanity_checks) {
        return;
    }
    if (sanity_checks->getType() != Element::map) {
        isc_throw(DhcpConfigError, "sanity-checks is supposed to be a map");
    }

    ConstElementPtr lease_checks = sanity_checks->get("lease-checks");
    if (lease_checks) {
        if (lease_checks->getType() != Element::string) {
            isc_throw(DhcpConfigError, "lease-checks must be a string");
        }
        std::string lc = lease_checks->stringValue();
        CfgConsistency::LeaseSanity check;
        if (lc == "none") {
            check = CfgConsistency::LEASE_CHECK_NONE;
        } else if (lc == "warn") {
            check = CfgConsistency::LEASE_CHECK_WARN;
        } else if (lc == "fix") {
            check = CfgConsistency::LEASE_CHECK_FIX;
        } else if (lc == "fix-del") {
            check = CfgConsistency::LEASE_CHECK_FIX_DEL;
        } else if (lc == "del") {
            check = CfgConsistency::LEASE_CHECK_DEL;
        } else {
            isc_throw(DhcpConfigError, "Unsupported lease-checks value: " << lc
                      << ", supported values are: none, warn, fix, fix-del, del");
        }
        cfg.getConsistency()->setLeaseSanityCheck(check);
    }

    // Additional sanity check fields will come in later here.
}

};
};