]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2815] Fix getting IPv6 hosts by reserved address
authorSlawek Figiel <slawek@isc.org>
Thu, 6 Apr 2023 16:39:09 +0000 (18:39 +0200)
committerSlawek Figiel <slawek@isc.org>
Thu, 25 May 2023 11:29:29 +0000 (13:29 +0200)
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/host_container.h
src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc

index 2ea5ad0fd79918bb74c2b69a3f458c1dba95faac..c21905bf7ec4c05e38d6c933835a5481c542092e 100644 (file)
@@ -644,16 +644,16 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const {
                   " for a host, specified address was " << address);
     }
     // Search for the Host using the reserved IPv6 address as a key.
-    const HostContainerIndex1& idx = hosts_.get<1>();
-    HostContainerIndex1Range r = idx.equal_range(address);
+    const HostContainer6Index4& idx = hosts6_.get<4>();
+    HostContainer6Index4Range r = idx.equal_range(address);
     // Append each Host object to the storage.
-    for (HostContainerIndex1::iterator host = r.first; host != r.second;
-         ++host) {
+    for (HostContainer6Index4::iterator reservation = r.first; reservation != r.second;
+         ++reservation) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA,
                   HOSTS_CFG_GET_ALL_ADDRESS6_HOST)
             .arg(address.toText())
-            .arg((*host)->toText());
-        storage.push_back(*host);
+            .arg(reservation->host_->toText());
+        storage.push_back(reservation->host_);
     }
 
     LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_ADDRESS6_COUNT)
index cb106adc24bf38abd6c7bcaa1e42728b25f4ba52..fd830760ddb3cff76b68eee2140dddebf01b70d1 100644 (file)
@@ -249,6 +249,14 @@ typedef boost::multi_index_container<
             // Index using values returned by the @c Host::getHostId
             boost::multi_index::const_mem_fun<HostResrv6Tuple, uint64_t,
                                               &HostResrv6Tuple::getHostId>
+        >,
+
+        // Fifth index is used to search by the reserved address.
+        boost::multi_index::ordered_non_unique<
+            boost::multi_index::const_mem_fun<
+                HostResrv6Tuple, const asiolink::IOAddress&,
+                &HostResrv6Tuple::getPrefix
+            >
         >
     >
 > HostContainer6;
@@ -292,6 +300,15 @@ typedef HostContainer6::nth_index<3>::type HostContainer6Index3;
 typedef std::pair<HostContainer6Index3::iterator,
                   HostContainer6Index3::iterator> HostContainer6Index3Range;
 
+/// @brief Fifth index type in the @c HostContainer6.
+///
+/// This index allows for searching for @c Host objects using an IP address.
+typedef HostContainer6::nth_index<4>::type HostContainer6Index4;
+
+/// @brief Results range returned using the @c HostContainer6Index4.
+typedef std::pair<HostContainer6Index4::iterator,
+                  HostContainer6Index4::iterator> HostContainer6Index4Range;
+
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
 
index 0abd18d200da985e12f02f9900666b341e108a26..de45d7965b1d3139919e123e60f7896555854a4c 100644 (file)
@@ -284,7 +284,7 @@ TEST_F(CfgHostsTest, getAll6ByAddress) {
     // Add 25 hosts identified by DUID in the same subnet.
     for (unsigned i = 0; i < 25; ++i) {
         HostPtr host = HostPtr(new Host(duids_[i]->toText(), "duid",
-                                        SUBNET_ID_UNUSED, SubnetID(1),
+                                        SUBNET_ID_UNUSED, SubnetID(i+1),
                                         IOAddress("0.0.0.0")));
         host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
                                        increase(IOAddress("2001:db8:1::1"),