From: Slawek Figiel Date: Fri, 7 Apr 2023 14:42:20 +0000 (+0200) Subject: [#2815] Revert BaseHostDataSource inheritance X-Git-Tag: Kea-2.3.8~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab112edb93e62a1569f5b4c335a68effb0499494;p=thirdparty%2Fkea.git [#2815] Revert BaseHostDataSource inheritance --- diff --git a/src/lib/dhcpsrv/host_mgr.cc b/src/lib/dhcpsrv/host_mgr.cc index fbda8a8f8e..b5d7ae53e4 100644 --- a/src/lib/dhcpsrv/host_mgr.cc +++ b/src/lib/dhcpsrv/host_mgr.cc @@ -141,6 +141,14 @@ HostMgr::getAll(const Host::IdentifierType& identifier_type, return (hosts); } +ConstHostCollection +HostMgr::getAll(const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const { + return getAll(identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target) const { ConstHostCollection hosts; @@ -156,6 +164,10 @@ HostMgr::getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target) return (hosts); } +ConstHostCollection +HostMgr::getAll4(const SubnetID& subnet_id) const { + return getAll4(subnet_id, HostMgrOperationTarget::ALL_SOURCES); +} ConstHostCollection HostMgr::getAll6(const SubnetID& subnet_id, const HostMgrOperationTarget target) const { @@ -172,6 +184,11 @@ HostMgr::getAll6(const SubnetID& subnet_id, const HostMgrOperationTarget target) return (hosts); } +ConstHostCollection +HostMgr::getAll6(const SubnetID& subnet_id) const { + return getAll6(subnet_id, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAllbyHostname(const std::string& hostname, const HostMgrOperationTarget target) const { ConstHostCollection hosts; @@ -187,6 +204,11 @@ HostMgr::getAllbyHostname(const std::string& hostname, const HostMgrOperationTar return (hosts); } +ConstHostCollection +HostMgr::getAllbyHostname(const std::string& hostname) const { + return getAllbyHostname(hostname, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id, @@ -205,6 +227,12 @@ HostMgr::getAllbyHostname4(const std::string& hostname, return (hosts); } +ConstHostCollection +HostMgr::getAllbyHostname4(const std::string& hostname, + const SubnetID& subnet_id) const { + return getAllbyHostname4(hostname, subnet_id, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id, @@ -223,6 +251,12 @@ HostMgr::getAllbyHostname6(const std::string& hostname, return (hosts); } +ConstHostCollection +HostMgr::getAllbyHostname6(const std::string& hostname, + const SubnetID& subnet_id) const { + return getAllbyHostname6(hostname, subnet_id, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getPage4(const SubnetID& subnet_id, size_t& source_index, @@ -360,6 +394,11 @@ HostMgr::getAll4(const IOAddress& address, const HostMgrOperationTarget target) return (hosts); } +ConstHostCollection +HostMgr::getAll4(const IOAddress& address) const { + return getAll4(address, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get4Any(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, @@ -415,6 +454,15 @@ HostMgr::get4Any(const SubnetID& subnet_id, return (ConstHostPtr()); } +ConstHostPtr +HostMgr::get4Any(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const { + return get4Any(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, @@ -432,6 +480,15 @@ HostMgr::get4(const SubnetID& subnet_id, return (host); } +ConstHostPtr +HostMgr::get4(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const { + return get4(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get4(const SubnetID& subnet_id, const asiolink::IOAddress& address, @@ -463,6 +520,12 @@ HostMgr::get4(const SubnetID& subnet_id, return (ConstHostPtr()); } +ConstHostPtr +HostMgr::get4(const SubnetID& subnet_id, + const asiolink::IOAddress& address) const { + return get4(subnet_id, address, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAll4(const SubnetID& subnet_id, const asiolink::IOAddress& address, @@ -486,6 +549,12 @@ HostMgr::getAll4(const SubnetID& subnet_id, return (hosts); } +ConstHostCollection +HostMgr::getAll4(const SubnetID& subnet_id, + const asiolink::IOAddress& address) const { + return getAll4(subnet_id, address, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len, const HostMgrOperationTarget target) const { @@ -514,6 +583,11 @@ HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len, return (ConstHostPtr()); } +ConstHostPtr +HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len) const { + return get6(prefix, prefix_len, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get6Any(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, @@ -565,6 +639,15 @@ HostMgr::get6Any(const SubnetID& subnet_id, return (ConstHostPtr()); } +ConstHostPtr +HostMgr::get6Any(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const { + return get6Any(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, @@ -582,6 +665,15 @@ HostMgr::get6(const SubnetID& subnet_id, return (host); } +ConstHostPtr +HostMgr::get6(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const { + return get6(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostPtr HostMgr::get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr, @@ -612,6 +704,12 @@ HostMgr::get6(const SubnetID& subnet_id, return (ConstHostPtr()); } +ConstHostPtr +HostMgr::get6(const SubnetID& subnet_id, + const asiolink::IOAddress& addr) const { + return get6(subnet_id, addr, HostMgrOperationTarget::ALL_SOURCES); +} + ConstHostCollection HostMgr::getAll6(const SubnetID& subnet_id, const asiolink::IOAddress& address, @@ -636,6 +734,12 @@ HostMgr::getAll6(const SubnetID& subnet_id, return (hosts); } +ConstHostCollection +HostMgr::getAll6(const SubnetID& subnet_id, + const asiolink::IOAddress& address) const { + return getAll6(subnet_id, address, HostMgrOperationTarget::ALL_SOURCES); +} + void HostMgr::add(const HostPtr& host, const HostMgrOperationTarget target) { if (target & HostMgrOperationTarget::PRIMARY_SOURCE) { @@ -661,6 +765,11 @@ HostMgr::add(const HostPtr& host, const HostMgrOperationTarget target) { } } +void +HostMgr::add(const HostPtr& host) { + return add(host, HostMgrOperationTarget::ALTERNATE_SOURCES); +} + bool HostMgr::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr, const HostMgrOperationTarget target) { @@ -687,6 +796,11 @@ HostMgr::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr, return (false); } +bool +HostMgr::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) { + return del(subnet_id, addr, HostMgrOperationTarget::ALTERNATE_SOURCES); +} + bool HostMgr::del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, @@ -715,6 +829,13 @@ HostMgr::del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_ return (false); } +bool +HostMgr::del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len) { + return del4(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALTERNATE_SOURCES); +} + bool HostMgr::del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, @@ -743,6 +864,13 @@ HostMgr::del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_ return (false); } +bool +HostMgr::del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len) { + return del6(subnet_id, identifier_type, identifier_begin, identifier_len, + HostMgrOperationTarget::ALTERNATE_SOURCES); +} + void HostMgr::update(HostPtr const& host) { if (alternate_sources_.empty()) { diff --git a/src/lib/dhcpsrv/host_mgr.h b/src/lib/dhcpsrv/host_mgr.h index c399a4ce00..3afd137abc 100644 --- a/src/lib/dhcpsrv/host_mgr.h +++ b/src/lib/dhcpsrv/host_mgr.h @@ -65,7 +65,7 @@ enum HostMgrOperationTarget { /// the use of alternate datasources, e.g. as a result of server's /// reconfiguration. However, the use of the primary host data source (i.e. /// reservations specified in the configuration file) can't be disabled. -class HostMgr : public boost::noncopyable { +class HostMgr : public boost::noncopyable, public BaseHostDataSource { public: /// @brief Creates new instance of the @c HostMgr. @@ -152,7 +152,14 @@ public: getAll(const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll(const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const; /// @brief Return all hosts in a DHCPv4 subnet. /// @@ -171,7 +178,12 @@ public: /// /// @return Collection of const @c Host objects. ConstHostCollection - getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll4(const SubnetID& subnet_id) const; /// @brief Return all hosts in a DHCPv6 subnet. /// @@ -191,7 +203,12 @@ public: /// @return Collection of const @c Host objects. ConstHostCollection getAll6(const SubnetID& subnet_id, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll6(const SubnetID& subnet_id) const; /// @brief Return all hosts with a hostname. /// @@ -204,7 +221,12 @@ public: /// @return Collection of const @c Host objects. ConstHostCollection getAllbyHostname(const std::string& hostname, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAllbyHostname compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAllbyHostname(const std::string& hostname) const; /// @brief Return all hosts with a hostname in a DHCPv4 subnet. /// @@ -218,7 +240,12 @@ public: /// @return Collection of const @c Host objects. ConstHostCollection getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAllbyHostname4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const; /// @brief Return all hosts with a hostname in a DHCPv6 subnet. /// @@ -232,7 +259,12 @@ public: /// @return Collection of const @c Host objects. ConstHostCollection getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAllbyHostname6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const; /// @brief Returns range of hosts in a DHCPv4 subnet. /// @@ -258,7 +290,7 @@ public: /// @param page_size maximum size of the page returned. /// /// @return Host collection (may be empty). - ConstHostCollection + virtual ConstHostCollection getPage4(const SubnetID& subnet_id, size_t& source_index, uint64_t lower_host_id, @@ -288,7 +320,7 @@ public: /// @param page_size maximum size of the page returned. /// /// @return Host collection (may be empty). - ConstHostCollection + virtual ConstHostCollection getPage6(const SubnetID& subnet_id, size_t& source_index, uint64_t lower_host_id, @@ -316,7 +348,7 @@ public: /// @param page_size maximum size of the page returned. /// /// @return Host collection (may be empty). - ConstHostCollection + virtual ConstHostCollection getPage4(size_t& source_index, uint64_t lower_host_id, const HostPageSize& page_size) const; @@ -343,7 +375,7 @@ public: /// @param page_size maximum size of the page returned. /// /// @return Host collection (may be empty). - ConstHostCollection + virtual ConstHostCollection getPage6(size_t& source_index, uint64_t lower_host_id, const HostPageSize& page_size) const; @@ -364,7 +396,12 @@ public: /// @return Collection of const @c Host objects. ConstHostCollection getAll4(const asiolink::IOAddress& address, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll4(const asiolink::IOAddress& address) const; /// @brief Returns any host connected to the IPv4 subnet. /// @@ -387,7 +424,15 @@ public: const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get4Any compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get4Any(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const; /// @brief Returns a host connected to the IPv4 subnet. /// @@ -406,7 +451,13 @@ public: ConstHostPtr get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len) const; /// @brief Returns a host connected to the IPv4 subnet and having /// a reservation for a specified IPv4 address. @@ -422,7 +473,12 @@ public: /// @return Const @c Host object using a specified IPv4 address. ConstHostPtr get4(const SubnetID& subnet_id, const asiolink::IOAddress& address, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const; /// @brief Returns all hosts connected to the IPv4 subnet and having /// a reservation for a specified address. @@ -451,7 +507,13 @@ public: ConstHostCollection getAll4(const SubnetID& subnet_id, const asiolink::IOAddress& address, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll4 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll4(const SubnetID& subnet_id, + const asiolink::IOAddress& address) const; /// @brief Returns any host connected to the IPv6 subnet. /// @@ -474,7 +536,15 @@ public: const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get6Any compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get6Any(const SubnetID& subnet_id, + const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, + const size_t identifier_len) const; /// @brief Returns a host connected to the IPv6 subnet. /// @@ -493,7 +563,13 @@ public: ConstHostPtr get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len) const; /// @brief Returns a host using the specified IPv6 prefix. /// @@ -507,7 +583,12 @@ public: /// @return Const @c Host object using a specified IPv6 prefix. ConstHostPtr get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const; /// @brief Returns a host from specific subnet and reserved address. /// @@ -518,7 +599,12 @@ public: /// @return Const @c host object that has a reservation for specified address. ConstHostPtr get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::get6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostPtr + get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const; /// @brief Returns all hosts connected to the IPv6 subnet and having /// a reservation for a specified address or delegated prefix (lease). @@ -547,7 +633,13 @@ public: ConstHostCollection getAll6(const SubnetID& subnet_id, const asiolink::IOAddress& address, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALL_SOURCES) const; + const HostMgrOperationTarget target) const; + + /// @brief The @c HostMgr::getAll6 compatible with @c BaseHostDataSource + /// interfaces. Operates on all host sources. + virtual ConstHostCollection + getAll6(const SubnetID& subnet_id, + const asiolink::IOAddress& address) const; /// @brief Adds a new host to the alternate data source. /// @@ -556,8 +648,11 @@ public: /// /// @param host Pointer to the new @c Host object being added. /// @param target The host data source being a target of the operation. - void add(const HostPtr& host, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALTERNATE_SOURCES); + void add(const HostPtr& host, const HostMgrOperationTarget target); + + /// @brief The @c HostMgr::add compatible with @c BaseHostDataSource + /// interfaces. Operates on alternate host sources only. + virtual void add(const HostPtr& host); /// @brief Attempts to delete hosts by address. /// @@ -573,7 +668,11 @@ public: /// @param target The host data source being a target of the operation. /// @return true if deletion was successful, false otherwise. bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALTERNATE_SOURCES); + const HostMgrOperationTarget target); + + /// @brief The @c HostMgr::del compatible with @c BaseHostDataSource + /// interfaces. Operates on alternate host sources only. + virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr); /// @brief Attempts to delete a host by (subnet4-id, identifier, /// identifier-type, operation-target) @@ -590,7 +689,13 @@ public: bool del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALTERNATE_SOURCES); + const HostMgrOperationTarget target); + + /// @brief The @c HostMgr::del4 compatible with @c BaseHostDataSource + /// interfaces. Operates on alternate host sources only. + virtual bool + del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len); /// @brief Attempts to delete a host by (subnet6-id, identifier, /// identifier-type, operation-target) @@ -607,7 +712,13 @@ public: bool del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, const size_t identifier_len, - const HostMgrOperationTarget target=HostMgrOperationTarget::ALTERNATE_SOURCES); + const HostMgrOperationTarget target); + + /// @brief The @c HostMgr::del6 compatible with @c BaseHostDataSource + /// interfaces. Operates on alternate host sources only. + virtual bool + del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type, + const uint8_t* identifier_begin, const size_t identifier_len); /// @brief Implements @ref BaseHostDataSource::update() for alternate sources. /// @@ -621,7 +732,7 @@ public: /// Returns the type of the backend (e.g. "mysql", "memfile" etc.) /// /// @return Type of the backend. - std::string getType() const { + virtual std::string getType() const { return (std::string("host_mgr")); } @@ -682,7 +793,7 @@ public: /// unique or can be non-unique. /// @return true if the new setting was accepted by the backend or false /// otherwise. - bool setIPReservationsUnique(const bool unique); + virtual bool setIPReservationsUnique(const bool unique); /// @brief Returns the boolean flag indicating if the IP reservations /// must be unique or can be non-unique. @@ -724,7 +835,7 @@ protected: /// @brief Cache an answer. /// /// @param host Pointer to the missed host. - void cache(ConstHostPtr host) const; + virtual void cache(ConstHostPtr host) const; /// @brief Cache a negative answer. /// @@ -733,7 +844,7 @@ protected: /// @param identifier_type Identifier type. /// @param identifier_begin Pointer to a beginning of the Identifier. /// @param identifier_len Identifier length. - void cacheNegative(const SubnetID& ipv4_subnet_id, + virtual void cacheNegative(const SubnetID& ipv4_subnet_id, const SubnetID& ipv6_subnet_id, const Host::IdentifierType& identifier_type, const uint8_t* identifier_begin, diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index 618dccd577..0754b3217e 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -2972,21 +2972,11 @@ HostMgrTest::getCfgHosts() const { } void -HostMgrTest::addHost4(BaseHostDataSource& host_manager, +HostMgrTest::addHost4(BaseHostDataSource& data_source, const HWAddrPtr& hwaddr, const SubnetID& subnet_id, const IOAddress& address) { - host_manager.add(HostPtr(new Host(hwaddr->toText(false), - "hw-address", subnet_id, SUBNET_ID_UNUSED, - address))); -} - -void -HostMgrTest::addHost4(HostMgr& host_manager, - const HWAddrPtr& hwaddr, - const SubnetID& subnet_id, - const IOAddress& address) { - host_manager.add(HostPtr(new Host(hwaddr->toText(false), + data_source.add(HostPtr(new Host(hwaddr->toText(false), "hw-address", subnet_id, SUBNET_ID_UNUSED, address))); } @@ -3005,19 +2995,6 @@ HostMgrTest::addHost6(BaseHostDataSource& data_source, data_source.add(new_host); } -void -HostMgrTest::addHost6(HostMgr& data_source, - const DuidPtr& duid, - const SubnetID& subnet_id, - const IOAddress& address, - const uint8_t prefix_len) { - HostPtr new_host(new Host(duid->toText(), "duid", SubnetID(1), - subnet_id, IOAddress::IPV4_ZERO_ADDRESS())); - new_host->addReservation(IPv6Resrv(prefix_len == 128 ? IPv6Resrv::TYPE_NA : - IPv6Resrv::TYPE_PD, - address, prefix_len)); - data_source.add(new_host); -} void HostMgrTest::testGetAll(BaseHostDataSource& data_source1, @@ -3287,8 +3264,8 @@ HostMgrTest::testGetAllbyHostnameSubnet6(BaseHostDataSource& data_source1, void HostMgrTest::testGetPage4(bool use_database) { - auto& data_source1 = *getCfgHosts(); - auto& data_source2 = HostMgr::instance(); + BaseHostDataSource& data_source1 = *getCfgHosts(); + BaseHostDataSource& data_source2 = HostMgr::instance(); // Initially, no reservations should be present. size_t idx(0); @@ -3304,11 +3281,8 @@ HostMgrTest::testGetPage4(bool use_database) { // Add two reservations for the same subnet. addHost4(data_source1, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.5")); - if (use_database) { - addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6")); - } else { - addHost4(data_source1, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6")); - } + addHost4(use_database ? data_source2 : data_source1, + hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6")); CfgMgr::instance().commit(); @@ -3372,8 +3346,8 @@ HostMgrTest::testGetPage4(bool use_database) { void HostMgrTest::testGetPage6(bool use_database) { - auto& data_source1 = *getCfgHosts(); - auto& data_source2 = HostMgr::instance(); + BaseHostDataSource& data_source1 = *getCfgHosts(); + BaseHostDataSource& data_source2 = HostMgr::instance(); // Initially, no reservations should be present. size_t idx(0); @@ -3389,13 +3363,8 @@ HostMgrTest::testGetPage6(bool use_database) { // Add two reservations for the same subnet. addHost6(data_source1, duids_[0], SubnetID(1), IOAddress("2001:db8:1::5")); - if (use_database) { - addHost6(data_source2, - duids_[1], SubnetID(1), IOAddress("2001:db8:1::6")); - } else { - addHost6(data_source1, - duids_[1], SubnetID(1), IOAddress("2001:db8:1::6")); - } + addHost6(use_database ? data_source2 : data_source1, + duids_[1], SubnetID(1), IOAddress("2001:db8:1::6")); CfgMgr::instance().commit(); @@ -3463,8 +3432,8 @@ HostMgrTest::testGetPage6(bool use_database) { void HostMgrTest::testGetPage4All(bool use_database) { - auto& data_source1 = *getCfgHosts(); - auto& data_source2 = HostMgr::instance(); + BaseHostDataSource& data_source1 = *getCfgHosts(); + BaseHostDataSource& data_source2 = HostMgr::instance(); // Initially, no reservations should be present. size_t idx(0); @@ -3480,13 +3449,8 @@ HostMgrTest::testGetPage4All(bool use_database) { // Add two reservations. addHost4(data_source1, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.5")); - if (use_database) { - addHost4(data_source2, - hwaddrs_[1], SubnetID(2), IOAddress("192.0.2.6")); - } else { - addHost4(data_source1, + addHost4(use_database ? data_source2 : data_source1, hwaddrs_[1], SubnetID(2), IOAddress("192.0.2.6")); - } CfgMgr::instance().commit(); @@ -3545,8 +3509,8 @@ HostMgrTest::testGetPage4All(bool use_database) { void HostMgrTest::testGetPage6All(bool use_database) { - auto& data_source1 = *getCfgHosts(); - auto& data_source2 = HostMgr::instance(); + BaseHostDataSource& data_source1 = *getCfgHosts(); + BaseHostDataSource& data_source2 = HostMgr::instance(); // Initially, no reservations should be present. size_t idx(0); @@ -3562,13 +3526,8 @@ HostMgrTest::testGetPage6All(bool use_database) { // Add two reservations. addHost6(data_source1, duids_[0], SubnetID(1), IOAddress("2001:db8:1::5")); - if (use_database) { - addHost6(data_source2, - duids_[1], SubnetID(2), IOAddress("2001:db8:1::6")); - } else { - addHost6(data_source1, + addHost6(use_database ? data_source2 : data_source1, duids_[1], SubnetID(2), IOAddress("2001:db8:1::6")); - } CfgMgr::instance().commit(); diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h index 4d15e390f7..c884776b83 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h @@ -724,19 +724,6 @@ protected: const SubnetID& subnet_id, const isc::asiolink::IOAddress& address); - /// @brief Inserts IPv4 reservation into the host manager. - /// - /// @param host_manager Reference to the host manager to which the reservation - /// should be inserted. - /// @param hwaddr Pointer to the hardware address to be associated with the - /// reservation. - /// @param subnet_id IPv4 subnet id. - /// @param address IPv4 address to be reserved. - void addHost4(HostMgr& host_manager, - const HWAddrPtr& hwaddr, - const SubnetID& subnet_id, - const isc::asiolink::IOAddress& address); - /// @brief Inserts IPv6 reservation into the host data source. /// /// @param data_source Reference to the data source to which the reservation @@ -753,22 +740,6 @@ protected: const isc::asiolink::IOAddress& address, const uint8_t prefix_len = 128); -/// @brief Inserts IPv6 reservation into the host manger. - /// - /// @param host_manager Reference to the host manager to which the - // reservation should be inserted. - /// @param duid Pointer to the DUID to be associated with the reservation. - /// @param subnet_id IPv6 subnet id. - /// @param address IPv6 address/prefix to be reserved. - /// @param prefix_len Prefix length. The default value is 128 which - /// indicates that the reservation is for an IPv6 address rather than a - /// prefix. - void addHost6(HostMgr& host_manager, - const DuidPtr& duid, - const SubnetID& subnet_id, - const isc::asiolink::IOAddress& address, - const uint8_t prefix_len = 128); - /// @brief This test verifies that HostMgr returns all reservations for the /// specified HW address. ///