From: Francis Dupont Date: Mon, 11 Feb 2019 12:59:21 +0000 (+0100) Subject: [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared getOption* X-Git-Tag: 397-cb-implement-mysqlconfigbackenddhcpv6_base~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a0db6c5182f86401ed97cfc68ef10b0d186ed98;p=thirdparty%2Fkea.git [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared getOption* --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 0a35a9d354..590f874192 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -1588,23 +1588,8 @@ public: OptionDescriptorPtr getOption4(const ServerSelector& server_selector, const uint16_t code, const std::string& space) { - - if (server_selector.amUnassigned()) { - isc_throw(NotImplemented, "managing configuration for no particular server" - " (unassigned) is unsupported at the moment"); - } - - auto tag = getServerTag(server_selector, "fetching global option"); - - OptionContainer options; - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag), - MySqlBinding::createInteger(static_cast(code)), - MySqlBinding::createString(space) - }; - getOptions(GET_OPTION4_CODE_SPACE, in_bindings, Option::V4, options); - return (options.empty() ? OptionDescriptorPtr() : - OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); + return (getOption(GET_OPTION4_CODE_SPACE, Option::V4, + server_selector, code, space));; } /// @brief Sends query to retrieve all global options. @@ -1613,18 +1598,8 @@ public: /// @return Container holding returned options. OptionContainer getAllOptions4(const ServerSelector& server_selector) { - OptionContainer options; - - auto tags = getServerTags(server_selector); - for (auto tag : tags) { - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag) - }; - getOptions(MySqlConfigBackendDHCPv4Impl::GET_ALL_OPTIONS4, - in_bindings, Option::V4, options); - } - - return (options); + return (getAllOptions(MySqlConfigBackendDHCPv4Impl::GET_ALL_OPTIONS4, + Option::V4, server_selector)); } /// @brief Sends query to retrieve global options with modification @@ -1635,23 +1610,12 @@ public: OptionContainer getModifiedOptions4(const ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) { - OptionContainer options; - - auto tags = getServerTags(server_selector); - for (auto tag : tags) { - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag), - MySqlBinding::createTimestamp(modification_time) - }; - getOptions(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_OPTIONS4, - in_bindings, Option::V4, options); - } - - return (options); + return (getModifiedOptions(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_OPTIONS4, + Option::V4, server_selector, modification_time)); } /// @brief Sends query to retrieve single option by code and option space - /// for a giben subnet id. + /// for a given subnet id. /// /// @param server_selector Server selector. /// @param subnet_id Subnet identifier. @@ -1664,25 +1628,8 @@ public: const SubnetID& subnet_id, const uint16_t code, const std::string& space) { - - if (server_selector.amUnassigned()) { - isc_throw(NotImplemented, "managing configuration for no particular server" - " (unassigned) is unsupported at the moment"); - } - - auto tag = getServerTag(server_selector, "fetching subnet level option"); - - OptionContainer options; - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag), - MySqlBinding::createInteger(static_cast(subnet_id)), - MySqlBinding::createInteger(static_cast(code)), - MySqlBinding::createString(space) - }; - getOptions(GET_OPTION4_SUBNET_ID_CODE_SPACE, in_bindings, Option::V4, - options); - return (options.empty() ? OptionDescriptorPtr() : - OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); + return (getOption(GET_OPTION4_SUBNET_ID_CODE_SPACE, Option::V4, + server_selector, subnet_id, code, space)); } /// @brief Sends query to retrieve single option by code and option space @@ -1699,25 +1646,8 @@ public: const uint64_t pool_id, const uint16_t code, const std::string& space) { - - if (server_selector.amUnassigned()) { - isc_throw(NotImplemented, "managing configuration for no particular server" - " (unassigned) is unsupported at the moment"); - } - - auto tag = getServerTag(server_selector, "fetching pool level option"); - - OptionContainer options; - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag), - MySqlBinding::createInteger(pool_id), - MySqlBinding::createInteger(static_cast(code)), - MySqlBinding::createString(space) - }; - getOptions(GET_OPTION4_POOL_ID_CODE_SPACE, in_bindings, Option::V4, - options); - return (options.empty() ? OptionDescriptorPtr() : - OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); + return (getOption(GET_OPTION4_POOL_ID_CODE_SPACE, Option::V4, + server_selector, pool_id, code, space)); } /// @brief Sends query to retrieve single option by code and option space @@ -1734,26 +1664,8 @@ public: const std::string& shared_network_name, const uint16_t code, const std::string& space) { - - if (server_selector.amUnassigned()) { - isc_throw(NotImplemented, "managing configuration for no particular server" - " (unassigned) is unsupported at the moment"); - } - - auto tag = getServerTag(server_selector, "fetching shared network" - " level option"); - - OptionContainer options; - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(tag), - MySqlBinding::createString(shared_network_name), - MySqlBinding::createInteger(static_cast(code)), - MySqlBinding::createString(space) - }; - getOptions(GET_OPTION4_SHARED_NETWORK_CODE_SPACE, in_bindings, Option::V4, - options); - return (options.empty() ? OptionDescriptorPtr() : - OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); + return (getOption(GET_OPTION4_SHARED_NETWORK_CODE_SPACE, Option::V4, + server_selector, shared_network_name, code, space)); } /// @brief Sends query to insert or update option definition. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 9f3b4aa23c..a90b993326 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -365,6 +365,161 @@ MySqlConfigBackendImpl::getOptionDefs(const int index, }); } +OptionDescriptorPtr +MySqlConfigBackendImpl::getOption(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector, + const uint16_t code, + const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + + auto tag = getServerTag(server_selector, "fetching global option"); + + OptionContainer options; + MySqlBindingCollection in_bindings; + in_bindings.push_back(MySqlBinding::createString(tag)); + if (universe == Option::V4) { + in_bindings.push_back(MySqlBinding::createInteger(static_cast(code))); + } else { + in_bindings.push_back(MySqlBinding::createInteger(code)); + } + in_bindings.push_back(MySqlBinding::createString(space)); + getOptions(index, in_bindings, universe, options); + return (options.empty() ? OptionDescriptorPtr() : + OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); +} + +OptionContainer +MySqlConfigBackendImpl::getAllOptions(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector) { + OptionContainer options; + + auto tags = getServerTags(server_selector); + for (auto tag : tags) { + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag) + }; + getOptions(index, in_bindings, universe, options); + } + + return (options); +} + +OptionContainer +MySqlConfigBackendImpl::getModifiedOptions(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) { + OptionContainer options; + + auto tags = getServerTags(server_selector); + for (auto tag : tags) { + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag), + MySqlBinding::createTimestamp(modification_time) + }; + getOptions(index, in_bindings, universe, options); + } + + return (options); +} + +OptionDescriptorPtr +MySqlConfigBackendImpl::getOption(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector, + const SubnetID& subnet_id, + const uint16_t code, + const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + + auto tag = getServerTag(server_selector, "fetching subnet level option"); + + OptionContainer options; + MySqlBindingCollection in_bindings; + in_bindings.push_back(MySqlBinding::createString(tag)); + uint32_t id = static_cast(subnet_id); + in_bindings.push_back(MySqlBinding::createInteger(id)); + if (universe == Option::V4) { + in_bindings.push_back(MySqlBinding::createInteger(static_cast(code))); + } else { + in_bindings.push_back(MySqlBinding::createInteger(code)); + } + in_bindings.push_back(MySqlBinding::createString(space)); + getOptions(index, in_bindings, universe, options); + return (options.empty() ? OptionDescriptorPtr() : + OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); +} + +OptionDescriptorPtr +MySqlConfigBackendImpl::getOption(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector, + const uint64_t pool_id, + const uint16_t code, + const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + + auto tag = getServerTag(server_selector, "fetching [pd] pool level option"); + + OptionContainer options; + MySqlBindingCollection in_bindings; + in_bindings.push_back(MySqlBinding::createString(tag)); + in_bindings.push_back(MySqlBinding::createInteger(pool_id)); + if (universe == Option::V4) { + in_bindings.push_back(MySqlBinding::createInteger(static_cast(code))); + } else { + in_bindings.push_back(MySqlBinding::createInteger(code)); + } + in_bindings.push_back(MySqlBinding::createString(space)); + getOptions(index, in_bindings, universe, options); + return (options.empty() ? OptionDescriptorPtr() : + OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); +} + +OptionDescriptorPtr +MySqlConfigBackendImpl::getOption(const int index, + const Option::Universe& universe, + const ServerSelector& server_selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + + auto tag = getServerTag(server_selector, "fetching shared network level option"); + + OptionContainer options; + MySqlBindingCollection in_bindings; + in_bindings.push_back(MySqlBinding::createString(tag)); + in_bindings.push_back(MySqlBinding::createString(shared_network_name)); + if (universe == Option::V4) { + in_bindings.push_back(MySqlBinding::createInteger(static_cast(code))); + } else { + in_bindings.push_back(MySqlBinding::createInteger(code)); + } + in_bindings.push_back(MySqlBinding::createString(space)); + getOptions(index, in_bindings, universe, options); + return (options.empty() ? OptionDescriptorPtr() : + OptionDescriptorPtr(new OptionDescriptor(*options.begin()))); +} + void MySqlConfigBackendImpl::getOptions(const int index, const db::MySqlBindingCollection& in_bindings, @@ -578,7 +733,5 @@ MySqlConfigBackendImpl::getPort() const { return (0); } - - } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index c97868dc78..2644faa6be 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -364,6 +365,101 @@ public: const db::MySqlBindingCollection& in_bindings, OptionDefContainer& option_defs); + /// @brief Sends query to retrieve single global option by code and + /// option space. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @param code Option code. + /// @param space Option space name. + /// + /// @return Pointer to the returned option or NULL if such option + /// doesn't exist. + OptionDescriptorPtr + getOption(const int index, const Option::Universe& universe, + const db::ServerSelector& server_selector, const uint16_t code, + const std::string& space); + + /// @brief Sends query to retrieve all global options. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @return Container holding returned options. + OptionContainer + getAllOptions(const int index, const Option::Universe& universe, + const db::ServerSelector& server_selector); + + /// @brief Sends query to retrieve global options with modification + /// time later than specified timestamp. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @return Container holding returned options. + OptionContainer + getModifiedOptions(const int index, const Option::Universe& universe, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time); + + /// @brief Sends query to retrieve single option by code and option space + /// for a given subnet id. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @param subnet_id Subnet identifier. + /// @param code Option code. + /// @param space Option space name. + /// + /// @return Pointer to the returned option descriptor or NULL if such + /// option doesn't exist. + OptionDescriptorPtr getOption(const int index, + const Option::Universe& universe, + const db::ServerSelector& server_selector, + const dhcp::SubnetID& subnet_id, + const uint16_t code, + const std::string& space); + + /// @brief Sends query to retrieve single option by code and option space + /// for a given [pd] pool id. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @param pool_id Pool identifier in the database. + /// @param code Option code. + /// @param space Option space name. + /// + /// @return Pointer to the returned option descriptor or NULL if such + /// option doesn't exist. + OptionDescriptorPtr getOption(const int index, + const Option::Universe& universe, + const db::ServerSelector& server_selector, + const uint64_t pool_id, + const uint16_t code, + const std::string& space); + + /// @brief Sends query to retrieve single option by code and option space + /// for a given shared network. + /// + /// @param index Index of the query to be used. + /// @param universe Option universe, i.e. V4 or V6. + /// @param server_selector Server selector. + /// @param shared_network_name Shared network name. + /// @param code Option code. + /// @param space Option space name. + /// + /// @return Pointer to the returned option descriptor or NULL if such + /// option doesn't exist. + OptionDescriptorPtr getOption(const int index, + const Option::Universe& universe, + const db::ServerSelector& server_selector, + const std::string& shared_network_name, + const uint16_t code, + const std::string& space); + /// @brief Sends query to the database to retrieve multiple options. /// /// Query should order by option_id.