Kea 3.1.1
host_cmds_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2017-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 <host_cmds.h>
15#include <host_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::host_cmds;
27
28extern "C" {
29
38 return (host_cmds.reservationAddHandler(handle));
39}
40
49 return (host_cmds.reservationGetHandler(handle));
50}
51
60 return (host_cmds.reservationGetByAddressHandler(handle));
61}
62
71 return (host_cmds.reservationDelHandler(handle));
72}
73
82 return (host_cmds.reservationGetAllHandler(handle));
83}
84
93 return (host_cmds.reservationGetPageHandler(handle));
94}
95
104 return (host_cmds.reservationGetByHostnameHandler(handle));
105}
106
115 return (host_cmds.reservationGetByIdHandler(handle));
116}
117
127 return (host_cmds.reservationUpdateHandler(handle));
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("reservation-add", reservation_add);
153 handle.registerCommandCallout("reservation-get", reservation_get);
154 handle.registerCommandCallout("reservation-del", reservation_del);
155 handle.registerCommandCallout("reservation-get-all",
157 handle.registerCommandCallout("reservation-get-page",
159 handle.registerCommandCallout("reservation-get-by-address",
161 handle.registerCommandCallout("reservation-get-by-hostname",
163 handle.registerCommandCallout("reservation-get-by-id",
165 handle.registerCommandCallout("reservation-update", reservation_update);
166 } catch (const std::exception& ex) {
168 .arg(ex.what());
169 return (1);
170 }
171
173 return (0);
174}
175
179int unload() {
181 return (0);
182}
183
188 return (1);
189}
190
191} // 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: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.
A wrapper class that provides handlers for the commands supported by this hooks library.
Definition host_cmds.h:53
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.
int reservation_add(CalloutHandle &handle)
This is a command callout for 'reservation-add' command.
int reservation_get(CalloutHandle &handle)
This is a command callout for 'reservation-get' command.
int reservation_get_page(CalloutHandle &handle)
This is a command callout for 'reservation-get-page' command.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int reservation_get_all(CalloutHandle &handle)
This is a command callout for 'reservation-get-all' command.
int reservation_get_by_address(CalloutHandle &handle)
This is a command callout for 'reservation-get-by-address' command.
int unload()
This function is called when the library is unloaded.
int reservation_update(CalloutHandle &handle)
This is a command callout for the reservation-update command.
int reservation_get_by_id(CalloutHandle &handle)
This is a command callout for 'reservation-get-by-id' command.
int reservation_del(CalloutHandle &handle)
This is a command callout for 'reservation-del' command.
int reservation_get_by_hostname(CalloutHandle &handle)
This is a command callout for 'reservation-get-by-hostname' command.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
const isc::log::MessageID HOST_CMDS_INIT_FAILED
const isc::log::MessageID HOST_CMDS_INIT_OK
const isc::log::MessageID HOST_CMDS_DEINIT_OK
#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 host_cmds_logger("host-cmds-hooks")