From: Slawek Figiel Date: Tue, 9 May 2023 17:09:20 +0000 (+0200) Subject: [#2815] Implement update for CfgHosts X-Git-Tag: Kea-2.3.8~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=385d9c1164af70677a8609e15516dbb53b29e370;p=thirdparty%2Fkea.git [#2815] Implement update for CfgHosts --- diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index 0eb88a90b4..e5cb6e5976 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -871,20 +871,34 @@ HostMgr::del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_ } void -HostMgr::update(HostPtr const& host) { - if (alternate_sources_.empty()) { - isc_throw(NoHostDataSourceManager, - "Unable to update existing host because there is no hosts-database configured."); +HostMgr::update(HostPtr const& host, const HostMgrOperationTarget target) { + if (target & HostMgrOperationTarget::PRIMARY_SOURCE) { + getCfgHostsForEdit()->update(host); } - for (HostDataSourcePtr const& source : alternate_sources_) { - source->update(host); + + if (target & HostMgrOperationTarget::ALTERNATE_SOURCES) { + // Don't throw if all targets were selected. + if (alternate_sources_.empty() && !(target & HostMgrOperationTarget::PRIMARY_SOURCE)) { + isc_throw(NoHostDataSourceManager, + "Unable to update existing host because there is no hosts-database configured."); + } + + for (HostDataSourcePtr const& source : alternate_sources_) { + source->update(host); + } } + // If no backend throws the host should be cached. if (cache_ptr_) { cache(host); } } +void +HostMgr::update(HostPtr const& host) { + update(host, HostMgrOperationTarget::ALTERNATE_SOURCES); +} + void HostMgr::cache(ConstHostPtr host) const { if (cache_ptr_) { diff --git a/src/lib/dhcpsrv/host_mgr.h b/src/lib/dhcpsrv/host_mgr.h index 3afd137abc..f4603e3b04 100644 --- a/src/lib/dhcpsrv/host_mgr.h +++ b/src/lib/dhcpsrv/host_mgr.h @@ -725,6 +725,11 @@ public: /// Attempts to update an existing host entry. /// /// @param host the host up to date with the requested changes + /// @param target The host data source being a target of the operation. + void update(HostPtr const& host, const HostMgrOperationTarget target); + + /// @brief The @c HostMgr::update with default operation target. Operates + /// on alternate host sources only. void update(HostPtr const& host); /// @brief Return backend type