]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2823] Add allocators to the MySQL CB
authorMarcin Siodelski <marcin@isc.org>
Tue, 4 Apr 2023 08:37:01 +0000 (10:37 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 19 Apr 2023 16:26:04 +0000 (18:26 +0200)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc
src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
src/lib/config_backend/constants.h
src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc

index 68e0ae181be6bed7b063f90fed82ea46ff386458..76a7fe48eabbee503c6536754f91e30f128b2c31 100644 (file)
@@ -356,6 +356,7 @@ public:
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
             MySqlBinding::createInteger<uint32_t>(), // offer lifetime
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // allocator
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -619,7 +620,12 @@ public:
                     last_subnet->setOfferLft(offer_lft);
                 }
 
-                // server_tag at 71.
+                // allocator at 71.
+                if (!out_bindings[71]->amNull()) {
+                    last_subnet->setAllocatorType(out_bindings[71]->getString());
+                }
+
+                // server_tag at 72.
 
                 // Subnet ready. Add it to the list.
                 auto ret = subnets.insert(last_subnet);
@@ -633,9 +639,9 @@ public:
             }
 
             // Check for new server tags at 71.
-            if (!out_bindings[71]->amNull() &&
-                (last_tag != out_bindings[71]->getString())) {
-                last_tag = out_bindings[71]->getString();
+            if (!out_bindings[72]->amNull() &&
+                (last_tag != out_bindings[72]->getString())) {
+                last_tag = out_bindings[72]->getString();
                 if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) {
                     last_subnet->setServerTag(last_tag);
                 }
@@ -1110,7 +1116,8 @@ public:
             MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(subnet->getCacheThreshold(Network::Inheritance::NONE)),
             condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE)),
