using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::util;
+using namespace isc::data;
using namespace std;
namespace {
/// @brief Maximum length of option space name.
const size_t OPTION_SPACE_MAX_LEN = 128;
+/// @brief Maximum length of user context.
+const size_t USER_CONTEXT_MAX_LEN = 8192;
+
/// @brief Maximum length of the server hostname.
const size_t SERVER_HOSTNAME_MAX_LEN = 64;
private:
/// @brief Number of columns holding DHCPv4 or DHCPv6 option information.
- static const size_t OPTION_COLUMNS = 6;
+ static const size_t OPTION_COLUMNS = 7;
/// @brief Receives DHCPv4 or DHCPv6 options information from the
/// dhcp4_options or dhcp6_options tables respectively.
const size_t start_column)
: universe_(universe), start_column_(start_column), option_id_(0),
code_(0), value_length_(0), formatted_value_length_(0),
- space_length_(0), persistent_(false), option_id_null_(MLM_FALSE),
- code_null_(MLM_FALSE), value_null_(MLM_FALSE),
- formatted_value_null_(MLM_FALSE), space_null_(MLM_FALSE),
+ space_length_(0), persistent_(false), user_context_length_(0),
+ option_id_null_(MLM_FALSE), code_null_(MLM_FALSE),
+ value_null_(MLM_FALSE), formatted_value_null_(MLM_FALSE),
+ space_null_(MLM_FALSE), user_context_null_(MLM_FALSE),
option_id_index_(start_column), code_index_(start_column_ + 1),
value_index_(start_column_ + 2),
formatted_value_index_(start_column_ + 3),
space_index_(start_column_ + 4),
persistent_index_(start_column_ + 5),
+ user_context_index_(start_column_ + 6),
most_recent_option_id_(0) {
memset(value_, 0, sizeof(value_));
memset(formatted_value_, 0, sizeof(formatted_value_));
memset(space_, 0, sizeof(space_));
+ memset(user_context_, 0, sizeof(user_context_));
}
/// @brief Returns identifier of the currently processed option.
formatted_value.assign(formatted_value_);
}
+ // Convert user_context to string as well.
+ std::string user_context;
+ if (user_context_null_ == MLM_FALSE) {
+ user_context_[user_context_length_] = '\0';
+ user_context.assign(user_context_);
+ }
+
// Options are held in a binary or textual format in the database.
// This is similar to having an option specified in a server
// configuration file. Such option is converted to appropriate C++
}
OptionDescriptor desc(option, persistent_, formatted_value);
+
+ // Set the user context if there is one into the option descriptor.
+ if (!user_context.empty()) {
+ try {
+ ConstElementPtr ctx = Element::fromJSON(user_context);
+ if (!ctx || (ctx->getType() != Element::map)) {
+ isc_throw(BadValue, "user context '" << user_context
+ << "' is no a JSON map");
+ }
+ desc.setContext(ctx);
+ } catch (const isc::data::JSONError& ex) {
+ isc_throw(BadValue, "user context '" << user_context
+ << "' is invalid JSON: " << ex.what());
+ }
+ }
+
cfg->add(desc, space);
}
columns[formatted_value_index_] = "formatted_value";
columns[space_index_] = "space";
columns[persistent_index_] = "persistent";
+ columns[user_context_index_] = "user_context";
}
/// @brief Initialize binding table fields for options.
bind[persistent_index_].buffer_type = MYSQL_TYPE_TINY;
bind[persistent_index_].buffer = reinterpret_cast<char*>(&persistent_);
bind[persistent_index_].is_unsigned = MLM_TRUE;
+
+ // user_context : TEXT NULL
+ user_context_length_ = sizeof(user_context_);
+ bind[user_context_index_].buffer_type = MYSQL_TYPE_STRING;
+ bind[user_context_index_].buffer = reinterpret_cast<char*>(user_context_);
+ bind[user_context_index_].buffer_length = user_context_length_;
+ bind[user_context_index_].length = &user_context_length_;
+ bind[user_context_index_].is_null = &user_context_null_;
}
private:
/// requested.
bool persistent_;
+ /// @brief Buffer holding textual user context of an option.
+ char user_context_[USER_CONTEXT_MAX_LEN];
+
+ /// @brief User context length.
+ unsigned long user_context_length_;
+
/// @name Boolean values indicating if values of specific columns in
/// the database are NULL.
//@{
/// @brief Boolean flag indicating if the DHCPv4 option space is NULL.
my_bool space_null_;
+ /// @brief Boolean flag indicating if the DHCPv4 option user context is NULL.
+ my_bool user_context_null_;
//@}
/// @name Indexes of the specific columns
size_t persistent_index_;
//@}
+ /// @brief User context;
+ size_t user_context_index_;
+
/// @brief Option id for last processed row.
uint32_t most_recent_option_id_;
};
private:
/// @brief Number of columns in the tables holding options.
- static const size_t OPTION_COLUMNS = 9;
+ static const size_t OPTION_COLUMNS = 10;
public:
/// @brief Constructor.
MySqlOptionExchange()
- : type_(0), value_len_(0), formatted_value_len_(0), space_(), space_len_(0),
- persistent_(false), client_class_(), client_class_len_(0),
+
+ : type_(0), value_len_(0), formatted_value_len_(0), space_(),
+ space_len_(0), persistent_(false), user_context_(),
+ user_context_len_(0), client_class_(), client_class_len_(0),
subnet_id_(0), host_id_(0), option_() {
- BOOST_STATIC_ASSERT(8 < OPTION_COLUMNS);
+ BOOST_STATIC_ASSERT(9 < OPTION_COLUMNS);
}
/// @brief Creates binding array to insert option data into database.
bind_[5].buffer = reinterpret_cast<char*>(&persistent_);
bind_[5].is_unsigned = MLM_TRUE;
+ // user_context: TEST NULL,
+ ConstElementPtr ctx = opt_desc.getContext();
+ if (ctx) {
+ user_context_ = ctx->str();
+ user_context_len_ = user_context_.size();
+ bind_[6].buffer_type = MYSQL_TYPE_STRING;
+ bind_[6].buffer = const_cast<char*>(user_context_.c_str());
+ bind_[6].buffer_length = user_context_len_;
+ bind_[6].length = &user_context_len_;
+ } else {
+ bind_[6].buffer_type = MYSQL_TYPE_NULL;
+ }
+
// dhcp_client_class: VARCHAR(128) NULL
/// @todo Assign actual value to client class string.
client_class_len_ = client_class_.size();
- bind_[6].buffer_type = MYSQL_TYPE_STRING;
- bind_[6].buffer = const_cast<char*>(client_class_.c_str());
- bind_[6].buffer_length = client_class_len_;
- bind_[6].length = &client_class_len_;
+ bind_[7].buffer_type = MYSQL_TYPE_STRING;
+ bind_[7].buffer = const_cast<char*>(client_class_.c_str());
+ bind_[7].buffer_length = client_class_len_;
+ bind_[7].length = &client_class_len_;
// dhcp4_subnet_id: INT UNSIGNED NULL
if (subnet_id.isSpecified()) {
subnet_id_ = subnet_id;
- bind_[7].buffer_type = MYSQL_TYPE_LONG;
- bind_[7].buffer = reinterpret_cast<char*>(subnet_id_);
- bind_[7].is_unsigned = MLM_TRUE;
+ bind_[8].buffer_type = MYSQL_TYPE_LONG;
+ bind_[8].buffer = reinterpret_cast<char*>(subnet_id_);
+ bind_[8].is_unsigned = MLM_TRUE;
} else {
- bind_[7].buffer_type = MYSQL_TYPE_NULL;
+ bind_[8].buffer_type = MYSQL_TYPE_NULL;
}
// host_id: INT UNSIGNED NOT NULL
host_id_ = host_id;
- bind_[8].buffer_type = MYSQL_TYPE_LONG;
- bind_[8].buffer = reinterpret_cast<char*>(&host_id_);
- bind_[8].is_unsigned = MLM_TRUE;
+ bind_[9].buffer_type = MYSQL_TYPE_LONG;
+ bind_[9].buffer = reinterpret_cast<char*>(&host_id_);
+ bind_[9].is_unsigned = MLM_TRUE;
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
/// a client or only when requested.
bool persistent_;
+ /// @brief User context.
+ std::string user_context_;
+
+ /// @brief User context length.
+ unsigned long user_context_len_;
+
/// @brief Client classes for the option.
std::string client_class_;
"h.hostname, h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o4.option_id, o4.code, o4.value, o4.formatted_value, o4.space, "
- "o4.persistent, "
+ "o4.persistent, o4.user_context, "
"o6.option_id, o6.code, o6.value, o6.formatted_value, o6.space, "
- "o6.persistent, "
+ "o6.persistent, o6.user_context, "
"r.reservation_id, r.address, r.prefix_len, r.type, "
"r.dhcp6_iaid "
"FROM hosts AS h "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent "
+ "o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o "
"ON h.host_id = o.host_id "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent "
+ "o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o "
"ON h.host_id = o.host_id "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent, "
+ "o.persistent, o.user_context, "
"r.reservation_id, r.address, r.prefix_len, r.type, "
"r.dhcp6_iaid "
"FROM hosts AS h "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent "
+ "o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o "
"ON h.host_id = o.host_id "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent, "
+ "o.persistent, o.user_context,"
"r.reservation_id, r.address, r.prefix_len, r.type, "
"r.dhcp6_iaid "
"FROM hosts AS h "
"h.dhcp4_client_classes, h.dhcp6_client_classes, "
"h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
- "o.persistent, "
+ "o.persistent, o.user_context, "
"r.reservation_id, r.address, r.prefix_len, r.type, "
"r.dhcp6_iaid "
"FROM hosts AS h "
// Using fixed scope_id = 3, which associates an option with host.
{MySqlHostDataSourceImpl::INSERT_V4_OPTION,
"INSERT INTO dhcp4_options(option_id, code, value, formatted_value, space, "
- "persistent, dhcp_client_class, dhcp4_subnet_id, host_id, scope_id) "
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 3)"},
+ "persistent, user_context, dhcp_client_class, dhcp4_subnet_id, host_id, scope_id) "
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 3)"},
// Inserts a single DHCPv6 option into 'dhcp6_options' table.
// Using fixed scope_id = 3, which associates an option with host.
{MySqlHostDataSourceImpl::INSERT_V6_OPTION,
"INSERT INTO dhcp6_options(option_id, code, value, formatted_value, space, "
- "persistent, dhcp_client_class, dhcp6_subnet_id, host_id, scope_id) "
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 3)"},
+ "persistent, user_context, dhcp_client_class, dhcp6_subnet_id, host_id, scope_id) "
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 3)"},
{MySqlHostDataSourceImpl::DEL_HOST_ADDR4,
"DELETE FROM hosts WHERE dhcp4_subnet_id = ? AND ipv4_address = ?"},
using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::util;
+using namespace isc::data;
using namespace std;
namespace {
private:
/// @brief Number of columns holding DHCPv4 or DHCPv6 option information.
- static const size_t OPTION_COLUMNS = 6;
+ static const size_t OPTION_COLUMNS = 7;
/// @brief Receives DHCPv4 or DHCPv6 options information from the
/// dhcp4_options or dhcp6_options tables respectively.
formatted_value_index_(start_column_ + 3),
space_index_(start_column_ + 4),
persistent_index_(start_column_ + 5),
+ user_context_index_(start_column_ + 6),
most_recent_option_id_(0) {
}
PgSqlExchange::getColumnValue(r, row, persistent_index_,
persistent);
+ // user_context: TEXT
+ std::string user_context;
+ if (!isColumnNull(r, row, user_context_index_)) {
+ PgSqlExchange::getColumnValue(r, row, user_context_index_,
+ user_context);
+ }
+
// Options are held in a binary or textual format in the database.
// This is similar to having an option specified in a server
// configuration file. Such option is converted to appropriate C++
}
OptionDescriptor desc(option, persistent, formatted_value);
+
+ // Set the user context if there is one into the option descriptor.
+ if (!user_context.empty()) {
+ try {
+ ConstElementPtr ctx = Element::fromJSON(user_context);
+ if (!ctx || (ctx->getType() != Element::map)) {
+ isc_throw(BadValue, "user context '" << user_context
+ << "' is no a JSON map");
+ }
+ desc.setContext(ctx);
+ } catch (const isc::data::JSONError& ex) {
+ isc_throw(BadValue, "user context '" << user_context
+ << "' is invalid JSON: " << ex.what());
+ }
+ }
+
cfg->add(desc, space);
}
columns[formatted_value_index_] = "formatted_value";
columns[space_index_] = "space";
columns[persistent_index_] = "persistent";
+ columns[user_context_index_] = "user_context";
}
private:
size_t persistent_index_;
//@}
+ /// @brief User context
+ size_t user_context_index_;
+
/// @brief Option id for last processed row.
uint64_t most_recent_option_id_;
};
static const int FORMATTED_VALUE_COL = 3;
static const int SPACE_COL = 4;
static const int PERSISTENT_COL = 5;
- static const int DHCP_CLIENT_CLASS_COL = 6;
- static const int DHCP_SUBNET_ID_COL = 7;
- static const int HOST_ID_COL = 8;
- static const int SCOPE_ID_COL = 9;
+ static const int USER_CONTEXT_COL = 6;
+ static const int DHCP_CLIENT_CLASS_COL = 7;
+ static const int DHCP_SUBNET_ID_COL = 8;
+ static const int HOST_ID_COL = 9;
+ static const int SCOPE_ID_COL = 10;
/// @brief Number of columns in the tables holding options.
- static const size_t OPTION_COLUMNS = 10;
+ static const size_t OPTION_COLUMNS = 11;
public:
columns_[FORMATTED_VALUE_COL] = "formatted_value";
columns_[SPACE_COL] = "space";
columns_[PERSISTENT_COL] = "persistent";
+ columns_[USER_CONTEXT_COL] = "user_context";
columns_[DHCP_CLIENT_CLASS_COL] = "dhcp_client_class";
columns_[DHCP_SUBNET_ID_COL] = "dhcp_subnet_id";
columns_[HOST_ID_COL] = "host_id";
columns_[SCOPE_ID_COL] = "scope_id";
- BOOST_STATIC_ASSERT(9 < OPTION_COLUMNS);
+ BOOST_STATIC_ASSERT(10 < OPTION_COLUMNS);
}
/// @brief Creates binding array to insert option data into database.
// persistent: BOOLEAN DEFAULT false
bind_array->add(opt_desc.persistent_);
+ // user_context: TEXT NULL,
+ ConstElementPtr ctx = opt_desc.getContext();
+ if (ctx) {
+ std::string user_context_ = ctx->str();
+ bind_array->addTempString(user_context_);
+ } else {
+ bind_array->addNull();
+ }
+
// host_id: INT NULL
if (!host_id) {
isc_throw(BadValue, "host_id cannot be null");
" h.hostname, h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
" o4.option_id, o4.code, o4.value, o4.formatted_value, o4.space, "
- " o4.persistent, "
+ " o4.persistent, o4.user_context, "
" o6.option_id, o6.code, o6.value, o6.formatted_value, o6.space, "
- " o6.persistent, "
+ " o6.persistent, o6.user_context, "
" r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o4 ON h.host_id = o4.host_id "
" h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
- " o.option_id, o.code, o.value, o.formatted_value, o.space, o.persistent "
+ " o.option_id, o.code, o.value, o.formatted_value, o.space, "
+ " o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o ON h.host_id = o.host_id "
"WHERE ipv4_address = $1 "
" h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
- " o.option_id, o.code, o.value, o.formatted_value, o.space, o.persistent "
+ " o.option_id, o.code, o.value, o.formatted_value, o.space, "
+ " o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o ON h.host_id = o.host_id "
"WHERE h.dhcp4_subnet_id = $1 AND h.dhcp_identifier_type = $2 "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
" o.option_id, o.code, o.value, o.formatted_value, o.space, "
- " o.persistent, "
+ " o.persistent, o.user_context, "
" r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid "
"FROM hosts AS h "
"LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
" h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
- " o.option_id, o.code, o.value, o.formatted_value, o.space, o.persistent "
+ " o.option_id, o.code, o.value, o.formatted_value, o.space, "
+ " o.persistent, o.user_context "
"FROM hosts AS h "
"LEFT JOIN dhcp4_options AS o ON h.host_id = o.host_id "
"WHERE h.dhcp4_subnet_id = $1 AND h.ipv4_address = $2 "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
" o.option_id, o.code, o.value, o.formatted_value, o.space, "
- " o.persistent, "
+ " o.persistent, o.user_context, "
" r.reservation_id, r.address, r.prefix_len, r.type, "
" r.dhcp6_iaid "
"FROM hosts AS h "
" h.dhcp4_client_classes, h.dhcp6_client_classes, "
" h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
" o.option_id, o.code, o.value, o.formatted_value, o.space, "
- " o.persistent, "
+ " o.persistent, o.user_context, "
" r.reservation_id, r.address, r.prefix_len, r.type, "
" r.dhcp6_iaid "
"FROM hosts AS h "
// PgSqlHostDataSourceImpl::INSERT_V4_HOST_OPTION
// Inserts a single DHCPv4 option into 'dhcp4_options' table.
// Using fixed scope_id = 3, which associates an option with host.
- {6,
+ {7,
{ OID_INT2, OID_BYTEA, OID_TEXT,
- OID_VARCHAR, OID_BOOL, OID_INT8},
+ OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8},
"insert_v4_host_option",
"INSERT INTO dhcp4_options(code, value, formatted_value, space, "
- " persistent, host_id, scope_id) "
- "VALUES ($1, $2, $3, $4, $5, $6, 3)"
+ " persistent, user_context, host_id, scope_id) "
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, 3)"
},
// PgSqlHostDataSourceImpl::INSERT_V6_HOST_OPTION
// Inserts a single DHCPv6 option into 'dhcp6_options' table.
// Using fixed scope_id = 3, which associates an option with host.
- {6,
+ {7,
{ OID_INT2, OID_BYTEA, OID_TEXT,
- OID_VARCHAR, OID_BOOL, OID_INT8},
+ OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8},
"insert_v6_host_option",
"INSERT INTO dhcp6_options(code, value, formatted_value, space, "
- " persistent, host_id, scope_id) "
- "VALUES ($1, $2, $3, $4, $5, $6, 3)"
+ " persistent, user_context, host_id, scope_id) "
+ "VALUES ($1, $2, $3, $4, $5, $6, $7, 3)"
},
// PgSqlHostDataSourceImpl::DEL_HOST_ADDR4