]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1139] Added globalHost() convenience method
authorMarcin Siodelski <marcin@isc.org>
Tue, 3 Mar 2020 10:04:01 +0000 (11:04 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 19 Mar 2020 12:14:51 +0000 (12:14 +0000)
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.

src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/alloc_engine.h

index 352fe8fc41743447f32822bbd78cae7ee64be385..fca462ec94db7abdec2d6c61115b2463baec7db6 100644 (file)
@@ -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.
index cdce92a2f96e04c1f503263154aa3606b84058fe..d18d64fcc21ae29d61f3490742385d97999b82e7 100644 (file)
@@ -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();