diff --git a/doc/sphinx/arm/hooks-lease-cmds.rst b/doc/sphinx/arm/hooks-lease-cmds.rst index 42f429f262..d778adf484 100644 --- a/doc/sphinx/arm/hooks-lease-cmds.rst +++ b/doc/sphinx/arm/hooks-lease-cmds.rst @@ -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 diff --git a/doc/sphinx/arm/hooks-subnet-cmds.rst b/doc/sphinx/arm/hooks-subnet-cmds.rst index b8c7529f2b..db7f42a3a3 100644 --- a/doc/sphinx/arm/hooks-subnet-cmds.rst +++ b/doc/sphinx/arm/hooks-subnet-cmds.rst @@ -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: diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index bd82a10210..a9ce781355 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -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() : "") .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() : ""); - 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() : "") .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() : ""); - LOG_WARN(lease_cmds_logger, LEASE_CMDS_WIPE6_DEPRECATED); return (0); } diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc index 0c03f67c96..862f186499 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.cc @@ -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 }; diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.h b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.h index 50af15b2ea..e5f5baf9e4 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.h +++ b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.h @@ -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 diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes index 20f1704651..ccf760fbf9 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes +++ b/src/hooks/dhcp/lease_cmds/lease_cmds_messages.mes @@ -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. diff --git a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc index 64814bf010..a405da4d00 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc @@ -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); diff --git a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc index cae59227e6..3f5a8bb201 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc @@ -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); diff --git a/src/hooks/dhcp/mysql/mysql_lb_messages.cc b/src/hooks/dhcp/mysql/mysql_lb_messages.cc index bd5bdafa2f..34037eb362 100644 --- a/src/hooks/dhcp/mysql/mysql_lb_messages.cc +++ b/src/hooks/dhcp/mysql/mysql_lb_messages.cc @@ -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 #include @@ -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", diff --git a/src/hooks/dhcp/mysql/mysql_lb_messages.h b/src/hooks/dhcp/mysql/mysql_lb_messages.h index 8b879cc875..2b3e9f86ff 100644 --- a/src/hooks/dhcp/mysql/mysql_lb_messages.h +++ b/src/hooks/dhcp/mysql/mysql_lb_messages.h @@ -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; diff --git a/src/hooks/dhcp/mysql/mysql_lb_messages.mes b/src/hooks/dhcp/mysql/mysql_lb_messages.mes index f6a3873f20..41b8afc13e 100644 --- a/src/hooks/dhcp/mysql/mysql_lb_messages.mes +++ b/src/hooks/dhcp/mysql/mysql_lb_messages.mes @@ -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 diff --git a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc index 186243db21..98e5fb4c11 100644 --- a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc +++ b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc @@ -92,11 +92,15 @@ boost::array 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(subnet_id); + inbind[0].buffer_type = MYSQL_TYPE_LONG; + inbind[0].buffer = reinterpret_cast(&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::wipeLeases6(const SubnetID& /*subnet_id*/) { - isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend"); +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) { + 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. diff --git a/src/hooks/dhcp/mysql/mysql_lease_mgr.h b/src/hooks/dhcp/mysql/mysql_lease_mgr.h index 19f401d457..103767987d 100644 --- a/src/hooks/dhcp/mysql/mysql_lease_mgr.h +++ b/src/hooks/dhcp/mysql/mysql_lease_mgr.h @@ -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 diff --git a/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc b/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc index 24591475f4..2739ef3c35 100644 --- a/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc +++ b/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc @@ -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(); } diff --git a/src/hooks/dhcp/pgsql/pgsql_lb_messages.cc b/src/hooks/dhcp/pgsql/pgsql_lb_messages.cc index 8bcbad8df9..55252d25e2 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lb_messages.cc +++ b/src/hooks/dhcp/pgsql/pgsql_lb_messages.cc @@ -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 #include @@ -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", diff --git a/src/hooks/dhcp/pgsql/pgsql_lb_messages.h b/src/hooks/dhcp/pgsql/pgsql_lb_messages.h index b208c33de9..bf476af3e5 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lb_messages.h +++ b/src/hooks/dhcp/pgsql/pgsql_lb_messages.h @@ -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; diff --git a/src/hooks/dhcp/pgsql/pgsql_lb_messages.mes b/src/hooks/dhcp/pgsql/pgsql_lb_messages.mes index ecacaf3146..3d798d4490 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lb_messages.mes +++ b/src/hooks/dhcp/pgsql/pgsql_lb_messages.mes @@ -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 diff --git a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc index 33eb67ae1e..03f616aa96 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc +++ b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc @@ -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(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::wipeLeases6(const SubnetID& /*subnet_id*/) { - isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend"); +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) { + 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 diff --git a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h index f6dc85febd..e17beaca15 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h +++ b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.h @@ -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 diff --git a/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc b/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc index 801ab2c82d..1a8a24dffe 100644 --- a/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc +++ b/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc @@ -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(); } diff --git a/src/hooks/dhcp/subnet_cmds/subnet_cmds_messages.mes b/src/hooks/dhcp/subnet_cmds/subnet_cmds_messages.mes index 40069cc3bd..894b09487f 100644 --- a/src/hooks/dhcp/subnet_cmds/subnet_cmds_messages.mes +++ b/src/hooks/dhcp/subnet_cmds/subnet_cmds_messages.mes @@ -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. diff --git a/src/share/api/lease4-wipe.json b/src/share/api/lease4-wipe.json index f823c223f4..5ee4fcc10a 100644 --- a/src/share/api/lease4-wipe.json +++ b/src/share/api/lease4-wipe.json @@ -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": [ "{", diff --git a/src/share/api/lease6-wipe.json b/src/share/api/lease6-wipe.json index 3d63134ef8..eb6f55a280 100644 --- a/src/share/api/lease6-wipe.json +++ b/src/share/api/lease6-wipe.json @@ -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."