// The remote server's name or IP.
pkt->setRemoteAddr(IOAddress(options_.getServerName()));
// Set local address.
- pkt->setLocalAddr(IOAddress(socket_.addr_));
+ pkt->setLocalAddr(socket_.addr_);
// Set relay (GIADDR) address to local address if multiple
// subnet mode is not enabled
if (!options_.checkMultiSubnet()) {
- pkt->setGiaddr(IOAddress(socket_.addr_));
+ pkt->setGiaddr(socket_.addr_);
} else {
pkt->setGiaddr(IOAddress(options_.getRandRelayAddr()));
}
if (options_.checkMultiSubnet()) {
relay_info.linkaddr_ = IOAddress(options_.getRandRelayAddr());
} else {
- relay_info.linkaddr_ = IOAddress(socket_.addr_);
+ relay_info.linkaddr_ = socket_.addr_;
}
- relay_info.peeraddr_ = IOAddress(socket_.addr_);
+ relay_info.peeraddr_ = socket_.addr_;
relay_info.options_.insert(options_.getRelayOpts().begin(), options_.getRelayOpts().end());
pkt->addRelayInfo(relay_info);
}
-// Copyright (C) 2021-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2021-2024 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
namespace {
-/// @brief Test timeout (ms).
-const long TEST_TIMEOUT = 10000;
-
/// @brief Simple test fixture for testing IoServiceThreadPool.
class IoServiceThreadPoolTest : public ::testing::Test {
public:
// data is parsed correctly.
TEST(OptionOpaqueDataTuples, unpack4NoTuple) {
// Prepare data to decode.
- const uint8_t buf_data[] = {
- };
- OptionBuffer buf(buf_data, buf_data + sizeof(buf_data));
+ std::vector<uint8_t> buf_vector;
+ const uint8_t* buf_data = buf_vector.data();
+ OptionBuffer buf(buf_data, buf_data + buf_vector.size());
OptionOpaqueDataTuplesPtr data_tuple;
ASSERT_NO_THROW(
// data is parsed correctly when tuple's length field is coded on 2 octets.
TEST(OptionOpaqueDataTuples, unpack4NoTuple_with_ltf) {
// Prepare data to decode.
- const uint8_t buf_data[] = {
- };
- OptionBuffer buf(buf_data, buf_data + sizeof(buf_data));
+ std::vector<uint8_t> buf_vector;
+ const uint8_t* buf_data = buf_vector.data();
+ OptionBuffer buf(buf_data, buf_data + buf_vector.size());
OptionOpaqueDataTuplesPtr data_tuple;
ASSERT_NO_THROW(
// data is parsed correctly.
TEST(OptionOpaqueDataTuples, unpack6NoTuple) {
// Prepare data to decode.
- const uint8_t buf_data[] = {
- };
- OptionBuffer buf(buf_data, buf_data + sizeof(buf_data));
+ std::vector<uint8_t> buf_vector;
+ const uint8_t* buf_data = buf_vector.data();
+ OptionBuffer buf(buf_data, buf_data + buf_vector.size());
OptionOpaqueDataTuplesPtr data_tuple;
ASSERT_NO_THROW(
columns_[AUTH_KEY_COL] = "auth_key";
BOOST_STATIC_ASSERT(13 < HOST_COLUMNS);
- };
+ }
/// @brief Virtual destructor.
virtual ~MySqlHostExchange() {
/// This method is used by derived classes.
uint64_t getHostId() const {
return (host_id_);
- };
+ }
/// @brief Set error indicators
///
error[i] = MLM_FALSE;
bind[i].error = reinterpret_cast<my_bool*>(&error[i]);
}
- };
+ }
/// @brief Return columns in error
///
}
return (result);
- };
+ }
/// @brief Create MYSQL_BIND objects for Host Pointer
///
vec.push_back(bind_[3]); // subnet_id
}
return (vec);
- };
+ }
/// @brief Create BIND array to receive Host data.
///
// Add the data to the vector. Note the end element is one after the
// end of the array.
return (bind_);
- };
+ }
/// @brief Copy received data into Host object
///
// set to 0.
SubnetID ipv4_subnet_id(SUBNET_ID_UNUSED);
if (dhcp4_subnet_id_null_ == MLM_FALSE) {
- ipv4_subnet_id = static_cast<SubnetID>(dhcp4_subnet_id_);
+ ipv4_subnet_id = dhcp4_subnet_id_;
}
// Set DHCPv6 subnet ID to the value returned. If NULL returned,
// set to 0.
SubnetID ipv6_subnet_id(SUBNET_ID_UNUSED);
if (dhcp6_subnet_id_null_ == MLM_FALSE) {
- ipv6_subnet_id = static_cast<SubnetID>(dhcp6_subnet_id_);
+ ipv6_subnet_id = dhcp6_subnet_id_;
}
// Set IPv4 address reservation if it was given, if not, set IPv4 zero
}
return (h);
- };
+ }
/// @brief Processes one row of data fetched from a database.
///
/// "(None)".
std::string getErrorColumns() {
return (getColumnsInError(error_, columns_));
- };
+ }
protected:
/// detects duplicated information and discards such entries.
///
/// @param [out] hosts Container holding parsed hosts and options.
- virtual void processFetchedData(ConstHostCollection& hosts) {
+ virtual void processFetchedData(ConstHostCollection& hosts) override {
// Holds pointer to the previously parsed host.
HostPtr most_recent_host;
if (!hosts.empty()) {
/// @brief Bind variables for receiving option data.
///
/// @return Vector of MYSQL_BIND object representing data to be retrieved.
- virtual std::vector<MYSQL_BIND> createBindForReceive() {
+ virtual std::vector<MYSQL_BIND> createBindForReceive() override {
// The following call sets bind_ values between 0 and 8.
static_cast<void>(MySqlHostExchange::createBindForReceive());
setErrorIndicators(bind_, error_);
return (bind_);
- };
+ }
private:
return (reservation_id_);
}
return (0);
- };
+ }
/// @brief Creates IPv6 reservation from the data contained in the
/// currently processed row.
IOAddress addr6 = IOAddress::fromBytes(AF_INET6, ipv6_address_buffer_);
IPv6Resrv r(type, addr6, prefix_len_);
return (r);
- };
+ }
/// @brief Processes one row of data fetched from a database.
///
///
/// @param [out] hosts Collection of hosts to which a new host created
/// from the processed data should be inserted.
- virtual void processFetchedData(ConstHostCollection& hosts) {
+ virtual void processFetchedData(ConstHostCollection& hosts) override {
// Call parent class to fetch host information and options.
MySqlHostWithOptionsExchange::processFetchedData(hosts);
/// objects with associated IPv6 reservations.
///
/// @return Vector of MYSQL_BIND objects representing data to be retrieved.
- virtual std::vector<MYSQL_BIND> createBindForReceive() {
+ virtual std::vector<MYSQL_BIND> createBindForReceive() override {
// Reset most recent reservation id value because we're now making
// a new SELECT query.
most_recent_reservation_id_ = 0;
setErrorIndicators(bind_, error_);
return (bind_);
- };
+ }
private:
///
/// This class supports inserting both DHCPv4 and DHCPv6 options.
class MySqlOptionExchange {
-private:
-
- static const size_t OPTION_ID_COL = 0;
- static const size_t CODE_COL = 1;
- static const size_t VALUE_COL = 2;
- static const size_t FORMATTED_VALUE_COL = 3;
- static const size_t SPACE_COL = 4;
- static const size_t PERSISTENT_COL = 5;
- static const size_t CANCELLED_COL = 6;
- static const size_t USER_CONTEXT_COL = 7;
- static const size_t DHCP_SUBNET_ID_COL = 8;
- static const size_t HOST_ID_COL = 9;
/// @brief Number of columns in the option tables holding bindable values.
static const size_t OPTION_COLUMNS = 10;
// Identifier type.
char identifier_type_copy = static_cast<char>(identifier_type);
inbind[1].buffer_type = MYSQL_TYPE_TINY;
- inbind[1].buffer = reinterpret_cast<char*>(&identifier_type_copy);
+ inbind[1].buffer = &identifier_type_copy;
inbind[1].is_unsigned = MLM_TRUE;
ConstHostCollection collection;
// identifier type
char identifier_type_copy = static_cast<char>(identifier_type);
inbind[1].buffer_type = MYSQL_TYPE_TINY;
- inbind[1].buffer = reinterpret_cast<char*>(&identifier_type_copy);
+ inbind[1].buffer = &identifier_type_copy;
inbind[1].is_unsigned = MLM_TRUE;
// identifier value
// identifier type
char identifier_type_copy = static_cast<char>(identifier_type);
inbind[1].buffer_type = MYSQL_TYPE_TINY;
- inbind[1].buffer = reinterpret_cast<char*>(&identifier_type_copy);
+ inbind[1].buffer = &identifier_type_copy;
inbind[1].is_unsigned = MLM_TRUE;
// identifier value
#include <boost/static_assert.hpp>
#include <mysqld_error.h>
+#include <ctime>
#include <iostream>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
-#include <time.h>
+#include <vector>
using namespace isc;
using namespace isc::asiolink;
namespace {
-/// @brief Maximum length of the hostname stored in DNS.
-///
-/// This length is restricted by the length of the domain-name carried
-/// in the Client FQDN %Option (see RFC4702 and RFC4704).
-const size_t HOSTNAME_MAX_LEN = 255;
-
-/// @brief Maximum size of an IPv6 address represented as a text string.
-///
-/// This is 32 hexadecimal characters written in 8 groups of four, plus seven
-/// colon separators.
-const size_t ADDRESS6_TEXT_MAX_LEN = 39;
-
-/// @brief Maximum length of user context.
-const size_t USER_CONTEXT_MAX_LEN = 8192;
-
/// @brief Maximum length of the text returned by the limit checking functions.
const size_t LIMITS_TEXT_MAX_LEN = 512;
size_t count) {
for (size_t i = 0; i < count; ++i) {
error[i] = MLM_FALSE;
- bind[i].error = reinterpret_cast<my_bool*>(&error[i]);
+ bind[i].error = &error[i];
}
}
/// type (v6 only) per subnet id. This method binds the statement to
/// the output bind array and then executes the statement, and fetches
/// entire result set.
- void start() {
+ void start() override {
// Set up where clause inputs if needed.
if (getSelectMode() != ALL_SUBNETS && getSelectMode() != ALL_SUBNET_POOLS) {
MYSQL_BIND inbind[2];
///
/// @return True if the fetch succeeded, false if there are no more
/// rows to fetch.
- bool getNextRow(LeaseStatsRow& row) {
+ bool getNextRow(LeaseStatsRow& row) override {
bool have_row = false;
int status = mysql_stmt_fetch(statement_);
if (status == MLM_MYSQL_FETCH_SUCCESS) {
- row.subnet_id_ = static_cast<SubnetID>(subnet_id_);
+ row.subnet_id_ = subnet_id_;
row.pool_id_ = pool_id_;
row.lease_type_ = static_cast<Lease::Type>(lease_type_);
row.lease_state_ = state_;
// See how many rows were affected. Note that the statement may delete
// multiple rows.
- return (static_cast<uint64_t>(mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex))));
+ return (mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex)));
}
bool
if (have_qet) {
++bindings;
}
- MYSQL_BIND inbind[bindings];
- memset(inbind, 0, sizeof(inbind));
+ MYSQL_BIND zeroed_out;
+ memset(&zeroed_out, 0, sizeof(zeroed_out));
+ vector<MYSQL_BIND> inbind(bindings, zeroed_out);
std::vector<uint8_t> relay_id_data = relay_id;
unsigned long relay_id_length = relay_id.size();
MySqlLeaseContextAlloc get_context(*this);
MySqlLeaseContextPtr ctx = get_context.ctx_;
- getLeaseCollection(ctx, stindex, inbind, result);
+ getLeaseCollection(ctx, stindex, inbind.data(), result);
return (result);
}
if (have_qet) {
++bindings;
}
- MYSQL_BIND inbind[bindings];
- memset(inbind, 0, sizeof(inbind));
+ MYSQL_BIND zeroed_out;
+ memset(&zeroed_out, 0, sizeof(zeroed_out));
+ vector<MYSQL_BIND> inbind(bindings, zeroed_out);
std::vector<uint8_t> remote_id_data = remote_id;
unsigned long remote_id_length = remote_id.size();
MySqlLeaseContextAlloc get_context(*this);
MySqlLeaseContextPtr ctx = get_context.ctx_;
- getLeaseCollection(ctx, stindex, inbind, result);
+ getLeaseCollection(ctx, stindex, inbind.data(), result);
return (result);
}
/// The most common errors are due to receiving malformed requests.
class HttpParseError : public Exception {
public:
- HttpParseError(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) { };
+ HttpParseError(const char* file, size_t line, const char* what)
+ : isc::Exception(file, line, what) {
+ }
};
/// @brief Base class for the HTTP message parsers.
protected:
/// @brief Define events used by the parser.
- virtual void defineEvents();
+ virtual void defineEvents() override ;
/// @brief Verifies events used by the parser.
- virtual void verifyEvents();
+ virtual void verifyEvents() override;
/// @brief Defines states of the parser.
- virtual void defineStates();
+ virtual void defineStates() override;
/// @brief Generic parser handler which reads a single byte of data and
/// parses it using specified callback function.
///
/// @param explanation Error message explaining the reason for parsing
/// failure.
- virtual void onModelFailure(const std::string& explanation);
+ virtual void onModelFailure(const std::string& explanation) override;
/// @brief Retrieves next bytes of data from the buffer.
///
// returned row the lambda provided as 4th argument should be executed.
ASSERT_NO_THROW_LOG(conn_.selectQuery(MySqlConnectionTest::GET_BY_INT_VALUE,
bindings, out_bindings,
- [&](MySqlBindingCollection& out_bindings) {
+ [&](MySqlBindingCollection& captured_out_bindings) {
// Compare received data with input data assuming they are both non-null.
- if (!out_bindings[0]->amNull() && !in_bindings[0]->amNull()) {
+ if (!captured_out_bindings[0]->amNull() && !in_bindings[0]->amNull()) {
EXPECT_EQ(static_cast<int>(in_bindings[0]->getInteger<uint8_t>()),
- static_cast<int>(out_bindings[0]->getInteger<uint8_t>()));
+ static_cast<int>(captured_out_bindings[0]->getInteger<uint8_t>()));
}
- if (!out_bindings[1]->amNull() && !in_bindings[1]->amNull()) {
+ if (!captured_out_bindings[1]->amNull() && !in_bindings[1]->amNull()) {
EXPECT_EQ(in_bindings[1]->getInteger<uint32_t>(),
- out_bindings[1]->getInteger<uint32_t>());
+ captured_out_bindings[1]->getInteger<uint32_t>());
}
- if (!out_bindings[2]->amNull() && !in_bindings[2]->amNull()) {
+ if (!captured_out_bindings[2]->amNull() && !in_bindings[2]->amNull()) {
EXPECT_EQ(in_bindings[2]->getInteger<int64_t>(),
- out_bindings[2]->getInteger<int64_t>());
+ captured_out_bindings[2]->getInteger<int64_t>());
}
- if (!out_bindings[3]->amNull() && !in_bindings[3]->amNull()) {
+ if (!captured_out_bindings[3]->amNull() && !in_bindings[3]->amNull()) {
EXPECT_EQ(in_bindings[3]->getString(),
- out_bindings[3]->getString());
+ captured_out_bindings[3]->getString());
}
- if (!out_bindings[4]->amNull() && !in_bindings[4]->amNull()) {
+ if (!captured_out_bindings[4]->amNull() && !in_bindings[4]->amNull()) {
EXPECT_EQ(in_bindings[4]->getBlob(),
- out_bindings[4]->getBlob());
+ captured_out_bindings[4]->getBlob());
}
- if (!out_bindings[5]->amNull() && !in_bindings[5]->amNull()) {
+ if (!captured_out_bindings[5]->amNull() && !in_bindings[5]->amNull()) {
EXPECT_TRUE(in_bindings[5]->getTimestamp() ==
- out_bindings[5]->getTimestamp());
+ captured_out_bindings[5]->getTimestamp());
}
}));
using namespace isc::asiolink;
namespace ph = std::placeholders;
-namespace {
-
-/// @brief Maximum size of a message that can be logged.
-///
-/// The part of the message beyond this value is truncated.
-const size_t MAX_LOGGED_MESSAGE_SIZE = 1024;
-
-}
-
namespace isc {
namespace tcp {