From: Francis Dupont Date: Fri, 14 Oct 2022 00:27:32 +0000 (+0200) Subject: [#2585] Checkpoint: tests to add X-Git-Tag: Kea-2.3.2~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04133ea65a5b24cce5ea99113abe1bd42ab4ea32;p=thirdparty%2Fkea.git [#2585] Checkpoint: tests to add --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index b068d3863e..afabc41851 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -918,6 +918,9 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess(); cfg_db->setAppendedParameters("universe=4"); + if (cfg_db->getExtendedInfoEnabled()) { + cfg_db->setAppendedParameters("extended-info-tables=true"); + } cfg_db->createManagers(); // Reset counters related to connections as all managers have been recreated. srv->getNetworkState()->reset(NetworkState::Origin::DB_CONNECTION); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 48e63333f7..0f8819ec33 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -922,6 +922,9 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) { CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess(); cfg_db->setAppendedParameters("universe=6"); + if (cfg_db->getExtendedInfoEnabled()) { + cfg_db->setAppendedParameters("extended-info-tables=true"); + } cfg_db->createManagers(); // Reset counters related to connections as all managers have been recreated. srv->getNetworkState()->reset(NetworkState::Origin::DB_CONNECTION); diff --git a/src/lib/dhcpsrv/cfg_db_access.cc b/src/lib/dhcpsrv/cfg_db_access.cc index dd843a97c4..0e1deacb3f 100644 --- a/src/lib/dhcpsrv/cfg_db_access.cc +++ b/src/lib/dhcpsrv/cfg_db_access.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2022 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 @@ -23,7 +23,8 @@ namespace dhcp { CfgDbAccess::CfgDbAccess() : appended_parameters_(), lease_db_access_("type=memfile"), - host_db_access_(), ip_reservations_unique_(true) { + host_db_access_(), ip_reservations_unique_(true), + extended_info_enabled_(false) { } std::string diff --git a/src/lib/dhcpsrv/cfg_db_access.h b/src/lib/dhcpsrv/cfg_db_access.h index 6d7bf01629..e04a851f33 100644 --- a/src/lib/dhcpsrv/cfg_db_access.h +++ b/src/lib/dhcpsrv/cfg_db_access.h @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2022 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 @@ -100,6 +100,23 @@ public: return (ip_reservations_unique_); } + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// @param enabled new setting to be used by @c LeaseMgr. + void setExtendedInfoEnabled(const bool enabled) { + extended_info_enabled_ = enabled; + } + + /// @brief Returns the setting indicating if lease extended info tables + /// are enabled. + /// + /// @return true if lease extended info tables are enabled or false + /// if they are disabled. + bool getExtendedInfoEnabled() const { + return (extended_info_enabled_); + } + /// @brief Creates instance of lease manager and host data sources /// according to the configuration specified. void createManagers() const; @@ -124,6 +141,10 @@ protected: /// @brief Holds the setting whether IP reservations should be unique /// or can be non-unique. bool ip_reservations_unique_; + + /// @brief Holds the setting whether the lease extended info tables + /// are enabled or disabled. The default is disabled. + bool extended_info_enabled_; }; /// @brief A pointer to the @c CfgDbAccess. diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 79932603f6..4b314ae2ea 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -224,7 +224,7 @@ class LeaseMgr { public: /// @brief Constructor /// - LeaseMgr() + LeaseMgr() : extended_info_enabled_(false) {} /// @brief Destructor @@ -924,6 +924,56 @@ public: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) = 0; + /// @brief Delete lease6 extended info from tables. + /// + /// @param addr The address of the lease. + virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) = 0; + + /// @brief Add lease6 extended info into by-relay-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the relay header. + /// @param relay_id The relay id from the relay header options. + virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& relay_id) = 0; + + /// @brief Add lease6 extended info into by-remote-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + /// @param remote_id The remote id from the relay header options. + virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& remote_id) = 0; + + /// @brief Add lease6 extended info into by-link-addr table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) = 0; + + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// @note This method is virtual so backend doing specific action + /// on value changes can intercept it by redefining it. + /// + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) { + extended_info_enabled_ = enabled; + } + + /// @brief Returns the setting indicating if lease extended info tables + /// are enabled. + /// + /// @return true if lease extended info tables are enabled or false + /// if they are disabled. + bool getExtendedInfoEnabled() const { + return (extended_info_enabled_); + } + /// @brief Write V4 leases to a file. /// /// @param filename File name to write leases. @@ -937,6 +987,10 @@ public: private: /// The IOService object, used for all ASIO operations. static isc::asiolink::IOServicePtr io_service_; + + /// @brief Holds the setting whether the lease extended info tables + /// are enabled or disabled. The default is disabled. + bool extended_info_enabled_; }; } // namespace dhcp diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 6cb209445d..7215c237ee 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -638,6 +638,19 @@ Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& param : LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) { bool conversion_needed = false; + // Check if the extended info tables are enabled. + bool extended_info_enabled = false; + std::string extended_info_tables; + try { + extended_info_tables = conn_.getParameter("extended-info-tables"); + } catch (const Exception&) { + extended_info_tables = "false"; + } + // If extended_info_tables is 'true' we will enable them. + if (extended_info_tables == "true") { + setExtendedInfoEnabled(true); + } + // Check the universe and use v4 file or v6 file. std::string universe = conn_.getParameter("universe"); if (universe == "4") { @@ -1831,13 +1844,19 @@ Memfile_LeaseMgr::loadLeasesFromFiles(const std::string& filename, // Ignore and default to 0. } - uint32_t max_row_errors = 0; + int64_t max_row_errors64; try { - max_row_errors = boost::lexical_cast(max_row_errors_str); + max_row_errors64 = boost::lexical_cast(max_row_errors_str); } catch (const boost::bad_lexical_cast&) { isc_throw(isc::BadValue, "invalid value of the max-row-errors " << max_row_errors_str << " specified"); } + if ((max_row_errors64 < 0) || + (max_row_errors64 > std::numeric_limits::max())) { + isc_throw(isc::BadValue, "invalid value of the max-row-errors " + << max_row_errors_str << " specified"); + } + uint32_t max_row_errors = static_cast(max_row_errors64); // Load the leasefile.completed, if exists. bool conversion_needed = false; @@ -2406,26 +2425,186 @@ Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& /* remote_id */, } Lease6Collection -Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */, - const IOAddress& /* link_addr */, - const IOAddress& /* lower_bound_address */, - const LeasePageSize& /* page_size */) { - isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByRelayId not implemented"); +Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id, + const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { + const std::vector& relay_id_data = relay_id.getDuid(); + Lease6Collection collection; + if (link_addr.isV6Zero()) { + const RelayIdIndex& idx = relay_id6_.get(); + RelayIdIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(relay_id_data, + lower_bound_address)); + + // Return all leases being within the page size. + IOAddress last_addr = lower_bound_address; + for (; lb != idx.end(); ++lb) { + if ((*lb)->lease_addr_ == last_addr) { + // Already seen: skip it. + continue; + } + last_addr = (*lb)->lease_addr_; + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr); + if (lease) { + collection.push_back(lease); + if (collection.size() >= page_size.page_size_) { + break; + } + } + } + } else { + const RelayIdLinkAddressIndex& idx = + relay_id6_.get(); + RelayIdLinkAddressIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(relay_id_data, + link_addr, + lower_bound_address)); + + // Return all leases being within the page size. + IOAddress last_addr = lower_bound_address; + for (; lb != idx.end(); ++lb) { + if ((*lb)->lease_addr_ == last_addr) { + // Already seen: skip it. + continue; + } + last_addr = (*lb)->lease_addr_; + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr); + if (lease) { + collection.push_back(lease); + if (collection.size() >= page_size.page_size_) { + break; + } + } + } + } + return (collection); } Lease6Collection -Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, - const IOAddress& /* link_addr */, - const IOAddress& /* lower_bound_address */, - const LeasePageSize& /* page_size*/) { - isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByRemoteId not implemented"); +Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id, + const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { + Lease6Collection collection; + std::set sorted; + if (link_addr.isV6Zero()) { + const RemoteIdIndex& idx = remote_id6_.get(); + RemoteIdIndexRange er = idx.equal_range(remote_id); + + // Store all addresses greater than lower_bound_address. + for (auto it = er.first; it != er.second; ++it) { + const IOAddress& addr = (*it)->lease_addr_; + if (addr <= lower_bound_address) { + continue; + } + static_cast(sorted.insert(addr)); + } + + // Return all leases being within the page size. + for (const IOAddress& addr : sorted) { + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, addr); + if (lease) { + collection.push_back(lease); + if (collection.size() >= page_size.page_size_) { + break; + } + } + } + } else { + const RemoteIdLinkAddressIndex& idx = + remote_id6_.get(); + RemoteIdLinkAddressRange er = + idx.equal_range(boost::make_tuple(remote_id, link_addr)); + + // Store all addresses greater than lower_bound_address. + for (auto it = er.first; it != er.second; ++it) { + const IOAddress& addr = (*it)->lease_addr_; + if (addr <= lower_bound_address) { + continue; + } + static_cast(sorted.insert(addr)); + } + + // Return all leases being within the page size. + for (const IOAddress& addr : sorted) { + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, addr); + if (lease) { + collection.push_back(lease); + if (collection.size() >= page_size.page_size_) { + break; + } + } + } + } + return (collection); } Lease6Collection -Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */, - const IOAddress& /* lower_bound_address */, - const LeasePageSize& /* page_size */) { - isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByLink not implemented"); +Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size) { + Lease6Collection collection; + const LinkAddressIndex& idx = link_addr6_.get(); + LinkAddressIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(link_addr, lower_bound_address)); + + // Return all leases being within the page size. + IOAddress last_addr = lower_bound_address; + for (; lb != idx.end(); ++lb) { + if ((*lb)->lease_addr_ == last_addr) { + // Already seen: skip it. + continue; + } + last_addr = (*lb)->lease_addr_; + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr); + if (lease) { + collection.push_back(lease); + if (collection.size() >= page_size.page_size_) { + break; + } + } + } + return (collection); +} + +void +Memfile_LeaseMgr::deleteExtendedInfo6(const IOAddress& addr) { + LeaseAddressRelayIdIndex& relay_id_idx = + relay_id6_.get(); + static_cast(relay_id_idx.erase(addr)); + LeaseAddressRemoteIdIndex& remote_id_idx = + remote_id6_.get(); + static_cast(remote_id_idx.erase(addr)); + LeaseAddressLinkAddressIndex& link_addr_idx = + link_addr6_.get(); + static_cast(link_addr_idx.erase(addr)); +} + +void +Memfile_LeaseMgr::addRelayId6(const IOAddress& lease_addr, + const IOAddress& link_addr, + const std::vector& relay_id) { + Lease6ExtendedInfoPtr ex_info; + ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_addr, relay_id)); + relay_id6_.insert(ex_info); +} + +void +Memfile_LeaseMgr::addRemoteId6(const IOAddress& lease_addr, + const IOAddress& link_addr, + const std::vector& remote_id) { + Lease6ExtendedInfoPtr ex_info; + ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_addr, remote_id)); + remote_id6_.insert(ex_info); +} + +void +Memfile_LeaseMgr::addLinkAddr6(const IOAddress& lease_addr, + const IOAddress& link_addr) { + Lease6SimpleExtendedInfoPtr ex_info; + ex_info.reset(new Lease6SimpleExtendedInfo(lease_addr, link_addr)); + link_addr6_.insert(ex_info); } void diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 6d119c7076..16d098c974 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -1066,6 +1066,15 @@ private: /// @brief stores IPv6 leases Lease6Storage storage6_; + /// @brief stores IPv6 by-relay-id cross-reference table + Lease6ExtendedInfoRelayIdTable relay_id6_; + + /// @brief stores IPv6 by-remote-id cross-reference table + Lease6ExtendedInfoRemoteIdTable remote_id6_; + + /// @brief stores IPv6 by-link-addr cross-reference table + Lease6SimpleExtendedInfoLinkAddrTable link_addr6_; + protected: /// @brief Holds the pointer to the DHCPv4 lease file IO. boost::shared_ptr lease_file4_; @@ -1358,6 +1367,36 @@ public: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; + /// @brief Delete lease6 extended info from tables. + /// + /// @param addr The address of the lease. + virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override; + + /// @brief Add lease6 extended info into by-relay-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the relay header. + /// @param relay_id The relay id from the relay header options. + virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& relay_id) override; + + /// @brief Add lease6 extended info into by-remote-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + /// @param remote_id The remote id from the relay header options. + virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& remote_id) override; + + /// @brief Add lease6 extended info into by-link-addr table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) override; + /// @brief Write V4 leases to a file. /// /// @param filename File name to write leases. diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 33380b0a6d..f4544c317b 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -19,6 +19,7 @@ #include #include +#include #include namespace isc { @@ -330,9 +331,10 @@ struct RemoteIdIndexTag { }; /// @brief A multi index container holding lease6 extended info for by relay id. /// /// The lease6 extended info may be accessed using different indexes: -/// - using a composite index: relay id and link address. -/// - using relay id. -/// - using lease address. +/// - using a composite index: relay id and link address, and lease address +/// for getting lower bounds. +/// - using relay id, and lease address for getting lower bounds. +/// - using lease address for deletes. /// /// The choice of binary trees was governed by the fact a large number of /// clients can be behind a relay. @@ -344,7 +346,7 @@ typedef boost::multi_index_container< // It holds pointers to lease6 extended info. Lease6ExtendedInfoPtr, boost::multi_index::indexed_by< - // First index is by relay id and link address. + // First index is by relay id, link and lease addresses. boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::composite_key< @@ -354,16 +356,25 @@ typedef boost::multi_index_container< &Lease6ExtendedInfo::id_>, boost::multi_index::member + &Lease6ExtendedInfo::link_addr_>, + boost::multi_index::member > >, - // Second index is by relay id. + // Second index is by relay id and lease address. boost::multi_index::ordered_non_unique< boost::multi_index::tag, - boost::multi_index::member, - &Lease6ExtendedInfo::id_> + boost::multi_index::composite_key< + Lease6ExtendedInfo, + boost::multi_index::member, + &Lease6ExtendedInfo::id_>, + boost::multi_index::member + > >, // Last index is by lease address. @@ -381,7 +392,7 @@ typedef boost::multi_index_container< /// The lease6 extended info may be accessed using different indexes: /// - using a composite index: remote id and link address. /// - using remote id. -/// - using lease address. +/// - using lease address for deletes. /// /// The internal layout of remote id is not used. The choice of hash tables /// was governed by the fact a small number of clients should share the same @@ -426,6 +437,39 @@ typedef boost::multi_index_container< > > Lease6ExtendedInfoRemoteIdTable; +/// @brief Lease6 extended information by relay id and link address index. +typedef Lease6ExtendedInfoRelayIdTable::index::type + RelayIdLinkAddressIndex; + +/// @brief Lease6 extended information by relay id index. +typedef Lease6ExtendedInfoRelayIdTable::index::type + RelayIdIndex; + +/// @brief Lease6 extended information by lease address index of by relay id table. +typedef Lease6ExtendedInfoRelayIdTable::index::type + LeaseAddressRelayIdIndex; + +/// @brief Lease6 extended information by remote id and link address index. +typedef Lease6ExtendedInfoRemoteIdTable::index::type + RemoteIdLinkAddressIndex; + +/// @brief Lease6 extended information by remote id index. +typedef Lease6ExtendedInfoRemoteIdTable::index::type + RemoteIdIndex; + +/// @brief Lease6 extended information by remote id and link address range. +typedef std::pair + RemoteIdLinkAddressRange; + +/// @brief Lease6 extended information by remote id range. +typedef std::pair + RemoteIdIndexRange; + +/// @brief Lease6 extended information by lease address index of by remote id table. +typedef Lease6ExtendedInfoRemoteIdTable::index::type + LeaseAddressRemoteIdIndex; + /// @brief Lease6 extended informations for Bulk Lease Query, /// simpler version (2 fields vs 3) for by link address table. class Lease6SimpleExtendedInfo { @@ -456,8 +500,9 @@ struct LinkAddressIndexTag { }; /// for by link address. /// /// The lease6 extended info may be accessed using different indexes: -/// - using a composite index: link and lease addresses. -/// - using lease address. +/// - using a composite index: link and lease addresses, the second for +/// getting lower bounds. +/// - using lease address for deletes. /// /// The choice of a binary tree was governed by the fact no hypothesis can /// be done on the number of clients. @@ -493,6 +538,14 @@ typedef boost::multi_index_container< > > Lease6SimpleExtendedInfoLinkAddrTable; +/// @brief Lease6 extended information by link address. +typedef Lease6SimpleExtendedInfoLinkAddrTable::index::type + LinkAddressIndex; + +/// @brief Lease6 extended information by lease address index of by link address table. +typedef Lease6SimpleExtendedInfoLinkAddrTable::index::type + LeaseAddressLinkAddressIndex; + //@} } // end of isc::dhcp namespace diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 70438a7afc..7377017c61 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -1799,6 +1799,18 @@ MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() { MySqlLeaseMgr::MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters) : parameters_(parameters), timer_name_("") { + // Check if the extended info tables are enabled. + std::string extended_info_tables; + try { + extended_info_tables = parameters_.at("extended-info-tables"); + } catch (const exception&) { + extended_info_tables = "false"; + } + // If extended_info_tables is 'true' we will enable them. + if (extended_info_tables == "true") { + setExtendedInfoEnabled(true); + } + // Create unique timer name per instance. timer_name_ = "MySqlLeaseMgr["; timer_name_ += boost::lexical_cast(reinterpret_cast(this)); @@ -3362,6 +3374,31 @@ MySqlLeaseMgr::checkError(MySqlLeaseContextPtr& ctx, ctx->conn_.checkError(status, index, what); } +void +MySqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) { + isc_throw(NotImplemented, "MySqlLeaseMgr::deleteExtendedInfo6 not implemented"); +} + +void +MySqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& relay_id) { + isc_throw(NotImplemented, "MySqlLeaseMgr::addRelayId6 not implemented"); +} + +void +MySqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& remote_id) { + isc_throw(NotImplemented, "MySqlLeaseMgr::addRemoteId6 not implemented"); +} + +void +MySqlLeaseMgr::addLinkAddr6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */) { + isc_throw(NotImplemented, "MySqlLeaseMgr::addLinkAddr6 not implemented"); +} + Lease4Collection MySqlLeaseMgr::getLeases4ByRelayId(const OptionBuffer& /* relay_id */, const IOAddress& /* lower_bound_address */, diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h index 15e08286d0..ff62eadab5 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h @@ -1103,6 +1103,48 @@ private: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; + /// @brief Delete lease6 extended info from tables. + /// + /// @param addr The address of the lease. + virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override; + + /// @brief Add lease6 extended info into by-relay-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the relay header. + /// @param relay_id The relay id from the relay header options. + virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& relay_id) override; + + /// @brief Add lease6 extended info into by-remote-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + /// @param remote_id The remote id from the relay header options. + virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& remote_id) override; + + /// @brief Add lease6 extended info into by-link-addr table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) override; + + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// Transient redefine to refuse the enable setting. + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) override { + if (enabled) { + isc_throw(isc::NotImplemented, + "extended info tables are not yet supported by mysql"); + } + } + /// @brief Context RAII Allocator. class MySqlLeaseContextAlloc { public: diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index 611fcbcc6e..b324b86ae6 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -1255,6 +1255,18 @@ PgSqlLeaseMgr::PgSqlLeaseContextAlloc::~PgSqlLeaseContextAlloc() { PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters) : parameters_(parameters), timer_name_("") { + // Check if the extended info tables are enabled. + std::string extended_info_tables; + try { + extended_info_tables = parameters_.at("extended-info-tables"); + } catch (const exception&) { + extended_info_tables = "false"; + } + // If extended_info_tables is 'true' we will enable them. + if (extended_info_tables == "true") { + setExtendedInfoEnabled(true); + } + // Create unique timer name per instance. timer_name_ = "PgSqlLeaseMgr["; timer_name_ += boost::lexical_cast(reinterpret_cast(this)); @@ -2556,6 +2568,31 @@ PgSqlLeaseMgr::rollback() { LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_ROLLBACK); } +void +PgSqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) { + isc_throw(NotImplemented, "PgSqlLeaseMgr::deleteExtendedInfo6 not implemented"); +} + +void +PgSqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& relay_id) { + isc_throw(NotImplemented, "PgSqlLeaseMgr::addRelayId6 not implemented"); +} + +void +PgSqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& remote_id) { + isc_throw(NotImplemented, "PgSqlLeaseMgr::addRemoteId6 not implemented"); +} + +void +PgSqlLeaseMgr::addLinkAddr6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */) { + isc_throw(NotImplemented, "PgSqlLeaseMgr::addLinkAddr6 not implemented"); +} + Lease4Collection PgSqlLeaseMgr::getLeases4ByRelayId(const OptionBuffer& /* relay_id */, const IOAddress& /* lower_bound_address */, diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.h b/src/lib/dhcpsrv/pgsql_lease_mgr.h index 999c58d7bd..afb0082f34 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.h +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.h @@ -1056,12 +1056,54 @@ private: const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; + /// @brief Delete lease6 extended info from tables. + /// + /// @param addr The address of the lease. + virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override; + + /// @brief Add lease6 extended info into by-relay-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the relay header. + /// @param relay_id The relay id from the relay header options. + virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& relay_id) override; + + /// @brief Add lease6 extended info into by-remote-id table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + /// @param remote_id The remote id from the relay header options. + virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& remote_id) override; + + /// @brief Add lease6 extended info into by-link-addr table. + /// + /// @param lease_addr The address of the lease. + /// @param link_addr The link address from the remote header. + virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) override; + /// @brief Write V4 leases to a file. virtual void writeLeases4(const std::string& /*filename*/) override; /// @brief Write V6 leases to a file. virtual void writeLeases6(const std::string& /*filename*/) override; + /// @brief Modifies the setting whether the lease extended info tables + /// are enabled. + /// + /// Transient redefine to refuse the enable setting. + /// @param enabled new setting. + virtual void setExtendedInfoEnabled(const bool enabled) override { + if (enabled) { + isc_throw(isc::NotImplemented, + "extended info tables are not yet supported by postgresql"); + } + } + /// @brief Context RAII Allocator. class PgSqlLeaseContextAlloc { public: diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc index 328d78915f..8414ca5aca 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc @@ -397,6 +397,35 @@ public: isc_throw(NotImplemented, "ConcreteLeaseMgr::clearClassLeaseCounts() not implemented"); } + /// @brief Stub implementation. + void + deleteExtendedInfo6(const IOAddress& /* addr */) override { + isc_throw(NotImplemented, "ConcreteLeaseMgr::deleteExtendedInfo6 not implemented"); + } + + /// @brief Stub implementation. + void + addRelayId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& relay_id) override { + isc_throw(NotImplemented, "ConcreteLeaseMgr::addRelayId6 not implemented"); + } + + /// @brief Stub implementation. + void + addRemoteId6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */, + const vector& remote_id) override { + isc_throw(NotImplemented, "ConcreteLeaseMgr::addRemoteId6 not implemented"); + } + + /// @brief Stub implementation. + void + addLinkAddr6(const IOAddress& /* lease_addr */, + const IOAddress& /* link_addr */) override { + isc_throw(NotImplemented, "ConcreteLeaseMgr::addLinkAddr6 not implemented"); + } + /// @brief Stub implementation. Lease4Collection getLeases4ByRelayId(const OptionBuffer& /* relay_id */, diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 0c923a6602..102896b1da 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -400,16 +400,19 @@ TEST_F(MemfileLeaseMgrTest, constructor) { EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); - pmap["lfc-interval"] = "10"; - pmap["persist"] = "true"; - pmap["name"] = getLeaseFilePath("leasefile4_1.csv"); - pmap["max-row-errors"] = "5"; + // Check the extended info enable flag. + EXPECT_FALSE(lease_mgr->getExtendedInfoEnabled()); + pmap["extended-info-tables"] = "true"; EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); + EXPECT_TRUE(lease_mgr->getExtendedInfoEnabled()); // Expecting that persist parameter is yes or no. Everything other than // that is wrong. - pmap["persist"] = "bogus"; + pmap["lfc-interval"] = "10"; + pmap["name"] = getLeaseFilePath("leasefile4_1.csv"); + pmap["max-row-errors"] = "5"; pmap["name"] = getLeaseFilePath("leasefile4_1.csv"); + pmap["persist"] = "bogus"; EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue); // The lfc-interval must be an integer. @@ -418,14 +421,17 @@ TEST_F(MemfileLeaseMgrTest, constructor) { EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue); // The max-row-errors must be an integer. - pmap["persist"] = "true"; + pmap["lfc-interval"] = "10"; pmap["max-row-errors"] = "bogus"; EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue); // The max-row-errors must be >= 0. - pmap["persist"] = "true"; pmap["max-row-errors"] = "-1"; EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue); + + // Moved to the end as it can leave the timer registered. + pmap["max-row-errors"] = "5"; + EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); } /// @brief Checks if there is no lease manager NoLeaseManager is thrown. diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 0b4f839abf..66473b2331 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -126,6 +126,8 @@ TEST(MySqlOpenTest, OpenDatabase) { try { LeaseMgrFactory::create(validMySQLConnectionString()); EXPECT_NO_THROW((void)LeaseMgrFactory::instance()); + EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true), + NotImplemented); LeaseMgrFactory::destroy(); } catch (const isc::Exception& ex) { FAIL() << "*** ERROR: unable to open database, reason:\n" diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 84d8d20416..8233cd0b5d 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -126,6 +126,8 @@ TEST(PgSqlOpenTest, OpenDatabase) { try { LeaseMgrFactory::create(validPgSQLConnectionString()); EXPECT_NO_THROW((void)LeaseMgrFactory::instance()); + EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true), + NotImplemented); LeaseMgrFactory::destroy(); } catch (const isc::Exception& ex) { FAIL() << "*** ERROR: unable to open database, reason:\n"