Kea 3.1.1
class_cmds_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2025 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
8// Functions accessed by the hooks framework use C linkage to avoid the name
9// mangling that accompanies use of the C++ compiler as well as to avoid
10// issues related to namespaces.
11
12#include <config.h>
13
14#include <class_cmds.h>
15#include <class_cmds_log.h>
17#include <hooks/hooks.h>
18#include <dhcpsrv/cfgmgr.h>
19#include <process/daemon.h>
20
21using namespace isc::config;
22using namespace isc::data;
23using namespace isc::dhcp;
24using namespace isc::hooks;
25using namespace isc::process;
26using namespace isc::class_cmds;
27
28extern "C" {
29
37 try {
39 class_cmds.addClass(handle);
40
41 } catch (const std::exception& ex) {
43 .arg(ex.what());
44 return (1);
45 }
46
47 return (0);
48}
49
57 try {
59 class_cmds.getClass(handle);
60
61 } catch (const std::exception& ex) {
63 .arg(ex.what());
64 return (1);
65 }
66
67 return (0);
68}
69
77 try {
79 class_cmds.getClassList(handle);
80
81 } catch (const std::exception& ex) {
83 .arg(ex.what());
84 return (1);
85 }
86
87 return (0);
88}
89
97 try {
99 class_cmds.updateClass(handle);
100
101 } catch (const std::exception& ex) {
103 .arg(ex.what());
104 return (1);
105 }
106
107 return (0);
108}
109
117 try {
119 class_cmds.delClass(handle);
120
121 } catch (const std::exception& ex) {
123 .arg(ex.what());
124 return (1);
125 }
126
127 return (0);
128}
129
134int load(LibraryHandle& handle) {
135 try {
136 // Make the hook library not loadable by d2 or ca.
137 uint16_t family = CfgMgr::instance().getFamily();
138 const std::string& proc_name = Daemon::getProcName();
139 if (family == AF_INET) {
140 if (proc_name != "kea-dhcp4") {
141 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
142 << ", expected kea-dhcp4");
143 }
144 } else {
145 if (proc_name != "kea-dhcp6") {
146 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
147 << ", expected kea-dhcp6");
148 }
149 }
150
151 // Register commands.
152 handle.registerCommandCallout("class-add", class_add);
153 handle.registerCommandCallout("class-get", class_get);
154 handle.registerCommandCallout("class-list", class_list);
155 handle.registerCommandCallout("class-update", class_update);
156 handle.registerCommandCallout("class-del", class_del);
157 } catch (const std::exception& ex) {
159 .arg(ex.what());
160 return (1);
161 }
162
164 return (0);
165}
166
170int unload() {
172 return (0);
173}
174
179 return (1);
180}
181
182} // end extern "C"
int class_update(CalloutHandle &handle)
This is a command callout for 'class-update' command.
int class_del(CalloutHandle &handle)
This is a command callout for 'class-del' command.
int class_get(CalloutHandle &handle)
This is a command callout for 'class-get' command.
int class_add(CalloutHandle &handle)
This is a command callout for 'class-add' command.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int class_list(CalloutHandle &handle)
This is a command callout for 'class-list' command.
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 CLASS_CMDS_CLASS_LIST_HANDLER_FAILED
const isc::log::MessageID CLASS_CMDS_CLASS_ADD_HANDLER_FAILED
const isc::log::MessageID CLASS_CMDS_CLASS_DEL_HANDLER_FAILED
const isc::log::MessageID CLASS_CMDS_DEINIT_OK
const isc::log::MessageID CLASS_CMDS_INIT_OK
const isc::log::MessageID CLASS_CMDS_CLASS_UPDATE_HANDLER_FAILED
const isc::log::MessageID CLASS_CMDS_CLASS_GET_HANDLER_FAILED
const isc::log::MessageID CLASS_CMDS_INIT_FAILED
A generic exception that is thrown when an unexpected error condition occurs.
Implements the logic for processing commands pertaining to client classes manipulation.
Definition class_cmds.h:60
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
Per-packet callout handle.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:151
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
isc::log::Logger class_cmds_logger("class-cmds-hooks")