From: Marcin Siodelski Date: Tue, 23 Jan 2018 14:24:22 +0000 (+0100) Subject: [5457] Added dhcp4_srv_configured hook point. X-Git-Tag: ha_checkpoints12~3^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=807e45cac6ef375c13a60b68bb3845af4cc3398d;p=thirdparty%2Fkea.git [5457] Added dhcp4_srv_configured hook point. --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 6a82e07be5..fd344d20b2 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -1,4 +1,4 @@ -// 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 @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,22 @@ using namespace std; 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 @@ -628,6 +645,19 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { 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); } diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index e06bf8d37e..eca6a10ccd 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1069,7 +1069,6 @@ Dhcpv4Srv::processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp, bool allow_packet_park) { } } callout_handle->setArgument("deleted_leases4", deleted_leases); - callout_handle->setArgument("io_service", getIOService()); // Call all installed callouts HooksManager::callCallouts(Hooks.hook_index_leases4_committed_, diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index a52e6cdaf8..481aa45092 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -108,6 +108,8 @@ public: // clear static buffers resetCalloutBuffers(); + + io_service_ = boost::make_shared(); } /// @brief destructor (deletes Dhcpv4Srv) @@ -668,11 +670,9 @@ public: 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); @@ -774,6 +774,9 @@ public: /// 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 @@ -818,6 +821,7 @@ public: // 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_; @@ -1845,7 +1849,6 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { 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); @@ -1932,7 +1935,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { 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)); @@ -1954,7 +1957,6 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { 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); @@ -1987,7 +1989,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { // 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()); @@ -2187,7 +2189,6 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRelease) { 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); @@ -2442,7 +2443,6 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedDecline) { 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);