Commit 09987b3f authored by Sebastian Schrader's avatar Sebastian Schrader Committed by Tomek Mrugalski
Browse files

[5184] Parse authoritative flag

parent 993f18e6
......@@ -1556,6 +1556,17 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"authoritative\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP4:
case isc::dhcp::Parser4Context::SUBNET4:
case isc::dhcp::Parser4Context::SHARED_NETWORK:
return isc::dhcp::Dhcp4Parser::make_AUTHORITATIVE(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("authoritative", driver.loc_);
}
}
\"next-server\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP4:
......
......@@ -67,6 +67,7 @@ using namespace std;
ECHO_CLIENT_ID "echo-client-id"
MATCH_CLIENT_ID "match-client-id"
AUTHORITATIVE "authoritative"
NEXT_SERVER "next-server"
SERVER_HOSTNAME "server-hostname"
BOOT_FILE_NAME "boot-file-name"
......@@ -451,6 +452,7 @@ global_param: valid_lifetime
| dhcp_ddns
| echo_client_id
| match_client_id
| authoritative
| next_server
| server_hostname
| boot_file_name
......@@ -501,6 +503,11 @@ match_client_id: MATCH_CLIENT_ID COLON BOOLEAN {
ctx.stack_.back()->set("match-client-id", match);
};
authoritative: AUTHORITATIVE COLON BOOLEAN {
ElementPtr prf(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("authoritative", prf);
};
interfaces_config: INTERFACES_CONFIG {
ElementPtr i(new MapElement(ctx.loc2pos(@1)));
......@@ -1041,6 +1048,7 @@ subnet4_param: valid_lifetime
| reservation_mode
| relay
| match_client_id
| authoritative
| next_server
| server_hostname
| boot_file_name
......@@ -1169,6 +1177,7 @@ shared_network_param: name
| rebind_timer
| option_data_list
| match_client_id
| authoritative
| next_server
| server_hostname
| boot_file_name
......
......@@ -515,7 +515,8 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
// decline-probation-period, dhcp4o6-port, echo-client-id,
// user-context are handled in global_parser.parse() which
// sets global parameters.
// match-client-id is derived to subnet scope level.
// match-client-id and authoritative are derived to subnet scope
// level.
if ( (config_pair.first == "renew-timer") ||
(config_pair.first == "rebind-timer") ||
(config_pair.first == "valid-lifetime") ||
......@@ -524,6 +525,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
(config_pair.first == "echo-client-id") ||
(config_pair.first == "user-context") ||
(config_pair.first == "match-client-id") ||
(config_pair.first == "authoritative") ||
(config_pair.first == "next-server") ||
(config_pair.first == "server-hostname") ||
(config_pair.first == "boot-file-name") ||
......
This diff is collapsed.
......@@ -92,6 +92,19 @@ public:
/// @param datadir New data directory.
void setDataDir(const std::string& datadir);
/// @brief Sets whether server should NAK unknown clients in DHCPv4
///
/// @param echo should unknown clients be rejected or not
void authoritative(const bool enabled) {
authoritative_ = enabled;
}
/// @brief Returns whether server should NAK requests for unknown leases
/// @return true if requests for unknown leases should be NAKed, false otherwise
bool authoritative() const {
return (authoritative_);
}
/// @brief Updates the DHCP-DDNS client configuration to the given value.
///
/// Passes the new configuration to the D2ClientMgr instance,
......@@ -270,6 +283,9 @@ private:
/// @brief directory where data files (e.g. server-id) are stored
std::string datadir_;
/// Indicates whether v4 server should NAK requests for unknown addresses
bool authoritative_;
/// @brief Manages the DHCP-DDNS client and its configuration.
D2ClientMgr d2_client_mgr_;
......
......@@ -195,6 +195,9 @@ Network4::toElement() const {
// Set match-client-id
map->set("match-client-id", Element::create(getMatchClientId()));
// Set authoritative
map->set("authoritative", Element::create(getAuthoritative()));
return (map);
}
......
......@@ -368,7 +368,7 @@ public:
/// @brief Constructor.
Network4()
: Network(), match_client_id_(true) {
: Network(), match_client_id_(true), authoritative_(false) {
}
/// @brief Returns the flag indicating if the client identifiers should
......@@ -388,6 +388,24 @@ public:
match_client_id_ = match;
}
/// @brief Returns the flag indicating if requests for unknown IP addresses
/// should be rejected with DHCPNAK instead of ignored.
///
/// @return true if requests for unknown IP addresses should be rejected,
/// false otherwise.
bool getAuthoritative() const {
return (authoritative_);
}
/// @brief Sets the flag indicating if requests for unknown IP addresses
/// should be rejected with DHCPNAK instead of ignored.
///
/// @param match If this value is true, the requests for unknown IP
/// addresses will be rejected with DHCPNAK messages
void setAuthoritative(const bool authoritative) {
authoritative_ = authoritative;
}
/// @brief Unparses network object.
///
/// @return A pointer to unparsed network configuration.
......@@ -404,6 +422,9 @@ private:
/// @brief Should server use client identifiers for client lease
/// lookup.
bool match_client_id_;
/// @brief Should requests for unknown IP addresses be rejected.
bool authoritative_;
};
/// @brief Specialization of the @ref Network object for DHCPv6 case.
......
......@@ -712,6 +712,12 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params,
bool match_client_id = getBoolean(params, "match-client-id");
subnet4->setMatchClientId(match_client_id);
// Set the authoritative value for the subnet. It is always present.
// If not explicitly specified, the default value was filled in when
// SimpleParser4::setAllDefaults was called.
bool authoritative = getBoolean(params, "authoritative");
subnet4->setAuthoritative(authoritative);
// Set next-server. The default value is 0.0.0.0. Nevertheless, the
// user could have messed that up by specifying incorrect value.
// To avoid using 0.0.0.0, user can specify "".
......
......@@ -65,6 +65,11 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
"match-client-id"));
}
if (shared_network_data->contains("authoritative")) {
shared_network->setAuthoritative(getBoolean(shared_network_data,
"authoritative"));
}
if (shared_network_data->contains("client-class")) {
std::string client_class = getString(shared_network_data, "client-class");
if (!client_class.empty()) {
......
......@@ -63,6 +63,7 @@ const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = {
{ "dhcp4o6-port", Element::integer, "0" },
{ "echo-client-id", Element::boolean, "true" },
{ "match-client-id", Element::boolean, "true" },
{ "authoritative", Element::boolean, "false" },
{ "next-server", Element::string, "0.0.0.0" },
{ "server-hostname", Element::string, "" },
{ "boot-file-name", Element::string, "" },
......@@ -125,6 +126,7 @@ const ParamsList SimpleParser4::INHERIT_TO_SUBNET4 = {
"client-class",
"interface",
"match-client-id",
"authoritative",
"next-server",
"rebind-timer",
"relay",
......
......@@ -125,6 +125,7 @@ TEST(CfgSharedNetworks4Test, unparse) {
std::string expected =
"[\n"
" {\n"
" \"authoritative\": false,\n"
" \"interface\": \"eth1\",\n"
" \"match-client-id\": true,\n"
" \"name\": \"dog\",\n"
......@@ -137,6 +138,7 @@ TEST(CfgSharedNetworks4Test, unparse) {
" \"valid-lifetime\": 300\n"
" },\n"
" {\n"
" \"authoritative\": false,\n"
" \"interface\": \"eth0\",\n"
" \"match-client-id\": true,\n"
" \"name\": \"frog\",\n"
......
......@@ -769,6 +769,7 @@ TEST(CfgSubnets4Test, unparseSubnet) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"reservation-mode\": \"all\",\n"
" \"option-data\": [ ],\n"
" \"pools\": [ ]\n"
......@@ -787,6 +788,7 @@ TEST(CfgSubnets4Test, unparseSubnet) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"reservation-mode\": \"all\",\n"
" \"user-context\": {},\n"
" \"option-data\": [ ],\n"
......@@ -806,6 +808,7 @@ TEST(CfgSubnets4Test, unparseSubnet) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"reservation-mode\": \"all\",\n"
" \"option-data\": [ ],\n"
" \"pools\": [ ]\n,"
......@@ -851,6 +854,7 @@ TEST(CfgSubnets4Test, unparsePool) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"reservation-mode\": \"all\",\n"
" \"option-data\": [],\n"
" \"pools\": [\n"
......
......@@ -131,6 +131,7 @@ public:
" \"rebind-timer\": 200,"
" \"valid-lifetime\": 300,"
" \"match-client-id\": false,"
" \"authoritative\": false,"
" \"next-server\": \"\","
" \"server-hostname\": \"\","
" \"boot-file-name\": \"\","
......@@ -152,6 +153,7 @@ public:
" \"rebind-timer\": 20,"
" \"valid-lifetime\": 30,"
" \"match-client-id\": false,"
" \"authoritative\": false,"
" \"next-server\": \"\","
" \"server-hostname\": \"\","
" \"boot-file-name\": \"\","
......
......@@ -316,6 +316,7 @@ TEST(SharedNetwork4Test, unparse) {
std::string expected = "{\n"
" \"comment\": \"bar\",\n"
" \"authoritative\": false,\n"
" \"interface\": \"eth1\",\n"
" \"match-client-id\": false,\n"
" \"name\": \"frog\",\n"
......@@ -332,6 +333,7 @@ TEST(SharedNetwork4Test, unparse) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"id\": 1,\n"
" \"match-client-id\": true,\n"
" \"next-server\": \"0.0.0.0\",\n"
......@@ -352,6 +354,7 @@ TEST(SharedNetwork4Test, unparse) {
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"id\": 2,\n"
" \"match-client-id\": true,\n"
" \"next-server\": \"0.0.0.0\",\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment