Browse Source

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

# Conflicts:
#	src/bin/dhcp6/json_config_parser.cc
Tomek Mrugalski 8 years ago
parent
commit
877cf3139f

File diff suppressed because it is too large
+ 1570 - 1517
src/bin/dhcp6/dhcp6_lexer.cc


+ 28 - 1
src/bin/dhcp6/dhcp6_lexer.ll

@@ -1,4 +1,4 @@
-/* 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
    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
    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\" {
 \"identifier\" {
     switch(driver.ctx_) {
     switch(driver.ctx_) {
     case isc::dhcp::Parser6Context::SERVER_ID:
     case isc::dhcp::Parser6Context::SERVER_ID:

File diff suppressed because it is too large
+ 1154 - 1082
src/bin/dhcp6/dhcp6_parser.cc


+ 98 - 59
src/bin/dhcp6/dhcp6_parser.h

@@ -305,6 +305,7 @@ namespace isc { namespace dhcp {
     union union_type
     union union_type
     {
     {
       // value
       // value
+      // duid_type
       char dummy1[sizeof(ElementPtr)];
       char dummy1[sizeof(ElementPtr)];
 
 
       // "boolean"
       // "boolean"
@@ -409,38 +410,41 @@ namespace isc { namespace dhcp {
         TOKEN_PARAMETERS = 323,
         TOKEN_PARAMETERS = 323,
         TOKEN_EXPIRED_LEASES_PROCESSING = 324,
         TOKEN_EXPIRED_LEASES_PROCESSING = 324,
         TOKEN_SERVER_ID = 325,
         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
       };
       };
     };
     };
 
 
@@ -833,6 +837,18 @@ namespace isc { namespace dhcp {
 
 
     static inline
     static inline
     symbol_type
     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);
     make_IDENTIFIER (const location_type& l);
 
 
     static inline
     static inline
@@ -1164,12 +1180,12 @@ namespace isc { namespace dhcp {
     enum
     enum
     {
     {
       yyeof_ = 0,
       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.
       yyfinal_ = 24, ///< Termination state number.
       yyterror_ = 1,
       yyterror_ = 1,
       yyerrcode_ = 256,
       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,
       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
       85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
       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;
     const token_number_type undef_token_ = 2;
 
 
     if (static_cast<int>(t) <= yyeof_)
     if (static_cast<int>(t) <= yyeof_)
@@ -1256,23 +1273,24 @@ namespace isc { namespace dhcp {
   {
   {
       switch (other.type_get ())
       switch (other.type_get ())
     {
     {
-      case 116: // value
+      case 119: // value
+      case 338: // duid_type
         value.copy< ElementPtr > (other.value);
         value.copy< ElementPtr > (other.value);
         break;
         break;
 
 
-      case 102: // "boolean"
+      case 105: // "boolean"
         value.copy< bool > (other.value);
         value.copy< bool > (other.value);
         break;
         break;
 
 
-      case 101: // "floating point"
+      case 104: // "floating point"
         value.copy< double > (other.value);
         value.copy< double > (other.value);
         break;
         break;
 
 
-      case 100: // "integer"
+      case 103: // "integer"
         value.copy< int64_t > (other.value);
         value.copy< int64_t > (other.value);
         break;
         break;
 
 
-      case 99: // "constant string"
+      case 102: // "constant string"
         value.copy< std::string > (other.value);
         value.copy< std::string > (other.value);
         break;
         break;
 
 
@@ -1293,23 +1311,24 @@ namespace isc { namespace dhcp {
     (void) v;
     (void) v;
       switch (this->type_get ())
       switch (this->type_get ())
     {
     {
-      case 116: // value
+      case 119: // value
+      case 338: // duid_type
         value.copy< ElementPtr > (v);
         value.copy< ElementPtr > (v);
         break;
         break;
 
 
-      case 102: // "boolean"
+      case 105: // "boolean"
         value.copy< bool > (v);
         value.copy< bool > (v);
         break;
         break;
 
 
-      case 101: // "floating point"
+      case 104: // "floating point"
         value.copy< double > (v);
         value.copy< double > (v);
         break;
         break;
 
 
-      case 100: // "integer"
+      case 103: // "integer"
         value.copy< int64_t > (v);
         value.copy< int64_t > (v);
         break;
         break;
 
 
-      case 99: // "constant string"
+      case 102: // "constant string"
         value.copy< std::string > (v);
         value.copy< std::string > (v);
         break;
         break;
 
 
@@ -1389,23 +1408,24 @@ namespace isc { namespace dhcp {
     // Type destructor.
     // Type destructor.
     switch (yytype)
     switch (yytype)
     {
     {
-      case 116: // value
+      case 119: // value
+      case 338: // duid_type
         value.template destroy< ElementPtr > ();
         value.template destroy< ElementPtr > ();
         break;
         break;
 
 
-      case 102: // "boolean"
+      case 105: // "boolean"
         value.template destroy< bool > ();
         value.template destroy< bool > ();
         break;
         break;
 
 
-      case 101: // "floating point"
+      case 104: // "floating point"
         value.template destroy< double > ();
         value.template destroy< double > ();
         break;
         break;
 
 
-      case 100: // "integer"
+      case 103: // "integer"
         value.template destroy< int64_t > ();
         value.template destroy< int64_t > ();
         break;
         break;
 
 
-      case 99: // "constant string"
+      case 102: // "constant string"
         value.template destroy< std::string > ();
         value.template destroy< std::string > ();
         break;
         break;
 
 
@@ -1432,23 +1452,24 @@ namespace isc { namespace dhcp {
     super_type::move(s);
     super_type::move(s);
       switch (this->type_get ())
       switch (this->type_get ())
     {
     {
-      case 116: // value
+      case 119: // value
+      case 338: // duid_type
         value.move< ElementPtr > (s.value);
         value.move< ElementPtr > (s.value);
         break;
         break;
 
 
-      case 102: // "boolean"
+      case 105: // "boolean"
         value.move< bool > (s.value);
         value.move< bool > (s.value);
         break;
         break;
 
 
-      case 101: // "floating point"
+      case 104: // "floating point"
         value.move< double > (s.value);
         value.move< double > (s.value);
         break;
         break;
 
 
-      case 100: // "integer"
+      case 103: // "integer"
         value.move< int64_t > (s.value);
         value.move< int64_t > (s.value);
         break;
         break;
 
 
-      case 99: // "constant string"
+      case 102: // "constant string"
         value.move< std::string > (s.value);
         value.move< std::string > (s.value);
         break;
         break;
 
 
@@ -1517,7 +1538,7 @@ namespace isc { namespace dhcp {
      325,   326,   327,   328,   329,   330,   331,   332,   333,   334,
      325,   326,   327,   328,   329,   330,   331,   332,   333,   334,
      335,   336,   337,   338,   339,   340,   341,   342,   343,   344,
      335,   336,   337,   338,   339,   340,   341,   342,   343,   344,
      345,   346,   347,   348,   349,   350,   351,   352,   353,   354,
      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]);
     return static_cast<token_type> (yytoken_number_[type]);
   }
   }
@@ -1937,6 +1958,24 @@ namespace isc { namespace dhcp {
   }
   }
 
 
   Dhcp6Parser::symbol_type
   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)
   Dhcp6Parser::make_IDENTIFIER (const location_type& l)
   {
   {
     return symbol_type (token::TOKEN_IDENTIFIER, l);
     return symbol_type (token::TOKEN_IDENTIFIER, l);
@@ -2131,7 +2170,7 @@ namespace isc { namespace dhcp {
 
 
 #line 14 "dhcp6_parser.yy" // lalr1.cc:377
 #line 14 "dhcp6_parser.yy" // lalr1.cc:377
 } } // isc::dhcp
 } } // isc::dhcp
-#line 2135 "dhcp6_parser.h" // lalr1.cc:377
+#line 2174 "dhcp6_parser.h" // lalr1.cc:377
 
 
 
 
 
 

+ 27 - 5
src/bin/dhcp6/dhcp6_parser.yy

@@ -1,4 +1,4 @@
-/* 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
    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
    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"
   EXPIRED_LEASES_PROCESSING "expired-leases-processing"
 
 
   SERVER_ID "server-id"
   SERVER_ID "server-id"
+  LLT "LLT"
+  EN "EN"
+  LL "LL"
   IDENTIFIER "identifier"
   IDENTIFIER "identifier"
   HTYPE "htype"
   HTYPE "htype"
   TIME "time"
   TIME "time"
@@ -185,6 +188,7 @@ using namespace std;
 %token <bool> BOOLEAN "boolean"
 %token <bool> BOOLEAN "boolean"
 
 
 %type <ElementPtr> value
 %type <ElementPtr> value
+%type <ElementPtr> duid_type
 
 
 %printer { yyoutput << $$; } <*>;
 %printer { yyoutput << $$; } <*>;
 
 
@@ -454,7 +458,7 @@ database_map_params: database_map_param
                    | database_map_params COMMA database_map_param
                    | database_map_params COMMA database_map_param
                    ;
                    ;
 
 
-database_map_param: type
+database_map_param: database_type
                   | user
                   | user
                   | password
                   | password
                   | host
                   | host
@@ -465,7 +469,7 @@ database_map_param: type
                   | unknown_map_entry
                   | unknown_map_entry
 ;
 ;
 
 
-type: TYPE {
+database_type: TYPE {
     ctx.enter(ctx.NO_KEYWORD);
     ctx.enter(ctx.NO_KEYWORD);
 } COLON STRING {
 } COLON STRING {
     ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
     ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
@@ -870,7 +874,13 @@ code: CODE COLON INTEGER {
 
 
 option_def_code: code;
 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 {
 option_def_record_types: RECORD_TYPES {
     ctx.enter(ctx.NO_KEYWORD);
     ctx.enter(ctx.NO_KEYWORD);
@@ -1328,7 +1338,7 @@ server_id_params: server_id_param
                 | server_id_params COMMA server_id_param
                 | server_id_params COMMA server_id_param
                 ;
                 ;
 
 
-server_id_param: type
+server_id_param: server_id_type
                | identifier
                | identifier
                | time
                | time
                | htype
                | htype
@@ -1337,6 +1347,18 @@ server_id_param: type
                | unknown_map_entry
                | 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 {
 htype: HTYPE COLON INTEGER {
     ElementPtr htype(new IntElement($3, ctx.loc2pos(@3)));
     ElementPtr htype(new IntElement($3, ctx.loc2pos(@3)));
     ctx.stack_.back()->set("htype", htype);
     ctx.stack_.back()->set("htype", htype);

+ 8 - 2
src/bin/dhcp6/json_config_parser.cc

@@ -724,9 +724,8 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id,
         parser = new ExpirationConfigParser();
         parser = new ExpirationConfigParser();
     } else if (config_id.compare("client-classes") == 0) {
     } else if (config_id.compare("client-classes") == 0) {
         parser = new ClientClassDefListParser(config_id, globalContext());
         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.
     // host-reservation-identifiers have been converted to SimpleParser already.
+    // server-id has been migrated to SimpleParser
     } else {
     } else {
         isc_throw(DhcpConfigError,
         isc_throw(DhcpConfigError,
                 "unsupported global configuration parameter: "
                 "unsupported global configuration parameter: "
@@ -925,6 +924,13 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
                 continue;
                 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,
             ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first,
                                                            config_pair.second));
                                                            config_pair.second));
             LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
             LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)

+ 1 - 1
src/bin/dhcp6/location.hh

@@ -1,4 +1,4 @@
-// Generated 201612201711
+// Generated 201701070039
 // A Bison parser, made by GNU Bison 3.0.4.
 // A Bison parser, made by GNU Bison 3.0.4.
 
 
 // Locations for Bison parsers in C++
 // Locations for Bison parsers in C++

+ 2 - 0
src/bin/dhcp6/parser_context.cc

@@ -147,6 +147,8 @@ Parser6Context::contextName()
         return ("client-classes");
         return ("client-classes");
     case SERVER_ID:
     case SERVER_ID:
         return ("server-id");
         return ("server-id");
+    case DUID_TYPE:
+        return ("duid-type");
     case CONTROL_SOCKET:
     case CONTROL_SOCKET:
         return ("control-socket");
         return ("control-socket");
     case POOLS:
     case POOLS:

+ 4 - 1
src/bin/dhcp6/parser_context.h

@@ -1,4 +1,4 @@
-// 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
 // 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
 // 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.
         /// Used while parsing Dhcp6/server-id structures.
         SERVER_ID,
         SERVER_ID,
 
 
+        /// Used while parsing Dhcp6/server-id/type structures.
+        DUID_TYPE,
+
         /// Used while parsing Dhcp6/control-socket structures.
         /// Used while parsing Dhcp6/control-socket structures.
         CONTROL_SOCKET,
         CONTROL_SOCKET,
 
 

+ 1 - 1
src/bin/dhcp6/position.hh

@@ -1,4 +1,4 @@
-// Generated 201612201711
+// Generated 201701070039
 // A Bison parser, made by GNU Bison 3.0.4.
 // A Bison parser, made by GNU Bison 3.0.4.
 
 
 // Positions for Bison parsers in C++
 // Positions for Bison parsers in C++

+ 1 - 1
src/bin/dhcp6/stack.hh

@@ -1,4 +1,4 @@
-// Generated 201612201711
+// Generated 201701070039
 // A Bison parser, made by GNU Bison 3.0.4.
 // A Bison parser, made by GNU Bison 3.0.4.
 
 
 // Stack handling for Bison parsers in C++
 // Stack handling for Bison parsers in C++

+ 1 - 1
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -276,7 +276,7 @@ TEST_F(Dhcpv6SrvTest, DUID) {
     case DUID::DUID_LLT: {
     case DUID::DUID_LLT: {
         // DUID must contain at least 6 bytes long MAC
         // DUID must contain at least 6 bytes long MAC
         // + 8 bytes of fixed header
         // + 8 bytes of fixed header
-        EXPECT_GE(14, len);
+        EXPECT_GE(len, 14);
 
 
         uint16_t hw_type = data.readUint16();
         uint16_t hw_type = data.readUint16();
         // there's no real way to find out "correct"
         // there's no real way to find out "correct"

+ 6 - 0
src/lib/dhcp/duid_factory.cc

@@ -285,6 +285,12 @@ DUIDFactory::createLinkLayerId(std::vector<uint8_t>& identifier,
         // Assign link layer address and type.
         // Assign link layer address and type.
         identifier.assign(iface->getMac(), iface->getMac() + iface->getMacLen());
         identifier.assign(iface->getMac(), iface->getMac() + iface->getMacLen());
         htype = iface->getHWType();
         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
     // We failed to find an interface which link layer address could be

+ 3 - 3
src/lib/dhcp/tests/iface_mgr_unittest.cc

@@ -641,10 +641,10 @@ TEST_F(IfaceMgrTest, getIface) {
     // Interface name, ifindex
     // Interface name, ifindex
     IfacePtr iface1(new Iface("lo1", 100));
     IfacePtr iface1(new Iface("lo1", 100));
     IfacePtr iface2(new Iface("eth9", 101));
     IfacePtr iface2(new Iface("eth9", 101));
-    IfacePtr iface3(new Iface("en3", 102));
+    IfacePtr iface3(new Iface("en7", 102));
     IfacePtr iface4(new Iface("e1000g4", 103));
     IfacePtr iface4(new Iface("e1000g4", 103));
     cout << "This test assumes that there are less than 100 network interfaces"
     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;
          << " or wifi15 interfaces present." << endl;
 
 
     // Note: real interfaces may be detected as well
     // Note: real interfaces may be detected as well
@@ -666,7 +666,7 @@ TEST_F(IfaceMgrTest, getIface) {
     IfacePtr tmp = ifacemgr->getIface(102);
     IfacePtr tmp = ifacemgr->getIface(102);
     ASSERT_TRUE(tmp);
     ASSERT_TRUE(tmp);
 
 
-    EXPECT_EQ("en3", tmp->getName());
+    EXPECT_EQ("en7", tmp->getName());
     EXPECT_EQ(102, tmp->getIndex());
     EXPECT_EQ(102, tmp->getIndex());
 
 
     // Check that interface can be retrieved by name
     // Check that interface can be retrieved by name

+ 19 - 25
src/lib/dhcpsrv/parsers/duid_config_parser.cc

@@ -1,4 +1,4 @@
-// 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
 // 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
 // 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/cfgmgr.h>
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/parsers/duid_config_parser.h>
 #include <dhcpsrv/parsers/duid_config_parser.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
@@ -22,28 +23,28 @@ using namespace isc::data;
 namespace isc {
 namespace isc {
 namespace dhcp {
 namespace dhcp {
 
 
-DUIDConfigParser::DUIDConfigParser()
-    : DhcpConfigParser() {
-}
-
 void
 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;
     bool type_present = false;
     BOOST_FOREACH(ConfigPair element, duid_configuration->mapValue()) {
     BOOST_FOREACH(ConfigPair element, duid_configuration->mapValue()) {
         try {
         try {
             if (element.first == "type") {
             if (element.first == "type") {
                 type_present = true;
                 type_present = true;
-                setType(element.second->stringValue());
+                setType(cfg, element.second->stringValue());
             } else if (element.first == "identifier") {
             } else if (element.first == "identifier") {
-                setIdentifier(element.second->stringValue());
+                setIdentifier(cfg, element.second->stringValue());
             } else if (element.first == "htype") {
             } else if (element.first == "htype") {
-                setHType(element.second->intValue());
+                setHType(cfg, element.second->intValue());
             } else if (element.first == "time") {
             } else if (element.first == "time") {
-                setTime(element.second->intValue());
+                setTime(cfg, element.second->intValue());
             } else if (element.first == "enterprise-id") {
             } else if (element.first == "enterprise-id") {
-                setEnterpriseId(element.second->intValue());
+                setEnterpriseId(cfg, element.second->intValue());
             } else if (element.first == "persist") {
             } else if (element.first == "persist") {
-                setPersist(element.second->boolValue());
+                setPersist(cfg, element.second->boolValue());
             } else {
             } else {
                 isc_throw(DhcpConfigError, "unsupported configuration "
                 isc_throw(DhcpConfigError, "unsupported configuration "
                           "parameter '" << element.first << "'");
                           "parameter '" << element.first << "'");
@@ -66,7 +67,7 @@ DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
 }
 }
 
 
 void
 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.
     // Map DUID type represented as text into numeric value.
     DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
     DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
     if (duid_type == "LLT") {
     if (duid_type == "LLT") {
@@ -80,41 +81,34 @@ DUIDConfigParser::setType(const std::string& duid_type) const {
                   << duid_type << "'. Expected: LLT, EN or LL");
                   << duid_type << "'. Expected: LLT, EN or LL");
     }
     }
 
 
-    const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
     cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
     cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
 }
 }
 
 
 void
 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);
     cfg->setIdentifier(identifier);
 }
 }
 
 
 void
 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);
     checkRange<uint16_t>("htype", htype);
     cfg->setHType(static_cast<uint16_t>(htype));
     cfg->setHType(static_cast<uint16_t>(htype));
-
 }
 }
 
 
 void
 void
-DUIDConfigParser::setTime(const int64_t new_time) const {
-    const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
+DUIDConfigParser::setTime(const CfgDUIDPtr& cfg, const int64_t new_time) const {
     checkRange<uint32_t>("time", new_time);
     checkRange<uint32_t>("time", new_time);
     cfg->setTime(static_cast<uint32_t>(new_time));
     cfg->setTime(static_cast<uint32_t>(new_time));
 }
 }
 
 
 void
 void
-DUIDConfigParser::setEnterpriseId(const int64_t enterprise_id) const {
-    const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
+DUIDConfigParser::setEnterpriseId(const CfgDUIDPtr& cfg, const int64_t enterprise_id) const {
     checkRange<uint32_t>("enterprise-id", enterprise_id);
     checkRange<uint32_t>("enterprise-id", enterprise_id);
     cfg->setEnterpriseId(static_cast<uint32_t>(enterprise_id));
     cfg->setEnterpriseId(static_cast<uint32_t>(enterprise_id));
 }
 }
 
 
 void
 void
-DUIDConfigParser::setPersist(const bool persist) {
-    const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
+DUIDConfigParser::setPersist(const CfgDUIDPtr& cfg, const bool persist) {
     cfg->setPersist(persist);
     cfg->setPersist(persist);
 }
 }
 
 

+ 18 - 19
src/lib/dhcpsrv/parsers/duid_config_parser.h

@@ -1,4 +1,4 @@
-// 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
 // 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
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,7 +8,7 @@
 #define DUID_CONFIG_PARSER_H
 #define DUID_CONFIG_PARSER_H
 
 
 #include <cc/data.h>
 #include <cc/data.h>
-#include <dhcpsrv/parsers/dhcp_config_parser.h>
+#include <cc/simple_parser.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <string>
 #include <string>
 
 
@@ -23,56 +23,55 @@ namespace dhcp {
 /// - DUID-LL
 /// - DUID-LL
 ///
 ///
 /// @todo Add support for DUID-UUID in the parser.
 /// @todo Add support for DUID-UUID in the parser.
-class DUIDConfigParser : public DhcpConfigParser {
+class DUIDConfigParser : public isc::data::SimpleParser {
 public:
 public:
-
-    /// @brief Constructor.
-    DUIDConfigParser();
-
     /// @brief Parses DUID configuration.
     /// @brief Parses DUID configuration.
     ///
     ///
+    /// @param cfg parsed DUID configuration will be stored here
     /// @param duid_configuration Data element holding a map representing
     /// @param duid_configuration Data element holding a map representing
     /// DUID configuration.
     /// DUID configuration.
     ///
     ///
     /// @throw DhcpConfigError If the configuration is invalid.
     /// @throw DhcpConfigError If the configuration is invalid.
-    virtual void build(isc::data::ConstElementPtr duid_configuration);
-
-    /// @brief Commit, unused.
-    virtual void commit() { }
-
+    void parse(const CfgDUIDPtr& cfg, isc::data::ConstElementPtr duid_configuration);
 private:
 private:
 
 
     /// @brief Validate and set DUID type.
     /// @brief Validate and set DUID type.
     ///
     ///
-    /// @param duid_type DUID type in textfual format.
-    void setType(const std::string& duid_type) const;
+    /// @param cfg parsed information will be stored here
+    /// @param duid_type DUID type in textual format.
+    void setType(const CfgDUIDPtr& cfg, const std::string& duid_type) const;
 
 
     /// @brief Validate and set identifier.
     /// @brief Validate and set identifier.
     ///
     ///
+    /// @param cfg parsed information will be stored here
     /// @param identifier Identifier.
     /// @param identifier Identifier.
-    void setIdentifier(const std::string& identifier) const;
+    void setIdentifier(const CfgDUIDPtr& cfg, const std::string& identifier) const;
 
 
     /// @brief Validate and set hardware type.
     /// @brief Validate and set hardware type.
     ///
     ///
+    /// @param cfg parsed information will be stored here
     /// @param htype Hardware type.
     /// @param htype Hardware type.
-    void setHType(const int64_t htype) const;
+    void setHType(const CfgDUIDPtr& cfg, const int64_t htype) const;
 
 
     /// @brief Validate and set time value.
     /// @brief Validate and set time value.
     ///
     ///
+    /// @param cfg parsed information will be stored here
     /// @param new_time Time value to be used for DUID.
     /// @param new_time Time value to be used for DUID.
-    void setTime(const int64_t new_time) const;
+    void setTime(const CfgDUIDPtr& cfg, const int64_t new_time) const;
 
 
     /// @brief Validate and set enterprise id.
     /// @brief Validate and set enterprise id.
     ///
     ///
+    /// @param cfg parsed information will be stored here
     /// @param enterprise_id Enterprise id.
     /// @param enterprise_id Enterprise id.
-    void setEnterpriseId(const int64_t enterprise_id) const;
+    void setEnterpriseId(const CfgDUIDPtr& cfg, const int64_t enterprise_id) const;
 
 
     /// @brief Set persistence flag.
     /// @brief Set persistence flag.
     ///
     ///
+    /// @param cfg parsed information will be stored here
     /// @param persist A boolean value indicating if the server
     /// @param persist A boolean value indicating if the server
     /// identifier should be stored on the disk (if true) or
     /// identifier should be stored on the disk (if true) or
     /// not (if false).
     /// not (if false).
-    void setPersist(const bool persist);
+    void setPersist(const CfgDUIDPtr& cfg, const bool persist);
 
 
     /// @brief Verifies if the specified parameter is in range.
     /// @brief Verifies if the specified parameter is in range.
     ///
     ///

+ 27 - 17
src/lib/dhcpsrv/tests/duid_config_parser_unittest.cc

@@ -1,4 +1,4 @@
-// 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
 // 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
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,6 +9,7 @@
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_duid.h>
 #include <dhcpsrv/cfg_duid.h>
 #include <dhcpsrv/parsers/duid_config_parser.h>
 #include <dhcpsrv/parsers/duid_config_parser.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <dhcpsrv/testutils/config_result_check.h>
 #include <dhcpsrv/testutils/config_result_check.h>
 #include <util/encode/hex.h>
 #include <util/encode/hex.h>
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
@@ -26,6 +27,13 @@ namespace {
 class DUIDConfigParserTest : public ::testing::Test {
 class DUIDConfigParserTest : public ::testing::Test {
 public:
 public:
 
 
+    /// @brief constructor
+    ///
+    /// Initializes cfg_duid_ to a new empty object
+    DUIDConfigParserTest()
+        :cfg_duid_(new CfgDUID()){
+    }
+
     /// @brief Creates simple configuration with DUID type only.
     /// @brief Creates simple configuration with DUID type only.
     ///
     ///
     /// @param duid_type DUID type in the textual format.
     /// @param duid_type DUID type in the textual format.
@@ -82,9 +90,12 @@ public:
     /// @param vec Input vector.
     /// @param vec Input vector.
     /// @return String of hexadecimal digits converted from vector.
     /// @return String of hexadecimal digits converted from vector.
     std::string toString(const std::vector<uint8_t>& vec) const;
     std::string toString(const std::vector<uint8_t>& vec) const;
+
+    /// Config DUID pointer
+    CfgDUIDPtr cfg_duid_;
 };
 };
 
 
-std::string 
+std::string
 DUIDConfigParserTest::createConfigWithType(const std::string& duid_type) const {
 DUIDConfigParserTest::createConfigWithType(const std::string& duid_type) const {
     std::ostringstream s;
     std::ostringstream s;
     s << "{ \"type\": \"" << duid_type << "\" }";
     s << "{ \"type\": \"" << duid_type << "\" }";
@@ -103,10 +114,9 @@ void
 DUIDConfigParserTest::build(const std::string& config) const {
 DUIDConfigParserTest::build(const std::string& config) const {
     ElementPtr config_element = Element::fromJSON(config);
     ElementPtr config_element = Element::fromJSON(config);
     DUIDConfigParser parser;
     DUIDConfigParser parser;
-    parser.build(config_element);
+    parser.parse(cfg_duid_, config_element);
 }
 }
 
 
-
 void
 void
 DUIDConfigParserTest::testTypeOnly(const DUID::DUIDType& duid_type,
 DUIDConfigParserTest::testTypeOnly(const DUID::DUIDType& duid_type,
                                    const std::string& duid_type_text) const {
                                    const std::string& duid_type_text) const {
@@ -115,12 +125,12 @@ DUIDConfigParserTest::testTypeOnly(const DUID::DUIDType& duid_type,
 
 
     // Make sure that the type is correct and that other parameters are set
     // Make sure that the type is correct and that other parameters are set
     // to their defaults.
     // to their defaults.
-    CfgDUIDPtr cfg_duid = CfgMgr::instance().getStagingCfg()->getCfgDUID();
-    EXPECT_EQ(duid_type, cfg_duid->getType());
-    EXPECT_TRUE(cfg_duid->getIdentifier().empty());
-    EXPECT_EQ(0, cfg_duid->getHType());
-    EXPECT_EQ(0, cfg_duid->getTime());
-    EXPECT_EQ(0, cfg_duid->getEnterpriseId());
+    ASSERT_TRUE(cfg_duid_);
+    EXPECT_EQ(duid_type, cfg_duid_->getType());
+    EXPECT_TRUE(cfg_duid_->getIdentifier().empty());
+    EXPECT_EQ(0, cfg_duid_->getHType());
+    EXPECT_EQ(0, cfg_duid_->getTime());
+    EXPECT_EQ(0, cfg_duid_->getEnterpriseId());
 }
 }
 
 
 void
 void
@@ -181,13 +191,13 @@ TEST_F(DUIDConfigParserTest, allParameters) {
                           "}"));
                           "}"));
 
 
     // Verify that parameters have been set correctly.
     // Verify that parameters have been set correctly.
-    CfgDUIDPtr cfg_duid = CfgMgr::instance().getStagingCfg()->getCfgDUID();
-    EXPECT_EQ(DUID::DUID_EN, cfg_duid->getType());
-    EXPECT_EQ("ABCDEF", toString(cfg_duid->getIdentifier()));
-    EXPECT_EQ(8, cfg_duid->getHType());
-    EXPECT_EQ(100, cfg_duid->getTime());
-    EXPECT_EQ(2024, cfg_duid->getEnterpriseId());
-    EXPECT_FALSE(cfg_duid->persist());
+    ASSERT_TRUE(cfg_duid_);
+    EXPECT_EQ(DUID::DUID_EN, cfg_duid_->getType());
+    EXPECT_EQ("ABCDEF", toString(cfg_duid_->getIdentifier()));
+    EXPECT_EQ(8, cfg_duid_->getHType());
+    EXPECT_EQ(100, cfg_duid_->getTime());
+    EXPECT_EQ(2024, cfg_duid_->getEnterpriseId());
+    EXPECT_FALSE(cfg_duid_->persist());
 }
 }
 
 
 // Test out of range values for time.
 // Test out of range values for time.