]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2795] add getAll6 by ip-address method
authorPiotrek Zadroga <piotrek@isc.org>
Thu, 15 Jun 2023 10:26:04 +0000 (12:26 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Mon, 26 Jun 2023 15:30:59 +0000 (15:30 +0000)
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/host_mgr.h

index f5a41f23671e49869d3cb0e2ea623ba20b581a87..a501f2fc86a6b5c6fbd5efb63c49794ee3f7e77c 100644 (file)
@@ -740,6 +740,23 @@ HostMgr::getAll6(const SubnetID& subnet_id,
         return getAll6(subnet_id, address, HostMgrOperationTarget::ALL_SOURCES);
 }
 
+ConstHostCollection
+HostMgr::getAll6(const IOAddress& address, const HostMgrOperationTarget target) const {
+    ConstHostCollection hosts;
+    if (target & HostMgrOperationTarget::PRIMARY_SOURCE) {
+        hosts = getCfgHosts()->getAll6(address);
+    }
+
+    if (target & HostMgrOperationTarget::ALTERNATE_SOURCES) {
+        for (auto source : alternate_sources_) {
+            ConstHostCollection hosts_plus = source->getAll4(address);
+            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
+        }
+    }
+
+    return (hosts);
+}
+
 void
 HostMgr::add(const HostPtr& host, const HostMgrOperationTarget target) {
     if (target & HostMgrOperationTarget::PRIMARY_SOURCE) {
@@ -959,6 +976,5 @@ HostMgr::setIPReservationsUnique(const bool unique) {
     return (true);
 }
 
-
 } // end of isc::dhcp namespace
 } // end of isc namespace
index c129f8f8b4aa58bd30de21a6885c620f4c659c71..33c806119248e990c8ba8d1b92511c8d847f5837 100644 (file)
@@ -641,6 +641,24 @@ public:
     getAll6(const SubnetID& subnet_id,
             const asiolink::IOAddress& address) const;
 
+    /// @brief Returns a collection of hosts using the specified IPv6 address.
+    ///
+    /// This method may return multiple @c Host objects if they are connected to
+    /// different subnets or if there are multiple hosts with the same IPv6 address.
+    ///
+    /// If matching reservations are both in the primary and the alternate
+    /// data source, all of them are returned. The reservations from the
+    /// primary data source are placed before the reservations from the
+    /// alternate source.
+    ///
+    /// @param address IPv6 address for which the @c Host object is searched.
+    /// @param target The host data source being a target of the operation.
+    ///
+    /// @return Collection of const @c Host objects.
+    ConstHostCollection
+    getAll6(const asiolink::IOAddress& address,
+            const HostMgrOperationTarget target) const;
+
     /// @brief Adds a new host to the alternate data source.
     ///
     /// This method will throw an exception if no alternate data source is