From: Francis Dupont Date: Thu, 30 May 2024 23:28:43 +0000 (+0200) Subject: [#3375] Fixed del bug (new UT?) X-Git-Tag: Kea-2.7.0~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85e05cde3b0d1ab205c4d7ef4a5298c0e6d99e77;p=thirdparty%2Fkea.git [#3375] Fixed del bug (new UT?) --- diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc index 2888e947ea..b715abf8de 100644 --- a/src/lib/dhcpsrv/cfg_hosts.cc +++ b/src/lib/dhcpsrv/cfg_hosts.cc @@ -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 ids; BOOST_FOREACH(auto const& key, range) { - erased_hosts += idx.erase(key.host_->getHostId()); + static_cast(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)