]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3814] implemented lease wipe for db
authorRazvan Becheriu <razvan@isc.org>
Fri, 13 Jun 2025 09:02:43 +0000 (12:02 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 13 Jun 2025 12:27:27 +0000 (12:27 +0000)
23 files changed:
doc/sphinx/arm/hooks-lease-cmds.rst
doc/sphinx/arm/hooks-subnet-cmds.rst
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc
src/hooks/dhcp/lease_cmds/lease_cmds_messages.h
src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc
src/hooks/dhcp/mysql/mysql_lb_messages.cc
src/hooks/dhcp/mysql/mysql_lb_messages.h
src/hooks/dhcp/mysql/mysql_lb_messages.mes
src/hooks/dhcp/mysql/mysql_lease_mgr.cc
src/hooks/dhcp/mysql/mysql_lease_mgr.h
src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
src/hooks/dhcp/pgsql/pgsql_lb_messages.cc
src/hooks/dhcp/pgsql/pgsql_lb_messages.h
src/hooks/dhcp/pgsql/pgsql_lb_messages.mes
src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc
src/hooks/dhcp/pgsql/pgsql_lease_mgr.h
src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc
src/hooks/dhcp/subnet_cmds/subnet_cmds_messages.mes
src/share/api/lease4-wipe.json
src/share/api/lease6-wipe.json

index 42f429f262a68f94654c16288c89e1d44bdd33c5..d778adf484959dbc0fef4beec2ba2e3e5e79223f 100644 (file)
@@ -91,12 +91,10 @@ This library provides the following commands:
 -  :isccmd:`lease6-update` - updates (replaces) an existing IPv6 lease.
 
 -  :isccmd:`lease4-wipe` - removes all leases from a specific IPv4 subnet or
-   from all subnets. This command is deprecated and it will be removed
-   in the future.
+   from all subnets.
 
 -  :isccmd:`lease6-wipe` - removes all leases from a specific IPv6 subnet or
-   from all subnets. This command is deprecated and it will be removed
-   in the future.
+   from all subnets.
 
 -  :isccmd:`lease4-resend-ddns` - resends a request to update DNS entries for
    an existing lease.
@@ -967,11 +965,6 @@ response, modifying it to the required outcome, and then issuing the
 The ``lease4-wipe``, ``lease6-wipe`` Commands
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-.. warning::
-
-   The :isccmd:`lease4-wipe` and :isccmd:`lease6-wipe` commands are deprecated
-   and they will be removed in the future.
-
 :isccmd:`lease4-wipe` and :isccmd:`lease6-wipe` are designed to remove all leases
 associated with a given subnet. This administrative task is expected to
 be used when an existing subnet is being retired. The leases
index b8c7529f2b2c5e9aa778944beb1de5aaf1056632..db7f42a3a3d35ebddf3ee16b93752773d3d59967 100644 (file)
@@ -70,10 +70,10 @@ The following commands are currently supported:
 The ``subnet4-list`` Command
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-This command is used to list all currently configured subnets. Each
-subnet is returned with a subnet identifier and
-subnet prefix. To retrieve
-detailed information about the subnet, use the :isccmd:`subnet4-get` command.
+This command is used to list all currently configured subnets. Each subnet
+is returned with a subnet identifier, subnet prefix and shared network name,
+if available. To retrieve detailed information about the subnet, use the
+:isccmd:`subnet4-get` command.
 
 This command has a simple structure:
 
@@ -115,10 +115,10 @@ error description.
 The ``subnet6-list`` Command
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-This command is used to list all currently configured subnets. Each
-subnet is returned with a subnet identifier and
-subnet prefix. To retrieve
-detailed information about the subnet, use the :isccmd:`subnet6-get` command.
+This command is used to list all currently configured subnets. Each subnet
+is returned with a subnet identifier, subnet prefix and shared network name,
+if available. To retrieve detailed information about the subnet, use the
+:isccmd:`subnet6-get` command.
 
 This command has a simple structure:
 
index bd82a102100ab1689b0e7d77fff0e66aa2c2bee3..a9ce781355b04de1763c1cfc9e367380b2d96321 100644 (file)
@@ -2373,8 +2373,7 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
         }
 
         stringstream tmp;
-        tmp << "Deleted " << num << " IPv4 lease(s) from subnet(s)" << ids.str()
-            << " WARNING: lease4-wipe is deprecated!";
+        tmp << "Deleted " << num << " IPv4 lease(s) from subnet(s)" << ids.str();
         ConstElementPtr response = createAnswer(num ? CONTROL_RESULT_SUCCESS
                                                     : CONTROL_RESULT_EMPTY, tmp.str());
         setResponse(handle, response);
@@ -2382,14 +2381,12 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
         LOG_ERROR(lease_cmds_logger, LEASE_CMDS_WIPE4_FAILED)
             .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
             .arg(ex.what());
