Kea 3.3.3
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
14#include <dhcpsrv/cfgmgr.h>
15#include <hooks/hooks.h>
18#include <process/daemon.h>
19
20#include <lease_cmds_log.h>
21#include <sflq_cmds.h>
22
23using namespace isc::config;
24using namespace isc::data;
25using namespace isc::dhcp;
26using namespace isc::hooks;
27using namespace isc::process;
28using namespace isc::lease_cmds;
29
30namespace isc {
31namespace lease_cmds {
32
35
36} // end of namespace lease_cmds
37} // end of namespace isc
38
39
40extern "C" {
41
50 return(lease_cmds.leaseAddHandler(handle));
51}
52
61 return(lease_cmds.leaseAddHandler(handle));
62}
63
72 return (lease_cmds.lease6BulkApplyHandler(handle));
73}
74
83 return(lease_cmds.leaseGetHandler(handle));
84}
85
94 return(lease_cmds.leaseGetHandler(handle));
95}
96
105 return (lease_cmds.leaseGetAllHandler(handle));
106}
107
116 return (lease_cmds.leaseGetAllHandler(handle));
117}
118
127 return (lease_cmds.leaseGetPageHandler(handle));
128}
129
138 return (lease_cmds.leaseGetPageHandler(handle));
139}
140
149 return (lease_cmds.leaseGetByHwAddressHandler(handle));
150}
151
160 return (lease_cmds.leaseGetByHwAddressHandler(handle));
161}
162
171 return (lease_cmds.leaseGetByClientIdHandler(handle));
172}
173
182 return (lease_cmds.leaseGetByDuidHandler(handle));
183}
184
193 return (lease_cmds.leaseGetByStateHandler(handle));
194}
195
204 return (lease_cmds.leaseGetByStateHandler(handle));
205}
206
215 return (lease_cmds.leaseGetByHostnameHandler(handle));
216}
217
226 return (lease_cmds.leaseGetByHostnameHandler(handle));
227}
228
237 return(lease_cmds.lease4DelHandler(handle));
238}
239
248 return(lease_cmds.lease6DelHandler(handle));
249}
250
259 return(lease_cmds.lease4UpdateHandler(handle));
260}
261
270 return(lease_cmds.lease6UpdateHandler(handle));
271}
272
281 return(lease_cmds.lease4WipeHandler(handle));
282}
283
292 return(lease_cmds.lease6WipeHandler(handle));
293}
294
303 return(lease_cmds.lease4ResendDdnsHandler(handle));
304}
305
314 return(lease_cmds.lease6ResendDdnsHandler(handle));
315}
316
325 return(lease_cmds.leaseWriteHandler(handle));
326}
327
336 return(lease_cmds.leaseWriteHandler(handle));
337}
338
346 SflqCmds sflq_cmds;
347 return(sflq_cmds.sflqPool4RebuildHandler(handle));
348}
349
357 SflqCmds sflq_cmds;
358 return(sflq_cmds.sflqPool4GetAllHandler(handle));
359}
360
368 SflqCmds sflq_cmds;
369 return(sflq_cmds.sflqPool4GetBySubnetHandler(handle));
370}
371
379 SflqCmds sflq_cmds;
380 return(sflq_cmds.sflqPool4GetByRangeHandler(handle));
381}
382
390 SflqCmds sflq_cmds;
391 return(sflq_cmds.sflqPool4DelHandler(handle));
392}
393
401 SflqCmds sflq_cmds;
402 return(sflq_cmds.sflqPool6RebuildHandler(handle));
403}
404
412 SflqCmds sflq_cmds;
413 return(sflq_cmds.sflqPool6GetAllHandler(handle));
414}
415
423 SflqCmds sflq_cmds;
424 return(sflq_cmds.sflqPool6GetBySubnetHandler(handle));
425}
426
434 SflqCmds sflq_cmds;
435 return(sflq_cmds.sflqPool6GetByRangeHandler(handle));
436}
437
445 SflqCmds sflq_cmds;
446 return(sflq_cmds.sflqPool6DelHandler(handle));
447}
448
453int load(LibraryHandle& handle) {
454 // Make the hook library not loadable by d2.
455 uint16_t family = CfgMgr::instance().getFamily();
456 const std::string& proc_name = Daemon::getProcName();
457 if (family == AF_INET) {
458 if (proc_name != "kea-dhcp4") {
459 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
460 << ", expected kea-dhcp4");
461 }
462 } else {
463 if (proc_name != "kea-dhcp6") {
464 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
465 << ", expected kea-dhcp6");
466 }
467 }
468
469 handle.registerCommandCallout("lease4-add", lease4_add);
470 handle.registerCommandCallout("lease6-add", lease6_add);
471 handle.registerCommandCallout("lease6-bulk-apply", lease6_bulk_apply);
472 handle.registerCommandCallout("lease4-get", lease4_get);
473 handle.registerCommandCallout("lease6-get", lease6_get);
474 handle.registerCommandCallout("lease4-get-all", lease4_get_all);
475 handle.registerCommandCallout("lease6-get-all", lease6_get_all);
476 handle.registerCommandCallout("lease4-get-page", lease4_get_page);
477 handle.registerCommandCallout("lease6-get-page", lease6_get_page);
478 handle.registerCommandCallout("lease4-get-by-hw-address",
480 handle.registerCommandCallout("lease6-get-by-hw-address",
482 handle.registerCommandCallout("lease4-get-by-client-id",
484 handle.registerCommandCallout("lease6-get-by-duid", lease6_get_by_duid);
485 handle.registerCommandCallout("lease4-get-by-state", lease4_get_by_state);
486 handle.registerCommandCallout("lease6-get-by-state", lease6_get_by_state);
487 handle.registerCommandCallout("lease4-get-by-hostname",
489 handle.registerCommandCallout("lease6-get-by-hostname",
491 handle.registerCommandCallout("lease4-del", lease4_del);
492 handle.registerCommandCallout("lease6-del", lease6_del);
493 handle.registerCommandCallout("lease4-update", lease4_update);
494 handle.registerCommandCallout("lease6-update", lease6_update);
495 handle.registerCommandCallout("lease4-wipe", lease4_wipe);
496 handle.registerCommandCallout("lease6-wipe", lease6_wipe);
497 handle.registerCommandCallout("lease4-resend-ddns", lease4_resend_ddns);
498 handle.registerCommandCallout("lease6-resend-ddns", lease6_resend_ddns);
499 handle.registerCommandCallout("lease4-write", lease4_write);
500 handle.registerCommandCallout("lease6-write", lease6_write);
501 handle.registerCommandCallout("sflq-pool4-rebuild", sflq_pool4_rebuild);
502 handle.registerCommandCallout("sflq-pool4-get-all", sflq_pool4_get_all);
503 handle.registerCommandCallout("sflq-pool4-get-by-subnet", sflq_pool4_get_by_subnet);
504 handle.registerCommandCallout("sflq-pool4-get-by-range", sflq_pool4_get_by_range);
505 handle.registerCommandCallout("sflq-pool4-del", sflq_pool4_del);
506 handle.registerCommandCallout("sflq-pool6-rebuild", sflq_pool6_rebuild);
507 handle.registerCommandCallout("sflq-pool6-get-all", sflq_pool6_get_all);
508 handle.registerCommandCallout("sflq-pool6-get-by-subnet", sflq_pool6_get_by_subnet);
509 handle.registerCommandCallout("sflq-pool6-get-by-range", sflq_pool6_get_by_range);
510 handle.registerCommandCallout("sflq-pool6-del", sflq_pool6_del);
511
512 // Instantiate the binding-variables manager singleton.
513 binding_var_mgr.reset(new BindingVariableMgr(family));
514
515 try {
516 // Configure binding variable manager using the hook library's parameters.
517 ConstElementPtr json = handle.getParameters();
518 if (json) {
519 binding_var_mgr->configure(json);
520 }
521 } catch (const std::exception& ex) {
523 .arg(ex.what());
524 return (1);
525 }
526
528 return (0);
529}
530
534int unload() {
536 return (0);
537}
538
543 return (1);
544}
545
551 if (status == CalloutHandle::NEXT_STEP_DROP ||
553 return (0);
554 }
555
556 try {
558 lease_cmds.lease4Offer(handle, binding_var_mgr);
559 } catch (const std::exception& ex) {
561 .arg(ex.what());
562 return (1);
563 }
564
565 return (0);
566}
567
573 if (status == CalloutHandle::NEXT_STEP_DROP ||
575 return (0);
576 }
577
578 try {
580 lease_cmds.leases4Committed(handle, binding_var_mgr);
581 } catch (const std::exception& ex) {
583 .arg(ex.what());
584 return (1);
585 }
586
587 return (0);
588}
589
595 if (status == CalloutHandle::NEXT_STEP_DROP ||
597 return (0);
598 }
599
600 try {
602 lease_cmds.leases6Committed(handle, binding_var_mgr);
603 } catch (const std::exception& ex) {
605 .arg(ex.what());
606 return (1);
607 }
608
609 return (0);
610}
611
612} // 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:156
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.