Kea 2.5.8
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
122int load(LibraryHandle& handle) {
123 try {
124 // Make the hook library only loadable for kea-dhcpX.
125 uint16_t family = CfgMgr::instance().getFamily();
126 const std::string& proc_name = Daemon::getProcName();
127 if (family == AF_INET) {
128 if (proc_name != "kea-dhcp4") {
129 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
130 << ", expected kea-dhcp4");
131 }
132 } else if (proc_name != "kea-dhcp6") {
133 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
134 << ", expected kea-dhcp6");
135 }
136
137 // Instantiate the manager singleton.
138 mgr.reset(new PerfMonMgr(family));
139
140 // Configure the manager using the hook library's parameters.
141 ConstElementPtr json = handle.getParameters();
142 mgr->configure(json);
143
146 } catch (const std::exception& ex) {
148 .arg(ex.what());
149 return (1);
150 }
151
153 return (0);
154}
155
159int unload() {
161 return (0);
162}
163
168 return (1);
169}
170
171} // end extern "C"
A generic exception that is thrown when an unexpected error condition occurs.
uint16_t getFamily() const
Returns address family.
Definition: cfgmgr.h:280
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.
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:27
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:498
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:663
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:31
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Definition: log_dbglevels.h:69
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
Definition: log_dbglevels.h:75
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.
Definition: perfmon_mgr.h:159
Defines the logger used by the top-level component of kea-lfc.
int dhcp6_srv_configured(CalloutHandle &)
int dhcp4_srv_configured(CalloutHandle &)
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.
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