From: Piotrek Zadroga Date: Thu, 15 Jun 2023 10:26:04 +0000 (+0200) Subject: [#2795] add getAll6 by ip-address method X-Git-Tag: Kea-2.4.0~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1ca2faffeaeb325d0eb9ee1f91e92d18d5087fc;p=thirdparty%2Fkea.git [#2795] add getAll6 by ip-address method --- 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