]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5457] Added dhcp4_srv_configured hook point.
authorMarcin Siodelski <marcin@isc.org>
Tue, 23 Jan 2018 14:24:22 +0000 (15:24 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 23 Jan 2018 14:24:22 +0000 (15:24 +0100)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/hooks_unittest.cc

index 6a82e07be5030f3dfb31638ead02990e8e9bca33..fd344d20b23f87b266ac1ff52db6a894b2c52c84 100644 (file)
@@ -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 <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>
@@ -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);
 }
 
index e06bf8d37e50067144abf0581b8579c374028610..eca6a10ccd731e605fac702a2936ab56a79fc2f7 100644 (file)
@@ -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_,
index a52e6cdaf8966dfefcf7130ad1ed944f8c0cec87..481aa4509272b8b42d2eb5cb8754ecc0e4f9064a 100644 (file)
@@ -108,6 +108,8 @@ public:
 
         // clear static buffers
         resetCalloutBuffers();
+
+        io_service_ = boost::make_shared<IOService>();
     }
 
     /// @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);