Kea 3.3.3
perfmon_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2024-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// Functions accessed by the hooks framework use C linkage to avoid the name
8// mangling that accompanies use of the C++ compiler as well as to avoid
9// issues related to namespaces.
10
11#include <config.h>
12
14#include <dhcpsrv/cfgmgr.h>
15#include <hooks/hooks.h>
16#include <perfmon/perfmon_mgr.h>
17#include <process/daemon.h>
18
19#include <perfmon_log.h>
20
21namespace isc {
22namespace perfmon {
23
26
27} // end of namespace perfmon
28}
29
30using namespace isc::data;
31using namespace isc::dhcp;
32using namespace isc::hooks;
33using namespace isc::log;
34using namespace isc::process;
35using namespace isc::perfmon;
36
37extern "C" {
38
40 // We do this here rather than in load() to ensure we check after the
41 // packet filter has been determined.
43 .arg(IfaceMgr::instance().isSocketReceivedTimeSupported() ? "Yes" : "No");
44 return (0);
45}
46
48 // We do this here rather than in load() to ensure we check after the
49 // packet filter has been determined.
51 .arg(IfaceMgr::instance().isSocketReceivedTimeSupported() ? "Yes" : "No");
52 return (0);
53}
54
62 if (status == CalloutHandle::NEXT_STEP_DROP ||
64 return (0);
65 }
66
67 Pkt4Ptr query;
68 handle.getArgument("query4", query);
69
70 Pkt4Ptr response;
71 handle.getArgument("response4", response);
72
73 ConstSubnet4Ptr subnet;
74 handle.getArgument("subnet4", subnet);
75
76 try {
77 mgr->processPktEventStack(query, response, subnet);
78 } catch (const std::exception& ex) {
80 .arg(query->getLabel())
81 .arg(ex.what());
82 }
83
84 return (0);
85}
86
94 if (status == CalloutHandle::NEXT_STEP_DROP ||
96 return (0);
97 }
98
99 Pkt6Ptr query;
100 handle.getArgument("query6", query);
101
102 Pkt6Ptr response;
103 handle.getArgument("response6", response);
104
105 ConstSubnet6Ptr subnet;
106 handle.getArgument("subnet6", subnet);
107
108 try {
109 mgr->processPktEventStack(query, response, subnet);
110 } catch (const std::exception& ex) {
112 .arg(query->getLabel())
113 .arg(ex.what());
114 }
115
116 return (0);
117}
118
126 return (mgr->perfmonControlHandler(handle));
127}
128
136 return (mgr->perfmonGetAllDurationsHandler(handle));
137}
138
143int load(LibraryHandle& handle) {
144 try {
145 // Make the hook library only loadable for kea-dhcpX.
146 uint16_t family = CfgMgr::instance().getFamily();
147 const std::string& proc_name = Daemon::getProcName();
148 if (family == AF_INET) {
149 if (proc_name != "kea-dhcp4") {
150 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
151 << ", expected kea-dhcp4");
152 }
153 } else if (proc_name != "kea-dhcp6") {
154 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
155 << ", expected kea-dhcp6");
156 }
157
158 // Instantiate the manager singleton.
159 mgr.reset(new PerfMonMgr(family));
160
161 // Configure the manager using the hook library's parameters.
162 ConstElementPtr json = handle.getParameters();
163 mgr->configure(json);
164
166 handle.registerCommandCallout("perfmon-control", perfmon_control);
167 handle.registerCommandCallout("perfmon-get-all-durations", perfmon_get_all_durations);
168 } catch (const std::exception& ex) {
170 .arg(ex.what());
171 return (1);
172 }
173
175 return (0);
176}
177
181int unload() {
183 return (0);
184}
185
190 return (1);
191}
192
193} // end extern "C"
CalloutNextStep
Specifies allowed next steps.
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
A generic exception that is thrown when an unexpected error condition occurs.
uint16_t getFamily() const
Returns address family.
Definition cfgmgr.h:246
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition iface_mgr.cc:52
Per-packet callout handle.
CalloutNextStep getStatus() const
Returns the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
Singleton which provides overall configuration, control, and state of the PerfMon hook library.
Definition perfmon_mgr.h:29
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:156
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Definition subnet.h:620
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
Definition subnet.h:455
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
const int DBGLVL_TRACE_BASIC
Trace basic operations.
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
isc::log::Logger perfmon_logger("perfmon-hooks")
Definition perfmon_log.h:17
PerfMonMgrPtr mgr
PerfMonMgr singleton.
boost::shared_ptr< PerfMonMgr > PerfMonMgrPtr
Defines a shared pointer to a PerfMonMgr.
Defines the logger used by the top-level component of kea-lfc.
int dhcp6_srv_configured(CalloutHandle &)
int dhcp4_srv_configured(CalloutHandle &)
int perfmon_control(CalloutHandle &handle)
This is a command callout for 'perfmon-control' command.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int pkt6_send(CalloutHandle &handle)
This callout is called at the "pkt6_send" hook.
int pkt4_send(CalloutHandle &handle)
This callout is called at the "pkt4_send" hook.
int unload()
This function is called when the library is unloaded.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
int perfmon_get_all_durations(CalloutHandle &handle)
This is a command callout for 'perfmon-get-all-durations' command.
const isc::log::MessageID PERFMON_INIT_OK
const isc::log::MessageID PERFMON_DHCP6_PKT_PROCESS_ERROR
const isc::log::MessageID PERFMON_INIT_FAILED
const isc::log::MessageID PERFMON_DHCP4_PKT_PROCESS_ERROR
const isc::log::MessageID PERFMON_DEINIT_OK
const isc::log::MessageID PERFMON_DHCP6_SOCKET_RECEIVED_TIME_SUPPORT
const isc::log::MessageID PERFMON_DHCP4_SOCKET_RECEIVED_TIME_SUPPORT