Kea 3.1.9
lease_cmds_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2026 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#include <sflq_cmds.h>
21
22using namespace isc::config;
23using namespace isc::data;
24using namespace isc::dhcp;
25using namespace isc::hooks;
26using namespace isc::process;
27using namespace isc::lease_cmds;
28
29namespace isc {
30namespace lease_cmds {
31
34
35} // end of namespace lease_cmds
36} // end of namespace isc
37
38
39extern "C" {
40
49 return(lease_cmds.leaseAddHandler(handle));
50}
51
60 return(lease_cmds.leaseAddHandler(handle));
61}
62
71 return (lease_cmds.lease6BulkApplyHandler(handle));
72}
73
82 return(lease_cmds.leaseGetHandler(handle));
83}
84
93 return(lease_cmds.leaseGetHandler(handle));
94}
95
104 return (lease_cmds.leaseGetAllHandler(handle));
105}
106
115 return (lease_cmds.leaseGetAllHandler(handle));
116}
117
126 return (lease_cmds.leaseGetPageHandler(handle));
127}
128
137 return (lease_cmds.leaseGetPageHandler(handle));
138}
139
148 return (lease_cmds.leaseGetByHwAddressHandler(handle));
149}
150
159 return (lease_cmds.leaseGetByHwAddressHandler(handle));
160}
161
170 return (lease_cmds.leaseGetByClientIdHandler(handle));
171}
172
181 return (lease_cmds.leaseGetByDuidHandler(handle));
182}
183
192 return (lease_cmds.leaseGetByStateHandler(handle));
193}
194
203 return (lease_cmds.leaseGetByStateHandler(handle));
204}
205
214 return (lease_cmds.leaseGetByHostnameHandler(handle));
215}
216
225 return (lease_cmds.leaseGetByHostnameHandler(handle));
226}
227
236 return(lease_cmds.lease4DelHandler(handle));
237}
238
247 return(lease_cmds.lease6DelHandler(handle));
248}
249
258 return(lease_cmds.lease4UpdateHandler(handle));
259}
260
269 return(lease_cmds.lease6UpdateHandler(handle));
270}
271
280 return(lease_cmds.lease4WipeHandler(handle));
281}
282
291 return(lease_cmds.lease6WipeHandler(handle));
292}
293
302 return(lease_cmds.lease4ResendDdnsHandler(handle));
303}
304
313 return(lease_cmds.lease6ResendDdnsHandler(handle));
314}
315
324 return(lease_cmds.leaseWriteHandler(handle));
325}
326
335 return(lease_cmds.leaseWriteHandler(handle));
336}
337
345 SflqCmds sflq_cmds;
346 return(sflq_cmds.sflqPool4RebuildHandler(handle));
347}
348
356 SflqCmds sflq_cmds;
357 return(sflq_cmds.sflqPool4GetAllHandler(handle));
358}
359
367 SflqCmds sflq_cmds;
368 return(sflq_cmds.sflqPool4GetBySubnetHandler(handle));
369}
370
378 SflqCmds sflq_cmds;
379 return(sflq_cmds.sflqPool4GetByRangeHandler(handle));
380}
381
389 SflqCmds sflq_cmds;
390 return(sflq_cmds.sflqPool4DelHandler(handle));
391}
392
400 SflqCmds sflq_cmds;
401 return(sflq_cmds.sflqPool6RebuildHandler(handle));
402}
403
411 SflqCmds sflq_cmds;
412 return(sflq_cmds.sflqPool6GetAllHandler(handle));
413}
414
422 SflqCmds sflq_cmds;
423 return(sflq_cmds.sflqPool6GetBySubnetHandler(handle));
424}
425
433 SflqCmds sflq_cmds;
434 return(sflq_cmds.sflqPool6GetByRangeHandler(handle));
435}
436
444 SflqCmds sflq_cmds;
445 return(sflq_cmds.sflqPool6DelHandler(handle));
446}
447
452int load(LibraryHandle& handle) {
453 // Make the hook library not loadable by d2.
454 uint16_t family = CfgMgr::instance().getFamily();
455 const std::string& proc_name = Daemon::getProcName();
456 if (family == AF_INET) {
457 if (proc_name != "kea-dhcp4") {
458 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
459 << ", expected kea-dhcp4");
460 }
461 } else {
462 if (proc_name != "kea-dhcp6") {
463 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
464 << ", expected kea-dhcp6");
465 }
466 }
467
468 handle.registerCommandCallout("lease4-add", lease4_add);
469 handle.registerCommandCallout("lease6-add", lease6_add);
470 handle.registerCommandCallout("lease6-bulk-apply", lease6_bulk_apply);
471 handle.registerCommandCallout("lease4-get", lease4_get);
472 handle.registerCommandCallout("lease6-get", lease6_get);
473 handle.registerCommandCallout("lease4-get-all", lease4_get_all);
474 handle.registerCommandCallout("lease6-get-all", lease6_get_all);
475 handle.registerCommandCallout("lease4-get-page", lease4_get_page);
476 handle.registerCommandCallout("lease6-get-page", lease6_get_page);
477 handle.registerCommandCallout("lease4-get-by-hw-address",
479 handle.registerCommandCallout("lease6-get-by-hw-address",
481 handle.registerCommandCallout("lease4-get-by-client-id",
483 handle.registerCommandCallout("lease6-get-by-duid", lease6_get_by_duid);
484 handle.registerCommandCallout("lease4-get-by-state", lease4_get_by_state);
485 handle.registerCommandCallout("lease6-get-by-state", lease6_get_by_state);
486 handle.registerCommandCallout("lease4-get-by-hostname",
488 handle.registerCommandCallout("lease6-get-by-hostname",
490 handle.registerCommandCallout("lease4-del", lease4_del);
491 handle.registerCommandCallout("lease6-del", lease6_del);
492 handle.registerCommandCallout("lease4-update", lease4_update);
493 handle.registerCommandCallout("lease6-update", lease6_update);
494 handle.registerCommandCallout("lease4-wipe", lease4_wipe);
495 handle.registerCommandCallout("lease6-wipe", lease6_wipe);
496 handle.registerCommandCallout("lease4-resend-ddns", lease4_resend_ddns);
497 handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
498 handle.registerCommandCallout("lease4-write", lease4_write);
499 handle.registerCommandCallout("lease6-write", lease6_write);
500 handle.registerCommandCallout("sflq-pool4-rebuild", sflq_pool4_rebuild);
501 handle.registerCommandCallout("sflq-pool4-get-all", sflq_pool4_get_all);
502 handle.registerCommandCallout("sflq-pool4-get-by-subnet", sflq_pool4_get_by_subnet);
503 handle.registerCommandCallout("sflq-pool4-get-by-range", sflq_pool4_get_by_range);
504 handle.registerCommandCallout("sflq-pool4-del", sflq_pool4_del);
505 handle.registerCommandCallout("sflq-pool6-rebuild", sflq_pool6_rebuild);
506 handle.registerCommandCallout("sflq-pool6-get-all", sflq_pool6_get_all);
507 handle.registerCommandCallout("sflq-pool6-get-by-subnet", sflq_pool6_get_by_subnet);
508 handle.registerCommandCallout("sflq-pool6-get-by-range", sflq_pool6_get_by_range);
509 handle.registerCommandCallout("sflq-pool6-del", sflq_pool6_del);
510
511 // Instantiate the binding-variables manager singleton.
512 binding_var_mgr.reset(new BindingVariableMgr(family));
513
514 try {
515 // Configure binding variable manager using the hook library's parameters.
516 ConstElementPtr json = handle.getParameters();
517 if (json) {
518 binding_var_mgr->configure(json);
519 }
520 } catch (const std::exception& ex) {
522 .arg(ex.what());
523 return (1);
524 }
525
527 return (0);
528}
529
533int unload() {
535 return (0);
536}
537
542 return (1);
543}
544
550 if (status == CalloutHandle::NEXT_STEP_DROP ||
552 return (0);
553 }
554
555 try {
557 lease_cmds.lease4Offer(handle, binding_var_mgr);
558 } catch (const std::exception& ex) {
560 .arg(ex.what());
561 return (1);
562 }
563
564 return (0);
565}
566
572 if (status == CalloutHandle::NEXT_STEP_DROP ||
574 return (0);
575 }
576
577 try {
579 lease_cmds.leases4Committed(handle, binding_var_mgr);
580 } catch (const std::exception& ex) {
582 .arg(ex.what());
583 return (1);
584 }
585
586 return (0);
587}
588
594 if (status == CalloutHandle::NEXT_STEP_DROP ||
596 return (0);
597 }
598
599 try {
601 lease_cmds.leases6Committed(handle, binding_var_mgr);
602 } catch (const std::exception& ex) {
604 .arg(ex.what());
605 return (1);
606 }
607
608 return (0);
609}
610
611} // 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
Wrapper class around SFLQ pool commands.
Definition sflq_cmds.h:375
int sflqPool4DelHandler(hooks::CalloutHandle &handle)
Delete the SFLQ V4 pool that matches a start and end address.
Definition sflq_cmds.cc:513
int sflqPool4GetBySubnetHandler(hooks::CalloutHandle &handle)
The 'sflq-pool4-get-by-subnet' command handler.
Definition sflq_cmds.cc:503
int sflqPool6RebuildHandler(hooks::CalloutHandle &handle)
The 'sflq-pool6-rebuild' command handler.
Definition sflq_cmds.cc:518
int sflqPool6GetAllHandler(hooks::CalloutHandle &handle)
The 'sflq-pool6-get-all' command handler.
Definition sflq_cmds.cc:523
int sflqPool4GetByRangeHandler(hooks::CalloutHandle &handle)
Handles a 'sflq-pool4-by-range' command.
Definition sflq_cmds.cc:508
int sflqPool4GetAllHandler(hooks::CalloutHandle &handle)
The 'sflq-pool4-get-all' command handler.
Definition sflq_cmds.cc:498
int sflqPool6GetByRangeHandler(hooks::CalloutHandle &handle)
Handles a 'sflq-pool6-by-range' command.
Definition sflq_cmds.cc:533
int sflqPool6DelHandler(hooks::CalloutHandle &handle)
Delete the SFLQ V6 pool that matches a start and end address.
Definition sflq_cmds.cc:538
int sflqPool6GetBySubnetHandler(hooks::CalloutHandle &handle)
The 'sflq-pool6-get-by-subnet' command handler.
Definition sflq_cmds.cc:528
int sflqPool4RebuildHandler(hooks::CalloutHandle &handle)
sflq-pool4-rebuild handler.
Definition sflq_cmds.cc:493
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 sflq_pool6_get_all(CalloutHandle &handle)
This is a command callout for 'sflq-pool6-get-all' command.
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 sflq_pool6_get_by_range(CalloutHandle &handle)
This is a command callout for 'sflq-pool6-get-by-range' 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 sflq_pool6_rebuild(CalloutHandle &handle)
This is a command callout for 'sflq-pool6-rebuild' command.
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 sflq_pool6_get_by_subnet(CalloutHandle &handle)
This is a command callout for 'sflq-pool6-get-by-subnet' command.
int lease4_resend_ddns(CalloutHandle &handle)
This is a command callout for 'lease4-resend-ddns' command.
int sflq_pool4_get_by_subnet(CalloutHandle &handle)
This is a command callout for 'sflq-pool4-get-by-subnet' 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 sflq_pool4_rebuild(CalloutHandle &handle)
This is a command callout for 'sflq-pool4-rebuild' command.
int sflq_pool4_get_by_range(CalloutHandle &handle)
This is a command callout for 'sflq-pool4-get-by-range' 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 sflq_pool4_get_all(CalloutHandle &handle)
This is a command callout for 'sflq-pool4-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 sflq_pool6_del(CalloutHandle &handle)
This is a command callout for 'sflq-pool6-del' command.
int sflq_pool4_del(CalloutHandle &handle)
This is a command callout for 'sflq-pool4-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.