]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1405] inherit reservation modes from global level
authorRazvan Becheriu <razvan@isc.org>
Fri, 9 Oct 2020 11:48:31 +0000 (14:48 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 18 Nov 2020 13:55:22 +0000 (15:55 +0200)
src/lib/dhcpsrv/network.h

index 2408ad2b730cf207013a62ca8dd0ae7c9ea1cf02..95cb0465a1b6bde16ecb8f6a30dc0ef9a07f9c7a 100644 (file)
@@ -406,10 +406,11 @@ public:
 
     /// @brief Specifies what type of Host Reservations are supported.
     ///
-    /// Host reservations may be either in-pool (they reserve an address that
-    /// is in the dynamic pool) or out-of-pool (they reserve an address that is
-    /// not in the dynamic pool). HR may also be completely disabled for
-    /// performance reasons.
+    /// Host reservations may be any of the combinations of in-subnet (they
+    /// reserve an address that is in the subnet either in-pool or out-of-pool),
+    /// out-of-pool (they reserve an address that is not in the dynamic pool) or
+    /// global (they are defined at global level). HR may also be completely
+    /// disabled for performance reasons.
     ///
     /// @param inheritance inheritance mode to be used.
     /// @return Host reservation mode enabled.
@@ -443,6 +444,31 @@ public:
                     // method doesn't throw. Let's just return unspecified.
                     return (hr_mode);
                 }
+            } else {
+                // Get global reservation modes and merge the values.
+                bool found = false;
+                uint8_t flags = 0;
+                util::Optional<bool> hr_mode_global;
+                getGlobalProperty(hr_mode_global, "reservation-modes.global");
+                if (!hr_mode_global.unspecified()) {
+                    flags |= Network::HR_GLOBAL;
+                    found = true;
+                }
+                util::Optional<bool> hr_mode_in_subnet;
+                getGlobalProperty(hr_mode_in_subnet, "reservation-modes.in-subnet");
+                if (!hr_mode_in_subnet.unspecified()) {
+                    flags |= Network::HR_IN_SUBNET;
+                    found = true;
+                }
+                util::Optional<bool> hr_mode_out_of_pool;
+                getGlobalProperty(hr_mode_out_of_pool, "reservation-modes.out-of-pool");
+                if (!hr_mode_out_of_pool.unspecified()) {
+                    flags |= Network::HR_OUT_OF_POOL;
+                    found = true;
+                }
+                if (found) {
+                    return (static_cast<Network::HRMode>(flags));
+                }
             }
         }
         return (hr_mode);