From: Marcin Siodelski Date: Tue, 3 Mar 2020 10:04:01 +0000 (+0100) Subject: [#1139] Added globalHost() convenience method X-Git-Tag: Kea-1.7.6~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5c189505ed5c9b59e0291cb0b3bdf2bc2fcdf2f;p=thirdparty%2Fkea.git [#1139] Added globalHost() convenience method This function was added to the ClientContext4 for the DHCPv4 server to be able to quickly check if there are any global host reservations present and if the reservations contain client classes which could be possibly used for leases allocation. --- diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 352fe8fc41..fca462ec94 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -3075,6 +3075,18 @@ AllocEngine::ClientContext4::currentHost() const { return (ConstHostPtr()); } +ConstHostPtr +AllocEngine::ClientContext4::globalHost() const { + if (subnet_ && subnet_->getHostReservationMode() == Network::HR_GLOBAL) { + auto host = hosts_.find(SUBNET_ID_GLOBAL); + if (host != hosts_.cend()) { + return (host->second); + } + } + + return (ConstHostPtr()); +} + DdnsParamsPtr AllocEngine::ClientContext4::getDdnsParams() { // We already have it, return it. diff --git a/src/lib/dhcpsrv/alloc_engine.h b/src/lib/dhcpsrv/alloc_engine.h index cdce92a2f9..d18d64fcc2 100644 --- a/src/lib/dhcpsrv/alloc_engine.h +++ b/src/lib/dhcpsrv/alloc_engine.h @@ -1409,6 +1409,16 @@ public: /// @return Pointer to the host object. ConstHostPtr currentHost() const; + /// @brief Returns global host reservation if there is one + /// + /// If the current subnet's reservation mode is global and + /// there is a global host (i.e. reservation belonging to + /// the global subnet), return it. Otherwise return an + /// empty pointer. + /// + /// @return Pointer to the host object. + ConstHostPtr globalHost() const; + /// @brief Default constructor. ClientContext4();