]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1405] separate flags from configuration modes
authorRazvan Becheriu <razvan@isc.org>
Thu, 29 Oct 2020 12:28:12 +0000 (14:28 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 18 Nov 2020 13:55:23 +0000 (15:55 +0200)
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/network.cc
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/parsers/reservation_modes_parser.cc
src/lib/dhcpsrv/tests/network_unittest.cc
src/lib/dhcpsrv/tests/reservation_modes_parser_unittest.cc
src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc

index f3442db9ba2164656a9e0b6bdda047f7b59ea3b0..2d05ce610bf0fa3c61fb375b31e6649b3499b1c3 100644 (file)
@@ -5348,7 +5348,7 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 
     // Subnet 3
     subnet = subnets->selectSubnet(IOAddress("192.0.3.1"));
@@ -5452,7 +5452,7 @@ TEST_F(Dhcp4ParserTest, hostReservationModesPerSubnet) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 
     // Subnet 3
     subnet = subnets->selectSubnet(IOAddress("192.0.3.1"));
@@ -5477,7 +5477,7 @@ TEST_F(Dhcp4ParserTest, hostReservationModesPerSubnet) {
     // Subnet 7
     subnet = subnets->selectSubnet(IOAddress("192.0.7.1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET|Network::HR_GLOBAL,
+    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_GLOBAL,
               subnet->getHostReservationMode());
 }
 
@@ -5540,7 +5540,7 @@ TEST_F(Dhcp4ParserTest, hostReservationGlobal) {
     subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 }
 
 /// The goal of this test is to verify that Host Reservation modes can be
@@ -5602,7 +5602,7 @@ TEST_F(Dhcp4ParserTest, hostReservationModesGlobal) {
     subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 }
 
 /// Check that the decline-probation-period has a default value when not
@@ -6536,7 +6536,7 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) {
     EXPECT_EQ("foo", s->getSname().get());
     EXPECT_EQ("bar", s->getFilename().get());
     EXPECT_TRUE(s->hasRelayAddress(IOAddress("5.6.7.8")));
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, s->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, s->getHostReservationMode());
 
     // For the second subnet, the renew-timer should be 100, because it
     // was specified explicitly. Other parameters a derived
index 9d15975363885ff3df3a7fc451a4204a8713a56a..18e0c681dc9dc1f0cc9a8b13e7b35686b6217c10 100644 (file)
@@ -5720,7 +5720,7 @@ TEST_F(Dhcp6ParserTest, hostReservationPerSubnet) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("2001:db8:2::1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 
     // Subnet 3
     subnet = subnets->selectSubnet(IOAddress("2001:db8:3::1"));
@@ -5827,7 +5827,7 @@ TEST_F(Dhcp6ParserTest, hostReservationModesPerSubnet) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("2001:db8:2::1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 
     // Subnet 3
     subnet = subnets->selectSubnet(IOAddress("2001:db8:3::1"));
@@ -5852,7 +5852,7 @@ TEST_F(Dhcp6ParserTest, hostReservationModesPerSubnet) {
     // Subnet 7
     subnet = subnets->selectSubnet(IOAddress("2001:db8:7::1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET|Network::HR_GLOBAL,
+    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_GLOBAL,
               subnet->getHostReservationMode());
 }
 
@@ -5910,7 +5910,7 @@ TEST_F(Dhcp6ParserTest, hostReservationGlobal) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("2001:db8:2::1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 }
 
 /// The goal of this test is to verify that Host Reservation modes can be
@@ -5967,7 +5967,7 @@ TEST_F(Dhcp6ParserTest, hostReservationModesGlobal) {
     // Subnet 2
     subnet = subnets->selectSubnet(IOAddress("2001:db8:2::1"));
     ASSERT_TRUE(subnet);
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, subnet->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, subnet->getHostReservationMode());
 }
 
 /// The goal of this test is to verify that configuration can include
@@ -6970,7 +6970,7 @@ TEST_F(Dhcp6ParserTest, sharedNetworksDerive) {
     EXPECT_TRUE(iface_id2.equals(s->getInterfaceId()));
     EXPECT_TRUE(s->hasRelayAddress(IOAddress("2222::2")));
     EXPECT_TRUE(s->getRapidCommit());
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, s->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, s->getHostReservationMode());
     EXPECT_TRUE(s->getStoreExtendedInfo());
 
     // Ok, now check the second shared subnet.
index 312fad771002486b2bba44aadf670b97d06b366f..482681d5d92ca3d1473732610ae966a6c1a921c7 100644 (file)
@@ -1074,8 +1074,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
             }
 
             // First check for reservation when it is the choice.
-            if (check_reservation_first && ((hr_mode & Network::HR_IN_SUBNET) &&
-                !(hr_mode & Network::HR_OUT_OF_POOL))) {
+            if (check_reservation_first && ((hr_mode & Network::HR_IN_SUBNET_FLAG) &&
+                !(hr_mode & Network::HR_OUT_OF_POOL_FLAG))) {
                 auto hosts = getIPv6Resrv(subnet->getID(), candidate);
                 if (!hosts.empty()) {
                     // Don't allocate.
@@ -1100,8 +1100,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
                 /// In-pool reservations: Check if this address is reserved for someone
                 /// else. There is no need to check for whom it is reserved, because if
                 /// it has been reserved for us we would have already allocated a lease.
-                if (!check_reservation_first && (hr_mode & Network::HR_IN_SUBNET) &&
-                    !(hr_mode & Network::HR_OUT_OF_POOL)) {
+                if (!check_reservation_first && (hr_mode & Network::HR_IN_SUBNET_FLAG) &&
+                    !(hr_mode & Network::HR_OUT_OF_POOL_FLAG)) {
                     auto hosts = getIPv6Resrv(subnet->getID(), candidate);
                     if (!hosts.empty()) {
                         // Don't allocate.
@@ -1133,8 +1133,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
                 // allocation attempts.
             } else if (existing->expired()) {
                 // Make sure it's not reserved.
-                if (!check_reservation_first && (hr_mode & Network::HR_IN_SUBNET) &&
-                    !(hr_mode & Network::HR_OUT_OF_POOL)) {
+                if (!check_reservation_first && (hr_mode & Network::HR_IN_SUBNET_FLAG) &&
+                    !(hr_mode & Network::HR_OUT_OF_POOL_FLAG)) {
                     auto hosts = getIPv6Resrv(subnet->getID(), candidate);
                     if (!hosts.empty()) {
                         // Don't allocate.
@@ -2954,8 +2954,8 @@ namespace {
 /// @return true if the address is reserved for another client.
 bool
 addressReserved(const IOAddress& address, const AllocEngine::ClientContext4& ctx) {
-    bool in_subnet = (ctx.subnet_->getHostReservationMode() & Network::HR_IN_SUBNET);
-    bool out_of_pool = (ctx.subnet_->getHostReservationMode() & Network::HR_OUT_OF_POOL);
+    bool in_subnet = (ctx.subnet_->getHostReservationMode() & Network::HR_IN_SUBNET_FLAG);
+    bool out_of_pool = (ctx.subnet_->getHostReservationMode() & Network::HR_OUT_OF_POOL_FLAG);
     if (ctx.subnet_ && ((in_subnet && !out_of_pool) ||
         (out_of_pool && (!ctx.subnet_->inPool(Lease::TYPE_V4, address))))) {
         // The global parameter ip-reservations-unique controls whether it is allowed
@@ -3035,8 +3035,8 @@ hasAddressReservation(AllocEngine::ClientContext4& ctx) {
         }
 
         auto host = ctx.hosts_.find(subnet->getID());
-        bool in_subnet = (subnet->getHostReservationMode() & Network::HR_IN_SUBNET);
-        bool out_of_pool = (subnet->getHostReservationMode() & Network::HR_OUT_OF_POOL);
+        bool in_subnet = (subnet->getHostReservationMode() & Network::HR_IN_SUBNET_FLAG);
+        bool out_of_pool = (subnet->getHostReservationMode() & Network::HR_OUT_OF_POOL_FLAG);
         if (host != ctx.hosts_.end()) {
             auto reservation = host->second->getIPv4Reservation();
             if (!reservation.isV4Zero() &&
index 08e65f673af3e0273d59cca57f232ec1989ce245..a0268d75640c9a5de8ad7fe44f466f17468163c3 100644 (file)
@@ -20,9 +20,12 @@ namespace isc {
 namespace dhcp {
 
 const uint8_t Network::HR_DISABLED = 0;
-const uint8_t Network::HR_OUT_OF_POOL = 1 << 0;
-const uint8_t Network::HR_IN_SUBNET = 1 << 1;
-const uint8_t Network::HR_GLOBAL = 1 << 2;
+const uint8_t Network::HR_OUT_OF_POOL_FLAG = 1 << 0;
+const uint8_t Network::HR_IN_SUBNET_FLAG = 1 << 1;
+const uint8_t Network::HR_GLOBAL_FLAG = 1 << 2;
+const uint8_t Network::HR_OUT_OF_POOL = HR_OUT_OF_POOL_FLAG | HR_IN_SUBNET_FLAG;
+const uint8_t Network::HR_IN_SUBNET = HR_IN_SUBNET_FLAG;
+const uint8_t Network::HR_GLOBAL = HR_GLOBAL_FLAG;
 const uint8_t Network::HR_ALL = Network::HR_IN_SUBNET;
 
 void
@@ -111,7 +114,7 @@ Network::hrModeFromString(const std::string& hr_mode_name) {
          (hr_mode_name.compare("off") == 0) )  {
         return (Network::HR_DISABLED);
     } else if (hr_mode_name.compare("out-of-pool") == 0) {
-        return (Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET);
+        return (Network::HR_OUT_OF_POOL);
     } else if (hr_mode_name.compare("global") == 0) {
         return (Network::HR_GLOBAL);
     } else if (hr_mode_name.compare("all") == 0) {
@@ -216,10 +219,10 @@ Network::toElement() const {
         if (hrmode & Network::HR_GLOBAL) {
             hr_global = true;
         }
-        if (hrmode & Network::HR_IN_SUBNET) {
+        if (hrmode & Network::HR_IN_SUBNET_FLAG) {
             hr_in_subnet = true;
         }
-        if (hrmode & Network::HR_OUT_OF_POOL) {
+        if (hrmode & Network::HR_OUT_OF_POOL_FLAG) {
             hr_out_of_pool = true;
         }
         if (hrmode == Network::HR_DISABLED) {
@@ -235,7 +238,6 @@ Network::toElement() const {
             }
             if (hr_out_of_pool) {
                 map->set("reservations-out-of-pool", Element::create(true));
-                map->set("reservations-in-subnet", Element::create(true));
             }
         }
     }
index 4c9e34ed411b3635cc9bc6d294b40bbc126fc827..66aa7b0e7c636c00d1f6cfa0d0fbaf9b56803f05 100644 (file)
@@ -158,19 +158,29 @@ public:
     /// are allowed.
     static const uint8_t HR_DISABLED; // value: 0
 
+    /// The out-of-pool reservations flag.
+    static const uint8_t HR_OUT_OF_POOL_FLAG; // value: 1 << 0
+
+    /// The in-subnet flag.
+    static const uint8_t HR_IN_SUBNET_FLAG; // value: 1 << 1
+
+    /// The global flag.
+    static const uint8_t HR_GLOBAL_FLAG; // value: 1 << 2
+
     /// Only out-of-pool reservations is allowed. This mode allows AllocEngine
     /// to skip reservation checks for dynamically allocated addressed.
-    /// When this is set, HR_IN_SUBNET is always enabled as well as there can
-    /// can be no reservations that are out-of-pool but not in-subnet.
-    static const uint8_t HR_OUT_OF_POOL; // value: 1 << 0
+    /// When this is set, both HR_OUT_OF_POOL_FLAG and HR_IN_SUBNET_FLAG are
+    /// enabled as there can can be no reservations that are out-of-pool but not
+    /// in-subnet.
+    static const uint8_t HR_OUT_OF_POOL; // value: HR_OUT_OF_POOL_FLAG | HR_IN_SUBNET_FLAG
 
     /// The in-subnet mode which also allows in-pool reservations.
     /// This is equivalent to HR_ALL flag.
-    static const uint8_t HR_IN_SUBNET; // value: 1 << 1
+    static const uint8_t HR_IN_SUBNET; // value: HR_IN_SUBNET_FLAG
 
     /// Only global reservations are allowed. This mode instructs AllocEngine
     /// to only look at global reservations.
-    static const uint8_t HR_GLOBAL; // value: 1 << 2
+    static const uint8_t HR_GLOBAL; // value: HR_GLOBAL_FLAG
 
     /// Both out-of-pool and in-pool reservations are allowed. This is the most
     /// flexible mode, where sysadmin have biggest liberty. However, there is a
@@ -469,7 +479,7 @@ public:
                                                         "reservations-out-of-pool");
                 if (!hr_mode_out_of_pool.unspecified()) {
                     if (hr_mode_out_of_pool.get()) {
-                        flags |= Network::HR_IN_SUBNET | Network::HR_OUT_OF_POOL;
+                        flags |= Network::HR_OUT_OF_POOL;
                     }
                     found = true;
                 }
index fecb0757da66dd467193c6366aa1b889f9907227..30c3fb47cfb53f9c0de1d7075be11d81072b0721 100644 (file)
@@ -34,7 +34,7 @@ HostReservationModesParser::parse(const ConstElementPtr& config_elem) {
         if (elem) {
             bool value = elem->boolValue();
             if (value) {
-                flags |= Network::HR_IN_SUBNET | Network::HR_OUT_OF_POOL;
+                flags |= Network::HR_OUT_OF_POOL;
                 force_true = true;
             }
         }
index 8a4d25c56466ed0220de5a1cdc3a44b0b8eae16d..7c88e21145d20b8526ff201403d6c165a0fc91f9 100644 (file)
@@ -150,7 +150,7 @@ public:
 TEST_F(NetworkTest, hrModeFromString) {
     EXPECT_EQ(Network::HR_DISABLED, Network::hrModeFromString("off"));
     EXPECT_EQ(Network::HR_DISABLED, Network::hrModeFromString("disabled"));
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, Network::hrModeFromString("out-of-pool"));
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, Network::hrModeFromString("out-of-pool"));
     EXPECT_EQ(Network::HR_GLOBAL, Network::hrModeFromString("global"));
     EXPECT_EQ(Network::HR_ALL, Network::hrModeFromString("all"));
     EXPECT_THROW(Network::hrModeFromString("bogus"), isc::BadValue);
index 323c3d04de5028ad559c4604613bf37be4431aa0..a956480f67e5cdac64ff6fda4c50f9b8561d8695 100644 (file)
@@ -141,7 +141,7 @@ TEST_F(HostReservationModesParserTest, validContent) {
         "   \"reservations-in-subnet\": true, \n"
         "   \"reservations-out-of-pool\": true \n"
         "} \n",
-        static_cast<uint8_t>(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET)
+        static_cast<uint8_t>(Network::HR_OUT_OF_POOL)
         },
         {
         "reservation modes out-of-pool enabled specifying in-subnet and out-of-pool",
@@ -149,14 +149,14 @@ TEST_F(HostReservationModesParserTest, validContent) {
         "   \"reservations-in-subnet\": true, \n"
         "   \"reservations-out-of-pool\": true \n"
         "} \n",
-        static_cast<uint8_t>(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET)
+        static_cast<uint8_t>(Network::HR_OUT_OF_POOL)
         },
         {
         "reservation modes out-of-pool enabled specifying only out-of-pool",
         "{ \n"
         "   \"reservations-out-of-pool\": true \n"
         "} \n",
-        static_cast<uint8_t>(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET)
+        static_cast<uint8_t>(Network::HR_OUT_OF_POOL)
         },
         {
         "reservation modes global and out-of-pool enabled specifying all parameters",
@@ -165,7 +165,7 @@ TEST_F(HostReservationModesParserTest, validContent) {
         "   \"reservations-in-subnet\": true, \n"
         "   \"reservations-out-of-pool\": true \n"
         "} \n",
-        static_cast<uint8_t>(Network::HR_GLOBAL|Network::HR_IN_SUBNET|Network::HR_OUT_OF_POOL)
+        static_cast<uint8_t>(Network::HR_OUT_OF_POOL|Network::HR_GLOBAL)
         },
         {
         "reservation modes global and out-of-pool enabled specifying global and out-of-pool",
@@ -173,7 +173,7 @@ TEST_F(HostReservationModesParserTest, validContent) {
         "   \"reservations-global\": true, \n"
         "   \"reservations-out-of-pool\": true \n"
         "} \n",
-        static_cast<uint8_t>(Network::HR_GLOBAL|Network::HR_IN_SUBNET|Network::HR_OUT_OF_POOL)
+        static_cast<uint8_t>(Network::HR_OUT_OF_POOL|Network::HR_GLOBAL)
         }
     };
 
index 57fda95588ec145777b31a08c378b1b56e406cd4..ae3c2f66f83fe87579251a6afaf0d68613e79a3e 100644 (file)
@@ -259,7 +259,7 @@ TEST_F(SharedNetwork4ParserTest, parse) {
     EXPECT_EQ("/dev/null", network->getFilename().get());
     EXPECT_EQ("10.0.0.1", network->getSiaddr().get().toText());
     EXPECT_EQ("example.org", network->getSname().get());
-    EXPECT_EQ(Network::HR_OUT_OF_POOL|Network::HR_IN_SUBNET, network->getHostReservationMode());
+    EXPECT_EQ(Network::HR_OUT_OF_POOL, network->getHostReservationMode());
     EXPECT_TRUE(network->getDdnsSendUpdates().get());
     EXPECT_TRUE(network->getDdnsOverrideNoUpdate().get());
     EXPECT_TRUE(network->getDdnsOverrideClientUpdate().get());