-        LOG_WARN(lease_cmds_logger, LEASE_CMDS_WIPE4_DEPRECATED);
         setErrorResponse(handle, ex.what());
         return (1);
     }
 
     LOG_INFO(lease_cmds_logger, LEASE_CMDS_WIPE4)
         .arg(cmd_args_ ? cmd_args_->str() : "<no args>");
-    LOG_WARN(lease_cmds_logger, LEASE_CMDS_WIPE4_DEPRECATED);
     return (0);
 }
 
@@ -2529,8 +2526,7 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
         }
 
         stringstream tmp;
-        tmp << "Deleted " << num << " IPv6 lease(s) from subnet(s)" << ids.str()
-            << " WARNING: lease6-wipe is deprecated!";
+        tmp << "Deleted " << num << " IPv6 lease(s) from subnet(s)" << ids.str();
         ConstElementPtr response = createAnswer(num ? CONTROL_RESULT_SUCCESS
                                                     : CONTROL_RESULT_EMPTY, tmp.str());
         setResponse(handle, response);
@@ -2538,14 +2534,12 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
         LOG_ERROR(lease_cmds_logger, LEASE_CMDS_WIPE6_FAILED)
             .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
             .arg(ex.what());
-        LOG_WARN(lease_cmds_logger, LEASE_CMDS_WIPE6_DEPRECATED);
         setErrorResponse(handle, ex.what());
         return (1);
     }
 
     LOG_INFO(lease_cmds_logger, LEASE_CMDS_WIPE6)
         .arg(cmd_args_ ? cmd_args_->str() : "<no args>");
-    LOG_WARN(lease_cmds_logger, LEASE_CMDS_WIPE6_DEPRECATED);
     return (0);
 }
 
index 0c03f67c9628259a50c1fe0554fd5921bbe58dc3..862f186499093f0e74899d84edbe6730b7e4f889 100644 (file)
@@ -37,10 +37,8 @@ extern const isc::log::MessageID LEASE_CMDS_UPDATE6 = "LEASE_CMDS_UPDATE6";
 extern const isc::log::MessageID LEASE_CMDS_UPDATE6_CONFLICT = "LEASE_CMDS_UPDATE6_CONFLICT";
 extern const isc::log::MessageID LEASE_CMDS_UPDATE6_FAILED = "LEASE_CMDS_UPDATE6_FAILED";
 extern const isc::log::MessageID LEASE_CMDS_WIPE4 = "LEASE_CMDS_WIPE4";
-extern const isc::log::MessageID LEASE_CMDS_WIPE4_DEPRECATED = "LEASE_CMDS_WIPE4_DEPRECATED";
 extern const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED = "LEASE_CMDS_WIPE4_FAILED";
 extern const isc::log::MessageID LEASE_CMDS_WIPE6 = "LEASE_CMDS_WIPE6";
