2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-04 16:05:17 +00:00

[#2868] Implemented getLeases6ByLink

This commit is contained in:
Francis Dupont
2023-05-24 02:21:08 +02:00
parent 9d33293c69
commit 02b5540f79
9 changed files with 468 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
#include <config.h>
#include <asiolink/io_address.h>
#include <asiolink/addr_utilities.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/cfg_db_access.h>
@@ -401,6 +401,18 @@ tagged_statements = { {
"AND expire < ? "
"ORDER BY expire ASC "
"LIMIT ?"},
{MySqlLeaseMgr::GET_LEASE6_LINK,
"SELECT 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 "
"FROM lease6 "
"WHERE binaddr IS NOT NULL "
"AND binaddr BETWEEN ? AND ? "
"ORDER BY binaddr "
"LIMIT ?"},
{MySqlLeaseMgr::INSERT_LEASE4,
"INSERT INTO lease4(address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
@@ -4031,11 +4043,87 @@ MySqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */,
}
Lease6Collection
MySqlLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
uint8_t /* link_len */,
const IOAddress& /* lower_bound_address */,
const LeasePageSize& /* page_size */) {
isc_throw(NotImplemented, "MySqlLeaseMgr::getLeases6ByLink not implemented");
MySqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
uint8_t link_len,
const IOAddress& lower_bound_address,
const LeasePageSize& page_size) {
// Expecting IPv6 valid prefix and address.
if (!link_addr.isV6()) {
isc_throw(InvalidAddressFamily, "expected IPv6 address while "
"retrieving leases from the lease database, got "
<< link_addr);
}
if ((link_len == 0) || (link_len > 128)) {
isc_throw(OutOfRange, "invalid IPv6 prefix length "
<< static_cast<unsigned>(link_len));
}
if (!lower_bound_address.isV6()) {
isc_throw(InvalidAddressFamily, "expected IPv6 address while "
"retrieving leases from the lease database, got "
<< lower_bound_address);
}
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_GET_LINKADDR6)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText())
.arg(link_addr.toText())
.arg(static_cast<unsigned>(link_len));
Lease6Collection result;
const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len);
const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len);
IOAddress start_addr = lower_bound_address;
if (lower_bound_address < first_addr) {
start_addr = first_addr;
} else if (last_addr <= lower_bound_address) {
// Range was already done.
return (result);
} else {
// The lower bound address is from the last call so skip it.
start_addr = IOAddress::increase(lower_bound_address);
}
// Prepare WHERE clause
MYSQL_BIND inbind[3];
memset(inbind, 0, sizeof(inbind));
// Bind start address
std::vector<uint8_t> start_addr_data = start_addr.toBytes();
if (start_addr_data.size() != 16) {
isc_throw(DbOperationError, "start address is not 16 byte long");
}
unsigned long start_addr_size = 16;
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
inbind[0].buffer = reinterpret_cast<char*>(&start_addr_data[0]);
inbind[0].buffer_length = 16;
inbind[0].length = &start_addr_size;
// Bind last address
std::vector<uint8_t> last_addr_data = last_addr.toBytes();
if (last_addr_data.size() != 16) {
isc_throw(DbOperationError, "last address is not 16 byte long");
}
unsigned long last_addr_size = 16;
inbind[1].buffer_type = MYSQL_TYPE_BLOB;
inbind[1].buffer = reinterpret_cast<char*>(&last_addr_data[0]);
inbind[1].buffer_length = 16;
inbind[1].length = &last_addr_size;
// Bind page size value
uint32_t ps = static_cast<uint32_t>(page_size.page_size_);
inbind[2].buffer_type = MYSQL_TYPE_LONG;
inbind[2].buffer = reinterpret_cast<char*>(&ps);
inbind[2].is_unsigned = MLM_TRUE;
// Get a context
MySqlLeaseContextAlloc get_context(*this);
MySqlLeaseContextPtr ctx = get_context.ctx_;
// Get the leases
getLeaseCollection(ctx, GET_LEASE6_LINK, inbind, result);
return (result);
}
size_t