2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 14:05:33 +00:00

[#2868] Checkpoint: finished upgradeBinaryAddress6

This commit is contained in:
Francis Dupont
2023-05-24 00:44:11 +02:00
parent 9623ed7694
commit 9d33293c69
12 changed files with 270 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
src/share/api/binary-address6-upgrade.json
src/share/api/build-report.json
src/share/api/cache-clear.json
src/share/api/cache-flush.json

View File

@@ -607,7 +607,7 @@ Updating Existing Leases in SQL Lease Backends
Bulk Lease Query required additions to the lease data stored. With SQL lease
backends, leases created prior to the server being configured for Bulk Lease
Query will not contain the new data required. In order to populate this data
it is necessary to run an API command:
it is necessary to run API commands:
.. _command-extended-info4-upgrade:
@@ -619,9 +619,21 @@ For DHCPv4 lease data, the command is:
"command": "extended-info4-upgrade"
}
.. _command-binary-address6-upgrade:
For DHCPv6 lease data, there are two commands, for upgrading the binary
address used for by link address query the command is:
::
{
"command": "binary-address6-upgrade"
}
.. _command-extended-info6-upgrade:
For DHCPv6 lease data, the command is (TO BE IMPLEMENTED):
for extended info used for by relay id and by remote id the command is
(TO BE IMPLEMENTED):
::
@@ -630,7 +642,7 @@ For DHCPv6 lease data, the command is (TO BE IMPLEMENTED):
}
In either case the response will indicate whether it succeeded or failed
In all cases the response will indicate whether it succeeded or failed
and include either the count of leases updated or the nature of the failure:
::
@@ -641,14 +653,15 @@ and include either the count of leases updated or the nature of the failure:
}
The command's operation is governed by ``extended-info-checks`` parameter
under the sanity-checks element. Please see :ref:`sanity-checks4` or
:ref:`sanity-checks6`.
The operation of extended info command is governed by ``extended-info-checks``
parameter under the sanity-checks element. Please see :ref:`sanity-checks4`
or :ref:`sanity-checks6`.
For large numbers of leases this command may take some time to complete.
.. note::
Existing leases must have been created by Kea with ``store-extended-info``
enabled in order for the new data to be extracted and stored.
enabled in order for the new data from extended info to be extracted
and stored.

View File

