diff options
author | Piotrek Zadroga <piotrek@isc.org> | 2023-06-20 10:49:11 +0200 |
---|---|---|
committer | Piotrek Zadroga <piotrek@isc.org> | 2023-06-26 17:30:59 +0200 |
commit | 71929865c3c98f86d0b1b4489eac59562eb2b04f (patch) | |
tree | 50acdb64281c38096eecf1362bb59520ae80dbce /src/lib | |
parent | [#2795] extend impl of MemHostDataSource::getAll4 (diff) | |
download | kea-71929865c3c98f86d0b1b4489eac59562eb2b04f.tar.xz kea-71929865c3c98f86d0b1b4489eac59562eb2b04f.zip |
[#2795] extend impl of BaseHostDataSource::getAll6
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dhcpsrv/base_host_data_source.h | 24 | ||||
-rw-r--r-- | src/lib/dhcpsrv/host_mgr.cc | 7 | ||||
-rw-r--r-- | src/lib/dhcpsrv/host_mgr.h | 5 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/host_cache_unittest.cc | 4 | ||||
-rw-r--r-- | src/lib/dhcpsrv/testutils/memory_host_data_source.cc | 30 | ||||
-rw-r--r-- | src/lib/dhcpsrv/testutils/memory_host_data_source.h | 10 |
6 files changed, 76 insertions, 4 deletions
diff --git a/src/lib/dhcpsrv/base_host_data_source.h b/src/lib/dhcpsrv/base_host_data_source.h index f3013a6591..1ca50900d6 100644 --- a/src/lib/dhcpsrv/base_host_data_source.h +++ b/src/lib/dhcpsrv/base_host_data_source.h @@ -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 diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index a501f2fc86..3771fd392e 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -741,6 +741,11 @@ HostMgr::getAll6(const SubnetID& subnet_id, } 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; if (target & HostMgrOperationTarget::PRIMARY_SOURCE) { @@ -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()); } } diff --git a/src/lib/dhcpsrv/host_mgr.h b/src/lib/dhcpsrv/host_mgr.h index 33c8061192..b4bdd95e67 100644 --- a/src/lib/dhcpsrv/host_mgr.h +++ b/src/lib/dhcpsrv/host_mgr.h @@ -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 diff --git a/src/lib/dhcpsrv/tests/host_cache_unittest.cc b/src/lib/dhcpsrv/tests/host_cache_unittest.cc index 2a210e6b39..fa2e6439b5 100644 --- a/src/lib/dhcpsrv/tests/host_cache_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_cache_unittest.cc @@ -611,6 +611,10 @@ public: return (getCollection()); } + ConstHostCollection getAll6(const IOAddress&) const { + return (getCollection()); + } + ConstHostCollection getAllbyHostname(const std::string&) const { return (getCollection()); } diff --git a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc index 2ba8a3737d..7b6bd22c03 100644 --- a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc +++ b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc @@ -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); } diff --git a/src/lib/dhcpsrv/testutils/memory_host_data_source.h b/src/lib/dhcpsrv/testutils/memory_host_data_source.h index 8ba8405a72..6bca9f27d1 100644 --- a/src/lib/dhcpsrv/testutils/memory_host_data_source.h +++ b/src/lib/dhcpsrv/testutils/memory_host_data_source.h @@ -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. |