Kea 2.7.6
lease_cmds_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2022 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 <lease_cmds.h>
14#include <lease_cmds_log.h>
16#include <dhcpsrv/cfgmgr.h>
17#include <hooks/hooks.h>
18#include <process/daemon.h>
19
20using namespace isc::config;
21using namespace isc::data;
22using namespace isc::dhcp;
23using namespace isc::hooks;
24using namespace isc::process;
25using namespace isc::lease_cmds;
26
27extern "C" {
28
36 LeaseCmds lease_cmds;
37 return(lease_cmds.leaseAddHandler(handle));
38}
39
47 LeaseCmds lease_cmds;
48 return(lease_cmds.leaseAddHandler(handle));
49}
50
58 LeaseCmds lease_cmds;
59 return (lease_cmds.lease6BulkApplyHandler(handle));
60}
61
69 LeaseCmds lease_cmds;
70 return(lease_cmds.leaseGetHandler(handle));
71}
72
80 LeaseCmds lease_cmds;
81 return(lease_cmds.leaseGetHandler(handle));
82}
83
91 LeaseCmds lease_cmds;
92 return (lease_cmds.leaseGetAllHandler(handle));
93}
94
102 LeaseCmds lease_cmds;
103 return (lease_cmds.leaseGetAllHandler(handle));
104}
105
113 LeaseCmds lease_cmds;
114 return (lease_cmds.leaseGetPageHandler(handle));
115}
116
124 LeaseCmds lease_cmds;
125 return (lease_cmds.leaseGetPageHandler(handle));
126}
127
135 LeaseCmds lease_cmds;
136 return (lease_cmds.leaseGetByHwAddressHandler(handle));
137}
138
146 LeaseCmds lease_cmds;
147 return (lease_cmds.leaseGetByClientIdHandler(handle));
148}
149
157 LeaseCmds lease_cmds;
158 return (lease_cmds.leaseGetByDuidHandler(handle));
159}
160
168 LeaseCmds lease_cmds;
169 return (lease_cmds.leaseGetByHostnameHandler(handle));
170}
171
179 LeaseCmds lease_cmds;
180 return (lease_cmds.leaseGetByHostnameHandler(handle));
181}
182
190 LeaseCmds lease_cmds;
191 return(lease_cmds.lease4DelHandler(handle));
192}
193
201 LeaseCmds lease_cmds;
202 return(lease_cmds.lease6DelHandler(handle));
203}
204
212 LeaseCmds lease_cmds;
213 return(lease_cmds.lease4UpdateHandler(handle));
214}
215
223 LeaseCmds lease_cmds;
224 return(lease_cmds.lease6UpdateHandler(handle));
225}
226
234 LeaseCmds lease_cmds;
235 return(lease_cmds.lease4WipeHandler(handle));
236}
237
245 LeaseCmds lease_cmds;
246 return(lease_cmds.lease6WipeHandler(handle));
247}
248
256 LeaseCmds lease_cmds;
257 return(lease_cmds.lease4ResendDdnsHandler(handle));
258}
259
267 LeaseCmds lease_cmds;
268 return(lease_cmds.lease6ResendDdnsHandler(handle));
269}
270
278 LeaseCmds lease_cmds;
279 return(lease_cmds.leaseWriteHandler(handle));
280}
281
289 LeaseCmds lease_cmds;
290 return(lease_cmds.leaseWriteHandler(handle));
291}
292
297int load(LibraryHandle& handle) {
298 // Make the hook library not loadable by d2 or ca.
299 uint16_t family = CfgMgr::instance().getFamily();
300 const std::string& proc_name = Daemon::getProcName();
301 if (family == AF_INET) {
302 if (proc_name != "kea-dhcp4") {
303 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
304 << ", expected kea-dhcp4");
305 }
306 } else {
307 if (proc_name != "kea-dhcp6") {
308 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
309 << ", expected kea-dhcp6");
310 }
311 }
312
313 handle.registerCommandCallout("lease4-add", lease4_add);
314 handle.registerCommandCallout("lease6-add", lease6_add);
315 handle.registerCommandCallout("lease6-bulk-apply", lease6_bulk_apply);
316 handle.registerCommandCallout("lease4-get", lease4_get);
317 handle.registerCommandCallout("lease6-get", lease6_get);
318 handle.registerCommandCallout("lease4-get-all", lease4_get_all);
319 handle.registerCommandCallout("lease6-get-all", lease6_get_all);
320 handle.registerCommandCallout("lease4-get-page", lease4_get_page);
321 handle.registerCommandCallout("lease6-get-page", lease6_get_page);
322 handle.registerCommandCallout("lease4-get-by-hw-address",
324 handle.registerCommandCallout("lease4-get-by-client-id",
326 handle.registerCommandCallout("lease6-get-by-duid", lease6_get_by_duid);
327 handle.registerCommandCallout("lease4-get-by-hostname",
329 handle.registerCommandCallout("lease6-get-by-hostname",
331 handle.registerCommandCallout("lease4-del", lease4_del);
332 handle.registerCommandCallout("lease6-del", lease6_del);
333 handle.registerCommandCallout("lease4-update", lease4_update);
334 handle.registerCommandCallout("lease6-update", lease6_update);
335 handle.registerCommandCallout("lease4-wipe", lease4_wipe);
336 handle.registerCommandCallout("lease6-wipe", lease6_wipe);
337 handle.registerCommandCallout("lease4-resend-ddns", lease4_resend_ddns);
338 handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
339 handle.registerCommandCallout("lease4-write", lease4_write);
340 handle.registerCommandCallout("lease6-write", lease6_write);
341
343 return (0);
344}
345
349int unload() {
351 return (0);
352}
353
358 return (1);
359}
360
361} // 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:235
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:28
Per-packet callout handle.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
Implements the logic for processing commands pertaining to lease manipulation.
Definition lease_cmds.h:26
int lease4ResendDdnsHandler(hooks::CalloutHandle &handle)
lease4-resend-ddns command handler
int lease6WipeHandler(hooks::CalloutHandle &handle)
lease6-wipe handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
int lease6DelHandler(hooks::CalloutHandle &handle)
lease6-del command handler
int leaseGetAllHandler(hooks::CalloutHandle &handle)
lease4-get-all, lease6-get-all commands handler
int leaseGetByHostnameHandler(hooks::CalloutHandle &handle)
lease4-get-by-hostname and lease6-get-by-hostname commands handler
int lease4DelHandler(hooks::CalloutHandle &handle)
lease4-del command handler
int leaseWriteHandler(hooks::CalloutHandle &handle)
lease4-write handler, lease6-write handler
int leaseAddHandler(hooks::CalloutHandle &handle)
lease4-add, lease6-add command handler
int leaseGetByClientIdHandler(hooks::CalloutHandle &handle)
lease4-get-by-client-id command handler
int lease4UpdateHandler(hooks::CalloutHandle &handle)
lease4-update handler
int leaseGetHandler(hooks::CalloutHandle &handle)
lease4-get, lease6-get command handler
int leaseGetByHwAddressHandler(hooks::CalloutHandle &handle)
lease4-get-by-hw-address command handler
int lease6UpdateHandler(hooks::CalloutHandle &handle)
lease6-update handler
int leaseGetByDuidHandler(hooks::CalloutHandle &handle)
lease6-get-by-duid command handler
int lease6BulkApplyHandler(hooks::CalloutHandle &handle)
lease6-bulk-apply command handler
int lease4WipeHandler(hooks::CalloutHandle &handle)
lease4-wipe handler
int lease6ResendDdnsHandler(hooks::CalloutHandle &handle)
lease6-resend-ddns 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: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.
int lease4_get(CalloutHandle &handle)
This is a command callout for 'lease4-get' command.
int lease4_get_page(CalloutHandle &handle)
This is a command callout for 'lease4-get-page' command.
int lease4_get_by_hw_address(CalloutHandle &handle)
This is a command callout for 'lease4-get-by-hw-address' command.
int lease4_update(CalloutHandle &handle)
This is a command callout for 'lease4-update' command.
int lease4_wipe(CalloutHandle &handle)
This is a command callout for 'lease4-wipe' command.
int lease6_resend_ddns(CalloutHandle &handle)
This is a command callout for 'lease6-resend-ddns' command.
int lease6_update(CalloutHandle &handle)
This is a command callout for 'lease6-update' command.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int lease6_get_by_duid(CalloutHandle &handle)
This is a command callout for 'lease6-get-by-duid' command.
int lease4_get_by_client_id(CalloutHandle &handle)
This is a command callout for 'lease4-get-by-client-id' command.
int lease4_get_all(CalloutHandle &handle)
This is a command callout for 'lease4-get-all' command.
int lease4_get_by_hostname(CalloutHandle &handle)
This is a command callout for 'lease4-get-by-hostname' command.
int lease6_bulk_apply(CalloutHandle &handle)
This is a command callout for 'lease6-bulk-apply' command.
int lease4_write(CalloutHandle &handle)
This is a command callout for 'lease4-write' command.
int lease6_get(CalloutHandle &handle)
This is a command callout for 'lease6-get' command.
int lease4_resend_ddns(CalloutHandle &handle)
This is a command callout for 'lease4-resend-ddns' command.
int unload()
This function is called when the library is unloaded.
int lease6_get_page(CalloutHandle &handle)
This is a command callout for 'lease6-get-page' command.
int lease6_add(CalloutHandle &handle)
This is a command callout for 'lease6-add' command.
int lease4_add(CalloutHandle &handle)
This is a command callout for 'lease4-add' command.
int lease6_get_all(CalloutHandle &handle)
This is a command callout for 'lease6-get-all' command.
int lease4_del(CalloutHandle &handle)
This is a command callout for 'lease4-del' command.
int lease6_get_by_hostname(CalloutHandle &handle)
This is a command callout for 'lease6-get-by-hostname' command.
int lease6_write(CalloutHandle &handle)
This is a command callout for 'lease6-write' command.
int lease6_del(CalloutHandle &handle)
This is a command callout for 'lease6-del' command.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
int lease6_wipe(CalloutHandle &handle)
This is a command callout for 'lease6-wipe' command.
const isc::log::MessageID LEASE_CMDS_INIT_OK
const isc::log::MessageID LEASE_CMDS_DEINIT_OK
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
isc::log::Logger lease_cmds_logger("lease-cmds-hooks")