From: Thomas Markwalder Date: Mon, 13 Mar 2023 20:05:12 +0000 (-0400) Subject: [#2719] Added CB support for offer-lifetime X-Git-Tag: Kea-2.3.6~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=042efe7cda7310e1e554aa3e5c4ee5e4c3f01aed;p=thirdparty%2Fkea.git [#2719] Added CB support for offer-lifetime Added config backend support for offer-lifetime for postgresql and mysql configure.ac src/bin/admin/tests/mysql_tests.sh.in src/bin/admin/tests/pgsql_tests.sh.in src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc src/hooks/dhcp/mysql_cb/mysql_cb_impl.h src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h src/lib/dhcpsrv/client_class_def.cc src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc src/lib/mysql/mysql_constants.h src/lib/pgsql/pgsql_connection.h src/share/database/scripts/mysql/.gitignore src/share/database/scripts/mysql/Makefile.am src/share/database/scripts/mysql/dhcpdb_create.mysql src/share/database/scripts/pgsql/.gitignore src/share/database/scripts/pgsql/Makefile.am src/share/database/scripts/pgsql/dhcpdb_create.pgsql --- diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 596b3884c2..5fa34b403f 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2014-2022 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2014-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 diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 456a66b6c8..410f8f08ae 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2015-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 @@ -761,6 +761,9 @@ pgsql_upgrade_12_to_13_test() { } pgsql_upgrade_13_to_14_test() { + run_command \ + pgsql_execute "$session_sql" + # Added cancelled column to dhcp4_options run_command \ pgsql_execute "select cancelled from dhcp4_options;" diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index c596bb7dba..315af52610 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -355,6 +355,7 @@ public: MySqlBinding::createInteger(), // reservations_out_of_pool MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // cache_max_age + MySqlBinding::createInteger(), // offer lifetime MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -612,6 +613,12 @@ public: last_subnet->setCacheMaxAge(out_bindings[69]->getInteger()); } + // offer lifetime at 70. + if (!out_bindings[70]->amNull()) { + Optional offer_lft(out_bindings[70]->getInteger()); + last_subnet->setOfferLft(offer_lft); + } + // server_tag at 70. // Subnet ready. Add it to the list. @@ -1102,7 +1109,8 @@ 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)), + condCreateInteger(subnet->getOfferLft(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); @@ -1351,6 +1359,7 @@ public: MySqlBinding::createInteger(), // reservations_out_of_pool MySqlBinding::createInteger(), // cache_threshold MySqlBinding::createInteger(), // cache_max_age + MySqlBinding::createInteger(), // offer lifetime MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -1555,7 +1564,13 @@ public: last_network->setCacheMaxAge(out_bindings[44]->getInteger()); } - // server_tag at 45. + // offer lifetime at 45. + if (!out_bindings[45]->amNull()) { + Optional offer_lft(out_bindings[45]->getInteger()); + last_network->setOfferLft(offer_lft); + } + + // server_tag at 46. // Add the shared network. auto ret = shared_networks.push_back(last_network); @@ -1569,9 +1584,9 @@ public: } // Check for new server tags. - if (!out_bindings[45]->amNull() && - (last_tag != out_bindings[45]->getString())) { - last_tag = out_bindings[45]->getString(); + if (!out_bindings[46]->amNull() && + (last_tag != out_bindings[46]->getString())) { + last_tag = out_bindings[46]->getString(); if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) { last_network->setServerTag(last_tag); } @@ -1724,7 +1739,8 @@ 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)), + condCreateInteger(shared_network->getOfferLft(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); @@ -2378,6 +2394,7 @@ public: MySqlBinding::createInteger(), // depend on known indirectly MySqlBinding::createTimestamp(), // modification_ts MySqlBinding::createString(USER_CONTEXT_BUF_LENGTH), // user_context + MySqlBinding::createInteger(), // offer lifetime MySqlBinding::createInteger(), // option def: id MySqlBinding::createInteger(), // option def: code MySqlBinding::createString(OPTION_NAME_BUF_LENGTH), // option def: name @@ -2476,6 +2493,12 @@ public: last_client_class->setContext(user_context); } + // offer lifetime + if (!out_bindings[14]->amNull()) { + Optional offer_lft(out_bindings[14]->getInteger()); + last_client_class->setOfferLft(offer_lft); + } + class_list.push_back(last_client_class); } @@ -2488,23 +2511,22 @@ public: } } - // Parse client class specific option definition from 14 to 23. - if (!out_bindings[14]->amNull() && - (last_option_def_id < out_bindings[14]->getInteger())) { - last_option_def_id = out_bindings[14]->getInteger(); + // Parse client class specific option definition from 15 to 24. + if (!out_bindings[15]->amNull() && + (last_option_def_id < out_bindings[15]->getInteger())) { + last_option_def_id = out_bindings[15]->getInteger(); - auto def = processOptionDefRow(out_bindings.begin() + 14); + auto def = processOptionDefRow(out_bindings.begin() + 15); if (def) { last_client_class->getCfgOptionDef()->add(def); } } - // Parse client class specific option from 24 to 36. - if (!out_bindings[24]->amNull() && - (last_option_id < out_bindings[24]->getInteger())) { - last_option_id = out_bindings[24]->getInteger(); - - OptionDescriptorPtr desc = processOptionRow(Option::V4, out_bindings.begin() + 24); + // Parse client class specific option from 25 to 36. + if (!out_bindings[25]->amNull() && + (last_option_id < out_bindings[25]->getInteger())) { + last_option_id = out_bindings[25]->getInteger(); + OptionDescriptorPtr desc = processOptionRow(Option::V4, out_bindings.begin() + 25); if (desc) { last_client_class->getCfgOption()->add(*desc, desc->space_name_); } @@ -2629,7 +2651,8 @@ public: (follow_class_name.empty() ? MySqlBinding::createNull() : MySqlBinding::createString(follow_class_name)), MySqlBinding::createTimestamp(client_class->getModificationTime()), - createInputContextBinding(client_class) + createInputContextBinding(client_class), + condCreateInteger(client_class->getOfferLft()) }; MySqlTransaction transaction(conn_); @@ -3202,9 +3225,10 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet," " reservations_out_of_pool," " cache_threshold," - " cache_max_age" + " cache_max_age," + " offer_lifetime" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the subnet with a server. { MySqlConfigBackendDHCPv4Impl::INSERT_SUBNET4_SERVER, @@ -3249,9 +3273,10 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet," " reservations_out_of_pool," " cache_threshold," - " cache_max_age" + " cache_max_age," + " offer_lifetime" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the shared network with a server. { MySqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4_SERVER, @@ -3298,8 +3323,9 @@ TaggedStatementArray tagged_statements = { { " depend_on_known_directly," " follow_class_name," " modification_ts," - " user_context " - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + " user_context, " + " offer_lifetime " + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of a client class with a server. @@ -3360,7 +3386,8 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet = ?," " reservations_out_of_pool = ?," " cache_threshold = ?," - " cache_max_age = ? " + " cache_max_age = ?, " + " offer_lifetime = ? " "WHERE subnet_id = ? OR subnet_prefix = ?" }, // Update existing shared network. @@ -3396,7 +3423,8 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet = ?," " reservations_out_of_pool = ?," " cache_threshold = ?," - " cache_max_age = ? " + " cache_max_age = ?," + " offer_lifetime = ? " "WHERE name = ?" }, // Update existing option definition. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 24d4152b7e..a50b101ba3 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -127,7 +127,7 @@ public: if (value.unspecified()) { return (db::MySqlBinding::createNull()); } - return (db::MySqlBinding::createInteger(value)); + return (db::MySqlBinding::createInteger(value.get())); } /// @brief Creates MySQL binding from a @c Triplet. 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 2f8906239c..8500b483ea 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -120,6 +120,7 @@ namespace { " s.reservations_out_of_pool," \ " s.cache_threshold," \ " s.cache_max_age," \ + " s.offer_lifetime, " \ " srv.tag " \ "FROM dhcp4_subnet AS s " \ server_join \ @@ -463,6 +464,7 @@ namespace { " n.reservations_out_of_pool," \ " n.cache_threshold," \ " n.cache_max_age," \ + " n.offer_lifetime, " \ " s.tag " \ "FROM dhcp4_shared_network AS n " \ server_join \ @@ -687,6 +689,7 @@ namespace { " o.depend_on_known_indirectly, " \ " c.modification_ts," \ " c.user_context," \ + " c.offer_lifetime," \ " d.id," \ " d.code," \ " d.name," \ @@ -1028,7 +1031,7 @@ namespace { " d.encapsulate = ?," \ " d.record_types = ?," \ " d.user_context = ? " \ - "WHERE d.class_id = (SELECT id FROM dhcp4_client_class WHERE name = ?) " \ + "WHERE d.class_id = (SELECT id FROM " #table_prefix "_client_class WHERE name = ?) " \ " AND s.tag = ? AND d.code = ? AND d.space = ?" #endif @@ -1091,7 +1094,8 @@ namespace { " depend_on_known_directly = ?," \ follow_class_name_set \ " modification_ts = ?, " \ - " user_context = ? " \ + " user_context = ?," \ + " offer_lifetime = ? "\ "WHERE name = ?" #endif diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc index dfd5b2ae82..ecf2510cd9 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc @@ -501,7 +501,12 @@ public: last_subnet->setCacheMaxAge(worker.getInt(69)); } - // server_tag at 70. + // offer_lifetime at 70. + if (!worker.isColumnNull(70)) { + last_subnet->setOfferLft(worker.getInt(70)); + } + + // server_tag at 71. // Subnet ready. Add it to the list. auto ret = subnets.insert(last_subnet); @@ -930,6 +935,7 @@ public: in_bindings.addOptional(subnet->getReservationsOutOfPool(Network::Inheritance::NONE)); in_bindings.addOptional(subnet->getCacheThreshold(Network::Inheritance::NONE)); in_bindings.addOptional(subnet->getCacheMaxAge(Network::Inheritance::NONE)); + in_bindings.addOptional(subnet->getOfferLft(Network::Inheritance::NONE)); // Start transaction. PgSqlTransaction transaction(conn_); @@ -1329,7 +1335,12 @@ public: last_network->setCacheMaxAge(worker.getInt(44)); } - // server_tag at 45. + // offer_lifetime at 45. + if (!worker.isColumnNull(45)) { + last_network->setOfferLft(worker.getInt(45)); + } + + // server_tag at 46. // Add the shared network. auto ret = shared_networks.push_back(last_network); @@ -1343,8 +1354,8 @@ public: } // Check for new server tags. - if (!worker.isColumnNull(45)) { - std::string new_tag = worker.getString(45); + if (!worker.isColumnNull(46)) { + std::string new_tag = worker.getString(46); if (last_tag != new_tag) { if (!new_tag.empty() && !last_network->hasServerTag(ServerTag(new_tag))) { last_network->setServerTag(new_tag); @@ -1495,6 +1506,7 @@ public: in_bindings.addOptional(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE)); in_bindings.addOptional(shared_network->getCacheThreshold(Network::Inheritance::NONE)); in_bindings.addOptional(shared_network->getCacheMaxAge(Network::Inheritance::NONE)); + in_bindings.addOptional(shared_network->getOfferLft(Network::Inheritance::NONE)); // Start transaction. PgSqlTransaction transaction(conn_); @@ -2271,6 +2283,11 @@ public: } } + // offer_lifetime at 14. + if (!worker.isColumnNull(14)) { + last_client_class->setOfferLft(worker.getInt(14)); + } + class_list.push_back(last_client_class); } @@ -2286,23 +2303,22 @@ public: } } - // Parse client class specific option definition from 14 to 23. - if (!worker.isColumnNull(14) && - (last_option_def_id < worker.getBigInt(14))) { - last_option_def_id = worker.getBigInt(14); + // Parse client class specific option definition from 15 to 24. + if (!worker.isColumnNull(15) && + (last_option_def_id < worker.getBigInt(15))) { + last_option_def_id = worker.getBigInt(15); - auto def = processOptionDefRow(worker, 14); + auto def = processOptionDefRow(worker, 15); if (def) { last_client_class->getCfgOptionDef()->add(def); } } - // Parse client class specific option from 24 to 36. - if (!worker.isColumnNull(24) && - (last_option_id < worker.getBigInt(24))) { - last_option_id = worker.getBigInt(24); - - OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 24); + // Parse client class specific option from 25 to 36. + if (!worker.isColumnNull(25) && + (last_option_id < worker.getBigInt(25))) { + last_option_id = worker.getBigInt(25); + OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 25); if (desc) { last_client_class->getCfgOption()->add(*desc, desc->space_name_); } @@ -2432,6 +2448,7 @@ public: in_bindings.addTimestamp(client_class->getModificationTime()); in_bindings.add(client_class->getContext()); + in_bindings.addOptional(client_class->getOfferLft()); PgSqlTransaction transaction(conn_); @@ -3276,7 +3293,7 @@ TaggedStatementArray tagged_statements = { { // Insert a subnet. { // PgSqlConfigBackendDHCPv4Impl::INSERT_SUBNET4, - 36, + 37, { OID_INT8, // 1 subnet_id, OID_VARCHAR, // 2 subnet_prefix @@ -3313,7 +3330,8 @@ TaggedStatementArray tagged_statements = { { OID_BOOL, // 33 reservations_in_subnet OID_BOOL, // 34 reservations_out_of_pool OID_TEXT, // 35 cache_threshold - cast as float - OID_INT8 // 36 cache_max_age" + OID_INT8, // 36 cache_max_age" + OID_INT8 // 37 offer_lifetime" }, "INSERT_SUBNET4", "INSERT INTO dhcp4_subnet(" @@ -3352,12 +3370,13 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet," " reservations_out_of_pool," " cache_threshold," - " cache_max_age" + " cache_max_age," + " offer_lifetime" ") VALUES (" "$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, " "cast($11 as inet), $12, $13, $14, $15, $16, $17, $18, cast($19 as json), $20, " "$21, $22, $23, cast($24 as float), cast($25 as float), $26, $27, $28, $29, $30, " - "$31, $32, $33, $34, cast($35 as float), $36" + "$31, $32, $33, $34, cast($35 as float), $36, $37" ")" }, @@ -3394,7 +3413,7 @@ TaggedStatementArray tagged_statements = { { // Insert a shared network. { // PgSqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4, - 31, + 32, { OID_VARCHAR, // 1 name, OID_VARCHAR, // 2 client_class, @@ -3426,7 +3445,8 @@ TaggedStatementArray tagged_statements = { { OID_BOOL, // 28 reservations_in_subnet, OID_BOOL, // 29 reservations_out_of_pool, OID_TEXT, // 30 cache_threshold - cast as float - OID_INT8 // 31 cache_max_age + OID_INT8, // 31 cache_max_age + OID_INT8 // 32 offer_lifetime }, "INSERT_SHARED_NETWORK4", "INSERT INTO dhcp4_shared_network(" @@ -3460,12 +3480,13 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet," " reservations_out_of_pool," " cache_threshold," - " cache_max_age" + " cache_max_age," + " offer_lifetime" ") VALUES (" "$1, $2, $3, $4, $5, $6, $7, $8, $9, $10," "cast($11 as json), $12, $13, $14, $15, " "cast($16 as float), cast($17 as float), $18, $19, cast($20 as inet), " - "$21, $22, $23, $24, $25, $26, $27, $28, $29, cast($30 as float), $31" + "$21, $22, $23, $24, $25, $26, $27, $28, $29, cast($30 as float), $31, $32" ")" }, @@ -3574,7 +3595,7 @@ TaggedStatementArray tagged_statements = { { // Insert client class. { // PgSqlConfigBackendDHCPv4Impl::INSERT_CLIENT_CLASS4, - 13, + 14, { OID_VARCHAR, // 1 name OID_TEXT, // 2 test @@ -3588,7 +3609,8 @@ TaggedStatementArray tagged_statements = { { OID_BOOL, // 10 depend_on_known_directly OID_VARCHAR, // 11 follow_class_name OID_TIMESTAMP, // 12 modification_ts - OID_TEXT // 13 user_context cast as JSON + OID_TEXT, // 13 user_context cast as JSON + OID_INT8 // 14 offer_lifetime }, "INSERT_CLIENT_CLASS4", "INSERT INTO dhcp4_client_class(" @@ -3604,9 +3626,10 @@ TaggedStatementArray tagged_statements = { { " depend_on_known_directly," " follow_class_name," " modification_ts, " - " user_context " + " user_context, " + " offer_lifetime " ") VALUES (" - "$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)" + "$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON), $14" ")" }, @@ -3667,7 +3690,7 @@ TaggedStatementArray tagged_statements = { { // Update existing subnet. { // PgSqlConfigBackendDHCPv4Impl::UPDATE_SUBNET4, - 38, + 39, { OID_INT8, // 1 subnet_id, OID_VARCHAR, // 2 subnet_prefix @@ -3705,8 +3728,9 @@ TaggedStatementArray tagged_statements = { { OID_BOOL, // 34 reservations_out_of_pool OID_TEXT, // 35 cache_threshold - cast as float OID_INT8, // 36 cache_max_age" - OID_INT8, // 37 subnet_id (of subnet to update) - OID_VARCHAR // 38 subnet_prefix (of subnet to update) + OID_INT8, // 37 offer_lifetime" + OID_INT8, // 38 subnet_id (of subnet to update) + OID_VARCHAR // 39 subnet_prefix (of subnet to update) }, "UPDATE_SUBNET4,", "UPDATE dhcp4_subnet SET" @@ -3745,14 +3769,15 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet = $33," " reservations_out_of_pool = $34," " cache_threshold = cast($35 as float)," - " cache_max_age = $36 " - "WHERE subnet_id = $37 OR subnet_prefix = $38" + " cache_max_age = $36," + " offer_lifetime = $37 " + "WHERE subnet_id = $38 OR subnet_prefix = $39" }, // Update existing shared network. { // PgSqlConfigBackendDHCPv4Impl::UPDATE_SHARED_NETWORK4, - 32, + 33, { OID_VARCHAR, // 1 name, OID_VARCHAR, // 2 client_class, @@ -3785,7 +3810,8 @@ TaggedStatementArray tagged_statements = { { OID_BOOL, // 29 reservations_out_of_pool, OID_TEXT, // 30 cache_threshold - cast as float OID_INT8, // 31 cache_max_age - OID_VARCHAR // 32 name (of network to update) + OID_INT8, // 32 offer_lifetime + OID_VARCHAR // 33 name (of network to update) }, "UPDATE_SHARED_NETWORK4", "UPDATE dhcp4_shared_network SET" @@ -3819,8 +3845,9 @@ TaggedStatementArray tagged_statements = { { " reservations_in_subnet = $28," " reservations_out_of_pool = $29," " cache_threshold = cast($30 as float)," - " cache_max_age = $31 " - "WHERE name = $32" + " cache_max_age = $31," + " offer_lifetime = $32 " + "WHERE name = $33" }, // Update existing option definition. @@ -4002,7 +4029,7 @@ TaggedStatementArray tagged_statements = { { // Update existing client class with specifying its position. { // PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4, - 14, + 15, { OID_VARCHAR, // 1 name OID_TEXT, // 2 test @@ -4017,7 +4044,8 @@ TaggedStatementArray tagged_statements = { { OID_VARCHAR, // 11 follow_class_name OID_TIMESTAMP, // 12 modification_ts OID_TEXT, // 13 user_context cast as JSON - OID_VARCHAR // 14 name (of class to update) + OID_INT8, // 14 offer_lifetime + OID_VARCHAR // 15 name (of class to update) }, "UPDATE_CLIENT_CLASS4", PGSQL_UPDATE_CLIENT_CLASS4("follow_class_name = $11,") @@ -4026,7 +4054,7 @@ TaggedStatementArray tagged_statements = { { // Update existing client class without specifying its position. { // PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4_SAME_POSITION, - 14, + 15, { OID_VARCHAR, // 1 name OID_TEXT, // 2 test @@ -4041,7 +4069,8 @@ TaggedStatementArray tagged_statements = { { OID_VARCHAR, // 11 follow_class_name OID_TIMESTAMP, // 12 modification_ts OID_TEXT, // 13 user_context cast as JSON - OID_VARCHAR // 14 name (of class to update) + OID_INT8, // 14 offer_lifetime + OID_VARCHAR // 15 name (of class to update) }, "UPDATE_CLIENT_CLASS4_SAME_POSITION", PGSQL_UPDATE_CLIENT_CLASS4("") diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h b/src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h index 8d459f197e..c1d918dc28 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h +++ b/src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h @@ -116,6 +116,7 @@ namespace { " s.reservations_out_of_pool," \ " s.cache_threshold," \ " s.cache_max_age," \ + " s.offer_lifetime," \ " srv.tag " \ "FROM dhcp4_subnet AS s " \ server_join \ @@ -459,6 +460,7 @@ namespace { " n.reservations_out_of_pool," \ " n.cache_threshold," \ " n.cache_max_age," \ + " n.offer_lifetime," \ " s.tag " \ "FROM dhcp4_shared_network AS n " \ server_join \ @@ -683,6 +685,7 @@ namespace { " o.depend_on_known_indirectly, " \ " gmt_epoch(c.modification_ts) as modification_ts, " \ " c.user_context," \ + " c.offer_lifetime," \ " d.id," \ " d.code," \ " d.name," \ @@ -1027,7 +1030,7 @@ namespace { " " #table_prefix "_server as s " \ "WHERE d.id = a.option_def_id AND " \ " a.server_id = s.id AND " \ - " d.class_id = (SELECT id FROM dhcp4_client_class WHERE name = $10) " \ + " d.class_id = (SELECT id FROM " #table_prefix "_client_class WHERE name = $10) " \ " AND s.tag = $11 AND d.code = $12 AND d.space = $13" #endif @@ -1105,8 +1108,9 @@ namespace { " depend_on_known_directly = $10," \ follow_class_name_set \ " modification_ts = $12, " \ - " user_context = cast($13 as json)" \ - "WHERE name = $14" + " user_context = cast($13 as json), " \ + " offer_lifetime = $14 " \ + "WHERE name = $15" #endif #ifndef PGSQL_UPDATE_CLIENT_CLASS6 diff --git a/src/lib/dhcpsrv/client_class_def.cc b/src/lib/dhcpsrv/client_class_def.cc index 25bf9a99b8..91d298293a 100644 --- a/src/lib/dhcpsrv/client_class_def.cc +++ b/src/lib/dhcpsrv/client_class_def.cc @@ -50,7 +50,8 @@ ClientClassDef::ClientClassDef(const ClientClassDef& rhs) match_expr_(ExpressionPtr()), test_(rhs.test_), required_(rhs.required_), depend_on_known_(rhs.depend_on_known_), cfg_option_(new CfgOption()), next_server_(rhs.next_server_), sname_(rhs.sname_), - filename_(rhs.filename_), valid_(rhs.valid_), preferred_(rhs.preferred_) { + filename_(rhs.filename_), valid_(rhs.valid_), preferred_(rhs.preferred_), + offer_lft_(rhs.offer_lft_) { if (rhs.match_expr_) { match_expr_.reset(new Expression()); @@ -371,6 +372,7 @@ ClientClassDictionary::addClass(const std::string& name, cclass->setValid(valid); cclass->setPreferred(preferred); cclass->setOfferLft(offer_lft); + std::cout << "OK WE called it!" << std::endl; addClass(cclass); } diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc index 9901786046..fc348707ea 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc @@ -125,6 +125,9 @@ GenericConfigBackendDHCPv4Test::initTestSubnets() { subnet->setT1Percent(0.345); subnet->setT2Percent(0.444); subnet->setDdnsSendUpdates(false); + subnet->setCacheThreshold(0.25); + subnet->setCacheMaxAge(20); + subnet->setOfferLft(77); Pool4Ptr pool1(new Pool4(IOAddress("192.0.2.10"), IOAddress("192.0.2.20"))); @@ -239,6 +242,9 @@ GenericConfigBackendDHCPv4Test::initTestSharedNetworks() { shared_network->setFilename("/dev/null"); shared_network->setAuthoritative(true); shared_network->setDdnsSendUpdates(false); + shared_network->setCacheThreshold(0.26); + shared_network->setCacheMaxAge(21); + shared_network->setOfferLft(78); // Add several options to the shared network. shared_network->getCfgOption()->add(test_options_[2]->option_, @@ -399,6 +405,7 @@ GenericConfigBackendDHCPv4Test::initTestClientClasses() { ElementPtr user_context = Element::createMap(); user_context->set("melon", Element::create("water")); class1->setContext(user_context); + class1->setOfferLft(20); test_client_classes_.push_back(class1); auto class2 = boost::make_shared("bar", match_expr, cfg_option); @@ -3994,6 +4001,7 @@ GenericConfigBackendDHCPv4Test::setAndGetAllClientClasses4Test() { "client class set", ServerSelector::ONE("server1")); } + // Create second class. auto class2 = test_client_classes_[1]; ASSERT_NO_THROW_LOG(cbptr_->createUpdateClientClass4(ServerSelector::ONE("server1"), class2, "")); @@ -4024,9 +4032,11 @@ GenericConfigBackendDHCPv4Test::setAndGetAllClientClasses4Test() { "client class set", ServerSelector::ONE("server1")); } + // Only the first class should be returned for the server selector ALL. auto client_classes = cbptr_->getAllClientClasses4(ServerSelector::ALL()); ASSERT_EQ(1, client_classes.getClasses()->size()); + // All three classes should be returned for the server1. client_classes = cbptr_->getAllClientClasses4(ServerSelector::ONE("server1")); auto classes_list = client_classes.getClasses(); diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql index 910ec2e42c..96c86bac61 100644 --- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql @@ -5624,7 +5624,25 @@ CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts UPDATE schema_version SET version = '13', minor = '0'; --- This line concludes the schema upgrade to version 13. +-- This line concludes the schema upgrade to version 12. + +-- This line starts the schema upgrade to version 14. + +-- Add offer_lifetime column to v4 tables. +ALTER TABLE dhcp4_shared_network + ADD COLUMN offer_lifetime BIGINT DEFAULT NULL; + +ALTER TABLE dhcp4_subnet + ADD COLUMN offer_lifetime BIGINT DEFAULT NULL; + +ALTER TABLE dhcp4_client_class + ADD COLUMN offer_lifetime BIGINT DEFAULT NULL; + +-- Update the schema version number. +UPDATE schema_version + SET version = '14', minor = '0'; + +-- This line concludes the schema upgrade to version 14. -- This line starts the schema upgrade to version 14.