]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2815] Implement update for CfgHosts
authorSlawek Figiel <slawek@isc.org>
Tue, 9 May 2023 17:09:20 +0000 (19:09 +0200)
committerSlawek Figiel <slawek@isc.org>
Thu, 25 May 2023 11:29:29 +0000 (13:29 +0200)
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/host_mgr.h

index 0eb88a90b4e3253ce12ed1eab986d927f6603fa6..e5cb6e5976653d74e751081f49f34f347f589665 100644 (file)
@@ -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_) {
index 3afd137abce4d7684d7c3a751c88e0d07220dee7..f4603e3b04445b10b6d0b90b2d40917c76ed049c 100644 (file)
@@ -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