From: Marcin Siodelski Date: Tue, 4 Apr 2023 08:37:01 +0000 (+0200) Subject: [#2823] Add allocators to the MySQL CB X-Git-Tag: Kea-2.3.7~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=271f0eb2786c1fd4d1209785d1071f9da0e8a49b;p=thirdparty%2Fkea.git [#2823] Add allocators to the MySQL CB --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 68e0ae181b..76a7fe48ea 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -356,6 +356,7 @@ public: MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // cache_max_age MySqlBinding::createInteger(), // 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(subnet->getCacheMaxAge(Network::Inheritance::NONE)), - condCreateInteger(subnet->getOfferLft(Network::Inheritance::NONE)) + condCreateInteger(subnet->getOfferLft(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(subnet->getAllocatorType(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); @@ -1360,6 +1367,7 @@ public: MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // cache_max_age MySqlBinding::createInteger(), // 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(shared_network->getCacheMaxAge(Network::Inheritance::NONE)), - condCreateInteger(shared_network->getOfferLft(Network::Inheritance::NONE)) + condCreateInteger(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. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc index 2cfab0a772..dfe19e10d2 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc @@ -388,6 +388,8 @@ public: MySqlBinding::createInteger(), // reservations_out_of_pool MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // 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()); } - // 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(subnet->getCacheMaxAge(Network::Inheritance::NONE)) + condCreateInteger(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(), // reservations_out_of_pool MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // 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()); } - // 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(shared_network->getCacheMaxAge(Network::Inheritance::NONE)) + condCreateInteger(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. diff --git a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h index deb2eb23e5..60b3e80ec2 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -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 \ diff --git a/src/lib/config_backend/constants.h b/src/lib/config_backend/constants.h index ba20b78604..b869a03128 100644 --- a/src/lib/config_backend/constants.h +++ b/src/lib/config_backend/constants.h @@ -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 diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc index 97c69e8b1d..505813d958 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc @@ -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_, diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc index 3fb60436a0..522400920e 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc @@ -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_,