]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[894-make-memfile-thread-safe] Updated after rebase
authorFrancis Dupont <fdupont@isc.org>
Mon, 4 Nov 2019 19:37:14 +0000 (20:37 +0100)
committerRazvan Becheriu <razvan@isc.org>
Thu, 23 Jan 2020 13:26:40 +0000 (15:26 +0200)
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h

index 4064f156fef43540a0b2aa7f9dbd04358e7f18cc..2b0b7501b6e6baa6bb7918ad467cd13c297ee412 100644 (file)
@@ -969,13 +969,6 @@ Memfile_LeaseMgr::getLeases4(SubnetID subnet_id) const {
     return (collection);
 }
 
-void
-Memfile_LeaseMgr::getLeases4Internal(Lease4Collection& collection) const {
-   for (auto lease = storage4_.begin(); lease != storage4_.end(); ++lease ) {
-       collection.push_back(Lease4Ptr(new Lease4(**lease)));
-   }
-}
-
 Lease4Collection
 Memfile_LeaseMgr::getLeases4(const std::string& hostname) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME4)
@@ -994,6 +987,29 @@ Memfile_LeaseMgr::getLeases4(const std::string& hostname) const {
     return (collection);
 }
 
+Lease4Collection
+Memfile_LeaseMgr::getLeases4(const std::string& hostname) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME4)
+        .arg(hostname);
+
+    Lease4Collection collection;
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lock(*mutex_);
+        getLeases4Internal(hostname, collection);
+    } else {
+        getLeases4Internal(hostname, collection);
+    }
+
+    return (collection);
+}
+
+void
+Memfile_LeaseMgr::getLeases4Internal(Lease4Collection& collection) const {
+   for (auto lease = storage4_.begin(); lease != storage4_.end(); ++lease ) {
+       collection.push_back(Lease4Ptr(new Lease4(**lease)));
+   }
+}
+
 Lease4Collection
 Memfile_LeaseMgr::getLeases4() const {
    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET4);
@@ -1189,13 +1205,6 @@ Memfile_LeaseMgr::getLeases6(SubnetID subnet_id) const {
     return (collection);
 }
 
-void
-Memfile_LeaseMgr::getLeases6Internal(Lease6Collection& collection) const {
-   for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease ) {
-       collection.push_back(Lease6Ptr(new Lease6(**lease)));
-   }
-}
-
 Lease6Collection
 Memfile_LeaseMgr::getLeases6(const std::string& hostname) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME6)
@@ -1214,6 +1223,29 @@ Memfile_LeaseMgr::getLeases6(const std::string& hostname) const {
     return (collection);
 }
 
+Lease6Collection
+Memfile_LeaseMgr::getLeases6(const std::string& hostname) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME6)
+        .arg(hostname);
+
+    Lease6Collection collection;
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lock(*mutex_);
+        getLeases6Internal(hostname, collection);
+    } else {
+        getLeases6Internal(hostname, collection);
+    }
+
+    return (collection);
+}
+
+void
+Memfile_LeaseMgr::getLeases6Internal(Lease6Collection& collection) const {
+   for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease ) {
+       collection.push_back(Lease6Ptr(new Lease6(**lease)));
+   }
+}
+
 Lease6Collection
 Memfile_LeaseMgr::getLeases6() const {
    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET6);
index bf1f3a7961e9ab4c124f65e7f97d2946d5f0dea4..a5e7c3b434778166442b1164de1117de0c4e1470 100644 (file)
@@ -524,6 +524,13 @@ private:
     void getLeases4Internal(SubnetID subnet_id,
                             Lease4Collection& collection) const;
 
+    /// @brief Returns all IPv4 leases for the particular hostname.
+    ///
+    /// @param hostname hostname in lower case.
+    /// @param collection lease collection
+    void getLeases4Internal(const std::string& hostname,
+                            Lease4Collection& collection) const;
+
     /// @brief Gets all IPv4 leases.
     ///
     /// @param collection lease collection
@@ -579,6 +586,13 @@ private:
     void getLeases6Internal(SubnetID subnet_id,
                             Lease6Collection& collection) const;
 
+    /// @brief Returns all IPv6 leases for the particular hostname.
+    ///
+    /// @param hostname hostname in lower case.
+    /// @param collection lease collection
+    void  getLeases6Internal(const std::string& hostname,
+                             Lease6Collection& collection) const;
+
     /// @brief Returns all IPv6 leases.
     ///
     /// @param collection lease collection