Kea 2.7.8
lease_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// 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>
15#include <binding_variables.h>
17#include <dhcpsrv/cfgmgr.h>
18#include <hooks/hooks.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::lease_cmds;
27
28namespace isc {
29namespace lease_cmds {
30
33
34} // end of namespace lease_cmds
35} // end of namespace isc
36
37
38extern "C" {
39
47 LeaseCmds lease_cmds;
48 return(lease_cmds.leaseAddHandler(handle));
49}
50
58 LeaseCmds lease_cmds;
59 return(lease_cmds.leaseAddHandler(handle));
60}
61
69 LeaseCmds lease_cmds;
70 return (lease_cmds.lease6BulkApplyHandler(handle));
71}
72
80 LeaseCmds lease_cmds;
81 return(lease_cmds.leaseGetHandler(handle));
82}
83
91 LeaseCmds lease_cmds;
92 return(lease_cmds.leaseGetHandler(handle));
93}
94
102 LeaseCmds lease_cmds;
103 return (lease_cmds.leaseGetAllHandler(handle));
104}
105
113 LeaseCmds lease_cmds;
114 return (lease_cmds.leaseGetAllHandler(handle));
115}
116
124 LeaseCmds lease_cmds;
125 return (lease_cmds.leaseGetPageHandler(handle));
126}
127
135 LeaseCmds lease_cmds;
136 return (lease_cmds.leaseGetPageHandler(handle));
137}
138
146 LeaseCmds lease_cmds;
147 return (lease_cmds.leaseGetByHwAddressHandler(handle));
148}
149
157 LeaseCmds lease_cmds;
158 return (lease_cmds.leaseGetByClientIdHandler(handle));
159}
160
168 LeaseCmds lease_cmds;
169 return (lease_cmds.leaseGetByDuidHandler(handle));
170}
171
179 LeaseCmds lease_cmds;
180 return (lease_cmds.leaseGetByHostnameHandler(handle));
181}
182
190 LeaseCmds lease_cmds;
191 return (lease_cmds.leaseGetByHostnameHandler(handle));
192}
193
201 LeaseCmds lease_cmds;
202 return(lease_cmds.lease4DelHandler(handle));
203}
204
212 LeaseCmds lease_cmds;
213 return(lease_cmds.lease6DelHandler(handle));
214}
215
223 LeaseCmds lease_cmds;
224 return(lease_cmds.lease4UpdateHandler(handle));
225}
226
234 LeaseCmds lease_cmds;
235 return(lease_cmds.lease6UpdateHandler(handle));
236}
237
245 LeaseCmds lease_cmds;
246 return(lease_cmds.lease4WipeHandler(handle));
247}
248
256 LeaseCmds lease_cmds;
257 return(lease_cmds.lease6WipeHandler(handle));
258}
259
267 LeaseCmds lease_cmds;
268 return(lease_cmds.lease4ResendDdnsHandler(handle));
269}
270
278 LeaseCmds lease_cmds;
279 return(lease_cmds.lease6ResendDdnsHandler(handle));
280}
281
289 LeaseCmds lease_cmds;
290 return(lease_cmds.leaseWriteHandler(handle));
291}
292
300 LeaseCmds lease_cmds;
301 return(lease_cmds.leaseWriteHandler(handle));
302}
303
308int load(LibraryHandle& handle) {
309 // Make the hook library not loadable by d2 or ca.
310 uint16_t family = CfgMgr::instance().getFamily();
311 const std::string& proc_name = Daemon::getProcName();
312 if (family == AF_INET) {
313 if (proc_name != "kea-dhcp4") {
314 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
315 << ", expected kea-dhcp4");
316 }
317 } else {
318 if (proc_name != "kea-dhcp6") {
319 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
320 << ", expected kea-dhcp6");
321 }
322 }
323
324 handle.registerCommandCallout("lease4-add", lease4_add);
325 handle.registerCommandCallout("lease6-add", lease6_add);
326 handle.registerCommandCallout("lease6-bulk-apply", lease6_bulk_apply);
327 handle.registerCommandCallout("lease4-get", lease4_get);
328 handle.registerCommandCallout("lease6-get", lease6_get);
329 handle.registerCommandCallout("lease4-get-all", lease4_get_all);
330 handle.registerCommandCallout("lease6-get-all", lease6_get_all);
331 handle.registerCommandCallout("lease4-get-page", lease4_get_page);
332 handle.registerCommandCallout("lease6-get-page", lease6_get_page);
333 handle.registerCommandCallout("lease4-get-by-hw-address",
335 handle.registerCommandCallout("lease4-get-by-client-id",
337 handle.registerCommandCallout("lease6-get-by-duid", lease6_get_by_duid);
338 handle.registerCommandCallout("lease4-get-by-hostname",
340 handle.registerCommandCallout("lease6-get-by-hostname",
342 handle.registerCommandCallout("lease4-del", lease4_del);
343 handle.registerCommandCallout("lease6-del", lease6_del);
344 handle.registerCommandCallout("lease4-update", lease4_update);
345 handle.registerCommandCallout("lease6-update", lease6_update);
346 handle.registerCommandCallout("lease4-wipe", lease4_wipe);
347 handle.registerCommandCallout("lease6-wipe", lease6_wipe);
348 handle.registerCommandCallout("lease4-resend-ddns", lease4_resend_ddns);
349 handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
350 handle.registerCommandCallout("lease4-write", lease4_write);
351 handle.registerCommandCallout("lease6-write", lease6_write);
352
353 // Instantiate the binding-variables manager singleton.
354 binding_var_mgr.reset(new BindingVariableMgr(family));
355
356 try {
357 // Configure binding variable manager using the hook library's parameters.
358 ConstElementPtr json = handle.getParameters();
359 if (json) {
360 binding_var_mgr->configure(json);
361 }
362 } catch (const std::exception& ex) {
364 .arg(ex.what());
365 return (1);
366 }
367
369 return (0);
370}
371
375int unload() {
377 return (0);
378}
379
384 return (1);
385}
386
392 if (status == CalloutHandle::NEXT_STEP_DROP ||
394 return (0);
395 }
396
397 try {
398 LeaseCmds lease_cmds;
399 lease_cmds.lease4Offer(handle, binding_var_mgr);
400 } catch (const std::exception& ex) {
402 .arg(ex.what());
403 return (1);
404 }
405
406 return (0);
407}
408
414 if (status == CalloutHandle::NEXT_STEP_DROP ||
416 return (0);
417 }
418
419 try {
420 LeaseCmds lease_cmds;
421 lease_cmds.leases4Committed(handle, binding_var_mgr);
422 } catch (const std::exception& ex) {
424 .arg(ex.what());
425 return (1);
426 }
427
428 return (0);
429}
430
436 if (status == CalloutHandle::NEXT_STEP_DROP ||
438 return (0);
439 }
440
441 try {
442 LeaseCmds lease_cmds;
443 lease_cmds.leases6Committed(handle, binding_var_mgr);
444 } catch (const std::exception& ex) {
446 .arg(ex.what());
447 return (1);
448 }
449
450 return (0);
451}
452
453
454} // 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.
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 registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
Singleton which warehouses the configured binding variables, and evaluation of variables for a given ...
Implements the logic for processing commands pertaining to lease manipulation.
Definition lease_cmds.h:27
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
void leases4Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases4_committed hookpoint 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
void lease4Offer(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
lease4_offer hookpoint 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
void leases6Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases6_committed hookpoint 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 leases6_committed(CalloutHandle &handle)
leases6_committed callout implementation.
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 leases4_committed(CalloutHandle &handle)
leases4_committed callout implementation.
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 lease4_offer(CalloutHandle &handle)
lease4_offer callout implementation.
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
const isc::log::MessageID LEASE_CMDS_LEASES6_COMMITTED_FAILED
const isc::log::MessageID LEASE_CMDS_LEASE4_OFFER_FAILED
const isc::log::MessageID LEASE_CMDS_LEASES4_COMMITTED_FAILED
const isc::log::MessageID LEASE_CMDS_LOAD_ERROR
#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
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::log::Logger lease_cmds_logger("lease-cmds-hooks")
BindingVariableMgrPtr binding_var_mgr
Singleton that manages configured binding variables.
boost::shared_ptr< BindingVariableMgr > BindingVariableMgrPtr
Defines a shared pointer to a BindingVariableMgr.
Defines the logger used by the top-level component of kea-lfc.