Kea 2.7.5
|
Hooks Manager. More...
#include <hooks_manager.h>
Static Public Member Functions | |
static void | callCallouts (int index, CalloutHandle &handle) |
Calls the callouts for a given hook. | |
static void | callCommandHandlers (const std::string &command_name, CalloutHandle &handle) |
Calls the callouts/command handlers for a given command name. | |
static bool | calloutsPresent (int index) |
Are callouts present? | |
static void | clearParkingLots () |
Clears any parking packets. | |
static bool | commandHandlersPresent (const std::string &command_name) |
Checks if control command handlers are present for the specified command. | |
static boost::shared_ptr< CalloutHandle > | createCalloutHandle () |
Return callout handle. | |
template<typename T > | |
static bool | drop (const std::string &hook_name, T parked_object) |
Removes parked object without calling a callback. | |
static HookLibsCollection | getLibraryInfo () |
Return list of loaded libraries with its parameters. | |
static std::vector< std::string > | getLibraryNames () |
Return list of loaded libraries. | |
static bool | getTestMode () |
Get test mode. | |
static bool | loadLibraries (const HookLibsCollection &libraries, bool multi_threading_enabled=false) |
Load and reload libraries. | |
template<typename T > | |
static void | park (const std::string &hook_name, T parked_object, std::function< void()> unpark_callback) |
Park an object (packet). | |
static LibraryHandle & | postCalloutsLibraryHandle () |
Return post-callouts library handle. | |
static LibraryHandle & | preCalloutsLibraryHandle () |
Return pre-callouts library handle. | |
static void | prepareUnloadLibraries () |
Prepare the unloading of libraries. | |
template<typename T > | |
static void | reference (const std::string &hook_name, T parked_object) |
Increases reference counter for the parked object. | |
static int | registerHook (const std::string &name) |
Register Hook. | |
static void | setTestMode (bool mode) |
Set test mode. | |
static bool | unloadLibraries () |
Unload libraries. | |
template<typename T > | |
static bool | unpark (const std::string &hook_name, T parked_object) |
Forces unparking the object (packet). | |
static std::vector< std::string > | validateLibraries (const std::vector< std::string > &libraries, bool multi_threading_enabled=false) |
Validate library list. | |
Static Public Attributes | |
static const int | CONTEXT_CREATE = ServerHooks::CONTEXT_CREATE |
Index numbers for pre-defined hooks. | |
static const int | CONTEXT_DESTROY = ServerHooks::CONTEXT_DESTROY |
Hooks Manager.
This is the overall manager of the hooks framework and is the main class used by a Kea module when handling hooks. It is responsible for the loading and unloading of user libraries, and for calling the callouts on each hook point.
The class is a singleton, the single instance of the object being accessed through the static getHooksManager() method.
Definition at line 50 of file hooks_manager.h.
|
static |
Calls the callouts for a given hook.
Iterates through the library handles and calls the callouts associated with the given hook index.
index | Index of the hook to call. |
handle | Reference to the CalloutHandle object for the current object being processed. |
Definition at line 76 of file hooks_manager.cc.
Referenced by isc::d2::D2Process::configure(), isc::dhcp::CBControlDHCPv4::databaseConfigApply(), isc::dhcp::CBControlDHCPv6::databaseConfigApply(), isc::dhcp::Dhcpv4Srv::declineLease(), isc::dhcp::Dhcpv6Srv::declineLease(), isc::dhcp::ControlledDhcpv4Srv::finishConfigHookLibraries(), isc::dhcp::ControlledDhcpv6Srv::finishConfigHookLibraries(), isc::dhcp::Dhcp4to6Ipc::handler(), isc::dhcp::Dhcp6to4Ipc::handler(), isc::dhcp::Dhcpv6Srv::processClientFqdn(), isc::dhcp::Dhcpv4Srv::processClientName(), isc::config::BaseCommandMgr::processCommand(), isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv4Srv::processPacket(), isc::dhcp::Dhcpv6Srv::processPacket(), isc::dhcp::Dhcpv4Srv::processPacketBufferSend(), isc::dhcp::Dhcpv6Srv::processPacketBufferSend(), isc::dhcp::Dhcpv4Srv::processPacketPktSend(), isc::dhcp::Dhcpv6Srv::processPacketPktSend(), isc::dhcp::Dhcpv4Srv::processRelease(), isc::dhcp::Dhcpv6Srv::releaseIA_NA(), isc::dhcp::Dhcpv6Srv::releaseIA_PD(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), isc::d2::NameChangeTransaction::selectTSIGKey(), isc::dhcp::Dhcpv4Srv::serverDecline(), isc::dhcp::Dhcpv4Exchange::setHostIdentifiers(), and isc::dhcp::Dhcpv6Srv::setHostIdentifiers().
|
static |
Calls the callouts/command handlers for a given command name.
Iterates through the library handles and calls the command handlers associated with the given command. It expects that the hook point for this command exists (with a name being a command_name prefixed with a dollar sign and with hyphens replaced with underscores).
command_name | Command name for which handlers should be called. |
handle | Reference to the CalloutHandle object for the current object being processed. |
NoSuchHook | if the hook point for the specified command does not exist. |
Definition at line 87 of file hooks_manager.cc.
Referenced by isc::config::HookedCommandMgr::delegateCommandToHookLibrary().
|
static |
Are callouts present?
Checks loaded libraries and returns true if at lease one callout has been registered by them for the given hook.
index | Hooks index for which callouts are checked. |
NoSuchHook | Given index does not correspond to a valid hook. |
Definition at line 54 of file hooks_manager.cc.
Referenced by isc::d2::D2Process::configure(), isc::dhcp::CBControlDHCPv4::databaseConfigApply(), isc::dhcp::CBControlDHCPv6::databaseConfigApply(), isc::dhcp::Dhcpv4Srv::declineLease(), isc::dhcp::Dhcpv6Srv::declineLease(), isc::dhcp::ControlledDhcpv4Srv::finishConfigHookLibraries(), isc::dhcp::ControlledDhcpv6Srv::finishConfigHookLibraries(), isc::dhcp::Dhcp4to6Ipc::handler(), isc::dhcp::Dhcp6to4Ipc::handler(), isc::dhcp::Dhcpv6Srv::processClientFqdn(), isc::dhcp::Dhcpv4Srv::processClientName(), isc::config::BaseCommandMgr::processCommand(), isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv4Srv::processPacket(), isc::dhcp::Dhcpv6Srv::processPacket(), isc::dhcp::Dhcpv4Srv::processPacketBufferSend(), isc::dhcp::Dhcpv6Srv::processPacketBufferSend(), isc::dhcp::Dhcpv4Srv::processPacketPktSend(), isc::dhcp::Dhcpv6Srv::processPacketPktSend(), isc::dhcp::Dhcpv4Srv::processRelease(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal(), isc::dhcp::Dhcpv6Srv::releaseIA_NA(), isc::dhcp::Dhcpv6Srv::releaseIA_PD(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), isc::d2::NameChangeTransaction::selectTSIGKey(), isc::dhcp::Dhcpv4Srv::serverDecline(), isc::dhcp::Dhcpv4Exchange::setHostIdentifiers(), and isc::dhcp::Dhcpv6Srv::setHostIdentifiers().
|
inlinestatic |
Clears any parking packets.
This method should be called during reconfiguration to ensure there are no dangling pointers that could possibly prevent the library from being unloaded.
Definition at line 350 of file hooks_manager.h.
References isc::hooks::ServerHooks::getServerHooks().
Referenced by isc::dhcp::Dhcpv4Srv::discardPackets(), and isc::dhcp::Dhcpv6Srv::discardPackets().
|
static |
Checks if control command handlers are present for the specified command.
command_name | Command name for which handlers' presence should be checked. |
Definition at line 64 of file hooks_manager.cc.
Referenced by isc::config::HookedCommandMgr::delegateCommandToHookLibrary(), and isc::config::HookedCommandMgr::handleCommand().
|
static |
Return callout handle.
Returns a callout handle to be associated with a request passed round the system.
Definition at line 203 of file hooks_manager.cc.
Referenced by isc::d2::D2Process::configure(), isc::dhcp::CBControlDHCPv4::databaseConfigApply(), isc::dhcp::CBControlDHCPv6::databaseConfigApply(), isc::config::HookedCommandMgr::delegateCommandToHookLibrary(), isc::dhcp::ControlledDhcpv4Srv::finishConfigHookLibraries(), isc::dhcp::ControlledDhcpv6Srv::finishConfigHookLibraries(), isc::hooks::CalloutHandleAssociate::getCalloutHandle(), isc::config::BaseCommandMgr::processCommand(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal(), and isc::d2::NameChangeTransaction::selectTSIGKey().
|
inlinestatic |
Removes parked object without calling a callback.
T | type of the parked object. |
hook_name | name of the hook point for which the packet is parked. |
parked_object | parked object to be removed. |
Definition at line 325 of file hooks_manager.h.
References drop(), and isc::hooks::ServerHooks::getServerHooks().
Referenced by drop(), isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), and isc::dhcp::Dhcpv4Srv::selectSubnet4o6().
|
static |
Return list of loaded libraries with its parameters.
Returns the names of the loaded libraries and their parameters.
Definition at line 225 of file hooks_manager.cc.
Referenced by isc::hooks::LibraryHandle::getParameters().
|
static |
Return list of loaded libraries.
Returns the names of the loaded libraries.
Definition at line 220 of file hooks_manager.cc.
Referenced by isc::process::DControllerBase::~DControllerBase(), isc::dhcp::Dhcpv4Srv::~Dhcpv4Srv(), isc::dhcp::Dhcpv6Srv::~Dhcpv6Srv(), and isc::hooks::HooksConfig::verifyLibraries().
|
static |
|
static |
Load and reload libraries.
Loads the list of libraries into the server address space. For each library, the "standard" functions (ones with the same names as the hook points) are configured and the libraries' "load" function called.
If any library fails to load, an error message will be logged. The remaining libraries will be loaded if possible.
libraries | List of libraries to be loaded. The order is important, as it determines the order that callouts on the same hook will be called. |
multi_threading_enabled | The flag which indicates if MT is enabled (used to check hook libraries compatibility with MT). |
LibrariesStillOpened | when some libraries are already loaded. |
Definition at line 133 of file hooks_manager.cc.
Referenced by isc::hooks::HooksConfig::loadLibraries().
|
inlinestatic |
Park an object (packet).
The typical use case for parking an object is when the server needs to suspend processing of a packet to perform an asynchronous operation, before the response is sent to a client. In this case, the object type is a pointer to the processed packet. Therefore, further in this description we're going to refer to the parked objects as "parked packets". However, any other object can be parked if necessary.
The following is the typical flow when packets are parked. The callouts responsible for performing an asynchronous operation signal this need to the server by returning the status NEXT_STEP_PARK
, which instructs the server to call this function. This function stops processing the packet and puts it in, so called, parking lot. In order to be able to resume the packet processing when instructed by the hooks library, the parked packet is associated with the callback which, when called, will resume packet processing.
The hook library must increase a reference count on the parked object by calling ParkingLotHandle::reference
prior to returning the NEXT_STEP_PARK
status. This is important when multiple callouts are installed on the same hook point and each of them schedules an asynchronous operation. In this case, the packet must not be unparked until all hook libraries call ParkingLotHandle::unpark
to mark that respective asynchronous operations are completed.
Type | of the parked object. |
hook_name | name of the hook point for which the packet is parked. |
parked_object | packet to be parked. |
unpark_callback | callback invoked when the packet is unparked. |
Definition at line 296 of file hooks_manager.h.
References isc::hooks::ServerHooks::getServerHooks().
Referenced by isc::dhcp::Dhcpv4Srv::processLocalizedQuery4(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv6Srv::selectSubnet(), and isc::dhcp::Dhcpv4Srv::selectSubnet4o6().
|
static |
Return post-callouts library handle.
Returns a library handle that can be used by the server to register callouts on a hook that are called _after any callouts belonging to a library.
Definition at line 254 of file hooks_manager.cc.
|
static |
Return pre-callouts library handle.
Returns a library handle that can be used by the server to register callouts on a hook that are called before any callouts belonging to a library.
Definition at line 244 of file hooks_manager.cc.
|
static |
Prepare the unloading of libraries.
Calls the unload functions when they exist and removes callouts.
Definition at line 191 of file hooks_manager.cc.
Referenced by isc::process::DControllerBase::~DControllerBase(), isc::dhcp::Dhcpv4Srv::~Dhcpv4Srv(), isc::dhcp::Dhcpv6Srv::~Dhcpv6Srv(), isc::dhcp::configureDhcp4Server(), and isc::dhcp::configureDhcp6Server().
|
inlinestatic |
Increases reference counter for the parked object.
Reference counter must be increased at least to 1 before the park()
method can be called.
Type | of the parked object. |
hook_name | name of the hook point for which the packet is parked. |
parked_object | parked object for which reference counter should be increased. |
Definition at line 340 of file hooks_manager.h.
References isc::hooks::ServerHooks::getServerHooks().
|
static |
Register Hook.
This is just a convenience shell around the ServerHooks::registerHook() method. It - along with the definitions of the two hook indexes for the context_create and context_destroy methods - means that server authors only need to deal with HooksManager and CalloutHandle, and not include any other hooks framework classes.
name | Name of the hook |
DuplicateHook | A hook with the same name has already been registered. |
Definition at line 232 of file hooks_manager.cc.
|
static |
Set test mode.
If enabled by unit tests will permit to register callouts before calling loadLibraries which will return immediately without changing current internal state.
mode | the test mode flag which enables or disabled the functionality. |
Definition at line 270 of file hooks_manager.cc.
|
static |
Unload libraries.
Unloads the loaded libraries and leaves the hooks subsystem in the state it was after construction but before loadLibraries() is called.
Definition at line 177 of file hooks_manager.cc.
Referenced by isc::process::DControllerBase::~DControllerBase(), isc::dhcp::Dhcpv4Srv::~Dhcpv4Srv(), isc::dhcp::Dhcpv6Srv::~Dhcpv6Srv(), isc::dhcp::configureDhcp4Server(), and isc::dhcp::configureDhcp6Server().
|
inlinestatic |
Forces unparking the object (packet).
This method unparks the object regardless of the reference counting value. This is used in the situations when the callouts fail to unpark the packet for some reason.
T | type of the parked object. |
hook_name | name of the hook point for which the packet is parked. |
parked_object | parked object to be unparked. |
Definition at line 313 of file hooks_manager.h.
References isc::hooks::ServerHooks::getServerHooks(), and unpark().
Referenced by unpark().
|
static |
Validate library list.
For each library passed to it, checks that the library can be opened and that the "version" function is present and gives the right answer. Each library is closed afterwards.
This is used during the configuration parsing - when the list of hooks libraries is changed, each of the new libraries is checked before the change is committed.
libraries | List of libraries to be validated. |
multi_threading_enabled | The flag which indicates if MT is enabled (used to check hook libraries compatibility with MT). |
Definition at line 261 of file hooks_manager.cc.
Referenced by isc::hooks::HooksConfig::verifyLibraries().
|
static |
Index numbers for pre-defined hooks.
Definition at line 262 of file hooks_manager.h.
|
static |
Definition at line 263 of file hooks_manager.h.