2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[#2868] Checkpoint: add binaddr

This commit is contained in:
Francis Dupont 2023-05-23 18:49:01 +02:00
parent 39f624ed5a
commit 942f201009
2 changed files with 48 additions and 24 deletions

View File

@ -402,8 +402,8 @@ tagged_statements = { {
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
"state, user_context, binaddr) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
{MySqlLeaseMgr::UPDATE_LEASE4,
"UPDATE lease4 SET address = ?, hwaddr = ?, "
"client_id = ?, valid_lifetime = ?, expire = ?, "
@ -418,7 +418,7 @@ tagged_statements = { {
"pref_lifetime = ?, lease_type = ?, iaid = ?, "
"prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
"hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
"state = ?, user_context = ? "
"state = ?, user_context = ?, binaddr = ? "
"WHERE address = ? AND expire = ?"},
{MySqlLeaseMgr::ALL_LEASE4_STATS,
"SELECT subnet_id, state, leases as state_count "
@ -1089,7 +1089,7 @@ private:
class MySqlLease6Exchange : public MySqlLeaseExchange {
/// @brief Set number of database columns for this lease structure
static const size_t LEASE_COLUMNS = 17;
static const size_t LEASE_COLUMNS = 18;
public:
@ -1104,7 +1104,7 @@ public:
fqdn_fwd_(false), fqdn_rev_(false),
hostname_length_(0), hwtype_(0), hwaddr_source_(0),
state_(0), user_context_length_(0),
user_context_null_(MLM_FALSE) {
user_context_null_(MLM_FALSE), binaddr_length_(16) {
memset(addr6_buffer_, 0, sizeof(addr6_buffer_));
memset(duid_buffer_, 0, sizeof(duid_buffer_));
memset(hostname_buffer_, 0, sizeof(hostname_buffer_));
@ -1130,7 +1130,8 @@ public:
columns_[14] = "hwaddr_source";
columns_[15] = "state";
columns_[16] = "user_context";
BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
columns_[17] = "binaddr";
BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
}
/// @brief Create MYSQL_BIND objects for Lease6 Pointer
@ -1266,7 +1267,7 @@ public:
bind_[9].buffer_type = MYSQL_TYPE_TINY;
bind_[9].buffer = reinterpret_cast<char*>(&lease_->fqdn_fwd_);
bind_[9].is_unsigned = MLM_TRUE;
// bind_[7].is_null = &MLM_FALSE; // commented out for performance
// bind_[9].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
// fqdn_rev: boolean
@ -1373,11 +1374,25 @@ public:
bind_[16].buffer_type = MYSQL_TYPE_NULL;
}
// binaddr: binary(16)
binaddr_ = lease->addr_.toBytes();
if (binaddr_.size() != 16) {
isc_throw(DbOperationError, "lease6 address is not 16 byte long");
}
binaddr_length_ = 16;
bind_[17].buffer_type = MYSQL_TYPE_BLOB;
bind_[17].buffer = reinterpret_cast<char*>(&binaddr_[0]);
bind_[17].buffer_length = 16;
bind_[17].length = &binaddr_length_;
// bind_[17].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS);
// .. and check that we have the numbers correct at compile time.
BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
@ -1536,14 +1551,14 @@ public:
bind_[16].is_null = &user_context_null_;
// Add the error flags
setErrorIndicators(bind_, error_, LEASE_COLUMNS);
setErrorIndicators(bind_, error_, LEASE_COLUMNS - 1);
// .. and check that we have the numbers correct at compile time.
BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS - 1);
// Add the data to the vector. Note the end element is one after the
// end of the array.
return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS - 1]));
}
/// @brief Copy Received Data into Lease6 Object
@ -1698,6 +1713,8 @@ private:
char user_context_[USER_CONTEXT_MAX_LEN]; ///< User context
unsigned long user_context_length_; ///< Length of user context
my_bool user_context_null_; ///< Used when user context is null
std::vector<uint8_t> binaddr_; ///< Binary address
unsigned long binaddr_length_; ///< Length of binary data
};
/// @brief MySql derivation of the statistical lease data query

View File

@ -418,16 +418,17 @@ PgSqlTaggedStatement tagged_statements[] = {
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"},
// INSERT_LEASE6
{ 17, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
{ 18, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_INT8, OID_INT2, OID_INT8, OID_INT2, OID_BOOL, OID_BOOL,
OID_VARCHAR, OID_BYTEA, OID_INT2, OID_INT2, OID_INT8, OID_TEXT },
OID_VARCHAR, OID_BYTEA, OID_INT2, OID_INT2, OID_INT8, OID_TEXT,
OID_BYTEA },
"insert_lease6",
"INSERT INTO lease6(address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context) "
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)"},
"state, user_context, binaddr) "
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"},
// UPDATE_LEASE4
{ 15, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
@ -441,18 +442,18 @@ PgSqlTaggedStatement tagged_statements[] = {
"WHERE address = $14 AND expire = $15"},
// UPDATE_LEASE6
{ 19, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
{ 20, { OID_VARCHAR, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8, OID_INT8,
OID_INT2, OID_INT8, OID_INT2, OID_BOOL, OID_BOOL, OID_VARCHAR,
OID_BYTEA, OID_INT2, OID_INT2,
OID_INT8, OID_TEXT, OID_VARCHAR, OID_TIMESTAMP },
OID_INT8, OID_TEXT, OID_BYTEA, OID_VARCHAR, OID_TIMESTAMP },
"update_lease6",
"UPDATE lease6 SET address = $1, duid = $2, "
"valid_lifetime = $3, expire = $4, subnet_id = $5, "
"pref_lifetime = $6, lease_type = $7, iaid = $8, "
"prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, "
"hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
"state = $16, user_context = $17 "
"WHERE address = $18 AND expire = $19"},
"state = $16, user_context = $17, binaddr = $18 "
"WHERE address = $19 AND expire = $20"},
// ALL_LEASE4_STATS
{ 0, { OID_NONE },
@ -549,7 +550,7 @@ public:
valid_lifetime_(0), valid_lifetime_str_(""), expire_(0),
expire_str_(""), subnet_id_(0), subnet_id_str_(""), cltt_(0),
fqdn_fwd_(false), fqdn_rev_(false), hostname_(""), state_str_(""),
user_context_("") {
user_context_(""), addr_bin_(16) {
}
virtual ~PgSqlLeaseExchange(){}
@ -574,6 +575,7 @@ protected:
std::string hostname_;
std::string state_str_;
std::string user_context_;
std::vector<uint8_t> addr_bin_;
//@}
};
@ -608,7 +610,7 @@ public:
: lease_(), addr4_(0), client_id_length_(0),
relay_id_length_(0), remote_id_length_(0) {
BOOST_STATIC_ASSERT(9 < LEASE_COLUMNS);
BOOST_STATIC_ASSERT(12 < LEASE_COLUMNS);
memset(hwaddr_buffer_, 0, sizeof(hwaddr_buffer_));
memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
@ -864,10 +866,11 @@ private:
static const int HWTYPE_COL = 13;
static const int HWADDR_SOURCE_COL = 14;
static const int STATE_COL = 15;
static const size_t USER_CONTEXT_COL = 16;
static const int USER_CONTEXT_COL = 16;
static const int BINADDR_COL = 17;
//@}
/// @brief Number of columns in the table holding DHCPv6 leases.
static const size_t LEASE_COLUMNS = 17;
static const size_t LEASE_COLUMNS = 18;
public:
@ -902,7 +905,7 @@ public:
preferred_lifetime_str_(""), hwtype_(0), hwtype_str_(""),
hwaddr_source_(0), hwaddr_source_str_("") {
BOOST_STATIC_ASSERT(15 < LEASE_COLUMNS);
BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
memset(duid_buffer_, 0, sizeof(duid_buffer_));
@ -924,6 +927,7 @@ public:
columns_.push_back("hwaddr_source");
columns_.push_back("state");
columns_.push_back("user_context");
columns_.push_back("binaddr");
}
/// @brief Creates the bind array for sending Lease6 data to the database.
@ -1038,6 +1042,9 @@ public:
user_context_ = "";
}
bind_array.add(user_context_);
addr_bin_ = lease_->addr_.toBytes();
bind_array.add(addr_bin_);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
"Could not create bind array from Lease6: "