-            condCreateInteger<uint32_t>(subnet->getOfferLft(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(subnet->getOfferLft(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(subnet->getAllocatorType(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -1360,6 +1367,7 @@ public:
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
             MySqlBinding::createInteger<uint32_t>(), // offer lifetime
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // allocator
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -1570,7 +1578,12 @@ public:
                     last_network->setOfferLft(offer_lft);
                 }
 
-                // server_tag at 46.
+                // allocator at 46.
+                if (!out_bindings[46]->amNull()) {
+                    last_network->setAllocatorType(out_bindings[46]->getString());
+                }
+
+                // server_tag at 47.
 
                 // Add the shared network.
                 auto ret = shared_networks.push_back(last_network);
@@ -1584,9 +1597,9 @@ public:
             }
 
             // Check for new server tags.
-            if (!out_bindings[46]->amNull() &&
-                (last_tag != out_bindings[46]->getString())) {
-                last_tag = out_bindings[46]->getString();
+            if (!out_bindings[47]->amNull() &&
+                (last_tag != out_bindings[47]->getString())) {
+                last_tag = out_bindings[47]->getString();
                 if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) {
                     last_network->setServerTag(last_tag);
                 }
@@ -1740,7 +1753,8 @@ public:
             MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(shared_network->getCacheThreshold(Network::Inheritance::NONE)),
             condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE)),
-            condCreateInteger<uint32_t>(shared_network->getOfferLft(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(shared_network->getOfferLft(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(shared_network->getAllocatorType(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -3226,9 +3240,10 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_out_of_pool,"
       "  cache_threshold,"
       "  cache_max_age,"
-      "  offer_lifetime"
+      "  offer_lifetime,"
+      "  allocator"
       ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
-      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the subnet with a server.
     { MySqlConfigBackendDHCPv4Impl::INSERT_SUBNET4_SERVER,
@@ -3274,9 +3289,10 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_out_of_pool,"
       "  cache_threshold,"
       "  cache_max_age,"
-      "  offer_lifetime"
+      "  offer_lifetime,"
+      "  allocator"
       ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
-      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the shared network with a server.
     { MySqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4_SERVER,
@@ -3387,7 +3403,8 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_out_of_pool = ?,"
       "  cache_threshold = ?,"
       "  cache_max_age = ?, "
-      "  offer_lifetime = ? "
+      "  offer_lifetime = ?, "
+      "  allocator = ? "
       "WHERE subnet_id = ? OR subnet_prefix = ?" },
 
     // Update existing shared network.
@@ -3424,7 +3441,8 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_out_of_pool = ?,"
       "  cache_threshold = ?,"
       "  cache_max_age = ?,"
-      "  offer_lifetime = ? "
+      "  offer_lifetime = ?, "
+      "  allocator = ? "
       "WHERE name = ?" },
 
     // Update existing option definition.
index 2cfab0a772fc497b6e83a8860a2b25b34bee0d85..dfe19e10d2e8eea068a0738f541c0073d08d2cc4 100644 (file)
@@ -388,6 +388,8 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // allocator
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // pd_allocator
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -635,7 +637,17 @@ public:
                     last_subnet->setCacheMaxAge(out_bindings[93]->getInteger<uint32_t>());
                 }
 
-                // server_tag (94 / last)
+                // allocator (94)
+                if (!out_bindings[94]->amNull()) {
+                    last_subnet->setAllocatorType(out_bindings[94]->getString());
+                }
+
+                // pd_allocator (95)
+                if (!out_bindings[95]->amNull()) {
+                    last_subnet->setPdAllocatorType(out_bindings[95]->getString());
+                }
+
+                // server_tag (96 / last)
 
                 // Subnet ready. Add it to the list.
                 auto ret = subnets.insert(last_subnet);
@@ -649,9 +661,9 @@ public:
             }
 
             // Check for new server tags.
-            if (!out_bindings[94]->amNull() &&
-                (last_tag != out_bindings[94]->getString())) {
-                last_tag = out_bindings[94]->getString();
+            if (!out_bindings[96]->amNull() &&
+                (last_tag != out_bindings[96]->getString())) {
+                last_tag = out_bindings[96]->getString();
                 if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) {
                     last_subnet->setServerTag(last_tag);
                 }
@@ -1353,7 +1365,9 @@ public:
             MySqlBinding::condCreateBool(subnet->getReservationsInSubnet(Network::Inheritance::NONE)),
             MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(subnet->getCacheThreshold(Network::Inheritance::NONE)),
-            condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(subnet->getAllocatorType(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(subnet->getPdAllocatorType(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -1680,6 +1694,8 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // allocator
+            MySqlBinding::createString(ALLOCATOR_TYPE_BUF_LENGTH), // pd_allocator
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -1885,7 +1901,17 @@ public:
                     last_network->setCacheMaxAge(out_bindings[45]->getInteger<uint32_t>());
                 }
 
-                // server_tag at 46.
+                // allocator at 46.
+                if (!out_bindings[46]->amNull()) {
+                    last_network->setAllocatorType(out_bindings[46]->getString());
+                }
+
+                // pd_allocator at 47.
+                if (!out_bindings[47]->amNull()) {
+                    last_network->setPdAllocatorType(out_bindings[47]->getString());
+                }
+
+                // server_tag at 48.
 
                 // Add the shared network.
                 auto ret = shared_networks.push_back(last_network);
@@ -1899,9 +1925,9 @@ public:
             }
 
             // Check for new server tags.
-            if (!out_bindings[46]->amNull() &&
-                (last_tag != out_bindings[46]->getString())) {
-                last_tag = out_bindings[46]->getString();
+            if (!out_bindings[48]->amNull() &&
+                (last_tag != out_bindings[48]->getString())) {
+                last_tag = out_bindings[48]->getString();
                 if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) {
                     last_network->setServerTag(last_tag);
                 }
@@ -2065,7 +2091,9 @@ public:
             MySqlBinding::condCreateBool(shared_network->getReservationsInSubnet(Network::Inheritance::NONE)),
             MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(shared_network->getCacheThreshold(Network::Inheritance::NONE)),
-            condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(shared_network->getAllocatorType(Network::Inheritance::NONE)),
+            MySqlBinding::condCreateString(shared_network->getPdAllocatorType(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -3651,9 +3679,11 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_in_subnet,"
       "  reservations_out_of_pool,"
       "  cache_threshold,"
-      "  cache_max_age"
+      "  cache_max_age,"
+      "  allocator,"
+      "  pd_allocator"
       ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
-      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the subnet with a server.
     { MySqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER,
@@ -3703,9 +3733,11 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_in_subnet,"
       "  reservations_out_of_pool,"
       "  cache_threshold,"
-      "  cache_max_age"
+      "  cache_max_age,"
+      "  allocator,"
+      "  pd_allocator"
       ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
-      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the shared network with a server.
     { MySqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER,
@@ -3811,7 +3843,9 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_in_subnet = ?,"
       "  reservations_out_of_pool = ?,"
       "  cache_threshold = ?,"
-      "  cache_max_age = ? "
+      "  cache_max_age = ?,"
+      "  allocator = ?,"
+      "  pd_allocator = ? "
       "WHERE subnet_id = ? OR subnet_prefix = ?" },
 
     // Update existing shared network.
@@ -3847,7 +3881,9 @@ TaggedStatementArray tagged_statements = { {
       "  reservations_in_subnet = ?,"
       "  reservations_out_of_pool = ?,"
       "  cache_threshold = ?,"
-      "  cache_max_age = ? "
+      "  cache_max_age = ?,"
+      "  allocator = ?,"
+      "  pd_allocator = ? "
       "WHERE name = ?" },
 
     // Update existing option definition.
index deb2eb23e54737bedfce56081956a9667b7886ac..60b3e80ec2c5b5ff97d4df9e53ec7155ab2f9959 100644 (file)
@@ -121,6 +121,7 @@ namespace {
     "  s.cache_threshold," \
     "  s.cache_max_age," \
     "  s.offer_lifetime, " \
+    "  s.allocator, " \
     "  srv.tag " \
     "FROM dhcp4_subnet AS s " \
     server_join \
@@ -252,6 +253,8 @@ namespace {
     "  s.reservations_out_of_pool," \
     "  s.cache_threshold," \
     "  s.cache_max_age," \
+    "  s.allocator," \
+    "  s.pd_allocator," \
     "  srv.tag " \
     "FROM dhcp6_subnet AS s " \
     server_join \
@@ -465,6 +468,7 @@ namespace {
     "  n.cache_threshold," \
     "  n.cache_max_age," \
     "  n.offer_lifetime, " \
+    "  n.allocator, " \
     "  s.tag " \
     "FROM dhcp4_shared_network AS n " \
     server_join \
@@ -546,6 +550,8 @@ namespace {
     "  n.reservations_out_of_pool," \
     "  n.cache_threshold," \
     "  n.cache_max_age," \
+    "  n.allocator," \
+    "  n.pd_allocator," \
     "  s.tag " \
     "FROM dhcp6_shared_network AS n " \
     server_join \
index ba20b786047ea5db60fe3e22e63ef47b3c9fc2ac..b869a03128fd26ef23deb8f717825379505427f3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,6 +80,8 @@ constexpr unsigned long SERVER_DESCRIPTION_BUF_LENGTH = 65536;
 
 constexpr unsigned long DNS_NAME_BUF_LENGTH = 255;
 
+constexpr unsigned long ALLOCATOR_TYPE_BUF_LENGTH = 64;
+
 //*}
 
 } // end of namespace isc::cb
index 97c69e8b1db268df568491836659f2aff87e25e3..505813d95817c4c34a617f9037c3ee5ecc394add 100644 (file)
@@ -128,6 +128,7 @@ GenericConfigBackendDHCPv4Test::initTestSubnets() {
     subnet->setCacheThreshold(0.25);
     subnet->setCacheMaxAge(20);
     subnet->setOfferLft(77);
+    subnet->setAllocatorType("random");
 
     Pool4Ptr pool1(new Pool4(IOAddress("192.0.2.10"),
                              IOAddress("192.0.2.20")));
@@ -245,6 +246,7 @@ GenericConfigBackendDHCPv4Test::initTestSharedNetworks() {
     shared_network->setCacheThreshold(0.26);
     shared_network->setCacheMaxAge(21);
     shared_network->setOfferLft(78);
+    shared_network->setAllocatorType("iterative");
 
     // Add several options to the shared network.
     shared_network->getCfgOption()->add(test_options_[2]->option_,
index 3fb60436a0b805ac510d48da96560a5c8e000d97..522400920e371112c9da9e31fa29a6f011b07a01 100644 (file)
@@ -122,6 +122,8 @@ GenericConfigBackendDHCPv6Test::initTestSubnets() {
     subnet->setT1Percent(0.345);
     subnet->setT2Percent(0.444);
     subnet->setDdnsSendUpdates(false);
+    subnet->setAllocatorType("random");
+    subnet->setPdAllocatorType("iterative");
 
     Pool6Ptr pool1(new Pool6(Lease::TYPE_NA,
                              IOAddress("2001:db8::10"),
@@ -276,6 +278,8 @@ GenericConfigBackendDHCPv6Test::initTestSharedNetworks() {
     shared_network->setT1Percent(0.345);
     shared_network->setT2Percent(0.444);
     shared_network->setDdnsSendUpdates(false);
+    shared_network->setAllocatorType("iterative");
+    shared_network->setPdAllocatorType("random");
 
     // Add several options to the shared network.
     shared_network->getCfgOption()->add(test_options_[2]->option_,