@@ -192,6 +192,9 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_START_TRANSACTION = "DHCPSRV_MYSQ
extern const isc::log::MessageID DHCPSRV_MYSQL_TLS_CIPHER = "DHCPSRV_MYSQL_TLS_CIPHER";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR4 = "DHCPSRV_MYSQL_UPDATE_ADDR4";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR6 = "DHCPSRV_MYSQL_UPDATE_ADDR6";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6 = "DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR = "DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE = "DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4 = "DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR = "DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR";
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE = "DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE";
@@ -246,6 +249,9 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_START_TRANSACTION = "DHCPSRV_PGSQ
extern const isc::log::MessageID DHCPSRV_PGSQL_TLS_SUPPORT = "DHCPSRV_PGSQL_TLS_SUPPORT";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR4 = "DHCPSRV_PGSQL_UPDATE_ADDR4";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR6 = "DHCPSRV_PGSQL_UPDATE_ADDR6";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6 = "DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR = "DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE = "DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4 = "DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_ERROR = "DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_ERROR";
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_PAGE = "DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_PAGE";
@@ -463,6 +469,9 @@ const char* values[] = {
"DHCPSRV_MYSQL_TLS_CIPHER", "TLS cipher: %1",
"DHCPSRV_MYSQL_UPDATE_ADDR4", "updating IPv4 lease for address %1",
"DHCPSRV_MYSQL_UPDATE_ADDR6", "updating IPv6 lease for address %1, lease type %2",
"DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6", "upgrading IPv6 leases done in %1 pages with %2 updated leases",
"DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR", "upgrading binary address for IPv6 lease at %1 failed with %2",
"DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE", "upgrading IPv6 lease binary addresses at page %1 starting at %2 (updated %3)",
"DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4", "upgrading IPv4 leases done in %1 pages with %2 updated leases",
"DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR", "upgrading extending info for IPv4 lease at %1 failed with %2",
"DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE", "upgrading IPv4 lease extended info at page %1 starting at %2 (updated %3)",
@@ -517,6 +526,9 @@ const char* values[] = {
"DHCPSRV_PGSQL_TLS_SUPPORT", "Attempt to configure TLS: %1",
"DHCPSRV_PGSQL_UPDATE_ADDR4", "updating IPv4 lease for address %1",
"DHCPSRV_PGSQL_UPDATE_ADDR6", "updating IPv6 lease for address %1, lease type %2",
"DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6", "upgrading IPv6 leases done in %1 pages with %2 updated leases",
"DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR", "upgrading binary address for IPv6 lease at %1 failed with %2",
"DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE", "upgrading IPv6 lease binary addresses at page %1 starting at %2 (updated %3)",
"DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4", "upgrading IPv4 leases done in %1 pages with %2 updated leases",
"DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_ERROR", "upgrading extending info for IPv4 lease at %1 failed with %2",
"DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_PAGE", "upgrading IPv4 lease extended info at page %1 starting at %2 (updated %3)",

View File

@@ -193,6 +193,9 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_START_TRANSACTION;
extern const isc::log::MessageID DHCPSRV_MYSQL_TLS_CIPHER;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR4;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR6;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR;
extern const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE;
@@ -247,6 +250,9 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_START_TRANSACTION;
extern const isc::log::MessageID DHCPSRV_PGSQL_TLS_SUPPORT;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR4;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR6;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_ERROR;
extern const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_PAGE;

View File

@@ -976,6 +976,19 @@ lease from the MySQL database for the specified address.
A debug message issued when the server is attempting to update IPv6
lease from the MySQL database for the specified address.
% DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6 upgrading IPv6 leases done in %1 pages with %2 updated leases
The server upgraded binary addresses. The number of pages and the
final count of updated leases are displayed.
% DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR upgrading binary address for IPv6 lease at %1 failed with %2
A debug message issued when the server failed to upgrade a binary address.
The address of the lease and the error message are displayed.
% DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE upgrading IPv6 lease binary addresses at page %1 starting at %2 (updated %3)
A debug message issued when the server upgrades IPv6 lease binary addresses.
The page number and started address, and the count of already updated leases
are displayed.
% DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4 upgrading IPv4 leases done in %1 pages with %2 updated leases
The server upgraded extended info. The number of pages and the final count of
updated leases are displayed.
@@ -1234,6 +1247,19 @@ lease from the PostgreSQL database for the specified address.
A debug message issued when the server is attempting to update IPv6
lease from the PostgreSQL database for the specified address.
% DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6 upgrading IPv6 leases done in %1 pages with %2 updated leases
The server upgraded binary addresses. The number of pages and the
final count of updated leases are displayed.
% DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR upgrading binary address for IPv6 lease at %1 failed with %2
A debug message issued when the server failed to upgrade a binary address.
The address of the lease and the error message are displayed.
% DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE upgrading IPv6 lease binary addresses at page %1 starting at %2 (updated %3)
A debug message issued when the server upgrades IPv6 lease binary addresses.
The page number and started address, and the count of already updated leases
are displayed.
% DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4 upgrading IPv4 leases done in %1 pages with %2 updated leases
The server upgraded extended info. The number of pages and the final count of
updated leases are displayed.

View File

@@ -4038,6 +4038,84 @@ MySqlLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
isc_throw(NotImplemented, "MySqlLeaseMgr::getLeases6ByLink not implemented");
}
size_t
MySqlLeaseMgr::upgradeBinaryAddress6(const LeasePageSize& page_size) {
auto check = CfgMgr::instance().getCurrentCfg()->
getConsistency()->getExtendedInfoSanityCheck();
size_t pages = 0;
size_t updated = 0;
IOAddress start_addr = IOAddress::IPV6_ZERO_ADDRESS();
for (;;) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_PAGE)
.arg(pages)
.arg(start_addr.toText())
.arg(updated);
// Prepare WHERE clause.
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
// Bind start address.
std::string start_addr_str = "0";
if (!start_addr.isV6Zero()) {
start_addr_str = start_addr.toText();
}
unsigned long start_addr_size = start_addr_str.size();
inbind[0].buffer_type = MYSQL_TYPE_STRING;
inbind[0].buffer = const_cast<char*>(start_addr_str.c_str());
inbind[0].buffer_length = start_addr_size;
inbind[0].length = &start_addr_size;
// Bind page size value.
uint32_t ps = static_cast<uint32_t>(page_size.page_size_);
inbind[1].buffer_type = MYSQL_TYPE_LONG;
inbind[1].buffer = reinterpret_cast<char*>(&ps);
inbind[1].is_unsigned = MLM_TRUE;
Lease6Collection leases;
// Get a context.
{
MySqlLeaseContextAlloc get_context(*this);
MySqlLeaseContextPtr ctx = get_context.ctx_;
getLeaseCollection(ctx, GET_LEASE6_BINADDR_PAGE, inbind, leases);
}
if (leases.empty()) {
// Done.
break;
}
++pages;
start_addr = leases.back()->addr_;
for (auto lease : leases) {
try {
updateLease6(lease);
++updated;
} catch (const NoSuchLease&) {
// The lease was modified in parallel:
// as its extended info was processed just ignore.
continue;
} catch (const std::exception& ex) {
// Something when wrong, for instance extract failed.
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6_ERROR)
.arg(lease->addr_.toText())
.arg(ex.what());
}
}
}
LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_UPGRADE_BINARY_ADDRESS6)
.arg(pages)
.arg(updated);
return (updated);
}
size_t
MySqlLeaseMgr::buildExtendedInfoTables6(bool /* update */, bool /* current */) {
isc_throw(isc::NotImplemented,

View File

@@ -1135,6 +1135,17 @@ private:
/// @return The number of updates in the database.
virtual size_t upgradeExtendedInfo4(const LeasePageSize& page_size) override;
/// @brief Upgrade binary address (v6).
///
/// On SQL backends for all leases with null binary address set this
/// new column. Memfile uses IOAddress objets so does not need it.
/// This function implements the new BLQ hook command named
/// "binary-address6-upgrade".
///
/// @param page_size The page size used for retrieval.
/// @return The number of updates in the database.
virtual size_t upgradeBinaryAddress6(const LeasePageSize& page_size) override;
/// @brief Build extended info v6 tables.
///
/// @param update Update extended info in database.

View File

@@ -3166,6 +3166,78 @@ PgSqlLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
isc_throw(NotImplemented, "PgSqlLeaseMgr::getLeases6ByLink not implemented");
}
size_t
PgSqlLeaseMgr::upgradeBinaryAddress6(const LeasePageSize& page_size) {
auto check = CfgMgr::instance().getCurrentCfg()->
getConsistency()->getExtendedInfoSanityCheck();
size_t pages = 0;
size_t updated = 0;
IOAddress start_addr = IOAddress::IPV6_ZERO_ADDRESS();
for (;;) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_PAGE)
.arg(pages)
.arg(start_addr.toText())
.arg(updated);
// Prepare WHERE clause.
PsqlBindArray bind_array;
// Bind start address.
std::string start_addr_data = "0";
if (!start_addr.isV6Zero()) {
start_addr_data = start_addr.toText();
}
bind_array.add(start_addr_data);
// Bind page size value.
std::string page_size_data =
boost::lexical_cast<std::string>(page_size.page_size_);
bind_array.add(page_size_data);
Lease6Collection leases;
// Get a context.
{
PgSqlLeaseContextAlloc get_context(*this);
PgSqlLeaseContextPtr ctx = get_context.ctx_;
getLeaseCollection(ctx, GET_LEASE6_BINADDR_PAGE, bind_array, leases);
}
if (leases.empty()) {
// Done.
break;
}
++pages;
start_addr = leases.back()->addr_;
for (auto lease : leases) {
try {
updateLease6(lease);
++updated;
} catch (const NoSuchLease&) {
// The lease was modified in parallel:
// as its extended info was processed just ignore.
continue;
} catch (const std::exception& ex) {
// Something when wrong, for instance extract failed.
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6_ERROR)
.arg(lease->addr_.toText())
.arg(ex.what());
}
}
}
LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_UPGRADE_BINARY_ADDRESS6)
.arg(pages)
.arg(updated);
return (updated);
}
size_t
PgSqlLeaseMgr::buildExtendedInfoTables6(bool /* update */, bool /* current */) {
isc_throw(isc::NotImplemented,

View File

@@ -1089,6 +1089,17 @@ private:
/// @return The number of updates in the database.
virtual size_t upgradeExtendedInfo4(const LeasePageSize& page_size) override;
/// @brief Upgrade binary address (v6).
///
/// On SQL backends for all leases with null binary address set this
/// new column. Memfile uses IOAddress objets so does not need it.
/// This function implements the new BLQ hook command named
/// "binary-address6-upgrade".
///
/// @param page_size The page size used for retrieval.
/// @return The number of updates in the database.
virtual size_t upgradeBinaryAddress6(const LeasePageSize& page_size) override;
/// @brief Build extended info v6 tables.
///
/// @param update Update extended info in database.

View File

@@ -1,3 +1,4 @@
api_files += $(top_srcdir)/src/share/api/binary-address6-upgrade.json
api_files += $(top_srcdir)/src/share/api/build-report.json
api_files += $(top_srcdir)/src/share/api/cache-clear.json
api_files += $(top_srcdir)/src/share/api/cache-flush.json

View File

@@ -0,0 +1,30 @@
{
"access": "write",
"avail": "2.3.8",
"brief": [
"This command fills the binary address column for all IPv6 leases where it is NULL in the SQL lease database."
],
"cmd-syntax": [
"{",
" \"command\": \"binary-address6-upgrade\"",
" }",
"}"
],
"description": "See <xref linkend=\"command-binary-address6-upgrade\"/>",
"hook": "lease_query",
"name": "binary-address6-upgrade",
"resp-comment": [
"This command should be used when some old IPv6 leases are present in the lease database using a SQL backend."
],
"resp-syntax": [
"{",
" \"arguments\": {",
" },",
" \"result\": 0,",
" \"text\": \"to be done\"",
"}"
],
"support": [
"kea-dhcp6"
]
}

View File

@@ -14,7 +14,7 @@
"hook": "lease_query",
"name": "extended-info4-upgrade",
"resp-comment": [
"This command should be used when some old leases are present in the lease database using a SQL backend."
"This command should be used when some old IPv4 leases are present in the lease database using a SQL backend."
],
"resp-syntax": [
"{",
@@ -25,6 +25,6 @@
"}"
],
"support": [
"kea-dhcp6"
"kea-dhcp4"
]
}