-extern const isc::log::MessageID LEASE_CMDS_WIPE6_DEPRECATED = "LEASE_CMDS_WIPE6_DEPRECATED";
 extern const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED = "LEASE_CMDS_WIPE6_FAILED";
 
 namespace {
@@ -79,10 +77,8 @@ const char* values[] = {
     "LEASE_CMDS_UPDATE6_CONFLICT", "lease6-update command failed due to conflict (parameters: %1, reason: %2)",
     "LEASE_CMDS_UPDATE6_FAILED", "lease6-add command failed (parameters: %1, reason: %2)",
     "LEASE_CMDS_WIPE4", "lease4-wipe command successful (parameters: %1)",
-    "LEASE_CMDS_WIPE4_DEPRECATED", "lease4-wipe command is deprecated and it will be removed in the future.",
     "LEASE_CMDS_WIPE4_FAILED", "lease4-wipe command failed (parameters: %1, reason: %2)",
     "LEASE_CMDS_WIPE6", "lease6-wipe command successful (parameters: %1)",
-    "LEASE_CMDS_WIPE6_DEPRECATED", "lease6-wipe command is deprecated and it will be removed in the future.",
     "LEASE_CMDS_WIPE6_FAILED", "lease6-wipe command failed (parameters: %1, reason: %2)",
     NULL
 };
index 50af15b2ea0dfb379e936173513ca36da7a75f0a..e5f5baf9e42f6aa63c15d42e27cef99c0d3db7b4 100644 (file)
@@ -38,10 +38,8 @@ extern const isc::log::MessageID LEASE_CMDS_UPDATE6;
 extern const isc::log::MessageID LEASE_CMDS_UPDATE6_CONFLICT;
 extern const isc::log::MessageID LEASE_CMDS_UPDATE6_FAILED;
 extern const isc::log::MessageID LEASE_CMDS_WIPE4;
-extern const isc::log::MessageID LEASE_CMDS_WIPE4_DEPRECATED;
 extern const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED;
 extern const isc::log::MessageID LEASE_CMDS_WIPE6;
-extern const isc::log::MessageID LEASE_CMDS_WIPE6_DEPRECATED;
 extern const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED;
 
 #endif // LEASE_CMDS_MESSAGES_H
index 20f1704651b8f05a74aa86a15896ebdd9aa87610..ccf760fbf9e54bee97076dd3d7da1629bc67d744 100644 (file)
@@ -155,9 +155,6 @@ parameters passed are logged.
 The lease4-wipe command has been successful. Parameters of the command
 are logged.
 
-% LEASE_CMDS_WIPE4_DEPRECATED lease4-wipe command is deprecated and it will be removed in the future.
-The lease4-wipe command is deprecated and it will be removed in the future.
-
 % LEASE_CMDS_WIPE4_FAILED lease4-wipe command failed (parameters: %1, reason: %2)
 The lease4-wipe command has failed. Both the reason as well as the
 parameters passed are logged.
@@ -166,9 +163,6 @@ parameters passed are logged.
 The lease6-wipe command has been successful. Parameters of the command
 are logged.
 
-% LEASE_CMDS_WIPE6_DEPRECATED lease6-wipe command is deprecated and it will be removed in the future.
-The lease6-wipe command is deprecated and it will be removed in the future.
-
 % LEASE_CMDS_WIPE6_FAILED lease6-wipe command failed (parameters: %1, reason: %2)
 The lease6-wipe command has failed. Both the reason as well as the
 parameters passed are logged.
index 64814bf01041c119113ba7372a2a2ab82924a2e0..a405da4d008045d967dd6b3e29d927e439af59f6 100644 (file)
@@ -2859,8 +2859,7 @@ void Lease4CmdsTest::testLease4Wipe() {
         "        \"subnet-id\": 44"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 2 IPv4 lease(s) from subnet(s) 44"
-                     " WARNING: lease4-wipe is deprecated!";
+    string exp_rsp = "Deleted 2 IPv4 lease(s) from subnet(s) 44";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -2894,8 +2893,7 @@ void Lease4CmdsTest::testLease4WipeAll() {
         "        \"subnet-id\": 0"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88"
-                     " WARNING: lease4-wipe is deprecated!";
+    string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -2926,8 +2924,7 @@ void Lease4CmdsTest::testLease4WipeAllNoArgs() {
         "{\n"
         "    \"command\": \"lease4-wipe\"\n"
         "}";
-    string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88"
-                     " WARNING: lease4-wipe is deprecated!";
+    string exp_rsp = "Deleted 4 IPv4 lease(s) from subnet(s) 44 88";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -2961,8 +2958,7 @@ void Lease4CmdsTest::testLease4WipeNoLeases() {
         "        \"subnet-id\": 44"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 0 IPv4 lease(s) from subnet(s) 44"
-                     " WARNING: lease4-wipe is deprecated!";
+    string exp_rsp = "Deleted 0 IPv4 lease(s) from subnet(s) 44";
     testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
 
     checkLease4Stats(44, 0, 0);
@@ -2986,8 +2982,7 @@ void Lease4CmdsTest::testLease4WipeNoLeasesAll() {
         "        \"subnet-id\": 0"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 0 IPv4 lease(s) from subnet(s) 44 88"
-                     " WARNING: lease4-wipe is deprecated!";
+    string exp_rsp = "Deleted 0 IPv4 lease(s) from subnet(s) 44 88";
     testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
 
     checkLease4Stats(44, 0, 0);
index cae59227e63e64e97eac9d88499b6351ab2fface..3f5a8bb2016ce878d2daedac7b0ddbb114d48c11 100644 (file)
@@ -3249,8 +3249,7 @@ void Lease6CmdsTest::testLease6Wipe() {
         "        \"subnet-id\": 66\n"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 2 IPv6 lease(s) from subnet(s) 66"
-                     " WARNING: lease6-wipe is deprecated!";
+    string exp_rsp = "Deleted 2 IPv6 lease(s) from subnet(s) 66";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -3284,8 +3283,7 @@ void Lease6CmdsTest::testLease6WipeAll() {
         "        \"subnet-id\": 0\n"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 4 IPv6 lease(s) from subnet(s) 66 99"
-                     " WARNING: lease6-wipe is deprecated!";
+    string exp_rsp = "Deleted 4 IPv6 lease(s) from subnet(s) 66 99";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -3316,8 +3314,7 @@ void Lease6CmdsTest::testLease6WipeAllNoArgs() {
         "{\n"
         "    \"command\": \"lease6-wipe\"\n"
         "}";
-    string exp_rsp = "Deleted 4 IPv6 lease(s) from subnet(s) 66 99"
-                     " WARNING: lease6-wipe is deprecated!";
+    string exp_rsp = "Deleted 4 IPv6 lease(s) from subnet(s) 66 99";
 
     // The status expected is success. The lease should be deleted.
     testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
@@ -3351,8 +3348,7 @@ void Lease6CmdsTest::testLease6WipeNoLeases() {
         "        \"subnet-id\": 66"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 0 IPv6 lease(s) from subnet(s) 66"
-                     " WARNING: lease6-wipe is deprecated!";
+    string exp_rsp = "Deleted 0 IPv6 lease(s) from subnet(s) 66";
     testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
 
     checkLease6Stats(66, 0, 0, 0, 0);
@@ -3376,8 +3372,7 @@ void Lease6CmdsTest::testLease6WipeNoLeasesAll() {
         "        \"subnet-id\": 0"
         "    }\n"
         "}";
-    string exp_rsp = "Deleted 0 IPv6 lease(s) from subnet(s) 66 99"
-                     " WARNING: lease6-wipe is deprecated!";
+    string exp_rsp = "Deleted 0 IPv6 lease(s) from subnet(s) 66 99";
     testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
 
     checkLease6Stats(66, 0, 0, 0, 0);
index bd5bdafa2f979c91475bb738b8328a2e59f34fff..34037eb3621725161f3acec28d8791231580c8c6 100644 (file)
@@ -1,4 +1,4 @@
-// File created from src/hooks/dhcp/mysql/mysql_lb_messages.mes
+// File created from ../src/hooks/dhcp/mysql/mysql_lb_messages.mes
 
 #include <cstddef>
 #include <log/message_types.h>
@@ -17,6 +17,8 @@ extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_ATTEMPT_FAILED = "MYSQL_L
 extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE = "MYSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE";
 extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_FAILED = "MYSQL_LB_DB_RECONNECT_FAILED";
 extern const isc::log::MessageID MYSQL_LB_DELETED_EXPIRED_RECLAIMED = "MYSQL_LB_DELETED_EXPIRED_RECLAIMED";
+extern const isc::log::MessageID MYSQL_LB_DELETED_SUBNET4_ID = "MYSQL_LB_DELETED_SUBNET4_ID";
+extern const isc::log::MessageID MYSQL_LB_DELETED_SUBNET6_ID = "MYSQL_LB_DELETED_SUBNET6_ID";
 extern const isc::log::MessageID MYSQL_LB_DELETE_ADDR4 = "MYSQL_LB_DELETE_ADDR4";
 extern const isc::log::MessageID MYSQL_LB_DELETE_ADDR6 = "MYSQL_LB_DELETE_ADDR6";
 extern const isc::log::MessageID MYSQL_LB_DELETE_EXPIRED_RECLAIMED4 = "MYSQL_LB_DELETE_EXPIRED_RECLAIMED4";
@@ -75,6 +77,8 @@ const char* values[] = {
     "MYSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE", "scheduling attempt %1 of %2 in %3 milliseconds",
     "MYSQL_LB_DB_RECONNECT_FAILED", "maximum number of database reconnect attempts: %1, has been exhausted without success",
     "MYSQL_LB_DELETED_EXPIRED_RECLAIMED", "deleted %1 reclaimed leases from the database",
+    "MYSQL_LB_DELETED_SUBNET4_ID", "deleted %1 leases that match Subnet ID %2.",
+    "MYSQL_LB_DELETED_SUBNET6_ID", "deleted %1 leases that match Subnet ID %2.",
     "MYSQL_LB_DELETE_ADDR4", "deleting lease for address %1",
     "MYSQL_LB_DELETE_ADDR6", "deleting lease for address %1",
     "MYSQL_LB_DELETE_EXPIRED_RECLAIMED4", "deleting reclaimed IPv4 leases that expired more than %1 seconds ago",
index 8b879cc8756879e04461ceee958092f84d2393c0..2b3e9f86ffdf60f7e9164cf5acfb9206b4dd3ca2 100644 (file)
@@ -1,4 +1,4 @@
-// File created from src/hooks/dhcp/mysql/mysql_lb_messages.mes
+// File created from ../src/hooks/dhcp/mysql/mysql_lb_messages.mes
 
 #ifndef MYSQL_LB_MESSAGES_H
 #define MYSQL_LB_MESSAGES_H
@@ -18,6 +18,8 @@ extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_ATTEMPT_FAILED;
 extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE;
 extern const isc::log::MessageID MYSQL_LB_DB_RECONNECT_FAILED;
 extern const isc::log::MessageID MYSQL_LB_DELETED_EXPIRED_RECLAIMED;
+extern const isc::log::MessageID MYSQL_LB_DELETED_SUBNET4_ID;
+extern const isc::log::MessageID MYSQL_LB_DELETED_SUBNET6_ID;
 extern const isc::log::MessageID MYSQL_LB_DELETE_ADDR4;
 extern const isc::log::MessageID MYSQL_LB_DELETE_ADDR6;
 extern const isc::log::MessageID MYSQL_LB_DELETE_EXPIRED_RECLAIMED4;
index f6a3873f20d0bb32facdba83575e51ec6800d6b1..41b8afc13e3f739d31ef0bed281f4e725461e905 100644 (file)
@@ -78,6 +78,16 @@ leases which have expired longer than a specified period of time.
 The argument is the amount of time Kea waits after a reclaimed
 lease expires before considering its removal.
 
+% MYSQL_LB_DELETED_SUBNET4_ID deleted %1 leases that match Subnet ID %2.
+Logged at debug log level 50.
+A debug message issued when the server is removing leases which match
+respective Subnet ID.
+
+% MYSQL_LB_DELETED_SUBNET6_ID deleted %1 leases that match Subnet ID %2.
+Logged at debug log level 50.
+A debug message issued when the server is removing leases which match
+respective Subnet ID.
+
 % MYSQL_LB_GET4 obtaining all IPv4 leases
 Logged at debug log level 50.
 A debug message issued when the server is attempting to obtain all IPv4
index 186243db21094dc8685300ff7e8c26cc34fdcee1..98e5fb4c11d4991ac71a07155e035b3f02635d94 100644 (file)
@@ -92,11 +92,15 @@ boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
 tagged_statements = { {
     {MySqlLeaseMgr::DELETE_LEASE4,
                     "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
+    {MySqlLeaseMgr::DELETE_LEASE4_SUBID,
+                    "DELETE FROM lease4 WHERE subnet_id = ?"},
     {MySqlLeaseMgr::DELETE_LEASE4_STATE_EXPIRED,
                     "DELETE FROM lease4 "
                         "WHERE state = ? AND expire < ?"},
     {MySqlLeaseMgr::DELETE_LEASE6,
                     "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
+    {MySqlLeaseMgr::DELETE_LEASE6_SUBID,
+                    "DELETE FROM lease6 WHERE subnet_id = ?"},
     {MySqlLeaseMgr::DELETE_LEASE6_STATE_EXPIRED,
                     "DELETE FROM lease6 "
                         "WHERE state = ? AND expire < ?"},
@@ -3828,13 +3832,39 @@ MySqlLeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_id,
 }
 
 size_t
-MySqlLeaseMgr::wipeLeases4(const SubnetID& /*subnet_id*/) {
-    isc_throw(NotImplemented, "wipeLeases4 is not implemented for MySQL backend");
+MySqlLeaseMgr::wipeLeasesCommon(const SubnetID& subnet_id, StatementIndex statement_index) {
+    // Set up the WHERE clause value
+    MYSQL_BIND inbind[1];
+    memset(inbind, 0, sizeof(inbind));
+
+    // Subnet ID.
+    uint32_t subnet = static_cast<uint32_t>(subnet_id);
+    inbind[0].buffer_type = MYSQL_TYPE_LONG;
+    inbind[0].buffer = reinterpret_cast<char*>(&subnet);
+    inbind[0].is_unsigned = MLM_TRUE;
+
+    // Get a context
+    MySqlLeaseContextAlloc get_context(*this);
+    MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Get the number of deleted leases and log it.
+    return (deleteLeaseCommon(ctx, statement_index, inbind));
+}
+
+size_t
+MySqlLeaseMgr::wipeLeases4(const SubnetID& subnet_id) {
+    uint64_t deleted_leases = wipeLeasesCommon(subnet_id, DELETE_LEASE4_SUBID);
+    LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_DELETED_SUBNET4_ID)
+        .arg(deleted_leases).arg(subnet_id);
+    return (deleted_leases);
 }
 
 size_t
-MySqlLeaseMgr::wipeLeases6(const SubnetID& /*subnet_id*/) {
-    isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend");
+MySqlLeaseMgr::wipeLeases6(const SubnetID& subnet_id) {
+    uint64_t deleted_leases = wipeLeasesCommon(subnet_id, DELETE_LEASE6_SUBID);
+    LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_DELETED_SUBNET6_ID)
+        .arg(deleted_leases).arg(subnet_id);;
+    return (deleted_leases);
 }
 
 // Miscellaneous database methods.
index 19f401d457b19e035b3901e3517c3c52513c6e72..103767987dc3343d9157f6a8f5d8e2bc4b2e464c 100644 (file)
@@ -734,8 +734,10 @@ public:
     /// statements
     enum StatementIndex {
         DELETE_LEASE4,               // Delete from lease4 by address
+        DELETE_LEASE4_SUBID,         // Delete from lease4 by subnet ID
         DELETE_LEASE4_STATE_EXPIRED, // Delete expired lease4 in a given state
         DELETE_LEASE6,               // Delete from lease6 by address
+        DELETE_LEASE6_SUBID,         // Delete from lease6 by subnet ID
         DELETE_LEASE6_STATE_EXPIRED, // Delete expired lease6 in a given state
         GET_LEASE4,                  // Get all IPv4 leases
         GET_LEASE4_ADDR,             // Get lease4 by address
@@ -985,6 +987,17 @@ private:
                                StatementIndex stindex,
                                MYSQL_BIND* bind);
 
+    /// @brief Removes all leases matching subnet ID.
+    ///
+    /// This rather dangerous method is able to remove all leases from specified
+    /// subnet.
+    ///
+    /// @param subnet_id identifier of the subnet
+    /// @param statement_index One of the @c DELETE_LEASE4_SUBID or
+    ///        @c DELETE_LEASE6_SUBID.
+    /// @return number of leases removed.
+    virtual size_t wipeLeasesCommon(const SubnetID& subnet_id, StatementIndex statement_index);
+
     /// @brief Delete expired-reclaimed leases.
     ///
     /// @param secs Number of seconds since expiration of leases before
index 24591475f4a80a3df5954047bf20f867f8c43b0d..2739ef3c35431c7782d3529485485fe57050e466 100644 (file)
@@ -952,23 +952,23 @@ TEST_F(MySqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4) {
+TEST_F(MySqlLeaseMgrTest, wipeLeases4) {
     testWipeLeases4();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
+TEST_F(MySqlLeaseMgrTest, wipeLeases4MultiThreading) {
     MultiThreadingTest mt(true);
     testWipeLeases4();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6) {
+TEST_F(MySqlLeaseMgrTest, wipeLeases6) {
     testWipeLeases6();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
+TEST_F(MySqlLeaseMgrTest, wipeLeases6MultiThreading) {
     MultiThreadingTest mt(true);
     testWipeLeases6();
 }
index 8bcbad8df98bdd63d152c94f48820df1ae8547cd..55252d25e251a7760aa5baa18d87ee505b09cc6b 100644 (file)
@@ -1,4 +1,4 @@
-// File created from src/hooks/dhcp/pgsql/pgsql_lb_messages.mes
+// File created from ../src/hooks/dhcp/pgsql/pgsql_lb_messages.mes
 
 #include <cstddef>
 #include <log/message_types.h>
@@ -16,6 +16,8 @@ extern const isc::log::MessageID PGSQL_LB_DB = "PGSQL_LB_DB";
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_ATTEMPT_FAILED = "PGSQL_LB_DB_RECONNECT_ATTEMPT_FAILED";
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE = "PGSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE";
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_FAILED = "PGSQL_LB_DB_RECONNECT_FAILED";
+extern const isc::log::MessageID PGSQL_LB_DELETED_SUBNET4_ID = "PGSQL_LB_DELETED_SUBNET4_ID";
+extern const isc::log::MessageID PGSQL_LB_DELETED_SUBNET6_ID = "PGSQL_LB_DELETED_SUBNET6_ID";
 extern const isc::log::MessageID PGSQL_LB_DELETE_ADDR4 = "PGSQL_LB_DELETE_ADDR4";
 extern const isc::log::MessageID PGSQL_LB_DELETE_ADDR6 = "PGSQL_LB_DELETE_ADDR6";
 extern const isc::log::MessageID PGSQL_LB_DELETE_EXPIRED_RECLAIMED4 = "PGSQL_LB_DELETE_EXPIRED_RECLAIMED4";
@@ -71,6 +73,8 @@ const char* values[] = {
     "PGSQL_LB_DB_RECONNECT_ATTEMPT_FAILED", "database reconnect failed: %1",
     "PGSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE", "scheduling attempt %1 of %2 in %3 milliseconds",
     "PGSQL_LB_DB_RECONNECT_FAILED", "maximum number of database reconnect attempts: %1, has been exhausted without success",
+    "PGSQL_LB_DELETED_SUBNET4_ID", "deleted %1 leases that match Subnet ID %2.",
+    "PGSQL_LB_DELETED_SUBNET6_ID", "deleted %1 leases that match Subnet ID %2.",
     "PGSQL_LB_DELETE_ADDR4", "deleting lease for address %1",
     "PGSQL_LB_DELETE_ADDR6", "deleting lease for address %1",
     "PGSQL_LB_DELETE_EXPIRED_RECLAIMED4", "deleting reclaimed IPv4 leases that expired more than %1 seconds ago",
index b208c33de9fc55f91f7e74baaf038fc998473ab6..bf476af3e51da532f0382bf5cb6179822fc1a429 100644 (file)
@@ -1,4 +1,4 @@
-// File created from src/hooks/dhcp/pgsql/pgsql_lb_messages.mes
+// File created from ../src/hooks/dhcp/pgsql/pgsql_lb_messages.mes
 
 #ifndef PGSQL_LB_MESSAGES_H
 #define PGSQL_LB_MESSAGES_H
@@ -17,6 +17,8 @@ extern const isc::log::MessageID PGSQL_LB_DB;
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_ATTEMPT_FAILED;
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_ATTEMPT_SCHEDULE;
 extern const isc::log::MessageID PGSQL_LB_DB_RECONNECT_FAILED;
+extern const isc::log::MessageID PGSQL_LB_DELETED_SUBNET4_ID;
+extern const isc::log::MessageID PGSQL_LB_DELETED_SUBNET6_ID;
 extern const isc::log::MessageID PGSQL_LB_DELETE_ADDR4;
 extern const isc::log::MessageID PGSQL_LB_DELETE_ADDR6;
 extern const isc::log::MessageID PGSQL_LB_DELETE_EXPIRED_RECLAIMED4;
index ecacaf3146387c4965f3a5e5c0f0b55a301e0a34..3d798d449018d7d6608c68f39cc2e3665761c9fe 100644 (file)
@@ -72,6 +72,16 @@ leases which have expired longer than a specified period of time.
 The argument is the amount of time Kea waits after a reclaimed
 lease expires before considering its removal.
 
+% PGSQL_LB_DELETED_SUBNET4_ID deleted %1 leases that match Subnet ID %2.
+Logged at debug log level 50.
+A debug message issued when the server is removing leases which match
+respective Subnet ID.
+
+% PGSQL_LB_DELETED_SUBNET6_ID deleted %1 leases that match Subnet ID %2.
+Logged at debug log level 50.
+A debug message issued when the server is removing leases which match
+respective Subnet ID.
+
 % PGSQL_LB_GET4 obtaining all IPv4 leases
 Logged at debug log level 50.
 A debug message issued when the server is attempting to obtain all IPv4
index 33eb67ae1e0a7c4d7c6a2db5689bd96ee6b72a76..03f616aa963a3d22b337ddc0adf142350a4f0007 100644 (file)
@@ -48,6 +48,11 @@ PgSqlTaggedStatement tagged_statements[] = {
       "delete_lease4",
       "DELETE FROM lease4 WHERE address = $1 AND expire = $2" },
 
+    // DELETE_LEASE4_SUBID
+    { 1, { OID_INT8 },
+      "delete_lease4_subid",
+      "DELETE FROM lease4 WHERE subnet_id = $1" },
+
     // DELETE_LEASE4_STATE_EXPIRED
     { 2, { OID_INT8, OID_TIMESTAMP },
       "delete_lease4_state_expired",
@@ -57,7 +62,12 @@ PgSqlTaggedStatement tagged_statements[] = {
     // DELETE_LEASE6
     { 2, { OID_VARCHAR, OID_TIMESTAMP },
       "delete_lease6",
-      "DELETE FROM lease6 WHERE address = cast($1 as inet) AND expire = $2"},
+      "DELETE FROM lease6 WHERE address = cast($1 as inet) AND expire = $2" },
+
+    // DELETE_LEASE6_SUBID
+    { 1, { OID_INT8 },
+      "delete_lease6_subid",
+      "DELETE FROM lease6 WHERE subnet_id = $1" },
 
     // DELETE_LEASE6_STATE_EXPIRED
     { 2, { OID_INT8, OID_TIMESTAMP },
@@ -301,7 +311,7 @@ PgSqlTaggedStatement tagged_statements[] = {
         "hwaddr, hwtype, hwaddr_source, "
         "state, user_context, pool_id "
       "FROM lease6 "
-      "ORDER BY address "},
+      "ORDER BY address},
 
     // GET_LEASE6_ADDR
     { 2, { OID_VARCHAR, OID_INT2 },
@@ -312,7 +322,7 @@ PgSqlTaggedStatement tagged_statements[] = {
         "hwaddr, hwtype, hwaddr_source, "
         "state, user_context, pool_id "
       "FROM lease6 "
-      "WHERE address = cast($1 as inet) AND lease_type = $2"},
+      "WHERE address = cast($1 as inet) AND lease_type = $2" },
 
     // GET_LEASE6_DUID_IAID
     { 3, { OID_BYTEA, OID_INT8, OID_INT2 },
@@ -348,7 +358,7 @@ PgSqlTaggedStatement tagged_statements[] = {
       "FROM lease6 "
       "WHERE address > cast($1 as inet) "
       "ORDER BY address "
-      "LIMIT $2"},
+      "LIMIT $2" },
 
     // GET_LEASE6_UCTX_PAGE
     { 2, { OID_VARCHAR, OID_INT8 },
@@ -2977,13 +2987,35 @@ PgSqlLeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_id,
 }
 
 size_t
-PgSqlLeaseMgr::wipeLeases4(const SubnetID& /*subnet_id*/) {
-    isc_throw(NotImplemented, "wipeLeases4 is not implemented for PostgreSQL backend");
+PgSqlLeaseMgr::wipeLeasesCommon(const SubnetID& subnet_id, StatementIndex statement_index) {
+    PsqlBindArray bind_array;
+
+    // Subnet ID.
+    std::string subnet_str = boost::lexical_cast<std::string>(subnet_id);
+    bind_array.add(subnet_str);
+
+    // Get a context
+    PgSqlLeaseContextAlloc get_context(*this);
+    PgSqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Delete leases.
+    return (deleteLeaseCommon(ctx, statement_index, bind_array));
+}
+
+size_t
+PgSqlLeaseMgr::wipeLeases4(const SubnetID& subnet_id) {
+    uint64_t deleted_leases = wipeLeasesCommon(subnet_id, DELETE_LEASE4_SUBID);
+    LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_DELETED_SUBNET4_ID)
+        .arg(deleted_leases).arg(subnet_id);
+    return (deleted_leases);
 }
 
 size_t
-PgSqlLeaseMgr::wipeLeases6(const SubnetID& /*subnet_id*/) {
-    isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend");
+PgSqlLeaseMgr::wipeLeases6(const SubnetID& subnet_id) {
+    uint64_t deleted_leases = wipeLeasesCommon(subnet_id, DELETE_LEASE6_SUBID);
+    LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_DELETED_SUBNET6_ID)
+        .arg(deleted_leases).arg(subnet_id);
+    return (deleted_leases);
 }
 
 std::string
index f6dc85febd0bd4a9f9b46466e87416c0ffe6273d..e17beaca1565780add7d9ad960e5705c2de0f1e3 100644 (file)
@@ -709,8 +709,10 @@ public:
     /// statements
     enum StatementIndex {
         DELETE_LEASE4,               // Delete from lease4 by address
+        DELETE_LEASE4_SUBID,         // Delete from lease4 by subnet ID
         DELETE_LEASE4_STATE_EXPIRED, // Delete expired lease4 in a given state
         DELETE_LEASE6,               // Delete from lease6 by address
+        DELETE_LEASE6_SUBID,         // Delete from lease6 by subnet ID
         DELETE_LEASE6_STATE_EXPIRED, // Delete expired lease6 in a given state
         GET_LEASE4,                  // Get all IPv4 leases
         GET_LEASE4_ADDR,             // Get lease4 by address
@@ -959,6 +961,17 @@ private:
                                StatementIndex stindex,
                                db::PsqlBindArray& bind_array);
 
+    /// @brief Removes all leases matching subnet ID.
+    ///
+    /// This rather dangerous method is able to remove all leases from specified
+    /// subnet.
+    ///
+    /// @param subnet_id identifier of the subnet
+    /// @param statement_index One of the @c DELETE_LEASE4_SUBID or
+    ///        @c DELETE_LEASE6_SUBID.
+    /// @return number of leases removed.
+    virtual size_t wipeLeasesCommon(const SubnetID& subnet_id, StatementIndex statement_index);
+
     /// @brief Delete expired-reclaimed leases.
     ///
     /// @param secs Number of seconds since expiration of leases before
index 801ab2c82d70d86daa3bf40d94d24d37c99d6fdc..1a8a24dffe02046fab10e7609e7b24a4a2436cfb 100644 (file)
@@ -919,23 +919,23 @@ TEST_F(PgSqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases4) {
+TEST_F(PgSqlLeaseMgrTest, wipeLeases4) {
     testWipeLeases4();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
+TEST_F(PgSqlLeaseMgrTest, wipeLeases4MultiThreading) {
     MultiThreadingTest mt(true);
     testWipeLeases4();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases6) {
+TEST_F(PgSqlLeaseMgrTest, wipeLeases6) {
     testWipeLeases6();
 }
 
 /// @brief Tests that leases from specific subnet can be removed.
-TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
+TEST_F(PgSqlLeaseMgrTest, wipeLeases6MultiThreading) {
     MultiThreadingTest mt(true);
     testWipeLeases6();
 }
index 40069cc3bd64963ffeca8612e13881b139e87cc0..894b09487f62af9a0e6b08174f8ea75617d75666 100644 (file)
@@ -225,7 +225,7 @@ but no subnet was found.
 
 % SUBNET_CMDS_SUBNET6_LIST_FAILED failed to return a list of IPv6 subnets: %1
 This error message is issued when the Subnet Commands hooks library fails
-to return a list of IPv4 subnets requested with 'subnet6-list' command. The
+to return a list of IPv6 subnets requested with 'subnet6-list' command. The
 reason for failure is provided within the error message. The error message
 will be returned to the controlling client with the error status code.
 
index f823c223f455647dd0f56acfc3d3ca8f66622501..5ee4fcc10ac7e1c14a4c75a5e3c52a7bf4dd3890 100644 (file)
@@ -2,8 +2,7 @@
     "access": "write",
     "avail": "1.3.0",
     "brief": [
-        "This command removes all leases associated with a given subnet.",
-        "This command is deprecated and it will be removed in the future."
+        "This command removes all leases associated with a given subnet."
     ],
     "cmd-syntax": [
         "{",
index 3d63134ef8df38e6320ad120de4d09f946180404..eb6f55a28071067b5a154a3dc7f63fe17f4b6a23 100644 (file)
@@ -2,8 +2,7 @@
     "access": "write",
     "avail": "1.3.0",
     "brief": [
-        "This command removes all leases associated with a given subnet.",
-        "This command is deprecated and it will be removed in the future."
+        "This command removes all leases associated with a given subnet."
     ],
     "cmd-comment": [
         "Note: not all backends support this command."