-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <dhcp4/json_config_parser.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_db_access.h>
+#include <hooks/hooks.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <cfgrpt/config_report.h>
namespace {
+/// Structure that holds registered hook indexes.
+struct Dhcp4Hooks {
+ int hooks_index_dhcp4_srv_configured_;
+
+ /// Constructor that registers hook points for the DHCPv4 server.
+ Dhcp4Hooks() {
+ hooks_index_dhcp4_srv_configured_ = HooksManager::registerHook("dhcp4_srv_configured");
+ }
+};
+
+// 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.
+Dhcp4Hooks Hooks;
+
/// @brief Signals handler for DHCPv4 server.
///
/// This signal handler handles the following signals received by the DHCPv4
return (isc::config::createAnswer(1, err.str()));
}
+ // This hook point notifies hooks libraries that the configuration of the
+ // DHCPv4 server has completed. Currently it only provides hooks libraries
+ // with the pointer to the common IO service. In the future, additional
+ // information can be provided.
+ if (HooksManager::calloutsPresent(Hooks.hooks_index_dhcp4_srv_configured_)) {
+ CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
+
+ callout_handle->setArgument("io_service", srv->getIOService());
+
+ HooksManager::callCallouts(Hooks.hooks_index_dhcp4_srv_configured_,
+ *callout_handle);
+ }
+
return (answer);
}
// clear static buffers
resetCalloutBuffers();
+
+ io_service_ = boost::make_shared<IOService>();
}
/// @brief destructor (deletes Dhcpv4Srv)
callout_handle.getArgument("query4", callback_qry_pkt4_);
- IOServicePtr io_service;
- callout_handle.getArgument("io_service", io_service);
- io_service->post(boost::bind(&HooksDhcpv4SrvTest::leases4_committed_unpark,
- callout_handle.getParkingLotHandlePtr(),
- callback_qry_pkt4_));
+ io_service_->post(boost::bind(&HooksDhcpv4SrvTest::leases4_committed_unpark,
+ callout_handle.getParkingLotHandlePtr(),
+ callback_qry_pkt4_));
callout_handle.getParkingLotHandlePtr()->reference(callback_qry_pkt4_);
callout_handle.setStatus(CalloutHandle::NEXT_STEP_PARK);
/// pointer to Dhcpv4Srv that is used in tests
NakedDhcpv4Srv* srv_;
+ /// Pointer to the IO service used in the tests.
+ static IOServicePtr io_service_;
+
// The following fields are used in testing pkt4_receive_callout
/// String name of the received callout
// The following fields are used in testing pkt4_receive_callout.
// See fields description in the class for details
+IOServicePtr HooksDhcpv4SrvTest::io_service_;
string HooksDhcpv4SrvTest::callback_name_;
Pkt4Ptr HooksDhcpv4SrvTest::callback_qry_pkt4_;
Pkt4Ptr HooksDhcpv4SrvTest::callback_resp_pkt4_;
expected_argument_names.push_back("query4");
expected_argument_names.push_back("deleted_leases4");
expected_argument_names.push_back("leases4");
- expected_argument_names.push_back("io_service");
sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
IfaceMgr::instance().openSockets4();
// This callout uses provided IO service object to post a function
- // that unparks the packet. The packet is pared and can be unparked
+ // that unparks the packet. The packet is parked and can be unparked
// by simply calling IOService::poll.
ASSERT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"leases4_committed", leases4_committed_park_callout));
expected_argument_names.push_back("query4");
expected_argument_names.push_back("deleted_leases4");
expected_argument_names.push_back("leases4");
- expected_argument_names.push_back("io_service");
sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
// There should be now two actions schedulede on our IO service
// by the invoked callouts. They unpark both DHCPACK messages.
- ASSERT_NO_THROW(client1.getServer()->getIOService()->poll());
+ ASSERT_NO_THROW(io_service_->poll());
// Receive and check the first response.
ASSERT_NO_THROW(client1.receiveResponse());
expected_argument_names.push_back("query4");
expected_argument_names.push_back("deleted_leases4");
expected_argument_names.push_back("leases4");
- expected_argument_names.push_back("io_service");
sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
expected_argument_names.push_back("query4");
expected_argument_names.push_back("deleted_leases4");
expected_argument_names.push_back("leases4");
- expected_argument_names.push_back("io_service");
sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names);