mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 22:45:18 +00:00
[2317] Parse record-types field in DHCPv4 option definition configuration.
This commit is contained in:
@@ -960,7 +960,8 @@ public:
|
|||||||
BOOST_FOREACH(ConfigPair param, option_def->mapValue()) {
|
BOOST_FOREACH(ConfigPair param, option_def->mapValue()) {
|
||||||
std::string entry(param.first);
|
std::string entry(param.first);
|
||||||
ParserPtr parser;
|
ParserPtr parser;
|
||||||
if (entry == "name" || entry == "type" || entry == "space") {
|
if (entry == "name" || entry == "type" ||
|
||||||
|
entry == "record-types" || entry == "space") {
|
||||||
StringParserPtr
|
StringParserPtr
|
||||||
str_parser(dynamic_cast<StringParser*>(StringParser::factory(entry)));
|
str_parser(dynamic_cast<StringParser*>(StringParser::factory(entry)));
|
||||||
if (str_parser) {
|
if (str_parser) {
|
||||||
@@ -981,8 +982,6 @@ public:
|
|||||||
array_parser->setStorage(&boolean_values_);
|
array_parser->setStorage(&boolean_values_);
|
||||||
parser = array_parser;
|
parser = array_parser;
|
||||||
}
|
}
|
||||||
} else if (entry == "record_types") {
|
|
||||||
// do nothing yet
|
|
||||||
} else {
|
} else {
|
||||||
isc_throw(DhcpConfigError, "invalid parameter: " << entry);
|
isc_throw(DhcpConfigError, "invalid parameter: " << entry);
|
||||||
}
|
}
|
||||||
@@ -1050,6 +1049,28 @@ private:
|
|||||||
|
|
||||||
OptionDefinitionPtr def(new OptionDefinition(name, code,
|
OptionDefinitionPtr def(new OptionDefinition(name, code,
|
||||||
type, array_type));
|
type, array_type));
|
||||||
|
// The record-types field may carry a list of comma separated names
|
||||||
|
// of data types that form a record.
|
||||||
|
std::string record_types = getParam<std::string>("record-types",
|
||||||
|
string_values_);
|
||||||
|
// Split the list of record types into tokens.
|
||||||
|
std::vector<std::string> record_tokens =
|
||||||
|
isc::util::str::tokens(record_types, ",");
|
||||||
|
// Iterate over each token and add a record typy into
|
||||||
|
// option definition.
|
||||||
|
BOOST_FOREACH(std::string record_type, record_tokens) {
|
||||||
|
try {
|
||||||
|
boost::trim(record_type);
|
||||||
|
if (!record_type.empty()) {
|
||||||
|
def->addRecordField(record_type);
|
||||||
|
}
|
||||||
|
} catch (const Exception& ex) {
|
||||||
|
isc_throw(DhcpConfigError, "invalid record type values"
|
||||||
|
<< " specified for the option definition: "
|
||||||
|
<< ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check the option definition parameters are valid.
|
// Check the option definition parameters are valid.
|
||||||
try {
|
try {
|
||||||
def->validate();
|
def->validate();
|
||||||
|
@@ -71,16 +71,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
{ "item_name": "record_types",
|
{ "item_name": "record_types",
|
||||||
"item_type": "list",
|
"item_type": "string",
|
||||||
"item_optional": false,
|
"item_optional": false,
|
||||||
"item_default": [],
|
"item_default": "",
|
||||||
"list_item_spec":
|
|
||||||
{
|
|
||||||
"item_name": "record-type",
|
|
||||||
"item_type": "string",
|
|
||||||
"item_optional": false,
|
|
||||||
"item_default": ""
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "item_name": "space",
|
{ "item_name": "space",
|
||||||
|
@@ -447,7 +447,7 @@ TEST_F(Dhcp4ParserTest, optionDefAdd) {
|
|||||||
" \"code\": 100,"
|
" \"code\": 100,"
|
||||||
" \"type\": \"ipv4-address\","
|
" \"type\": \"ipv4-address\","
|
||||||
" \"array\": False,"
|
" \"array\": False,"
|
||||||
// " \"record_types\": [ ],"
|
" \"record-types\": \"\","
|
||||||
" \"space\": \"isc\""
|
" \"space\": \"isc\""
|
||||||
" } ]"
|
" } ]"
|
||||||
"}";
|
"}";
|
||||||
|
Reference in New Issue
Block a user