Kea 2.7.5
perfmon_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2024 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
13#include <perfmon_log.h>
14#include <perfmon_mgr.h>
16#include <dhcpsrv/cfgmgr.h>
17#include <hooks/hooks.h>
18#include <process/daemon.h>
19
20namespace isc {
21namespace perfmon {
22
25
26} // end of namespace perfmon
27}
28
29using namespace isc::data;
30using namespace isc::dhcp;
31using namespace isc::hooks;
32using namespace isc::log;
33using namespace isc::process;
34using namespace isc::perfmon;
35
36extern "C" {
37
39 // We do this here rather than in load() to ensure we check after the
40 // packet filter has been determined.
42 .arg(IfaceMgr::instance().isSocketReceivedTimeSupported() ? "Yes" : "No");
43 return (0);
44}
45
47 // We do this here rather than in load() to ensure we check after the
48 // packet filter has been determined.
50 .arg(IfaceMgr::instance().isSocketReceivedTimeSupported() ? "Yes" : "No");
51 return (0);
52}
53
61 if (status == CalloutHandle::NEXT_STEP_DROP ||
63 return (0);
64 }
65
66 Pkt4Ptr query;
67 handle.getArgument("query4", query);
68
69 Pkt4Ptr response;
70 handle.getArgument("response4", response);
71
72 Subnet4Ptr subnet;
73 handle.getArgument("subnet4", subnet);
74
75 try {
76 mgr->processPktEventStack(query, response, subnet);
77 } catch (const std::exception& ex) {
79 .arg(query->getLabel())
80 .arg(ex.what());
81 }
82
83 return (0);
84}
85
93 if (status == CalloutHandle::NEXT_STEP_DROP ||
95 return (0);
96 }
97
98 Pkt6Ptr query;
99 handle.getArgument("query6", query);
100
101 Pkt6Ptr response;
102 handle.getArgument("response6", response);
103
104 Subnet6Ptr subnet;
105 handle.getArgument("subnet6", subnet);
106
107 try {
108 mgr->processPktEventStack(query, response, subnet);
109 } catch (const std::exception& ex) {
111 .arg(query->getLabel())
112 .arg(ex.what());
113 }
114
115 return (0);
116}
117
125 return (mgr->perfmonControlHandler(handle));
126}
127
135 return (mgr->perfmonGetAllDurationsHandler(handle));
136}
137
142int load(LibraryHandle& handle) {
143 try {
144 // Make the hook library only loadable for kea-dhcpX.
145 uint16_t family = CfgMgr::instance().getFamily();
146 const std::string& proc_name = Daemon::getProcName();
147 if (family == AF_INET) {
148 if (proc_name != "kea-dhcp4") {
149 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
150 << ", expected kea-dhcp4");
151 }
152 } else if (proc_name != "kea-dhcp6") {
153 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
154 << ", expected kea-dhcp6");
155 }
156
157 // Instantiate the manager singleton.
158 mgr.reset(new PerfMonMgr(family));
159
160 // Configure the manager using the hook library's parameters.
161 ConstElementPtr json = handle.getParameters();
162 mgr->configure(json);
163
165 handle.registerCommandCallout("perfmon-control", perfmon_control);
166 handle.registerCommandCallout("perfmon-get-all-durations", perfmon_get_all_durations);
167 } catch (const std::exception& ex) {
169 .arg(ex.what());
170 return (1);
171 }
172
174 return (0);
175}
176
180int unload() {
182 return (0);
183}
184
189 return (1);
190}
191
192} // end extern "C"
A generic exception that is thrown when an unexpected error condition occurs.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:25
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition iface_mgr.cc:54
Per-packet callout handle.
CalloutNextStep
Specifies allowed next steps.
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
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:129
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:29
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
Definition subnet.h:461
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:555
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition subnet.h:626
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