2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[5360] client-class and match-client-id params on shared-network level

This commit is contained in:
Tomek Mrugalski
2017-09-15 20:00:40 +02:00
parent 29dd276bc5
commit 67c386b582
6 changed files with 64 additions and 2 deletions

View File

@@ -1023,7 +1023,7 @@ shared_network_param: name
| next_server
| relay
| reservation_mode
| client_classes
| client_class
| valid_lifetime
| unknown_map_entry
;

View File

@@ -1009,7 +1009,7 @@ shared_network_param: name
| option_data_list
| relay
| reservation_mode
| client_classes
| client_class
| preferred_lifetime
| rapid_commit
| valid_lifetime

View File

@@ -57,6 +57,19 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
shared_network->add(*subnet);
}
}
if (shared_network_data->contains("match-client-id")) {
shared_network->setMatchClientId(getBoolean(shared_network_data,
"match-client-id"));
}
if (shared_network_data->contains("client-class")) {
std::string client_class = getString(shared_network_data, "client-class");
if (!client_class.empty()) {
shared_network->allowClientClass(client_class);
}
}
} catch (const std::exception& ex) {
isc_throw(DhcpConfigError, ex.what() << " ("
<< shared_network_data->getPosition() << ")");
@@ -88,6 +101,13 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
parser.parse(cfg_option, json);
}
if (shared_network_data->contains("client-class")) {
std::string client_class = getString(shared_network_data, "client-class");
if (!client_class.empty()) {
shared_network->allowClientClass(client_class);
}
}
if (shared_network_data->contains("subnet6")) {
auto json = shared_network_data->get("subnet6");

View File

@@ -118,6 +118,7 @@ const SimpleDefaults SimpleParser4::IFACE4_DEFAULTS = {
/// This list is also used for inheriting from global to shared networks
/// and from shared networks to subnets within it.
const ParamsList SimpleParser4::INHERIT_TO_SUBNET4 = {
"client-class",
"interface",
"match-client-id",
"next-server",

View File

@@ -103,6 +103,7 @@ const SimpleDefaults SimpleParser6::IFACE6_DEFAULTS = {
/// This list is also used for inheriting from global to shared networks
/// and from shared networks to subnets within it.
const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = {
"client-class",
"interface",
"interface-id",
"preferred-lifetime",

View File

@@ -140,6 +140,28 @@ TEST_F(SharedNetwork4ParserTest, missingName) {
ASSERT_THROW(network = parser.parse(config_element), DhcpConfigError);
}
// This test verifies that it's possible to specify client-class
// and match-client-id on shared-network level.
TEST_F(SharedNetwork4ParserTest, clientClassMatchClientId) {
std::string config = getWorkingConfig();
ElementPtr config_element = Element::fromJSON(config);
config_element->set("match-client-id", Element::create(false));
config_element->set("client-class", Element::create("alpha"));
// Parse configuration specified above.
SharedNetwork4Parser parser;
SharedNetwork4Ptr network;
network = parser.parse(config_element);
ASSERT_TRUE(network);
const ClientClasses classes = network->getClientClasses();
ASSERT_EQ(1, classes.size());
EXPECT_TRUE(classes.contains("alpha"));
EXPECT_FALSE(network->getMatchClientId());
}
/// @brief Test fixture class for SharedNetwork6Parser class.
class SharedNetwork6ParserTest : public ::testing::Test {
public:
@@ -238,5 +260,23 @@ TEST_F(SharedNetwork6ParserTest, parse) {
EXPECT_EQ("2001:db8:1::cafe", addresses[0].toText());
}
// This test verifies that it's possible to specify client-class
// on shared-network level.
TEST_F(SharedNetwork6ParserTest, clientClass) {
std::string config = getWorkingConfig();
ElementPtr config_element = Element::fromJSON(config);
config_element->set("client-class", Element::create("alpha"));
// Parse configuration specified above.
SharedNetwork6Parser parser;
SharedNetwork6Ptr network;
network = parser.parse(config_element);
ASSERT_TRUE(network);
const ClientClasses classes = network->getClientClasses();
ASSERT_EQ(1, classes.size());
EXPECT_TRUE(classes.contains("alpha"));
}
} // end of anonymous namespace