Kea: load_unload.cc Source File

| Kea 3.2.0-git

limits/load_unload.cc
Go to the documentation of this file.
1// Copyright (C) 2022-2026 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 <cc/dhcp_config_error.h>
10#include <dhcpsrv/cfgmgr.h>
11#include <dhcpsrv/lease_mgr_factory.h>
12#include <dhcpsrv/srv_config.h>
13#include <exceptions/exceptions.h>
14#include <hooks/library_handle.h>
15#include <limits/limit_manager.h>
16#include <process/daemon.h>
17
18namespace isc {
19namespace limits {
20
21using namespace isc::dhcp;
22using namespace isc::process;
23
24// Functions accessed by the hooks framework use C linkage to avoid the name
25// mangling that accompanies use of the C++ compiler as well as to avoid
26// issues related to namespaces
27extern "C" {
28
34int
35load(isc::hooks::LibraryHandle& handle) {
36 // Make the hook library not loadable by d2.
37 uint16_t family = CfgMgr::instance().getFamily();
38 const std::string& proc_name = Daemon::getProcName();
39 if (family == AF_INET) {
40 if (proc_name != "kea-dhcp4") {
41 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
42 << ", expected kea-dhcp4");
43 }
44 } else {
45 if (proc_name != "kea-dhcp6") {
46 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
47 << ", expected kea-dhcp6");
48 }
49 }
50
51 if (handle.getParameters()) {
52 isc_throw(ConfigError, "expected no parameters for libdhcp_limits.so, found "
53 << handle.getParameters()->str());
54 }
55
56 // Parse the configuration to get the limits of interest. Take them from the
57 // staging configuration since we are still in the hook library load phase.
58 LimitManager::instance().initialize(CfgMgr::instance().getStagingCfg());
59
60 return (0);
61}
62
66int
67unload() {
68 // Parse an empty config to clear configuration and packet counters.
69 LimitManager::instance().initialize(SrvConfigPtr());
70
71 // Clear the class lease counters.
72 if (LeaseMgrFactory::haveInstance() &&
73 LeaseMgrFactory::instance().getType() == "memfile") {
74 LeaseMgrFactory::instance().clearClassLeaseCounts();
75 }
76
77 return (0);
78}
79
83int
84multi_threading_compatible() {
85 return (1);
86}
87
88} // extern "C"
89
90} // namespace limits
91} // namespace isc
cfgmgr.h
isc::ConfigError
An exception that is thrown if an error occurs while configuring any server.
Definition dhcp_config_error.h:43
isc::Unexpected
A generic exception that is thrown when an unexpected error condition occurs.
Definition exceptions/exceptions.h:153
isc::dhcp::CfgMgr::getFamily
uint16_t getFamily() const
Returns address family.
Definition cfgmgr.h:246
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::dhcp::LeaseMgrFactory::instance
static TrackingLeaseMgr & instance()
Return current lease manager.
Definition lease_mgr_factory.cc:148
isc::dhcp::LeaseMgrFactory::haveInstance
static bool haveInstance()
Indicates if the lease manager has been instantiated.
Definition lease_mgr_factory.cc:143
isc::dhcp::LeaseMgr::clearClassLeaseCounts
virtual void clearClassLeaseCounts()=0
Clears the class-lease count map.
isc::hooks::LibraryHandle
Library handle.
Definition library_handle.h:60
isc::hooks::LibraryHandle::getParameters
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
Definition library_handle.cc:74
isc::process::Daemon::getProcName
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:154
daemon.h
dhcp_config_error.h
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
lease_mgr_factory.h
library_handle.h
limit_manager.h
isc::dhcp::SrvConfigPtr
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition srv_config.h:1148
isc::limits
Definition configuration.cc:18
isc::limits::load
int load(isc::hooks::LibraryHandle &handle)
Called by the hooks library manager when the library is loaded.
Definition limits/load_unload.cc:35
isc::limits::unload
int unload()
Called by the hooks library manager when the library is unloaded.
Definition limits/load_unload.cc:67
isc::limits::multi_threading_compatible
int multi_threading_compatible()
Return multi-threading compatibility.
Definition limits/load_unload.cc:84
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
srv_config.h
isc::limits::LimitManager::initialize
void initialize(isc::dhcp::SrvConfigPtr const &config)
Reinitialize data structures required for limiting.
Definition limit_manager.cc:43
isc::limits::LimitManager::instance
static LimitManager & instance()
singleton access function
Definition limit_manager.cc:31