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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (C) 2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Kea Hooks Basic
// Commercial End User License Agreement v2.0. See COPYING file in the premium/
// directory.

#include <config.h>

#include <ping_check_config.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc;
using namespace isc::data;
using namespace isc::dhcp;

namespace isc {
namespace ping_check {

const data::SimpleKeywords
PingCheckConfig::CONFIG_KEYWORDS =
{
    { "enable-ping-check",      Element::boolean },
    { "min-ping-requests",      Element::integer },
    { "reply-timeout",          Element::integer },
    { "ping-cltt-secs",         Element::integer},
    { "ping-channel-threads",   Element::integer}
};

PingCheckConfig::PingCheckConfig() :
    enable_ping_check_(true),
    min_ping_requests_(1),
    reply_timeout_(100),
    ping_cltt_secs_(60),
    ping_channel_threads_(0) {
}

void
PingCheckConfig::parse(data::ConstElementPtr config) {
    // Use a local instance to collect values.  This way we
    // avoid corrupting current values if there are any errors.
    PingCheckConfig local;

    // Note checkKeywords() will throw DhcpConfigError if there is a problem.
    SimpleParser::checkKeywords(CONFIG_KEYWORDS, config);
    ConstElementPtr value = config->get("enable-ping-check");
    if (value) {
        local.setEnablePingCheck(value->boolValue());
    }

    value = config->get("min-ping-requests");
    if (value) {
        int64_t val = value->intValue();
        if (val <= 0) {
            isc_throw(DhcpConfigError, "invalid min-ping-requests: '"
                      << val << "', must be greater than 0");
        }

        local.setMinPingRequests(static_cast<size_t>(val));
    }

    value = config->get("reply-timeout");
    if (value) {
        int64_t val = value->intValue();
        if (val <= 0) {
            isc_throw(DhcpConfigError, "invalid reply-timeout: '"
                      << val << "', must be greater than 0");
        }

        local.setReplyTimeout(static_cast<size_t>(val));
    }

    value = config->get("ping-cltt-secs");
    if (value) {
        int64_t val = value->intValue();
        if (val < 0) {
            isc_throw(DhcpConfigError, "invalid ping-cltt-secs: '"
                      << val << "', cannot be less than 0");<--- Shifting by a negative value is undefined behaviour
        }

        local.setPingClttSecs(static_cast<size_t>(val));
    }

    value = config->get("ping-channel-threads");
    if (value) {
        int64_t val = value->intValue();
        if (val < 0) {
            isc_throw(DhcpConfigError, "invalid ping-channel-threads: '"
                      << val << "', cannot be less than 0");<--- Shifting by a negative value is undefined behaviour
        }

        local.setPingChannelThreads(static_cast<size_t>(val));
    }

    // All values good, copy from local instance.
    *this = local;
}

} // end of namespace ping_check
} // end of namespace isc