Commit 877cf313 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[master] Merge branch 'trac5044' (DUID configuration to SimpleParser)

# Conflicts:
#	src/bin/dhcp6/json_config_parser.cc
parents 5a836032 45ddaa8a
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
......@@ -799,6 +799,33 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"LLT\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DUID_TYPE:
return isc::dhcp::Dhcp6Parser::make_LLT(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("LLT", driver.loc_);
}
}
\"EN\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DUID_TYPE:
return isc::dhcp::Dhcp6Parser::make_EN(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("EN", driver.loc_);
}
}
\"LL\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DUID_TYPE:
return isc::dhcp::Dhcp6Parser::make_LL(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("LL", driver.loc_);
}
}
\"identifier\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::SERVER_ID:
......
This diff is collapsed.
......@@ -305,6 +305,7 @@ namespace isc { namespace dhcp {
union union_type
{
// value
// duid_type
char dummy1[sizeof(ElementPtr)];
// "boolean"
......@@ -409,38 +410,41 @@ namespace isc { namespace dhcp {
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_DHCP4 = 341,
TOKEN_DHCPDDNS = 342,
TOKEN_TOPLEVEL_JSON = 343,
TOKEN_TOPLEVEL_DHCP6 = 344,
TOKEN_SUB_DHCP6 = 345,
TOKEN_SUB_INTERFACES6 = 346,
TOKEN_SUB_SUBNET6 = 347,
TOKEN_SUB_POOL6 = 348,
TOKEN_SUB_PD_POOL = 349,
TOKEN_SUB_RESERVATION = 350,
TOKEN_SUB_OPTION_DEF = 351,
TOKEN_SUB_OPTION_DATA = 352,
TOKEN_SUB_HOOKS_LIBRARY = 353,
TOKEN_STRING = 354,
TOKEN_INTEGER = 355,
TOKEN_FLOAT = 356,
TOKEN_BOOLEAN = 357
TOKEN_LLT = 326,
TOKEN_EN = 327,
TOKEN_LL = 328,
TOKEN_IDENTIFIER = 329,
TOKEN_HTYPE = 330,
TOKEN_TIME = 331,
TOKEN_ENTERPRISE_ID = 332,
TOKEN_DHCP4O6_PORT = 333,
TOKEN_CONTROL_SOCKET = 334,
TOKEN_SOCKET_TYPE = 335,
TOKEN_SOCKET_NAME = 336,
TOKEN_DHCP_DDNS = 337,
TOKEN_LOGGING = 338,
TOKEN_LOGGERS = 339,
TOKEN_OUTPUT_OPTIONS = 340,
TOKEN_OUTPUT = 341,
TOKEN_DEBUGLEVEL = 342,
TOKEN_SEVERITY = 343,
TOKEN_DHCP4 = 344,
TOKEN_DHCPDDNS = 345,
TOKEN_TOPLEVEL_JSON = 346,
TOKEN_TOPLEVEL_DHCP6 = 347,
TOKEN_SUB_DHCP6 = 348,
TOKEN_SUB_INTERFACES6 = 349,
TOKEN_SUB_SUBNET6 = 350,
TOKEN_SUB_POOL6 = 351,
TOKEN_SUB_PD_POOL = 352,
TOKEN_SUB_RESERVATION = 353,
TOKEN_SUB_OPTION_DEF = 354,
TOKEN_SUB_OPTION_DATA = 355,
TOKEN_SUB_HOOKS_LIBRARY = 356,
TOKEN_STRING = 357,
TOKEN_INTEGER = 358,
TOKEN_FLOAT = 359,
TOKEN_BOOLEAN = 360
};
};
......@@ -831,6 +835,18 @@ namespace isc { namespace dhcp {
symbol_type
make_SERVER_ID (const location_type& l);
static inline
symbol_type
make_LLT (const location_type& l);
static inline
symbol_type
make_EN (const location_type& l);
static inline
symbol_type
make_LL (const location_type& l);
static inline
symbol_type
make_IDENTIFIER (const location_type& l);
......@@ -1164,12 +1180,12 @@ namespace isc { namespace dhcp {
enum
{
yyeof_ = 0,
yylast_ = 630, ///< Last index in yytable_.
yynnts_ = 271, ///< Number of nonterminal symbols.
yylast_ = 640, ///< Last index in yytable_.
yynnts_ = 275, ///< Number of nonterminal symbols.
yyfinal_ = 24, ///< Termination state number.
yyterror_ = 1,
yyerrcode_ = 256,
yyntokens_ = 103 ///< Number of tokens.
yyntokens_ = 106 ///< Number of tokens.
};
......@@ -1221,9 +1237,10 @@ 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, 102
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105
};
const unsigned int user_token_number_max_ = 357;
const unsigned int user_token_number_max_ = 360;
const token_number_type undef_token_ = 2;
if (static_cast<int>(t) <= yyeof_)
......@@ -1256,23 +1273,24 @@ namespace isc { namespace dhcp {
{
switch (other.type_get ())
{
case 116: // value
case 119: // value
case 338: // duid_type
value.copy< ElementPtr > (other.value);
break;
case 102: // "boolean"
case 105: // "boolean"
value.copy< bool > (other.value);
break;
case 101: // "floating point"
case 104: // "floating point"
value.copy< double > (other.value);
break;
case 100: // "integer"
case 103: // "integer"
value.copy< int64_t > (other.value);
break;
case 99: // "constant string"
case 102: // "constant string"
value.copy< std::string > (other.value);
break;
......@@ -1293,23 +1311,24 @@ namespace isc { namespace dhcp {
(void) v;
switch (this->type_get ())
{
case 116: // value
case 119: // value
case 338: // duid_type
value.copy< ElementPtr > (v);
break;
case 102: // "boolean"
case 105: // "boolean"
value.copy< bool > (v);
break;
case 101: // "floating point"
case 104: // "floating point"
value.copy< double > (v);
break;
case 100: // "integer"
case 103: // "integer"
value.copy< int64_t > (v);
break;
case 99: // "constant string"
case 102: // "constant string"
value.copy< std::string > (v);
break;
......@@ -1389,23 +1408,24 @@ namespace isc { namespace dhcp {
// Type destructor.
switch (yytype)
{
case 116: // value
case 119: // value
case 338: // duid_type
value.template destroy< ElementPtr > ();
break;
case 102: // "boolean"
case 105: // "boolean"
value.template destroy< bool > ();
break;
case 101: // "floating point"
case 104: // "floating point"
value.template destroy< double > ();
break;
case 100: // "integer"
case 103: // "integer"
value.template destroy< int64_t > ();
break;
case 99: // "constant string"
case 102: // "constant string"
value.template destroy< std::string > ();
break;
......@@ -1432,23 +1452,24 @@ namespace isc { namespace dhcp {
super_type::move(s);
switch (this->type_get ())
{
case 116: // value
case 119: // value
case 338: // duid_type
value.move< ElementPtr > (s.value);
break;
case 102: // "boolean"
case 105: // "boolean"
value.move< bool > (s.value);
break;
case 101: // "floating point"
case 104: // "floating point"
value.move< double > (s.value);
break;
case 100: // "integer"
case 103: // "integer"
value.move< int64_t > (s.value);
break;
case 99: // "constant string"
case 102: // "constant string"
value.move< std::string > (s.value);
break;
......@@ -1517,7 +1538,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, 357
355, 356, 357, 358, 359, 360
};
return static_cast<token_type> (yytoken_number_[type]);
}
......@@ -1936,6 +1957,24 @@ namespace isc { namespace dhcp {
return symbol_type (token::TOKEN_SERVER_ID, l);
}
Dhcp6Parser::symbol_type
Dhcp6Parser::make_LLT (const location_type& l)
{
return symbol_type (token::TOKEN_LLT, l);
}
Dhcp6Parser::symbol_type
Dhcp6Parser::make_EN (const location_type& l)
{
return symbol_type (token::TOKEN_EN, l);
}
Dhcp6Parser::symbol_type
Dhcp6Parser::make_LL (const location_type& l)
{
return symbol_type (token::TOKEN_LL, l);
}
Dhcp6Parser::symbol_type
Dhcp6Parser::make_IDENTIFIER (const location_type& l)
{
......@@ -2131,7 +2170,7 @@ namespace isc { namespace dhcp {
#line 14 "dhcp6_parser.yy" // lalr1.cc:377
} } // isc::dhcp
#line 2135 "dhcp6_parser.h" // lalr1.cc:377
#line 2174 "dhcp6_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
......@@ -121,6 +121,9 @@ using namespace std;
EXPIRED_LEASES_PROCESSING "expired-leases-processing"
SERVER_ID "server-id"
LLT "LLT"
EN "EN"
LL "LL"
IDENTIFIER "identifier"
HTYPE "htype"
TIME "time"
......@@ -185,6 +188,7 @@ using namespace std;
%token <bool> BOOLEAN "boolean"
%type <ElementPtr> value
%type <ElementPtr> duid_type
%printer { yyoutput << $$; } <*>;
......@@ -454,7 +458,7 @@ database_map_params: database_map_param
| database_map_params COMMA database_map_param
;
database_map_param: type
database_map_param: database_type
| user
| password
| host
......@@ -465,7 +469,7 @@ database_map_param: type
| unknown_map_entry
;
type: TYPE {
database_type: TYPE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
......@@ -870,7 +874,13 @@ code: CODE COLON INTEGER {
option_def_code: code;
option_def_type: type;
option_def_type: TYPE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("type", prf);
ctx.leave();
};
option_def_record_types: RECORD_TYPES {
ctx.enter(ctx.NO_KEYWORD);
......@@ -1328,7 +1338,7 @@ server_id_params: server_id_param
| server_id_params COMMA server_id_param
;
server_id_param: type
server_id_param: server_id_type
| identifier
| time
| htype
......@@ -1337,6 +1347,18 @@ server_id_param: type
| unknown_map_entry
;
server_id_type: TYPE {
ctx.enter(ctx.DUID_TYPE);
} COLON duid_type {
ctx.stack_.back()->set("type", $4);
ctx.leave();
};
duid_type: LLT { $$ = ElementPtr(new StringElement("LLT", ctx.loc2pos(@1))); }
| EN { $$ = ElementPtr(new StringElement("EN", ctx.loc2pos(@1))); }
| LL { $$ = ElementPtr(new StringElement("LL", ctx.loc2pos(@1))); }
;
htype: HTYPE COLON INTEGER {
ElementPtr htype(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("htype", htype);
......
......@@ -724,9 +724,8 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id,
parser = new ExpirationConfigParser();
} else if (config_id.compare("client-classes") == 0) {
parser = new ClientClassDefListParser(config_id, globalContext());
} else if (config_id.compare("server-id") == 0) {
parser = new DUIDConfigParser();
// host-reservation-identifiers have been converted to SimpleParser already.
// server-id has been migrated to SimpleParser
} else {
isc_throw(DhcpConfigError,
"unsupported global configuration parameter: "
......@@ -925,6 +924,13 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
continue;
}
if (config_pair.first == "server-id") {
DUIDConfigParser parser;
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
parser.parse(cfg, config_pair.second);
continue;
}
ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first,
config_pair.second));
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
......
// Generated 201612201711
// Generated 201701070039
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......
......@@ -147,6 +147,8 @@ Parser6Context::contextName()
return ("client-classes");
case SERVER_ID:
return ("server-id");
case DUID_TYPE:
return ("duid-type");
case CONTROL_SOCKET:
return ("control-socket");
case POOLS:
......
// 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
......@@ -228,6 +228,9 @@ public:
/// Used while parsing Dhcp6/server-id structures.
SERVER_ID,
/// Used while parsing Dhcp6/server-id/type structures.
DUID_TYPE,
/// Used while parsing Dhcp6/control-socket structures.
CONTROL_SOCKET,
......
// Generated 201612201711
// Generated 201701070039
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......
// Generated 201612201711
// Generated 201701070039
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......
......@@ -276,7 +276,7 @@ TEST_F(Dhcpv6SrvTest, DUID) {
case DUID::DUID_LLT: {
// DUID must contain at least 6 bytes long MAC
// + 8 bytes of fixed header
EXPECT_GE(14, len);
EXPECT_GE(len, 14);
uint16_t hw_type = data.readUint16();
// there's no real way to find out "correct"
......
......@@ -285,6 +285,12 @@ DUIDFactory::createLinkLayerId(std::vector<uint8_t>& identifier,
// Assign link layer address and type.
identifier.assign(iface->getMac(), iface->getMac() + iface->getMacLen());
htype = iface->getHWType();
// If it looks like an Ethernet interface we should be happy
if ((htype == static_cast<uint16_t>(HTYPE_ETHER)) &&
(iface->getMacLen() == 6)) {
break;
}
}
// We failed to find an interface which link layer address could be
......
......@@ -641,10 +641,10 @@ TEST_F(IfaceMgrTest, getIface) {
// Interface name, ifindex
IfacePtr iface1(new Iface("lo1", 100));
IfacePtr iface2(new Iface("eth9", 101));
IfacePtr iface3(new Iface("en3", 102));
IfacePtr iface3(new Iface("en7", 102));
IfacePtr iface4(new Iface("e1000g4", 103));
cout << "This test assumes that there are less than 100 network interfaces"
<< " in the tested system and there are no lo1, eth9, en3, e1000g4"
<< " in the tested system and there are no lo1, eth9, en7, e1000g4"
<< " or wifi15 interfaces present." << endl;
// Note: real interfaces may be detected as well
......@@ -666,7 +666,7 @@ TEST_F(IfaceMgrTest, getIface) {
IfacePtr tmp = ifacemgr->getIface(102);
ASSERT_TRUE(tmp);
EXPECT_EQ("en3", tmp->getName());
EXPECT_EQ("en7", tmp->getName());
EXPECT_EQ(102, tmp->getIndex());
// Check that interface can be retrieved by name
......
// Copyright (C) 2015 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
......@@ -11,6 +11,7 @@
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/parsers/duid_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <exceptions/exceptions.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
......@@ -22,28 +23,28 @@ using namespace isc::data;
namespace isc {
namespace dhcp {
DUIDConfigParser::DUIDConfigParser()
: DhcpConfigParser() {
}
void
DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
DUIDConfigParser::parse(const CfgDUIDPtr& cfg, isc::data::ConstElementPtr duid_configuration) {
if (!cfg) {
isc_throw(DhcpConfigError, "Must provide valid pointer to cfg when parsing duid");
}
bool type_present = false;
BOOST_FOREACH(ConfigPair element, duid_configuration->mapValue()) {
try {
if (element.first == "type") {
type_present = true;
setType(element.second->stringValue());
setType(cfg, element.second->stringValue());
} else if (element.first == "identifier") {
setIdentifier(element.second->stringValue());
setIdentifier(cfg, element.second->stringValue());
} else if (element.first == "htype") {
setHType(element.second->intValue());
setHType(cfg, element.second->intValue());
} else if (element.first == "time") {
setTime(element.second->intValue());
setTime(cfg, element.second->intValue());
} else if (element.first == "enterprise-id") {
setEnterpriseId(element.second->intValue());
setEnterpriseId(cfg, element.second->intValue());
} else if (element.first == "persist") {
setPersist(element.second->boolValue());
setPersist(cfg, element.second->boolValue());
} else {
isc_throw(DhcpConfigError, "unsupported configuration "
"parameter '" << element.first << "'");
......@@ -66,7 +67,7 @@ DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
}
void
DUIDConfigParser::setType(const std::string& duid_type) const {
DUIDConfigParser::setType(const CfgDUIDPtr& cfg, const std::string& duid_type) const {
// Map DUID type represented as text into numeric value.
DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
if (duid_type == "LLT") {
......@@ -80,41 +81,34 @@ DUIDConfigParser::setType(const std::string& duid_type) const {
<< duid_type << "'. Expected: LLT, EN or LL");
}
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
}
void
DUIDConfigParser::setIdentifier(const std::string& identifier) const {
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
DUIDConfigParser::setIdentifier(const CfgDUIDPtr& cfg, const std::string& identifier) const {
cfg->setIdentifier(identifier);
}
void
DUIDConfigParser::setHType(const int64_t htype) const {
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
DUIDConfigParser::setHType(const CfgDUIDPtr& cfg, const int64_t htype) const {
checkRange<uint16_t>("htype", htype);
cfg->setHType(static_cast<uint16_t>(htype));
}
void