Commit 3d8e48c6 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[master] Merge branch 'trac5020' (interfaces parser migrated to SimpleParser)

# Conflicts:
#	src/bin/dhcp4/json_config_parser.cc
#	src/bin/dhcp6/json_config_parser.cc
parents 837ed739 f32bbafd
This diff is collapsed.
/* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
/* Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -196,6 +196,24 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"raw\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP_SOCKET_TYPE:
return isc::dhcp::Dhcp4Parser::make_RAW(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("raw", driver.loc_);
}
}
\"udp\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP_SOCKET_TYPE:
return isc::dhcp::Dhcp4Parser::make_UDP(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("udp", driver.loc_);
}
}
\"interfaces\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::INTERFACES_CONFIG:
......
This diff is collapsed.
......@@ -305,6 +305,7 @@ namespace isc { namespace dhcp {
union union_type
{
// value
// socket_type
char dummy1[sizeof(ElementPtr)];
// "boolean"
......@@ -352,94 +353,96 @@ namespace isc { namespace dhcp {
TOKEN_INTERFACES_CONFIG = 266,
TOKEN_INTERFACES = 267,
TOKEN_DHCP_SOCKET_TYPE = 268,
TOKEN_ECHO_CLIENT_ID = 269,
TOKEN_MATCH_CLIENT_ID = 270,
TOKEN_NEXT_SERVER = 271,
TOKEN_SERVER_HOSTNAME = 272,
TOKEN_BOOT_FILE_NAME = 273,
TOKEN_LEASE_DATABASE = 274,
TOKEN_HOSTS_DATABASE = 275,
TOKEN_TYPE = 276,
TOKEN_USER = 277,
TOKEN_PASSWORD = 278,
TOKEN_HOST = 279,
TOKEN_PERSIST = 280,
TOKEN_LFC_INTERVAL = 281,
TOKEN_READONLY = 282,
TOKEN_VALID_LIFETIME = 283,
TOKEN_RENEW_TIMER = 284,
TOKEN_REBIND_TIMER = 285,
TOKEN_DECLINE_PROBATION_PERIOD = 286,
TOKEN_SUBNET4 = 287,
TOKEN_SUBNET_4O6_INTERFACE = 288,
TOKEN_SUBNET_4O6_INTERFACE_ID = 289,
TOKEN_SUBNET_4O6_SUBNET = 290,
TOKEN_OPTION_DEF = 291,
TOKEN_OPTION_DATA = 292,
TOKEN_NAME = 293,
TOKEN_DATA = 294,
TOKEN_CODE = 295,
TOKEN_SPACE = 296,
TOKEN_CSV_FORMAT = 297,
TOKEN_RECORD_TYPES = 298,
TOKEN_ENCAPSULATE = 299,
TOKEN_ARRAY = 300,
TOKEN_POOLS = 301,
TOKEN_POOL = 302,
TOKEN_SUBNET = 303,
TOKEN_INTERFACE = 304,
TOKEN_INTERFACE_ID = 305,
TOKEN_ID = 306,
TOKEN_RAPID_COMMIT = 307,
TOKEN_RESERVATION_MODE = 308,
TOKEN_HOST_RESERVATION_IDENTIFIERS = 309,
TOKEN_CLIENT_CLASSES = 310,
TOKEN_TEST = 311,
TOKEN_CLIENT_CLASS = 312,
TOKEN_RESERVATIONS = 313,
TOKEN_DUID = 314,
TOKEN_HW_ADDRESS = 315,
TOKEN_CIRCUIT_ID = 316,
TOKEN_CLIENT_ID = 317,
TOKEN_HOSTNAME = 318,
TOKEN_RELAY = 319,
TOKEN_IP_ADDRESS = 320,
TOKEN_HOOKS_LIBRARIES = 321,
TOKEN_LIBRARY = 322,
TOKEN_PARAMETERS = 323,
TOKEN_EXPIRED_LEASES_PROCESSING = 324,
TOKEN_SERVER_ID = 325,
TOKEN_IDENTIFIER = 326,
TOKEN_HTYPE = 327,
TOKEN_TIME = 328,
TOKEN_ENTERPRISE_ID = 329,
TOKEN_DHCP4O6_PORT = 330,
TOKEN_CONTROL_SOCKET = 331,
TOKEN_SOCKET_TYPE = 332,
TOKEN_SOCKET_NAME = 333,
TOKEN_DHCP_DDNS = 334,
TOKEN_LOGGING = 335,
TOKEN_LOGGERS = 336,
TOKEN_OUTPUT_OPTIONS = 337,
TOKEN_OUTPUT = 338,
TOKEN_DEBUGLEVEL = 339,
TOKEN_SEVERITY = 340,
TOKEN_DHCP6 = 341,
TOKEN_DHCPDDNS = 342,
TOKEN_TOPLEVEL_JSON = 343,
TOKEN_TOPLEVEL_DHCP4 = 344,
TOKEN_SUB_DHCP4 = 345,
TOKEN_SUB_INTERFACES4 = 346,
TOKEN_SUB_SUBNET4 = 347,
TOKEN_SUB_POOL4 = 348,
TOKEN_SUB_RESERVATION = 349,
TOKEN_SUB_OPTION_DEF = 350,
TOKEN_SUB_OPTION_DATA = 351,
TOKEN_SUB_HOOKS_LIBRARY = 352,
TOKEN_STRING = 353,
TOKEN_INTEGER = 354,
TOKEN_FLOAT = 355,
TOKEN_BOOLEAN = 356
TOKEN_RAW = 269,
TOKEN_UDP = 270,
TOKEN_ECHO_CLIENT_ID = 271,
TOKEN_MATCH_CLIENT_ID = 272,
TOKEN_NEXT_SERVER = 273,
TOKEN_SERVER_HOSTNAME = 274,
TOKEN_BOOT_FILE_NAME = 275,
TOKEN_LEASE_DATABASE = 276,
TOKEN_HOSTS_DATABASE = 277,
TOKEN_TYPE = 278,
TOKEN_USER = 279,
TOKEN_PASSWORD = 280,
TOKEN_HOST = 281,
TOKEN_PERSIST = 282,
TOKEN_LFC_INTERVAL = 283,
TOKEN_READONLY = 284,
TOKEN_VALID_LIFETIME = 285,
TOKEN_RENEW_TIMER = 286,
TOKEN_REBIND_TIMER = 287,
TOKEN_DECLINE_PROBATION_PERIOD = 288,
TOKEN_SUBNET4 = 289,
TOKEN_SUBNET_4O6_INTERFACE = 290,
TOKEN_SUBNET_4O6_INTERFACE_ID = 291,
TOKEN_SUBNET_4O6_SUBNET = 292,
TOKEN_OPTION_DEF = 293,
TOKEN_OPTION_DATA = 294,
TOKEN_NAME = 295,
TOKEN_DATA = 296,
TOKEN_CODE = 297,
TOKEN_SPACE = 298,
TOKEN_CSV_FORMAT = 299,
TOKEN_RECORD_TYPES = 300,
TOKEN_ENCAPSULATE = 301,
TOKEN_ARRAY = 302,
TOKEN_POOLS = 303,
TOKEN_POOL = 304,
TOKEN_SUBNET = 305,
TOKEN_INTERFACE = 306,
TOKEN_INTERFACE_ID = 307,
TOKEN_ID = 308,
TOKEN_RAPID_COMMIT = 309,
TOKEN_RESERVATION_MODE = 310,
TOKEN_HOST_RESERVATION_IDENTIFIERS = 311,
TOKEN_CLIENT_CLASSES = 312,
TOKEN_TEST = 313,
TOKEN_CLIENT_CLASS = 314,
TOKEN_RESERVATIONS = 315,
TOKEN_DUID = 316,
TOKEN_HW_ADDRESS = 317,
TOKEN_CIRCUIT_ID = 318,
TOKEN_CLIENT_ID = 319,
TOKEN_HOSTNAME = 320,
TOKEN_RELAY = 321,
TOKEN_IP_ADDRESS = 322,
TOKEN_HOOKS_LIBRARIES = 323,
TOKEN_LIBRARY = 324,
TOKEN_PARAMETERS = 325,
TOKEN_EXPIRED_LEASES_PROCESSING = 326,
TOKEN_SERVER_ID = 327,
TOKEN_IDENTIFIER = 328,
TOKEN_HTYPE = 329,
TOKEN_TIME = 330,
TOKEN_ENTERPRISE_ID = 331,
TOKEN_DHCP4O6_PORT = 332,
TOKEN_CONTROL_SOCKET = 333,
TOKEN_SOCKET_TYPE = 334,
TOKEN_SOCKET_NAME = 335,
TOKEN_DHCP_DDNS = 336,
TOKEN_LOGGING = 337,
TOKEN_LOGGERS = 338,
TOKEN_OUTPUT_OPTIONS = 339,
TOKEN_OUTPUT = 340,
TOKEN_DEBUGLEVEL = 341,
TOKEN_SEVERITY = 342,
TOKEN_DHCP6 = 343,
TOKEN_DHCPDDNS = 344,
TOKEN_TOPLEVEL_JSON = 345,
TOKEN_TOPLEVEL_DHCP4 = 346,
TOKEN_SUB_DHCP4 = 347,
TOKEN_SUB_INTERFACES4 = 348,
TOKEN_SUB_SUBNET4 = 349,
TOKEN_SUB_POOL4 = 350,
TOKEN_SUB_RESERVATION = 351,
TOKEN_SUB_OPTION_DEF = 352,
TOKEN_SUB_OPTION_DATA = 353,
TOKEN_SUB_HOOKS_LIBRARY = 354,
TOKEN_STRING = 355,
TOKEN_INTEGER = 356,
TOKEN_FLOAT = 357,
TOKEN_BOOLEAN = 358
};
};
......@@ -602,6 +605,14 @@ namespace isc { namespace dhcp {
symbol_type
make_DHCP_SOCKET_TYPE (const location_type& l);
static inline
symbol_type
make_RAW (const location_type& l);
static inline
symbol_type
make_UDP (const location_type& l);
static inline
symbol_type
make_ECHO_CLIENT_ID (const location_type& l);
......@@ -1159,12 +1170,12 @@ namespace isc { namespace dhcp {
enum
{
yyeof_ = 0,
yylast_ = 624, ///< Last index in yytable_.
yynnts_ = 267, ///< Number of nonterminal symbols.
yylast_ = 626, ///< Last index in yytable_.
yynnts_ = 268, ///< Number of nonterminal symbols.
yyfinal_ = 22, ///< Termination state number.
yyterror_ = 1,
yyerrcode_ = 256,
yyntokens_ = 102 ///< Number of tokens.
yyntokens_ = 104 ///< Number of tokens.
};
......@@ -1216,9 +1227,9 @@ namespace isc { namespace dhcp {
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101
95, 96, 97, 98, 99, 100, 101, 102, 103
};
const unsigned int user_token_number_max_ = 356;
const unsigned int user_token_number_max_ = 358;
const token_number_type undef_token_ = 2;
if (static_cast<int>(t) <= yyeof_)
......@@ -1251,23 +1262,24 @@ namespace isc { namespace dhcp {
{
switch (other.type_get ())
{
case 114: // value
case 116: // value
case 155: // socket_type
value.copy< ElementPtr > (other.value);
break;
case 101: // "boolean"
case 103: // "boolean"
value.copy< bool > (other.value);
break;
case 100: // "floating point"
case 102: // "floating point"
value.copy< double > (other.value);
break;
case 99: // "integer"
case 101: // "integer"
value.copy< int64_t > (other.value);
break;
case 98: // "constant string"
case 100: // "constant string"
value.copy< std::string > (other.value);
break;
......@@ -1288,23 +1300,24 @@ namespace isc { namespace dhcp {
(void) v;
switch (this->type_get ())
{
case 114: // value
case 116: // value
case 155: // socket_type
value.copy< ElementPtr > (v);
break;
case 101: // "boolean"
case 103: // "boolean"
value.copy< bool > (v);
break;
case 100: // "floating point"
case 102: // "floating point"
value.copy< double > (v);
break;
case 99: // "integer"
case 101: // "integer"
value.copy< int64_t > (v);
break;
case 98: // "constant string"
case 100: // "constant string"
value.copy< std::string > (v);
break;
......@@ -1384,23 +1397,24 @@ namespace isc { namespace dhcp {
// Type destructor.
switch (yytype)
{
case 114: // value
case 116: // value
case 155: // socket_type
value.template destroy< ElementPtr > ();
break;
case 101: // "boolean"
case 103: // "boolean"
value.template destroy< bool > ();
break;
case 100: // "floating point"
case 102: // "floating point"
value.template destroy< double > ();
break;
case 99: // "integer"
case 101: // "integer"
value.template destroy< int64_t > ();
break;
case 98: // "constant string"
case 100: // "constant string"
value.template destroy< std::string > ();
break;
......@@ -1427,23 +1441,24 @@ namespace isc { namespace dhcp {
super_type::move(s);
switch (this->type_get ())
{
case 114: // value
case 116: // value
case 155: // socket_type
value.move< ElementPtr > (s.value);
break;
case 101: // "boolean"
case 103: // "boolean"
value.move< bool > (s.value);
break;
case 100: // "floating point"
case 102: // "floating point"
value.move< double > (s.value);
break;
case 99: // "integer"
case 101: // "integer"
value.move< int64_t > (s.value);
break;
case 98: // "constant string"
case 100: // "constant string"
value.move< std::string > (s.value);
break;
......@@ -1512,7 +1527,7 @@ namespace isc { namespace dhcp {
325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
355, 356
355, 356, 357, 358
};
return static_cast<token_type> (yytoken_number_[type]);
}
......@@ -1589,6 +1604,18 @@ namespace isc { namespace dhcp {
return symbol_type (token::TOKEN_DHCP_SOCKET_TYPE, l);
}
Dhcp4Parser::symbol_type
Dhcp4Parser::make_RAW (const location_type& l)
{
return symbol_type (token::TOKEN_RAW, l);
}
Dhcp4Parser::symbol_type
Dhcp4Parser::make_UDP (const location_type& l)
{
return symbol_type (token::TOKEN_UDP, l);
}
Dhcp4Parser::symbol_type
Dhcp4Parser::make_ECHO_CLIENT_ID (const location_type& l)
{
......@@ -2120,7 +2147,7 @@ namespace isc { namespace dhcp {
#line 14 "dhcp4_parser.yy" // lalr1.cc:377
} } // isc::dhcp
#line 2124 "dhcp4_parser.h" // lalr1.cc:377
#line 2151 "dhcp4_parser.h" // lalr1.cc:377
......
/* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
/* Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -53,6 +53,8 @@ using namespace std;
INTERFACES_CONFIG "interfaces-config"
INTERFACES "interfaces"
DHCP_SOCKET_TYPE "dhcp-socket-type"
RAW "raw"
UDP "udp"
ECHO_CLIENT_ID "echo-client-id"
MATCH_CLIENT_ID "match-client-id"
......@@ -185,6 +187,7 @@ using namespace std;
%token <bool> BOOLEAN "boolean"
%type <ElementPtr> value
%type <ElementPtr> socket_type
%printer { yyoutput << $$; } <*>;
......@@ -444,13 +447,16 @@ interfaces_list: INTERFACES {
};
dhcp_socket_type: DHCP_SOCKET_TYPE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr type(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("dhcp-socket-type", type);
ctx.enter(ctx.DHCP_SOCKET_TYPE);
} COLON socket_type {
ctx.stack_.back()->set("dhcp-socket-type", $4);
ctx.leave();
};
socket_type: RAW { $$ = ElementPtr(new StringElement("raw", ctx.loc2pos(@1))); }
| UDP { $$ = ElementPtr(new StringElement("udp", ctx.loc2pos(@1))); }
;
lease_database: LEASE_DATABASE {
ElementPtr i(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("lease-database", i);
......@@ -1363,11 +1369,11 @@ control_socket_params: control_socket_param
| control_socket_params COMMA control_socket_param
;
control_socket_param: socket_type
| socket_name
control_socket_param: control_socket_type
| control_socket_name
;
socket_type: SOCKET_TYPE {
control_socket_type: SOCKET_TYPE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr stype(new StringElement($4, ctx.loc2pos(@4)));
......@@ -1375,7 +1381,7 @@ socket_type: SOCKET_TYPE {
ctx.leave();
};
socket_name: SOCKET_NAME {
control_socket_name: SOCKET_NAME {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
......
......@@ -418,10 +418,9 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
(config_id.compare("dhcp4o6-port") == 0) ) {
parser = new Uint32Parser(config_id,
globalContext()->uint32_values_);
} else if (config_id.compare("interfaces-config") == 0) {
parser = new IfacesConfigParser4();
} else if (config_id.compare("subnet4") == 0) {
parser = new Subnets4ListConfigParser(config_id);
// interface-config has been migrated to SimpleParser already.
// option-data and option-def have been converted to SimpleParser already.
} else if ((config_id.compare("next-server") == 0)) {
parser = new StringParser(config_id,
......@@ -571,7 +570,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// Please do not change this order!
ParserCollection independent_parsers;
ParserPtr subnet_parser;
ParserPtr iface_parser;
ParserPtr leases_parser;
ParserPtr client_classes_parser;
......@@ -620,6 +618,11 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
const std::map<std::string, ConstElementPtr>& values_map =
mutable_cfg->mapValue();
BOOST_FOREACH(config_pair, values_map) {
// In principle we could have the following code structured as a series
// of long if else if clauses. That would give a marginal performance
// boost, but would make the code less readable. We had serious issues
// with the parser code debugability, so I decided to keep it as a
// series of independent ifs.
if (config_pair.first == "option-def") {
// This is converted to SimpleParser and is handled already above.
......@@ -646,6 +649,14 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
continue;
}
if (config_pair.first == "interfaces-config") {
IfacesConfigParser parser(AF_INET);
CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface();
parser.parse(cfg_iface, config_pair.second);
continue;
}
// Legacy DhcpConfigParser stuff below
ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
config_pair.second));
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
......@@ -654,11 +665,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
subnet_parser = parser;
} else if (config_pair.first == "lease-database") {
leases_parser = parser;
} else if (config_pair.first == "interfaces-config") {
// The interface parser is independent from any other
// parser and can be run here before any other parsers.
iface_parser = parser;
parser->build(config_pair.second);
} else if (config_pair.first == "hooks-libraries") {
// Executing commit will alter currently-loaded hooks
// libraries. Check if the supplied libraries are valid,
......
// Generated 201612201711
// Generated 201701062338
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......
......@@ -127,6 +127,8 @@ Parser4Context::contextName()
return ("Logging");
case INTERFACES_CONFIG:
return ("interfaces-config");
case DHCP_SOCKET_TYPE:
return ("dhcp-socket-type");
case LEASE_DATABASE:
return ("lease-database");
case HOSTS_DATABASE:
......
// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -193,6 +193,9 @@ public:
/// Used while parsing Dhcp4/interfaces structures.
INTERFACES_CONFIG,
/// Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.
DHCP_SOCKET_TYPE,
/// Used while parsing Dhcp4/lease-database structures.
LEASE_DATABASE,
......
// Generated 201612201711
// Generated 201701062338
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......
// Generated 201612201711
// Generated 201701062338
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......
......@@ -699,15 +699,12 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id,
(config_id.compare("dhcp4o6-port") == 0) ) {
parser = new Uint32Parser(config_id,
globalContext()->uint32_values_);
} else if (config_id.compare("interfaces-config") == 0) {
parser = new IfacesConfigParser6();
} else if (config_id.compare("subnet6") == 0) {
parser = new Subnets6ListConfigParser(config_id);
// option-data and option-def are no longer needed here. They're now
// converted to SimpleParser and are handled in configureDhcp6Server
} else if (config_id.compare("version") == 0) {
parser = new StringParser(config_id,
globalContext()->string_values_);
// converted to SimpleParser and are handled in configureDhcp6Server.
// interfaces-config has been converted to SimpleParser.
// version was removed - it was a leftover from bindctrl.
} else if (config_id.compare("lease-database") == 0) {
parser = new DbAccessParser(config_id, DbAccessParser::LEASE_DB);
} else if (config_id.compare("hosts-database") == 0) {
......@@ -842,7 +839,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
// Please do not change this order!
ParserCollection independent_parsers;
ParserPtr subnet_parser;
ParserPtr iface_parser;
ParserPtr leases_parser;
ParserPtr client_classes_parser;
......@@ -891,6 +887,11 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {