diff options
author | Francis Dupont <fdupont@isc.org> | 2023-12-14 15:21:15 +0100 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2024-01-17 11:06:16 +0100 |
commit | 032a8ad465b57d7ffeb119c34c3e5606f81c57bf (patch) | |
tree | 03a92d3721a5a8686252c4d285bd6e27a192aa95 /src/lib/dhcpsrv/memfile_lease_mgr.cc | |
parent | [#3149] Fixed mysql admin tests (diff) | |
download | kea-032a8ad465b57d7ffeb119c34c3e5606f81c57bf.tar.xz kea-032a8ad465b57d7ffeb119c34c3e5606f81c57bf.zip |
[#3149] Rewrote getLeases6ByLink
Diffstat (limited to 'src/lib/dhcpsrv/memfile_lease_mgr.cc')
-rw-r--r-- | src/lib/dhcpsrv/memfile_lease_mgr.cc | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 3c63422619..eb4ab39408 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -3172,27 +3172,16 @@ Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, } Lease6Collection -Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, - uint8_t link_len, +Memfile_LeaseMgr::getLeases6ByLink(SubnetID subnet_id, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_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 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 address while " "retrieving leases from the lease database, got " @@ -3201,46 +3190,40 @@ Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, if (MultiThreadingMgr::instance().getMode()) { std::lock_guard<std::mutex> lock(*mutex_); - return (getLeases6ByLinkInternal(link_addr, - link_len, + return (getLeases6ByLinkInternal(subnet_id, lower_bound_address, page_size)); } else { - return (getLeases6ByLinkInternal(link_addr, - link_len, + return (getLeases6ByLinkInternal(subnet_id, lower_bound_address, page_size)); } } Lease6Collection -Memfile_LeaseMgr::getLeases6ByLinkInternal(const IOAddress& link_addr, - uint8_t link_len, +Memfile_LeaseMgr::getLeases6ByLinkInternal(SubnetID subnet_id, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { - const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len); - const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len); - const IOAddress& start_addr = - (lower_bound_address < first_addr ? first_addr : lower_bound_address); Lease6Collection collection; - const Lease6StorageAddressIndex& idx = storage6_.get<AddressIndexTag>(); - Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(start_addr); - Lease6StorageAddressIndex::const_iterator eb = idx.upper_bound(last_addr); + const Lease6StorageSubnetIdIndex& idx = storage6_.get<SubnetIdIndexTag>(); + Lease6StorageSubnetIdIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(subnet_id, lower_bound_address)); // Return all leases being within the page size. - IOAddress last_seen_addr = lower_bound_address; - for (auto it = lb; it != eb; ++it) { - if ((*it)->addr_ == last_seen_addr) { + IOAddress last_addr = lower_bound_address; + for (auto it = lb; it != idx.end(); ++it) { + if ((*it)->addr_ == last_addr) { // Already seen: skip it. continue; } - last_seen_addr = (*it)->addr_; - Lease6Ptr lease = getAnyLease6Internal(last_seen_addr); - if (lease) { - collection.push_back(lease); - if (collection.size() >= page_size.page_size_) { - break; - } + if ((*it)->subnet_id_ != subnet_id) { + // Gone after the subnet id index. + break; + } + last_addr = (*it)->addr_; + collection.push_back(Lease6Ptr(new Lease6(**it))); + if (collection.size() >= page_size.page_size_) { + break; } } return (collection); |