]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3375] Fixed del bug (new UT?)
authorFrancis Dupont <fdupont@isc.org>
Thu, 30 May 2024 23:28:43 +0000 (01:28 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 10 Jun 2024 07:19:53 +0000 (09:19 +0200)
src/lib/dhcpsrv/cfg_hosts.cc

index 2888e947eaba19df11e20ee936b797ec6c3f00c9..b715abf8de39ab976aa4c8b38dc708deb48527d8 100644 (file)
@@ -1161,14 +1161,21 @@ CfgHosts::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) {
     } else {
         HostContainer6Index1& idx6 = hosts6_.get<1>();
         HostContainerIndex4& idx = hosts_.get<4>();
-        // Delete IPv6 reservations.
+        HostContainer6Index3& idx3 = hosts6_.get<3>();
+
+        // Delete hosts and IPv6 reservations.
         auto const& range = idx6.equal_range(boost::make_tuple(subnet_id, addr));
-        erased_addresses = boost::distance(range);
-        // Delete hosts.
+        // Find hosts to delete: we can't delete them now because a host
+        // can have more than one reservation for the address.
+        set<HostID> ids;
         BOOST_FOREACH(auto const& key, range) {
-            erased_hosts += idx.erase(key.host_->getHostId());
+            static_cast<void>(ids.insert(key.host_->getHostId()));
+        }
+        // Delete them.
+        for(auto const& id : ids) {
+            erased_hosts += idx.erase(id);
+            erased_addresses += idx3.erase(id);
         }
-        idx6.erase(range.first, range.second);
     }
 
     LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_DEL)