2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 22:45:18 +00:00

[#3149] Rewrote getLeases6ByLink

This commit is contained in:
Francis Dupont
2023-12-14 15:21:15 +01:00
parent d73fc1466d
commit 032a8ad465
14 changed files with 104 additions and 188 deletions

View File

@@ -398,7 +398,7 @@ tagged_statements = { {
"hwaddr, hwtype, hwaddr_source, "
"state, user_context, pool_id "
"FROM lease6 "
"WHERE address BETWEEN ? AND ? "
"WHERE subnet_id = ? AND address > ? "
"ORDER BY address "
"LIMIT ?"},
{MySqlLeaseMgr::INSERT_LEASE4,
@@ -4468,27 +4468,16 @@ MySqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id,
}
Lease6Collection
MySqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
uint8_t link_len,
MySqlLeaseMgr::getLeases6ByLink(SubnetID subnet_id,
const IOAddress& lower_bound_address,
const LeasePageSize& page_size) {
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));
.arg(subnet_id);
// Expecting IPv6 valid prefix and address.
if (!link_addr.isV6()) {
isc_throw(InvalidAddressFamily, "expected IPv6 link 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));
}
// Expecting IPv6 valid address.
if (!lower_bound_address.isV6()) {
isc_throw(InvalidAddressFamily, "expected IPv6 start address while "
"retrieving leases from the lease database, got "
@@ -4496,44 +4485,25 @@ MySqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
}
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 bytes 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 the subnet id.
inbind[0].buffer_type = MYSQL_TYPE_LONG;
inbind[0].buffer = reinterpret_cast<char*>(&subnet_id);
inbind[0].is_unsigned = MLM_TRUE;
// 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 bytes long");
// Bind the lower bound address.
std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
unsigned long lb_addr_size = lb_addr_data.size();
if (lb_addr_size != 16) {
isc_throw(DbOperationError, "lower bound address is not 16 bytes 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;
inbind[1].buffer = reinterpret_cast<char*>(&lb_addr_data[0]);
inbind[1].buffer_length = lb_addr_size;
inbind[1].length = &lb_addr_size;
// Bind page size value
uint32_t ps = static_cast<uint32_t>(page_size.page_size_);