Commit 682cac0d authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2995] Hook point registration now matches guide document.

parent 19c93b08
......@@ -157,11 +157,6 @@ public:
}
virtual ~Dhcpv4SrvTest() {
// Remove all registered hook points (it must be done even for tests that
// do not use hooks as the base class - Dhcpv4Srv calls allocation engine
// that registers hooks)
isc::hooks::ServerHooks::getServerHooks().reset();
}
/// @brief Add 'Parameter Request List' option to the packet.
......
......@@ -56,6 +56,30 @@ using namespace isc::hooks;
using namespace isc::util;
using namespace std;
namespace {
/// Structure that holds registered hook indexes
struct Dhcp6Hooks {
int hook_index_pkt6_receive_; ///< index for "pkt6_receive" hook point
int hook_index_subnet6_select_; ///< index for "subnet6_select" hook point
int hook_index_pkt6_send_; ///< index for "pkt6_send" hook point
/// Constructor that registers hook points for DHCPv6 engine
Dhcp6Hooks() {
hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
}
};
// Declare a Hooks object. As this is outside any function or method, it
// will be instantiated (and the constructor run) when the module is loaded.
// As a result, the hook indexes will be defined before any method in this
// module is called.
Dhcp6Hooks Hooks;
}; // anonymous namespace
namespace isc {
namespace dhcp {
......@@ -112,9 +136,9 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
// Register hook points
hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
hook_index_pkt6_receive_ = Hooks.hook_index_pkt6_receive_;
hook_index_subnet6_select_ = Hooks.hook_index_subnet6_select_;
hook_index_pkt6_send_ = Hooks.hook_index_pkt6_send_;
/// @todo call loadLibraries() when handling configuration changes
vector<string> libraries; // no libraries at this time
......@@ -133,9 +157,6 @@ Dhcpv6Srv::~Dhcpv6Srv() {
IfaceMgr::instance().closeSockets();
LeaseMgrFactory::destroy();
/// @todo Unregister hooks once ServerHooks::deregisterHooks() becomes
/// available
}
void Dhcpv6Srv::shutdown() {
......
......@@ -109,10 +109,6 @@ public:
}
virtual ~NakedDhcpv6Srv() {
// Remove all registered hook points (it must be done even for tests that
// do not use hooks as the base class - Dhcpv6Srv registers hooks)
ServerHooks::getServerHooks().reset();
// Close the lease database
LeaseMgrFactory::destroy();
}
......
......@@ -26,6 +26,26 @@
using namespace isc::asiolink;
using namespace isc::hooks;
namespace {
/// Structure that holds registered hook indexes
struct Dhcp6Hooks {
int hook_index_lease6_select_; ///< index for "lease6_receive" hook point
/// Constructor that registers hook points for AllocationEngine
Dhcp6Hooks() {
hook_index_lease6_select_ = HooksManager::registerHook("lease6_select");
}
};
// Declare a Hooks object. As this is outside any function or method, it
// will be instantiated (and the constructor run) when the module is loaded.
// As a result, the hook indexes will be defined before any method in this
// module is called.
Dhcp6Hooks Hooks;
}; // anonymous namespace
namespace isc {
namespace dhcp {
......@@ -167,7 +187,7 @@ AllocEngine::AllocEngine(AllocType engine_type, unsigned int attempts)
}
// Register hook points
hook_index_lease6_select_ = ServerHooks::getServerHooks().registerHook("lease6_select");
hook_index_lease6_select_ = Hooks.hook_index_lease6_select_;
}
Lease6Ptr
......
......@@ -112,10 +112,6 @@ public:
virtual ~AllocEngine6Test() {
factory_.destroy();
// Remove all registered hook points (it must be done even for tests that
// do not use hooks as the base class - Dhcpv6Srv registers hooks
ServerHooks::getServerHooks().reset();
}
DuidPtr duid_; ///< client-identifier (value used in tests)
......@@ -184,10 +180,6 @@ public:
virtual ~AllocEngine4Test() {
factory_.destroy();
// Remove all registered hook points (it must be done even for tests that
// do not use hooks as the base class - Dhcpv6Srv registers hooks
ServerHooks::getServerHooks().reset();
}
ClientIdPtr clientid_; ///< Client-identifier (value used in tests)
......@@ -1045,7 +1037,8 @@ public:
}
virtual ~HookAllocEngine6Test() {
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts(
"lease6_select");
}
/// @brief clears out buffers, so callouts can store received arguments
......
......@@ -55,7 +55,8 @@ ServerHooks::registerHook(const string& name) {
inverse_hooks_[index] = name;
// Log it if debug is enabled
LOG_DEBUG(hooks_logger, HOOKS_DBG_TRACE, HOOKS_HOOK_REGISTERED).arg(name);
/// @todo See todo comment in reset() below.
//LOG_DEBUG(hooks_logger, HOOKS_DBG_TRACE, HOOKS_HOOK_REGISTERED).arg(name);
// ... and return numeric index.
return (index);
......@@ -85,7 +86,12 @@ ServerHooks::reset() {
// Log a warning - although this is done during testing, it should never be
// seen in a production system.
LOG_WARN(hooks_logger, HOOKS_HOOK_LIST_RESET);
/// @todo Implement proper workaround here. The issue is when the first
/// module (e.g. Dhcp6Srv module) initializes global structure it calls
/// HooksManager::registerHooks() which in turn creates ServerHooks object.
/// Its constructor calls reset() method, but the loggers are not initialized
/// yet and exception is thrown.
//LOG_WARN(hooks_logger, HOOKS_HOOK_LIST_RESET);
}
// Find the name associated with a hook index.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment