Kea 3.1.7
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
48 return(lease_cmds.leaseAddHandler(handle));
49}
50
59 return(lease_cmds.leaseAddHandler(handle));
60}
61
70 return (lease_cmds.lease6BulkApplyHandler(handle));
71}
72
81 return(lease_cmds.leaseGetHandler(handle));
82}
83
92 return(lease_cmds.leaseGetHandler(handle));
93}
94
103 return (lease_cmds.leaseGetAllHandler(handle));
104}
105
114 return (lease_cmds.leaseGetAllHandler(handle));
115}
116
125 return (lease_cmds.leaseGetPageHandler(handle));
126}
127
136 return (lease_cmds.leaseGetPageHandler(handle));
137}
138
147 return (lease_cmds.leaseGetByHwAddressHandler(handle));
148}
149
158 return (lease_cmds.leaseGetByHwAddressHandler(handle));
159}
160
169 return (lease_cmds.leaseGetByClientIdHandler(handle));
170}
171
180 return (lease_cmds.leaseGetByDuidHandler(handle));
181}
182
191 return (lease_cmds.leaseGetByStateHandler(handle));
192}
193
202 return (lease_cmds.leaseGetByStateHandler(handle));
203}
204
213 return (lease_cmds.leaseGetByHostnameHandler(handle));
214}
215
224 return (lease_cmds.leaseGetByHostnameHandler(handle));
225}
226
235 return(lease_cmds.lease4DelHandler(handle));
236}
237
246 return(lease_cmds.lease6DelHandler(handle));
247}
248
257 return(lease_cmds.lease4UpdateHandler(handle));
258}
259
268 return(lease_cmds.lease6UpdateHandler(handle));
269}
270
279 return(lease_cmds.lease4WipeHandler(handle));
280}
281
290 return(lease_cmds.lease6WipeHandler(handle));
291}
292
301 return(lease_cmds.lease4ResendDdnsHandler(handle));
302}
303
312 return(lease_cmds.lease6ResendDdnsHandler(handle));
313}
314
323 return(lease_cmds.leaseWriteHandler(handle));
324}
325
334 return(lease_cmds.leaseWriteHandler(handle));
335}
336
341int load(LibraryHandle& handle) {
342 // Make the hook library not loadable by d2 or ca.
343 uint16_t family = CfgMgr::instance().getFamily();
344 const std::string& proc_name = Daemon::getProcName();
345 if (family == AF_INET) {
346 if (proc_name != "kea-dhcp4") {
347 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
348 << ", expected kea-dhcp4");
349 }
350 } else {
351 if (proc_name != "kea-dhcp6") {
352 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
353 << ", expected kea-dhcp6");
354 }
355 }
356
357 handle.registerCommandCallout("lease4-add", lease4_add);
358 handle.registerCommandCallout("lease6-add", lease6_add);
359 handle.registerCommandCallout("lease6-bulk-apply", lease6_bulk_apply);
360 handle.registerCommandCallout("lease4-get", lease4_get);
361 handle.registerCommandCallout("lease6-get", lease6_get);
362 handle.registerCommandCallout("lease4-get-all", lease4_get_all);
363 handle.registerCommandCallout("lease6-get-all", lease6_get_all);
364 handle.registerCommandCallout("lease4-get-page", lease4_get_page);
365 handle.registerCommandCallout("lease6-get-page", lease6_get_page);
366 handle.registerCommandCallout("lease4-get-by-hw-address",
368 handle.registerCommandCallout("lease6-get-by-hw-address",
370 handle.registerCommandCallout("lease4-get-by-client-id",
372 handle.registerCommandCallout("lease6-get-by-duid", lease6_get_by_duid);
373 handle.registerCommandCallout("lease4-get-by-state", lease4_get_by_state);
374 handle.registerCommandCallout("lease6-get-by-state", lease6_get_by_state);
375 handle.registerCommandCallout("lease4-get-by-hostname",
377 handle.registerCommandCallout("lease6-get-by-hostname",
379 handle.registerCommandCallout("lease4-del", lease4_del);
380 handle.registerCommandCallout("lease6-del", lease6_del);
381 handle.registerCommandCallout("lease4-update", lease4_update);
382 handle.registerCommandCallout("lease6-update", lease6_update);
383 handle.registerCommandCallout("lease4-wipe", lease4_wipe);
384 handle.registerCommandCallout("lease6-wipe", lease6_wipe);
385 handle.registerCommandCallout("lease4-resend-ddns", lease4_resend_ddns);
386 handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
387 handle.registerCommandCallout("lease4-write", lease4_write);
388 handle.registerCommandCallout("lease6-write", lease6_write);
389
390 // Instantiate the binding-variables manager singleton.
391 binding_var_mgr.reset(new BindingVariableMgr(family));
392
393 try {
394 // Configure binding variable manager using the hook library's parameters.
395 ConstElementPtr json = handle.getParameters();
396 if (json) {
397 binding_var_mgr->configure(json);
398 }
399 } catch (const std::exception& ex) {
401 .arg(ex.what());
402 return (1);
403 }
404
406 return (0);
407}
408
412int unload() {
414 return (0);
415}
416
421 return (1);
422}
423
429 if (status == CalloutHandle::NEXT_STEP_DROP ||
431 return (0);
432 }
433
434 try {
436 lease_cmds.lease4Offer(handle, binding_var_mgr);
437 } catch (const std::exception& ex) {
439 .arg(ex.what());
440 return (1);
441 }
442
443 return (0);
444}
445
451 if (status == CalloutHandle::NEXT_STEP_DROP ||
453 return (0);
454 }
455
456 try {
458 lease_cmds.leases4Committed(handle, binding_var_mgr);
459 } catch (const std::exception& ex) {
461 .arg(ex.what());
462 return (1);
463 }
464
465 return (0);
466}
467
473 if (status == CalloutHandle::NEXT_STEP_DROP ||
475 return (0);
476 }
477
478 try {
480 lease_cmds.leases6Committed(handle, binding_var_mgr);
481 } catch (const std::exception& ex) {
483 .arg(ex.what());
484 return (1);
485 }
486
487 return (0);
488}
489
490
491} // end extern "C"
CalloutNextStep
Specifies allowed next steps.
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
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.
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
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:154
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 lease6_get_by_state(CalloutHandle &handle)
This is a command callout for 'lease6-get-by-state' 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 lease6_get_by_hw_address(CalloutHandle &handle)
This is a command callout for 'lease6-get-by-hw-address' 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 lease4_get_by_state(CalloutHandle &handle)
This is a command callout for 'lease4-get-by-state' 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:30
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.