Kea  2.1.7-git
duid_config_parser.cc
Go to the documentation of this file.
1 // Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 #include <cc/data.h>
9 #include <dhcp/duid.h>
10 #include <dhcpsrv/cfg_duid.h>
11 #include <dhcpsrv/cfgmgr.h>
12 #include <dhcpsrv/dhcpsrv_log.h>
15 #include <exceptions/exceptions.h>
16 #include <boost/foreach.hpp>
17 #include <boost/lexical_cast.hpp>
18 #include <limits>
19 #include <string>
20 
21 using namespace isc::data;
22 
23 namespace isc {
24 namespace dhcp {
25 
26 void
27 DUIDConfigParser::parse(const CfgDUIDPtr& cfg,
28  isc::data::ConstElementPtr duid_configuration) {
29  if (!cfg) {
30  // Sanity check
31  isc_throw(DhcpConfigError, "Must provide valid pointer to cfg when parsing duid");
32  }
33 
34  std::string param;
35  try {
36  param = "type";
37  std::string duid_type = getString(duid_configuration, "type");
38  // Map DUID type represented as text into numeric value.
39  DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
40  if (duid_type == "LLT") {
41  numeric_type = DUID::DUID_LLT;
42  } else if (duid_type == "EN") {
43  numeric_type = DUID::DUID_EN;
44  } else if (duid_type == "LL") {
45  numeric_type = DUID::DUID_LL;
46  } else {
47  isc_throw(BadValue, "unsupported DUID type '"
48  << duid_type << "'. Expected: LLT, EN or LL");
49  }
50 
51  cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
52 
53  param = "identifier";
54  if (duid_configuration->contains(param)) {
55  cfg->setIdentifier(getString(duid_configuration, param));
56  }
57 
58  param = "htype";
59  if (duid_configuration->contains(param)) {
60  cfg->setHType(getUint16(duid_configuration, param));
61  }
62 
63  param = "time";
64  if (duid_configuration->contains(param)) {
65  cfg->setTime(getUint32(duid_configuration, param));
66  }
67 
68  param = "enterprise-id";
69  if (duid_configuration->contains(param)) {
70  cfg->setEnterpriseId(getUint32(duid_configuration, param));
71  }
72 
73  param = "persist";
74  if (duid_configuration->contains(param)) {
75  cfg->setPersist(getBoolean(duid_configuration, param));
76  }
77 
78  param = "user-context";
79  ConstElementPtr user_context = duid_configuration->get("user-context");
80  if (user_context) {
81  cfg->setContext(user_context);
82  }
83  } catch (const DhcpConfigError&) {
84  throw;
85  } catch (const std::exception& ex) {
86  // Append position.
87  isc_throw(DhcpConfigError, ex.what() << " ("
88  << getPosition(param, duid_configuration) << ")");
89  }
90 
92 }
93 
94 } // end of namespace isc::dhcp
95 } // end of namespace isc
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition: macros.h:26
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
DUIDType
specifies DUID type
Definition: duid.h:38
To be removed. Please use ConfigError instead.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
const isc::log::MessageID DHCPSRV_CFGMGR_CONFIGURE_SERVERID
Defines the logger used by the top-level component of kea-lfc.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Definition: dhcpsrv_log.h:56
boost::shared_ptr< CfgDUID > CfgDUIDPtr
Pointer to the Non-const object.
Definition: cfg_duid.h:161