]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1733] Addressed review comments
authorThomas Markwalder <tmark@isc.org>
Mon, 12 Apr 2021 13:50:14 +0000 (09:50 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 12 Apr 2021 14:37:04 +0000 (10:37 -0400)
Minor clean-up and typos.

src/hooks/dhcp/high_availability/ha_impl.cc
    HAImpl::leases4Committed()
    HAImpl::leases6Committed() - added try-catch to ensure
    we call dereference on error

src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
src/hooks/dhcp/high_availability/ha_impl.cc
src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
src/lib/hooks/parking_lots.h
src/lib/hooks/tests/parking_lots_unittest.cc

index 1efd83fed80ad71f74581dbb4243e34b78deabf6..ef19c45743cf45b69b5fb07c26e268e79f0740a7 100644 (file)
@@ -666,14 +666,14 @@ Dhcpv4Srv::~Dhcpv4Srv() {
 
     try {
         stopD2();
-    } catch(const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // Highly unlikely, but lets Report it but go on
         LOG_ERROR(dhcp4_logger, DHCP4_SRV_D2STOP_ERROR).arg(ex.what());
     }
 
     try {
         Dhcp4to6Ipc::instance().close();
-    } catch(const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // Highly unlikely, but lets Report it but go on
         LOG_ERROR(dhcp4_logger, DHCP4_SRV_DHCP4O6_ERROR).arg(ex.what());
     }
@@ -1369,7 +1369,7 @@ Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
             // Call all installed callouts
             HooksManager::callCallouts(Hooks.hook_index_leases4_committed_,
                                        *callout_handle);
-        } catch(...) {
+        } catch (...) {
             // Make sure we don't orphan a parked packet.
             if (allow_packet_park) {
                 HooksManager::drop("leases4_committed", query);
index 3b758bd9c271acd5a7b1697e008d1ec2587c2363..b18913000d57ce867d6f19eef1e80a4665446aec 100644 (file)
@@ -266,14 +266,14 @@ Dhcpv6Srv::~Dhcpv6Srv() {
 
     try {
         stopD2();
-    } catch(const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // Highly unlikely, but lets Report it but go on
         LOG_ERROR(dhcp6_logger, DHCP6_SRV_D2STOP_ERROR).arg(ex.what());
     }
 
     try {
         Dhcp6to4Ipc::instance().close();
-    } catch(const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // Highly unlikely, but lets Report it but go on
         // LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what());
     }
@@ -1040,7 +1040,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
             // Call all installed callouts
             HooksManager::callCallouts(Hooks.hook_index_leases6_committed_,
                                        *callout_handle);
-        } catch(...) {
+        } catch (...) {
             // Make sure we don't orphan a parked packet.
             HooksManager::drop("leases4_committed", query);
             throw;
index 06182202d13ffb665702c05d0c8029b664c1b603..9ca69f07127c741302015297977f1afa8009b1ae 100644 (file)
@@ -142,14 +142,20 @@ HAImpl::leases4Committed(CalloutHandle& callout_handle) {
     // e.g. when this server is in the partner-down state and there are no backup
     // servers. In those cases we simply return without parking the DHCP query.
     // The response will be sent to the client immediately.
-    if (service_->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
-        // Dereference the parked packet.  This releases our stake in it.
+    try {
+        if (service_->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
+            // Dereference the parked packet.  This releases our stake in it.
+            parking_lot->dereference(query4);
+            return;
+        } 
+    } catch (...) {
+        // Make sure we dereference.
         parking_lot->dereference(query4);
-        return;
+        throw;
     }
 
     // The callout returns this status code to indicate to the server that it
-    // should leave the packet parked.  It will be unparked until each hook
+    // should leave the packet parked.  It will be parked until each hook
     // library with a reference, unparks the packet.
     callout_handle.setStatus(CalloutHandle::NEXT_STEP_PARK);
 }
@@ -250,10 +256,16 @@ HAImpl::leases6Committed(CalloutHandle& callout_handle) {
     // e.g. when this server is in the partner-down state and there are no backup
     // servers. In those cases we simply return without parking the DHCP query.
     // The response will be sent to the client immediately.
-    if (service_->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
-        // Dereference the parked packet.  This releases our stake in it.
+    try {
+        if (service_->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
+            // Dereference the parked packet.  This releases our stake in it.
+            parking_lot->dereference(query6);
+            return;
+        } 
+    } catch (...) {
+        // Make sure we dereference.
         parking_lot->dereference(query6);
-        return;
+        throw;
     }
 
     // The callout returns this status code to indicate to the server that it
index 04f8b4d4c0cce5995e181c25c05418106d25536d..79ea532f5cb799ec08cf935f976e225311977175 100644 (file)
@@ -414,7 +414,7 @@ TEST_F(CloseHATest, close4) {
         ScopedCalloutHandleState handle_state(handle);
         handle->setArgument("query4", query);
 
-        // Park the packtet proactively as the server normally would.
+        // Park the packet proactively as the server normally would.
         HooksManager::park("leases4_committed", query, []{});
 
         // Invoke the callouts.
@@ -652,7 +652,7 @@ TEST_F(CloseHATest, close6) {
         ScopedCalloutHandleState handle_state(handle);
         handle->setArgument("query6", query);
 
-        // Park the packtet proactively as the server normally would.
+        // Park the packet proactively as the server normally would.
         HooksManager::park("leases6_committed", query, []{});
 
         // Invoke the callouts.
index fa09162dea1a66f463394397d0cfbb473c950144..e54272cac4a0b630e0a1cb9114a265eb00a2d973 100644 (file)
@@ -412,7 +412,7 @@ TEST_F(HAImplTest, leases4Committed) {
     HooksManager::park("leases4_committed", query4, []{});
 
     // Run the callout again.
-    ASSERT_NO_THROW_LOG(ha_impl.leases4Committed(*callout_handle));
+    ASSERT_NO_THROW(ha_impl.leases4Committed(*callout_handle));
 
     // This time the lease update should be generated and the status should
     // be set to "park".
index 921eff3bb5b0314be712061b285696934b2d108d..374e7dcac5e232b7579858934485beb15d348363 100644 (file)
@@ -90,7 +90,6 @@ public:
         // Add the object to the parking lot. At this point refcount = 0.
         ParkingInfo pinfo(parked_object, unpark_callback);
         parking_[makeKey(parked_object)] = pinfo;
-        return;
     }
 
     /// @brief Increases reference counter for the parked object.
@@ -133,7 +132,7 @@ public:
         }
 
         // Decrement and return the reference count.
-       return (--it->second.refcount_);
+        return (--it->second.refcount_);
     }
 
     /// @brief Signals that the object should be unparked.
@@ -260,7 +259,7 @@ private:
     std::string makeKey(T parked_object) {
         std::stringstream ss;
         ss << boost::any_cast<T>(parked_object);
-        return(ss.str());
+        return (ss.str());
     }
 
     /// @brief Search for the information about the parked object.
@@ -271,7 +270,7 @@ private:
     /// if no such object found.
     template<typename T>
     ParkingInfoListIterator find(T parked_object) {
-        return(parking_.find(makeKey(parked_object)));
+        return (parking_.find(makeKey(parked_object)));
     }
 
     /// @brief The mutex to protect parking lot internal state.
index f906492304776b6bac46b46ed5880d10ed32446c..c17f02a749fefead91ea8d98a2c5e8f89d8abe10 100644 (file)
@@ -97,8 +97,12 @@ TEST(ParkingLotsTest, unpark) {
 
     StringPtr parked_object(new std::string("foo"));
 
+    // Unparking should return false if the object isn't parked.
+    EXPECT_FALSE(parking_lot->unpark(parked_object));
+
     // This flag will indicate if the callback has been called.
     bool unparked = false;
+
     ASSERT_NO_THROW(parking_lot->park(parked_object, [&unparked] {
         unparked = true;
     }));
@@ -192,7 +196,7 @@ TEST(ParkingLotsTest, clear) {
     EXPECT_TRUE(weak_parked_object.expired());
 }
 
-// Verify that an object can be derefernced.
+// Verify that an object can be dereferenced.
 TEST(ParkingLotsTest, dereference) {
     ParkingLotPtr parking_lot = boost::make_shared<ParkingLot>();
     ParkingLotHandlePtr parking_lot_handle =
@@ -232,7 +236,7 @@ TEST(ParkingLotsTest, dereference) {
     ASSERT_EQ(0, ref_count);
     EXPECT_FALSE(unparked);
 
-    // Try to dereference the object. It should -1.
+    // Try to dereference the object. It should decrement to -1
     // but not unpark the packet or invoke the callback.
     ASSERT_NO_THROW(ref_count = parking_lot_handle->dereference(parked_object));
     EXPECT_EQ(-1, ref_count);