]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2719] Added CB support for offer-lifetime
authorThomas Markwalder <tmark@isc.org>
Mon, 13 Mar 2023 20:05:12 +0000 (16:05 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 23 Mar 2023 11:18:26 +0000 (07:18 -0400)
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

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/share/database/scripts/pgsql/dhcpdb_create.pgsql

index 596b3884c2d515c87544e04816a75a67e0851b7a..5fa34b403f3b9754edb110342ed43b5878a6117c 100644 (file)
@@ -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
index 456a66b6c8cff871c9fbbfad20c2f7eac1ee653f..410f8f08ae3fa602e0c0d14c0d1f0df973e98bdd 100644 (file)
@@ -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;"
index c596bb7dba917fb084f56f2d87dd600dc88c34f8..315af5261029fa957e65fc8489a5f13c1b9abc99 100644 (file)
@@ -355,6 +355,7 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
+            MySqlBinding::createInteger<uint32_t>(), // offer lifetime
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -612,6 +613,12 @@ public:
                     last_subnet->setCacheMaxAge(out_bindings[69]->getInteger<uint32_t>());
                 }
 
+                // offer lifetime at 70.
+                if (!out_bindings[70]->amNull()) {
+                    Optional<uint32_t> offer_lft(out_bindings[70]->getInteger<uint32_t>());
+                    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<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE)),
+            condCreateInteger<uint32_t>(subnet->getOfferLft(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -1351,6 +1359,7 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
             MySqlBinding::createInteger<float>(), // cache_threshold
             MySqlBinding::createInteger<uint32_t>(), // cache_max_age
+            MySqlBinding::createInteger<uint32_t>(), // offer lifetime
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -1555,7 +1564,13 @@ public:
                     last_network->setCacheMaxAge(out_bindings[44]->getInteger<uint32_t>());
                 }
 
-                // server_tag at 45.
+                // offer lifetime at 45.
+                if (!out_bindings[45]->amNull()) {
+                    Optional<uint32_t> offer_lft(out_bindings[45]->getInteger<uint32_t>());
+                    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<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE))
+            condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE)),
+            condCreateInteger<uint32_t>(shared_network->getOfferLft(Network::Inheritance::NONE))
         };
 
         MySqlTransaction transaction(conn_);
@@ -2378,6 +2394,7 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // depend on known indirectly
             MySqlBinding::createTimestamp(), // modification_ts
             MySqlBinding::createString(USER_CONTEXT_BUF_LENGTH), // user_context
+            MySqlBinding::createInteger<uint32_t>(), // offer lifetime
             MySqlBinding::createInteger<uint64_t>(), // option def: id
             MySqlBinding::createInteger<uint16_t>(), // 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<uint32_t> offer_lft(out_bindings[14]->getInteger<uint32_t>());
+                    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<uint64_t>())) {
-                last_option_def_id = out_bindings[14]->getInteger<uint64_t>();
+            // Parse client class specific option definition from 15 to 24.
+            if (!out_bindings[15]->amNull() &&
+                (last_option_def_id < out_bindings[15]->getInteger<uint64_t>())) {
+                last_option_def_id = out_bindings[15]->getInteger<uint64_t>();
 
-                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<uint64_t>())) {
-                last_option_id = out_bindings[24]->getInteger<uint64_t>();
-
-                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<uint64_t>())) {
+                last_option_id = out_bindings[25]->getInteger<uint64_t>();
+                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.
index 24d4152b7eb5f60291d79bfa7e35763cc1fc8ed4..a50b101ba34ed495f77c08a0d92df143e8b3c5d7 100644 (file)
@@ -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.
index 2f8906239c1322b519a5f1da09ee98553fe9b5c6..8500b483ea8409a77b227170734199c0f9f29eaf 100644 (file)
@@ -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
 
index dfd5b2ae8277e67374539c1c6f9898f5458be0d8..ecf2510cd97161e3b92464c6806aabd5a515588c 100644 (file)
@@ -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("")
index 8d459f197e1367468d12ce32f170428e8510ce2b..c1d918dc280ba1fe5ae6015f964be3770a4c8a5e 100644 (file)
@@ -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
index 25bf9a99b810f01f11204d1c326bc9e22b8d6f64..91d298293adc22b0c55d4ee9e22dab77e4d4d121 100644 (file)
@@ -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);
 }
 
index 990178604646b2946527b0b55861afd3a76c0c61..fc348707eaa1f25538d78d71375112d4df651a2e 100644 (file)
@@ -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<ClientClassDef>("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();
index 910ec2e42c7eceb9145103b385296130df6a1c56..96c86bac618662139107d5c3e2bebbdf2cf05979 100644 (file)
@@ -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.