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<uint8_t>(static_cast<uint8_t>(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.
/// @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
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.
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<uint32_t>(static_cast<uint32_t>(subnet_id)),
- MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(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
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<uint64_t>(pool_id),
- MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(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
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<uint8_t>(static_cast<uint8_t>(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.
});
}
+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<uint8_t>(static_cast<uint8_t>(code)));
+ } else {
+ in_bindings.push_back(MySqlBinding::createInteger<uint16_t>(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<uint32_t>(subnet_id);
+ in_bindings.push_back(MySqlBinding::createInteger<uint32_t>(id));
+ if (universe == Option::V4) {
+ in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(code)));
+ } else {
+ in_bindings.push_back(MySqlBinding::createInteger<uint16_t>(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<uint64_t>(pool_id));
+ if (universe == Option::V4) {
+ in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(code)));
+ } else {
+ in_bindings.push_back(MySqlBinding::createInteger<uint16_t>(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<uint8_t>(static_cast<uint8_t>(code)));
+ } else {
+ in_bindings.push_back(MySqlBinding::createInteger<uint16_t>(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,
return (0);
}
-
-
} // end of namespace isc::dhcp
} // end of namespace isc
#include <dhcp/option_definition.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/network.h>
+#include <dhcpsrv/subnet_id.h>
#include <exceptions/exceptions.h>
#include <mysql/mysql_binding.h>
#include <mysql/mysql_connection.h>
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.