From: Andrei Pavel Date: Thu, 23 Oct 2025 12:02:35 +0000 (+0300) Subject: [#4100] Log enums as strings where possible X-Git-Tag: Kea-3.1.3~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=19095d7f6d5358e0a4019a96d01e202946d4e491;p=thirdparty%2Fkea.git [#4100] Log enums as strings where possible --- diff --git a/src/bin/d2/d2_queue_mgr.cc b/src/bin/d2/d2_queue_mgr.cc index f902b221b8..4943fcd7ef 100644 --- a/src/bin/d2/d2_queue_mgr.cc +++ b/src/bin/d2/d2_queue_mgr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2025 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 @@ -78,7 +78,7 @@ D2QueueMgr::operator()(const dhcp_ddns::NameChangeListener::Result result, // this is unexpected so we will treat it as a receive error. // This is most likely an unforeseen programmatic issue. LOG_ERROR(dhcp_to_d2_logger, DHCP_DDNS_QUEUE_MGR_UNEXPECTED_STOP) - .arg(mgr_state_); + .arg(D2QueueMgr::stateToText(mgr_state_)); stopListening(STOPPED_RECV_ERROR); } diff --git a/src/bin/d2/d2_queue_mgr.h b/src/bin/d2/d2_queue_mgr.h index 4c730b83b1..4d34b726b1 100644 --- a/src/bin/d2/d2_queue_mgr.h +++ b/src/bin/d2/d2_queue_mgr.h @@ -10,13 +10,14 @@ /// @file d2_queue_mgr.h This file defines the class D2QueueMgr. #include -#include -#include #include +#include +#include -#include #include +#include + namespace isc { namespace d2 { @@ -145,6 +146,25 @@ public: STOPPED = 6, }; + /// @brief Convert enum to string. + /// + /// @param state input enum + /// + /// @return reference to static string + static std::string const& stateToText(State const& state) { + static std::vector const text_vector { + "NOT_INITTED", + "INITTED", + "RUNNING", + "STOPPING", + "STOPPED_QUEUE_FULL", + "STOPPED_RECV_ERROR", + "STOPPED", + }; + static std::string const unknown("UNKNOWN"); + return (state < text_vector.size() ? text_vector[state] : unknown); + } + /// @brief Constructor /// /// Creates a D2QueueMgr instance. Note that the listener is not created diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 3dd73ec1d8..b1de5c68a8 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -5106,11 +5106,11 @@ Dhcpv4Srv::stopD2() { } void -Dhcpv4Srv::d2ClientErrorHandler(const - dhcp_ddns::NameChangeSender::Result result, +Dhcpv4Srv::d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr& ncr) { - LOG_ERROR(ddns4_logger, DHCP4_DDNS_REQUEST_SEND_FAILED). - arg(result).arg((ncr ? ncr->toText() : " NULL ")); + LOG_ERROR(ddns4_logger, DHCP4_DDNS_REQUEST_SEND_FAILED) + .arg(NameChangeSender::resultToText(result)) + .arg((ncr ? ncr->toText() : " NULL ")); // We cannot communicate with kea-dhcp-ddns, suspend further updates. /// @todo We may wish to revisit this, but for now we will simply turn /// them off. diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 78145dedeb..c7cb73f360 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -5060,11 +5060,11 @@ Dhcpv6Srv::stopD2() { } void -Dhcpv6Srv::d2ClientErrorHandler(const - dhcp_ddns::NameChangeSender::Result result, +Dhcpv6Srv::d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr& ncr) { - LOG_ERROR(ddns6_logger, DHCP6_DDNS_REQUEST_SEND_FAILED). - arg(result).arg((ncr ? ncr->toText() : " NULL ")); + LOG_ERROR(ddns6_logger, DHCP6_DDNS_REQUEST_SEND_FAILED) + .arg(NameChangeSender::resultToText(result)) + .arg((ncr ? ncr->toText() : " NULL ")); // We cannot communicate with kea-dhcp-ddns, suspend further updates. /// @todo We may wish to revisit this, but for now we will simply turn /// them off. diff --git a/src/hooks/d2/gss_tsig/tkey_exchange.cc b/src/hooks/d2/gss_tsig/tkey_exchange.cc index c79aa15727..f7293b7d4e 100644 --- a/src/hooks/d2/gss_tsig/tkey_exchange.cc +++ b/src/hooks/d2/gss_tsig/tkey_exchange.cc @@ -256,7 +256,7 @@ TKeyExchangeImpl::operator()(IOFetch::Result result) { default: LOG_ERROR(gss_tsig_logger, TKEY_EXCHANGE_FAIL_IO_ERROR) - .arg(result); + .arg(IOFetch::resultToText(result)); incrStats("tkey-error"); callCallback(TKeyExchange::OTHER); return; diff --git a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc index 8668752619..7b3bfb3a71 100644 --- a/src/hooks/dhcp/mysql/mysql_lease_mgr.cc +++ b/src/hooks/dhcp/mysql/mysql_lease_mgr.cc @@ -2380,7 +2380,7 @@ bool MySqlLeaseMgr::addLease(const Lease6Ptr& lease) { LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_ADD_ADDR6) .arg(lease->addr_.toText()) - .arg(lease->type_); + .arg(Lease::typeToText(lease->type_)); lease->extended_info_action_ = Lease6::ACTION_IGNORE; @@ -2847,7 +2847,7 @@ MySqlLeaseMgr::getLease6(Lease::Type lease_type, const IOAddress& addr) const { LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_GET_ADDR6) .arg(addr.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value MYSQL_BIND inbind[2]; @@ -2928,7 +2928,7 @@ MySqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid, LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_GET_IAID_DUID) .arg(iaid) .arg(duid.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value MYSQL_BIND inbind[3]; @@ -2992,7 +2992,7 @@ MySqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid, .arg(iaid) .arg(subnet_id) .arg(duid.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value MYSQL_BIND inbind[4]; @@ -3386,7 +3386,7 @@ MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) { LOG_DEBUG(mysql_lb_logger, MYSQL_LB_DBG_TRACE_DETAIL, MYSQL_LB_UPDATE_ADDR6) .arg(lease->addr_.toText()) - .arg(lease->type_); + .arg(Lease::typeToText(lease->type_)); // Get the recorded action and reset it. Lease6::ExtendedInfoAction recorded_action = lease->extended_info_action_; diff --git a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc index 0aaddd7ebe..1a315cf3b1 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc +++ b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc @@ -1821,7 +1821,7 @@ bool PgSqlLeaseMgr::addLease(const Lease6Ptr& lease) { LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_ADD_ADDR6) .arg(lease->addr_.toText()) - .arg(lease->type_); + .arg(Lease::typeToText(lease->type_)); lease->extended_info_action_ = Lease6::ACTION_IGNORE; @@ -2162,7 +2162,7 @@ PgSqlLeaseMgr::getLease6(Lease::Type lease_type, const IOAddress& addr) const { LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_GET_ADDR6) .arg(addr.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value PsqlBindArray bind_array; @@ -2220,7 +2220,7 @@ PgSqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid, LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_GET_IAID_DUID) .arg(iaid) .arg(duid.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value PsqlBindArray bind_array; @@ -2255,7 +2255,7 @@ PgSqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid, .arg(iaid) .arg(subnet_id) .arg(duid.toText()) - .arg(lease_type); + .arg(Lease::typeToText(lease_type)); // Set up the WHERE clause value PsqlBindArray bind_array; @@ -2583,7 +2583,7 @@ PgSqlLeaseMgr::updateLease6(const Lease6Ptr& lease) { LOG_DEBUG(pgsql_lb_logger, PGSQL_LB_DBG_TRACE_DETAIL, PGSQL_LB_UPDATE_ADDR6) .arg(lease->addr_.toText()) - .arg(lease->type_); + .arg(Lease::typeToText(lease->type_)); // Get the recorded action and reset it. Lease6::ExtendedInfoAction recorded_action = lease->extended_info_action_; diff --git a/src/lib/asiodns/io_fetch.h b/src/lib/asiodns/io_fetch.h index 8bdda974e8..a2c8c92dd2 100644 --- a/src/lib/asiodns/io_fetch.h +++ b/src/lib/asiodns/io_fetch.h @@ -17,9 +17,9 @@ #include #include +#include #include #include -#include #include namespace isc { @@ -60,9 +60,25 @@ public: SUCCESS = 0, // Success, fetch completed TIME_OUT = 1, // Failure, fetch timed out STOPPED = 2, // Control code, fetch has been stopped - NOTSET = 3 // For testing, indicates value not set + NOTSET = 3, // For testing, indicates value not set }; + /// @brief Convert enum to string. + /// + /// @param result input enum + /// + /// @return reference to static string + static std::string const& resultToText(Result const& result) { + static std::vector const text_vector { + "SUCCESS", + "TIME_OUT", + "STOPPED", + "NOTSET", + }; + static std::string const unknown("UNKNOWN"); + return (result < text_vector.size() ? text_vector[result] : unknown); + } + /// @note The next enum is a "trick" to allow constants to be defined in a class /// declaration. diff --git a/src/lib/cryptolink/cryptolink.h b/src/lib/cryptolink/cryptolink.h index 6dd375a258..4749dc136b 100644 --- a/src/lib/cryptolink/cryptolink.h +++ b/src/lib/cryptolink/cryptolink.h @@ -32,7 +32,7 @@ enum HashAlgorithm : int { SHA256 = 3, // SHA-256 SHA224 = 4, // SHA-224 SHA384 = 5, // SHA-384 - SHA512 = 6 // SHA-512 + SHA512 = 6, // SHA-512 }; /// @brief Forward declaration for createHash(). diff --git a/src/lib/cryptolink/tests/hmac_unittests.cc b/src/lib/cryptolink/tests/hmac_unittests.cc index d5c6a83ab2..b737f321c1 100644 --- a/src/lib/cryptolink/tests/hmac_unittests.cc +++ b/src/lib/cryptolink/tests/hmac_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2025 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 @@ -6,29 +6,45 @@ #include +#include +#include +#include +#include +#include + #include #include #include +#include #include -#include - -#include -#include - -#include -#include - -#include - using boost::lexical_cast; using namespace isc::util; using namespace isc::util::encode; using namespace isc::cryptolink; namespace { + /// @brief Convert enum to string. + /// + /// @param algorithm input enum + /// + /// @return reference to static string + static std::string const& hashAlgorithmToText(HashAlgorithm const& algorithm) { + static std::vector const text_vector { + "UNKNOWN_HASH", + "MD5", + "SHA1", + "SHA256", + "SHA224", + "SHA384", + "SHA512", + }; + static std::string const unknown("UNKNOWN"); + return (algorithm < text_vector.size() ? text_vector[algorithm] : unknown); + } + /// @brief Fill a string with copies of an out of char range value /// @param data String to fill /// @param len Number of copies @@ -479,8 +495,8 @@ doRFC4231Tests(HashAlgorithm hash_algorithm, for (std::vector::size_type i = 0; i < data_list.size(); ++i) { - SCOPED_TRACE("RFC4231 HMAC test for algorithm ID: " + - lexical_cast(hash_algorithm) + + SCOPED_TRACE("RFC4231 HMAC test for algorithm " + + hashAlgorithmToText(hash_algorithm) + ", data ID: " + lexical_cast(i)); // Until #920 is resolved we have to skip truncation cases. if (data_list[i] == "Test With Truncation") { diff --git a/src/lib/d2srv/dns_client.h b/src/lib/d2srv/dns_client.h index cf2f60f4ac..5c1f2c2f2a 100644 --- a/src/lib/d2srv/dns_client.h +++ b/src/lib/d2srv/dns_client.h @@ -63,6 +63,23 @@ public: OTHER = 4, ///< Other, unclassified error. }; + /// @brief Convert enum to string. + /// + /// @param status input enum + /// + /// @return reference to static string + static std::string const& statusToText(Status const& status) { + static std::vector const text_vector { + "SUCCESS", + "TIMEOUT", + "IO_STOPPED", + "INVALID_RESPONSE", + "OTHER", + }; + static std::string const unknown("UNKNOWN"); + return (status < text_vector.size() ? text_vector[status] : unknown); + } + /// @brief Callback for the @c DNSClient class. /// /// This is an abstract class which represents the external callback for the diff --git a/src/lib/dhcp_ddns/ncr_io.h b/src/lib/dhcp_ddns/ncr_io.h index f759d4332b..db0d572cfc 100644 --- a/src/lib/dhcp_ddns/ncr_io.h +++ b/src/lib/dhcp_ddns/ncr_io.h @@ -52,12 +52,12 @@ #include #include -#include -#include - #include #include +#include +#include + namespace isc { namespace dhcp_ddns { @@ -482,6 +482,22 @@ public: ERROR = 3, }; + /// @brief Convert enum to string. + /// + /// @param result input enum + /// + /// @return reference to static string + static std::string const& resultToText(Result const& result) { + static std::vector const text_vector { + "SUCCESS", + "TIME_OUT", + "STOPPED", + "ERROR", + }; + static std::string const unknown("UNKNOWN"); + return (result < text_vector.size() ? text_vector[result] : unknown); + } + /// @brief Abstract class for defining application layer send callbacks. /// /// Applications which will send NameChangeRequests must provide a diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h index 620afe1391..1ef85c25e3 100644 --- a/src/lib/dhcpsrv/host.h +++ b/src/lib/dhcpsrv/host.h @@ -339,7 +339,7 @@ public: IDENT_DUID = 1, IDENT_CIRCUIT_ID = 2, IDENT_CLIENT_ID = 3, - IDENT_FLEX = 4, ///< Flexible host identifier. + IDENT_FLEX = 4, ///< Flexible host identifier. }; /// @brief Constant pointing to the last identifier of the