From b1ca2faffeaeb325d0eb9ee1f91e92d18d5087fc Mon Sep 17 00:00:00 2001 From: Piotrek Zadroga Date: Thu, 15 Jun 2023 12:26:04 +0200 Subject: [PATCH] [#2795] add getAll6 by ip-address method --- src/lib/dhcpsrv/host_mgr.cc | 18 +++++++++++++++++- src/lib/dhcpsrv/host_mgr.h | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index f5a41f2367..a501f2fc86 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -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 diff --git a/src/lib/dhcpsrv/host_mgr.h b/src/lib/dhcpsrv/host_mgr.h index c129f8f8b4..33c8061192 100644 --- a/src/lib/dhcpsrv/host_mgr.h +++ b/src/lib/dhcpsrv/host_mgr.h @@ -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 -- 2.47.2