diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 4064f156fe..2b0b7501b6 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -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 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 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); diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index bf1f3a7961..a5e7c3b434 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -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