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

[5682] DHCP4, DHCP6 parsers extended to support sanity-checks

This commit is contained in:
Tomek Mrugalski
2018-07-24 20:42:04 +02:00
parent 5bf6881bbf
commit 4cb3ae1902
10 changed files with 132 additions and 1 deletions

View File

@@ -203,6 +203,24 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"sanity-checks\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP4:
return isc::dhcp::Dhcp4Parser::make_SANITY_CHECKS(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("sanity-checks", driver.loc_);
}
}
\"lease-checks\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::SANITY_CHECKS:
return isc::dhcp::Dhcp4Parser::make_LEASE_CHECKS(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("lease-checks", driver.loc_);
}
}
\"dhcp-socket-type\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::INTERFACES_CONFIG:

View File

@@ -60,6 +60,9 @@ using namespace std;
USE_ROUTING "use-routing"
RE_DETECT "re-detect"
SANITY_CHECKS "sanity-checks"
LEASE_CHECKS "lease-checks"
ECHO_CLIENT_ID "echo-client-id"
MATCH_CLIENT_ID "match-client-id"
NEXT_SERVER "next-server"
@@ -449,6 +452,7 @@ global_param: valid_lifetime
| boot_file_name
| user_context
| comment
| sanity_checks
| unknown_map_entry
;
@@ -568,6 +572,39 @@ lease_database: LEASE_DATABASE {
ctx.leave();
};
sanity_checks: SANITY_CHECKS {
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("sanity-checks", m);
ctx.stack_.push_back(m);
ctx.enter(ctx.SANITY_CHECKS);
} COLON LCURLY_BRACKET sanity_checks_params RCURLY_BRACKET {
ctx.stack_.pop_back();
ctx.leave();
};
sanity_checks_params: sanity_checks_param
| sanity_checks_params COMMA sanity_checks_param;
sanity_checks_param: lease_checks;
lease_checks: LEASE_CHECKS {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
if ( (string($4) == "none") ||
(string($4) == "warn") ||
(string($4) == "fix") ||
(string($4) == "fix-del") ||
(string($4) == "del")) {
ElementPtr user(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("lease-checks", user);
ctx.leave();
} else {
error(@4, "Unsupported 'lease-checks value: " + string($4) +
", supported values are: none, warn, fix, fix-del, del");
}
}
hosts_database: HOSTS_DATABASE {
ElementPtr i(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("hosts-database", i);

View File

@@ -25,6 +25,7 @@
#include <dhcpsrv/parsers/option_data_parser.h>
#include <dhcpsrv/parsers/simple_parser4.h>
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/parsers/sanity_checks_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/timer_mgr.h>
#include <hooks/hooks_parser.h>
@@ -388,6 +389,11 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
continue;
}
if (config_pair.first == "sanity-checks") {
SanityChecksParser parser;
parser.parse(*srv_cfg, config_pair.second);
}
if (config_pair.first == "expired-leases-processing") {
ExpirationConfigParser parser;
parser.parse(config_pair.second);

View File

@@ -194,6 +194,8 @@ Parser4Context::contextName()
return ("replace-client-name");
case SHARED_NETWORK:
return ("shared-networks");
case SANITY_CHECKS:
return ("sanity-checks");
default:
return ("__unknown__");
}

View File

@@ -214,6 +214,9 @@ public:
/// Used while parsing Dhcp4/interfaces structures.
INTERFACES_CONFIG,
/// Sanity checks.
SANITY_CHECKS,
/// Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.
DHCP_SOCKET_TYPE,

View File

@@ -466,6 +466,24 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"sanity-checks\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DHCP6:
return isc::dhcp::Dhcp6Parser::make_SANITY_CHECKS(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("sanity-checks", driver.loc_);
}
}
\"lease-checks\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::SANITY_CHECKS:
return isc::dhcp::Dhcp6Parser::make_LEASE_CHECKS(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("lease-checks", driver.loc_);
}
}
\"lease-database\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DHCP6:

View File

@@ -122,6 +122,9 @@ using namespace std;
RELAY_SUPPLIED_OPTIONS "relay-supplied-options"
HOST_RESERVATION_IDENTIFIERS "host-reservation-identifiers"
SANITY_CHECKS "sanity-checks"
LEASE_CHECKS "lease-checks"
CLIENT_CLASSES "client-classes"
REQUIRE_CLIENT_CLASSES "require-client-classes"
TEST "test"
@@ -450,6 +453,7 @@ global_param: preferred_lifetime
| dhcp_ddns
| user_context
| comment
| sanity_checks
| unknown_map_entry
;
@@ -712,6 +716,38 @@ keyspace: KEYSPACE {
ctx.leave();
};
sanity_checks: SANITY_CHECKS {
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("sanity-checks", m);
ctx.stack_.push_back(m);
ctx.enter(ctx.SANITY_CHECKS);
} COLON LCURLY_BRACKET sanity_checks_params RCURLY_BRACKET {
ctx.stack_.pop_back();
ctx.leave();
};
sanity_checks_params: sanity_checks_param
| sanity_checks_params COMMA sanity_checks_param;
sanity_checks_param: lease_checks;
lease_checks: LEASE_CHECKS {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
if ( (string($4) == "none") ||
(string($4) == "warn") ||
(string($4) == "fix") ||
(string($4) == "fix-del") ||
(string($4) == "del")) {
ElementPtr user(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("lease-checks", user);
ctx.leave();
} else {
error(@4, "Unsupported 'lease-checks value: " + string($4) +
", supported values are: none, warn, fix, fix-del, del");
}
}
mac_sources: MAC_SOURCES {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));

View File

@@ -33,6 +33,7 @@
#include <dhcpsrv/parsers/option_data_parser.h>
#include <dhcpsrv/parsers/simple_parser6.h>
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/parsers/sanity_checks_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <hooks/hooks_parser.h>
#include <log/logger_support.h>
@@ -502,6 +503,11 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
continue;
}
if (config_pair.first == "sanity-checks") {
SanityChecksParser parser;
parser.parse(*srv_config, config_pair.second);
}
if (config_pair.first == "expired-leases-processing") {
ExpirationConfigParser parser;
parser.parse(config_pair.second);

View File

@@ -196,7 +196,9 @@ Parser6Context::contextName()
return ("replace-client-name");
case SHARED_NETWORK:
return ("shared-networks");
default:
case SANITY_CHECKS:
return ("sanity-checks");
default:
return ("__unknown__");
}
}

View File

@@ -218,6 +218,9 @@ public:
/// Used while parsing Dhcp6/interfaces structures.
INTERFACES_CONFIG,
/// Sanity checks.
SANITY_CHECKS,
/// Used while parsing Dhcp6/lease-database structures.
LEASE_DATABASE,