]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2795] extend impl of BaseHostDataSource::getAll6
authorPiotrek Zadroga <piotrek@isc.org>
Tue, 20 Jun 2023 08:49:11 +0000 (10:49 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Mon, 26 Jun 2023 15:30:59 +0000 (15:30 +0000)
src/lib/dhcpsrv/base_host_data_source.h
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/host_mgr.h
src/lib/dhcpsrv/tests/host_cache_unittest.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.h

index f3013a659123ce147d9a43996972d206dfa25855..1ca50900d6fcf25b83a7311b3a641d7ad8d08a0d 100644 (file)
@@ -408,6 +408,30 @@ public:
     getAll6(const SubnetID& subnet_id,
             const asiolink::IOAddress& address) const = 0;
 
+    /// @brief Returns all hosts having a reservation for a specified
+    /// address or delegated prefix (lease) in all subnets.
+    ///
+    /// In most cases it is desired that there is at most one reservation
+    /// for a given IPv6 lease within a subnet. In a default configuration,
+    /// the backend does not allow for inserting more than one host with
+    /// the same IPv6 address or prefix.
+    ///
+    /// If the backend is configured to allow multiple hosts with reservations
+    /// for the same IPv6 lease in the given subnet, this method can return
+    /// more than one host per subnet.
+    ///
+    /// The typical use case when a single IPv6 lease is reserved for multiple
+    /// hosts is when these hosts represent different interfaces of the same
+    /// machine and each interface comes with a different MAC address. In that
+    /// case, the same IPv6 lease is assigned regardless of which interface is
+    /// used by the DHCP client to communicate with the server.
+    ///
+    /// @param address reserved IPv6 address/prefix.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll6(const asiolink::IOAddress& address) const = 0;
+
     /// @brief Adds a new host to the collection.
     ///
     /// The implementations of this method should guard against duplicate
index a501f2fc86a6b5c6fbd5efb63c49794ee3f7e77c..3771fd392e50bdeb89d52c52f95787e61a83be7a 100644 (file)
@@ -740,6 +740,11 @@ HostMgr::getAll6(const SubnetID& subnet_id,
         return getAll6(subnet_id, address, HostMgrOperationTarget::ALL_SOURCES);
 }
 
+ConstHostCollection
+HostMgr::getAll6(const IOAddress& address) const {
+        return (getAll6(address, HostMgrOperationTarget::ALL_SOURCES));
+}
+
 ConstHostCollection
 HostMgr::getAll6(const IOAddress& address, const HostMgrOperationTarget target) const {
     ConstHostCollection hosts;
@@ -749,7 +754,7 @@ HostMgr::getAll6(const IOAddress& address, const HostMgrOperationTarget target)
 
     if (target & HostMgrOperationTarget::ALTERNATE_SOURCES) {
         for (auto source : alternate_sources_) {
-            ConstHostCollection hosts_plus = source->getAll4(address);
+            ConstHostCollection hosts_plus = source->getAll6(address);
             hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
         }
     }
index 33c806119248e990c8ba8d1b92511c8d847f5837..b4bdd95e6731b09515487293f861e9acd22aa666 100644 (file)
@@ -641,6 +641,11 @@ public:
     getAll6(const SubnetID& subnet_id,
             const asiolink::IOAddress& address) const;
 
+    /// @brief The @c HostMgr::getAll6 compatible with @c BaseHostDataSource
+    /// interfaces. Operates on all host sources.
+    virtual ConstHostCollection
+    getAll6(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
index 2a210e6b39983d30110b3ec212176bc4a489dde0..fa2e6439b54a61f50f4fc78d275382c382721733 100644 (file)
@@ -611,6 +611,10 @@ public:
         return (getCollection());
     }
 
+    ConstHostCollection getAll6(const IOAddress&) const {
+        return (getCollection());
+    }
+
     ConstHostCollection getAllbyHostname(const std::string&) const {
         return (getCollection());
     }
index 2ba8a3737d0d86f997b7bd446e18318c64dccf44..7b6bd22c033da5f5288eb4dce5f71756dfd5a938 100644 (file)
@@ -296,10 +296,34 @@ ConstHostCollection
 MemHostDataSource::getAll6(const SubnetID& subnet_id,
                            const asiolink::IOAddress& address) const {
     ConstHostCollection hosts;
-    auto host = get6(subnet_id, address);
-    if (host) {
-        hosts.push_back(host);
+    for (const auto & h : store_) {
+        if (h->getIPv6SubnetID() != subnet_id) {
+            continue;
+        }
+
+        auto resrvs = h->getIPv6Reservations();
+        for (auto r = resrvs.first; r != resrvs.second; ++r) {
+            if ((*r).second.getPrefix() == address) {
+                hosts.push_back(h);
+            }
+        }
     }
+
+    return (hosts);
+}
+
+ConstHostCollection
+MemHostDataSource::getAll6(const asiolink::IOAddress& address) const {
+    ConstHostCollection hosts;
+    for (const auto & h : store_) {
+        auto resrvs = h->getIPv6Reservations();
+        for (auto r = resrvs.first; r != resrvs.second; ++r) {
+            if ((*r).second.getPrefix() == address) {
+                hosts.push_back(h);
+            }
+        }
+    }
+
     return (hosts);
 }
 
index 8ba8405a7259b5e91af8778343310d0351beeb0f..6bca9f27d1002b1aa96ee6c1dff4e08721a01b7f 100644 (file)
@@ -218,6 +218,16 @@ public:
     getAll6(const SubnetID& subnet_id,
             const asiolink::IOAddress& address) const;
 
+    // @brief Returns all hosts having a reservation for a specified
+    // address or delegated prefix (lease).
+    ///
+    /// @param address reserved IPv6 address/prefix.
+    ///
+    /// @return Collection of const @c Host objects.
+    virtual ConstHostCollection
+    getAll6(const asiolink::IOAddress& address) const;
+
+
     /// @brief Adds a new host to the collection.
     ///
     /// @param host Pointer to the new @c Host object being added.