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
// Copyright (C) 2022 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 <cc/dhcp_config_error.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/srv_config.h>
#include <exceptions/exceptions.h>
#include <hooks/library_handle.h>
#include <limits/limit_manager.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <process/daemon.h>

namespace isc {
namespace limits {

using namespace isc::dhcp;
using namespace isc::process;

// Functions accessed by the hooks framework use C linkage to avoid the name
// mangling that accompanies use of the C++ compiler as well as to avoid
// issues related to namespaces
extern "C" {

/// @brief Called by the hooks library manager when the library is loaded.
///
/// @param handle LibraryHandle
///
/// @return 0 on success, non-zero otherwise.
int
load(isc::hooks::LibraryHandle& handle) {
    // Make the hook library not loadable by d2 or ca.
    uint16_t family = CfgMgr::instance().getFamily();
    const std::string& proc_name = Daemon::getProcName();
    if (family == AF_INET) {
        if (proc_name != "kea-dhcp4") {
            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
                      << ", expected kea-dhcp4");
        }
    } else {
        if (proc_name != "kea-dhcp6") {
            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
                      << ", expected kea-dhcp6");
        }
    }

    if (handle.getParameters()) {
        isc_throw(ConfigError, "expected no parameters for libdhcp_limits.so, found "
                                   << handle.getParameters()->str());
    }

    // Parse the configuration to get the limits of interest. Take them from the
    // staging configuration since we are still in the hook library load phase.
    LimitManager::instance().initialize(CfgMgr::instance().getStagingCfg());

    return (0);
}

/// @brief Called by the hooks library manager when the library is unloaded.
///
/// @param handle LibraryHandle
///
/// @return 0 on success, non-zero otherwise.
int
unload() {
    // Parse an empty config to clear configuration and packet counters.
    LimitManager::instance().initialize(SrvConfigPtr());

    // Clear the class lease counters.
    if (LeaseMgrFactory::haveInstance() &&
        LeaseMgrFactory::instance().getType() == "memfile") {
        LeaseMgrFactory::instance().clearClassLeaseCounts();
    }

    return (0);
}

/// @brief Return multi-threading compatibility.
///
/// @return 1 means compatible with multi-threading.
int
multi_threading_compatible() {
    return (1);
}

}  // extern "C"

}  // namespace limits
}  // namespace isc