json_config_parser.cc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <cc/command_interpreter.h>
  16. #include <dhcp4/dhcp4_log.h>
  17. #include <dhcp/libdhcp++.h>
  18. #include <dhcp/option_definition.h>
  19. #include <dhcpsrv/cfg_option.h>
  20. #include <dhcpsrv/cfgmgr.h>
  21. #include <dhcp4/json_config_parser.h>
  22. #include <dhcpsrv/option_space_container.h>
  23. #include <dhcpsrv/parsers/dbaccess_parser.h>
  24. #include <dhcpsrv/parsers/dhcp_parsers.h>
  25. #include <dhcpsrv/parsers/host_reservation_parser.h>
  26. #include <dhcpsrv/parsers/host_reservations_list_parser.h>
  27. #include <dhcpsrv/parsers/ifaces_config_parser.h>
  28. #include <util/encode/hex.h>
  29. #include <util/strutil.h>
  30. #include <boost/foreach.hpp>
  31. #include <boost/lexical_cast.hpp>
  32. #include <boost/algorithm/string.hpp>
  33. #include <limits>
  34. #include <iostream>
  35. #include <vector>
  36. #include <map>
  37. using namespace std;
  38. using namespace isc;
  39. using namespace isc::dhcp;
  40. using namespace isc::data;
  41. using namespace isc::asiolink;
  42. namespace {
  43. /// @brief Parser for IPv4 pool definitions.
  44. ///
  45. /// This is the IPv4 derivation of the PoolParser class and handles pool
  46. /// definitions, i.e. a list of entries of one of two syntaxes: min-max and
  47. /// prefix/len for IPv4 pools. Pool4 objects are created and stored in chosen
  48. /// PoolStorage container.
  49. ///
  50. /// It is useful for parsing Dhcp4/subnet4[X]/pool parameters.
  51. class Pool4Parser : public PoolParser {
  52. public:
  53. /// @brief Constructor.
  54. ///
  55. /// @param param_name name of the parameter. Note, it is passed through
  56. /// but unused, parameter is currently always "Dhcp4/subnet4[X]/pool"
  57. /// @param pools storage container in which to store the parsed pool
  58. /// upon "commit"
  59. Pool4Parser(const std::string& param_name, PoolStoragePtr pools)
  60. :PoolParser(param_name, pools) {
  61. }
  62. protected:
  63. /// @brief Creates a Pool4 object given a IPv4 prefix and the prefix length.
  64. ///
  65. /// @param addr is the IPv4 prefix of the pool.
  66. /// @param len is the prefix length.
  67. /// @param ignored dummy parameter to provide symmetry between the
  68. /// PoolParser derivations. The V6 derivation requires a third value.
  69. /// @return returns a PoolPtr to the new Pool4 object.
  70. PoolPtr poolMaker (IOAddress &addr, uint32_t len, int32_t) {
  71. return (PoolPtr(new Pool4(addr, len)));
  72. }
  73. /// @brief Creates a Pool4 object given starting and ending IPv4 addresses.
  74. ///
  75. /// @param min is the first IPv4 address in the pool.
  76. /// @param max is the last IPv4 address in the pool.
  77. /// @param ignored dummy parameter to provide symmetry between the
  78. /// PoolParser derivations. The V6 derivation requires a third value.
  79. /// @return returns a PoolPtr to the new Pool4 object.
  80. PoolPtr poolMaker (IOAddress &min, IOAddress &max, int32_t) {
  81. return (PoolPtr(new Pool4(min, max)));
  82. }
  83. };
  84. class Pools4ListParser : public PoolsListParser {
  85. public:
  86. Pools4ListParser(const std::string& dummy, PoolStoragePtr pools)
  87. :PoolsListParser(dummy, pools) {
  88. }
  89. protected:
  90. virtual ParserPtr poolParserMaker(PoolStoragePtr storage) {
  91. return (ParserPtr(new Pool4Parser("pool", storage)));
  92. }
  93. };
  94. /// @brief This class parses a single IPv4 subnet.
  95. ///
  96. /// This is the IPv4 derivation of the SubnetConfigParser class and it parses
  97. /// the whole subnet definition. It creates parsersfor received configuration
  98. /// parameters as needed.
  99. class Subnet4ConfigParser : public SubnetConfigParser {
  100. public:
  101. /// @brief Constructor
  102. ///
  103. /// @param ignored first parameter
  104. /// stores global scope parameters, options, option definitions.
  105. Subnet4ConfigParser(const std::string&)
  106. :SubnetConfigParser("", globalContext(), IOAddress("0.0.0.0")) {
  107. }
  108. /// @brief Parses a single IPv4 subnet configuration and adds to the
  109. /// Configuration Manager.
  110. ///
  111. /// @param subnet A new subnet being configured.
  112. void build(ConstElementPtr subnet) {
  113. SubnetConfigParser::build(subnet);
  114. if (subnet_) {
  115. Subnet4Ptr sub4ptr = boost::dynamic_pointer_cast<Subnet4>(subnet_);
  116. if (!sub4ptr) {
  117. // If we hit this, it is a programming error.
  118. isc_throw(Unexpected,
  119. "Invalid cast in Subnet4ConfigParser::commit");
  120. }
  121. // Set relay information if it was parsed
  122. if (relay_info_) {
  123. sub4ptr->setRelayInfo(*relay_info_);
  124. }
  125. // Adding a subnet to the Configuration Manager may fail if the
  126. // subnet id is invalid (duplicate). Thus, we catch exceptions
  127. // here to append a position in the configuration string.
  128. try {
  129. CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(sub4ptr);
  130. } catch (const std::exception& ex) {
  131. isc_throw(DhcpConfigError, ex.what() << " ("
  132. << subnet->getPosition() << ")");
  133. }
  134. }
  135. // Parse Host Reservations for this subnet if any.
  136. ConstElementPtr reservations = subnet->get("reservations");
  137. if (reservations) {
  138. ParserPtr parser(new HostReservationsListParser<
  139. HostReservationParser4>(subnet_->getID()));
  140. parser->build(reservations);
  141. }
  142. }
  143. /// @brief Commits subnet configuration.
  144. ///
  145. /// This function is currently no-op because subnet should already
  146. /// be added into the Config Manager in the build().
  147. void commit() { }
  148. protected:
  149. /// @brief Creates parsers for entries in subnet definition.
  150. ///
  151. /// @param config_id name of the entry
  152. ///
  153. /// @return parser object for specified entry name. Note the caller is
  154. /// responsible for deleting the parser created.
  155. /// @throw isc::dhcp::DhcpConfigError if trying to create a parser
  156. /// for unknown config element
  157. DhcpConfigParser* createSubnetConfigParser(const std::string& config_id) {
  158. DhcpConfigParser* parser = NULL;
  159. if ((config_id.compare("valid-lifetime") == 0) ||
  160. (config_id.compare("renew-timer") == 0) ||
  161. (config_id.compare("rebind-timer") == 0) ||
  162. (config_id.compare("id") == 0)) {
  163. parser = new Uint32Parser(config_id, uint32_values_);
  164. } else if ((config_id.compare("subnet") == 0) ||
  165. (config_id.compare("interface") == 0) ||
  166. (config_id.compare("client-class") == 0) ||
  167. (config_id.compare("next-server") == 0) ||
  168. (config_id.compare("reservation-mode") == 0)) {
  169. parser = new StringParser(config_id, string_values_);
  170. } else if (config_id.compare("pools") == 0) {
  171. parser = new Pools4ListParser(config_id, pools_);
  172. } else if (config_id.compare("relay") == 0) {
  173. parser = new RelayInfoParser(config_id, relay_info_, Option::V4);
  174. } else if (config_id.compare("option-data") == 0) {
  175. parser = new OptionDataListParser(config_id, options_, AF_INET);
  176. } else {
  177. isc_throw(NotImplemented, "unsupported parameter: " << config_id);
  178. }
  179. return (parser);
  180. }
  181. /// @brief Issues a DHCP4 server specific warning regarding duplicate subnet
  182. /// options.
  183. ///
  184. /// @param code is the numeric option code of the duplicate option
  185. /// @param addr is the subnet address
  186. /// @todo a means to know the correct logger and perhaps a common
  187. /// message would allow this method to be emitted by the base class.
  188. virtual void duplicate_option_warning(uint32_t code,
  189. isc::asiolink::IOAddress& addr) {
  190. LOG_WARN(dhcp4_logger, DHCP4_CONFIG_OPTION_DUPLICATE)
  191. .arg(code).arg(addr.toText());
  192. }
  193. /// @brief Instantiates the IPv4 Subnet based on a given IPv4 address
  194. /// and prefix length.
  195. ///
  196. /// @param addr is IPv4 address of the subnet.
  197. /// @param len is the prefix length
  198. void initSubnet(isc::asiolink::IOAddress addr, uint8_t len) {
  199. // The renew-timer and rebind-timer are optional. If not set, the
  200. // option 58 and 59 will not be sent to a client. In this case the
  201. // client will use default values based on the valid-lifetime.
  202. Triplet<uint32_t> t1 = getOptionalParam("renew-timer");
  203. Triplet<uint32_t> t2 = getOptionalParam("rebind-timer");
  204. // The valid-lifetime is mandatory. It may be specified for a
  205. // particular subnet. If not, the global value should be present.
  206. // If there is no global value, exception is thrown.
  207. Triplet<uint32_t> valid = getParam("valid-lifetime");
  208. // Subnet ID is optional. If it is not supplied the value of 0 is used,
  209. // which means autogenerate.
  210. SubnetID subnet_id =
  211. static_cast<SubnetID>(uint32_values_->getOptionalParam("id", 0));
  212. stringstream s;
  213. s << addr << "/" << static_cast<int>(len) << " with params: ";
  214. // t1 and t2 are optional may be not specified.
  215. if (!t1.unspecified()) {
  216. s << "t1=" << t1 << ", ";
  217. }
  218. if (!t2.unspecified()) {
  219. s << "t2=" << t2 << ", ";
  220. }
  221. s <<"valid-lifetime=" << valid;
  222. LOG_INFO(dhcp4_logger, DHCP4_CONFIG_NEW_SUBNET).arg(s.str());
  223. Subnet4Ptr subnet4(new Subnet4(addr, len, t1, t2, valid, subnet_id));
  224. subnet_ = subnet4;
  225. // Try global value first
  226. try {
  227. string next_server = globalContext()->string_values_->getParam("next-server");
  228. if (!next_server.empty()) {
  229. subnet4->setSiaddr(IOAddress(next_server));
  230. }
  231. } catch (const DhcpConfigError&) {
  232. // Don't care. next_server is optional. We can live without it
  233. } catch (...) {
  234. isc_throw(DhcpConfigError, "invalid parameter next-server ("
  235. << globalContext()->string_values_->getPosition("next-server")
  236. << ")");
  237. }
  238. // Try subnet specific value if it's available
  239. try {
  240. string next_server = string_values_->getParam("next-server");
  241. if (!next_server.empty()) {
  242. subnet4->setSiaddr(IOAddress(next_server));
  243. }
  244. } catch (const DhcpConfigError&) {
  245. // Don't care. next_server is optional. We can live without it
  246. } catch (...) {
  247. isc_throw(DhcpConfigError, "invalid parameter next-server ("
  248. << string_values_->getPosition("next-server")
  249. << ")");
  250. }
  251. // Try setting up client class (if specified)
  252. try {
  253. string client_class = string_values_->getParam("client-class");
  254. subnet4->allowClientClass(client_class);
  255. } catch (const DhcpConfigError&) {
  256. // That's ok if it fails. client-class is optional.
  257. }
  258. }
  259. };
  260. /// @brief this class parses list of DHCP4 subnets
  261. ///
  262. /// This is a wrapper parser that handles the whole list of Subnet4
  263. /// definitions. It iterates over all entries and creates Subnet4ConfigParser
  264. /// for each entry.
  265. class Subnets4ListConfigParser : public DhcpConfigParser {
  266. public:
  267. /// @brief constructor
  268. ///
  269. /// @param dummy first argument, always ignored. All parsers accept a
  270. /// string parameter "name" as their first argument.
  271. Subnets4ListConfigParser(const std::string&) {
  272. }
  273. /// @brief parses contents of the list
  274. ///
  275. /// Iterates over all entries on the list and creates Subnet4ConfigParser
  276. /// for each entry.
  277. ///
  278. /// @param subnets_list pointer to a list of IPv4 subnets
  279. void build(ConstElementPtr subnets_list) {
  280. BOOST_FOREACH(ConstElementPtr subnet, subnets_list->listValue()) {
  281. ParserPtr parser(new Subnet4ConfigParser("subnet"));
  282. parser->build(subnet);
  283. }
  284. }
  285. /// @brief commits subnets definitions.
  286. ///
  287. /// Does nothing.
  288. void commit() {
  289. }
  290. /// @brief Returns Subnet4ListConfigParser object
  291. /// @param param_name name of the parameter
  292. /// @return Subnets4ListConfigParser object
  293. static DhcpConfigParser* factory(const std::string& param_name) {
  294. return (new Subnets4ListConfigParser(param_name));
  295. }
  296. };
  297. } // anonymous namespace
  298. namespace isc {
  299. namespace dhcp {
  300. /// @brief creates global parsers
  301. ///
  302. /// This method creates global parsers that parse global parameters, i.e.
  303. /// those that take format of Dhcp4/param1, Dhcp4/param2 and so forth.
  304. ///
  305. /// @param config_id pointer to received global configuration entry
  306. /// @param element pointer to the element to be parsed
  307. /// @return parser for specified global DHCPv4 parameter
  308. /// @throw NotImplemented if trying to create a parser for unknown
  309. /// config element
  310. DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
  311. ConstElementPtr element) {
  312. DhcpConfigParser* parser = NULL;
  313. if ((config_id.compare("valid-lifetime") == 0) ||
  314. (config_id.compare("renew-timer") == 0) ||
  315. (config_id.compare("rebind-timer") == 0)) {
  316. parser = new Uint32Parser(config_id,
  317. globalContext()->uint32_values_);
  318. } else if (config_id.compare("interfaces-config") == 0) {
  319. parser = new IfacesConfigParser4();
  320. } else if (config_id.compare("subnet4") == 0) {
  321. parser = new Subnets4ListConfigParser(config_id);
  322. } else if (config_id.compare("option-data") == 0) {
  323. parser = new OptionDataListParser(config_id, CfgOptionPtr(), AF_INET);
  324. } else if (config_id.compare("option-def") == 0) {
  325. parser = new OptionDefListParser(config_id, globalContext());
  326. } else if ((config_id.compare("version") == 0) ||
  327. (config_id.compare("next-server") == 0)) {
  328. parser = new StringParser(config_id,
  329. globalContext()->string_values_);
  330. } else if (config_id.compare("lease-database") == 0) {
  331. parser = new DbAccessParser(config_id, *globalContext());
  332. } else if (config_id.compare("hooks-libraries") == 0) {
  333. parser = new HooksLibrariesParser(config_id);
  334. } else if (config_id.compare("echo-client-id") == 0) {
  335. parser = new BooleanParser(config_id, globalContext()->boolean_values_);
  336. } else if (config_id.compare("dhcp-ddns") == 0) {
  337. parser = new D2ClientConfigParser(config_id);
  338. } else {
  339. isc_throw(DhcpConfigError,
  340. "unsupported global configuration parameter: "
  341. << config_id << " (" << element->getPosition() << ")");
  342. }
  343. return (parser);
  344. }
  345. void commitGlobalOptions() {
  346. // Although the function is modest for now, it is certain that the number
  347. // of global switches will increase over time, hence the name.
  348. // Set whether v4 server is supposed to echo back client-id (yes = RFC6842
  349. // compatible, no = backward compatibility)
  350. try {
  351. bool echo_client_id = globalContext()->boolean_values_->getParam("echo-client-id");
  352. CfgMgr::instance().echoClientId(echo_client_id);
  353. } catch (...) {
  354. // Ignore errors. This flag is optional
  355. }
  356. }
  357. isc::data::ConstElementPtr
  358. configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
  359. if (!config_set) {
  360. ConstElementPtr answer = isc::config::createAnswer(1,
  361. string("Can't parse NULL config"));
  362. return (answer);
  363. }
  364. LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND,
  365. DHCP4_CONFIG_START).arg(config_set->str());
  366. // Before starting any subnet operations, let's reset the subnet-id counter,
  367. // so newly recreated configuration starts with first subnet-id equal 1.
  368. Subnet::resetSubnetID();
  369. // Some of the values specified in the configuration depend on
  370. // other values. Typically, the values in the subnet4 structure
  371. // depend on the global values. Also, option values configuration
  372. // must be performed after the option definitions configurations.
  373. // Thus we group parsers and will fire them in the right order:
  374. // all parsers other than: lease-database, subnet4 and option-data parser,
  375. // then: option-data parser, subnet4 parser, lease-database parser.
  376. // Please do not change this order!
  377. ParserCollection independent_parsers;
  378. ParserPtr subnet_parser;
  379. ParserPtr option_parser;
  380. ParserPtr iface_parser;
  381. ParserPtr leases_parser;
  382. // Some of the parsers alter the state of the system in a way that can't
  383. // easily be undone. (Or alter it in a way such that undoing the change has
  384. // the same risk of failure as doing the change.)
  385. ParserPtr hooks_parser;
  386. // The subnet parsers implement data inheritance by directly
  387. // accessing global storage. For this reason the global data
  388. // parsers must store the parsed data into global storages
  389. // immediately. This may cause data inconsistency if the
  390. // parsing operation fails after the global storage has been
  391. // modified. We need to preserve the original global data here
  392. // so as we can rollback changes when an error occurs.
  393. ParserContext original_context(*globalContext());
  394. // Answer will hold the result.
  395. ConstElementPtr answer;
  396. // Rollback informs whether error occurred and original data
  397. // have to be restored to global storages.
  398. bool rollback = false;
  399. // config_pair holds the details of the current parser when iterating over
  400. // the parsers. It is declared outside the loops so in case of an error,
  401. // the name of the failing parser can be retrieved in the "catch" clause.
  402. ConfigPair config_pair;
  403. try {
  404. // Make parsers grouping.
  405. const std::map<std::string, ConstElementPtr>& values_map =
  406. config_set->mapValue();
  407. BOOST_FOREACH(config_pair, values_map) {
  408. ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
  409. config_pair.second));
  410. LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
  411. .arg(config_pair.first);
  412. if (config_pair.first == "subnet4") {
  413. subnet_parser = parser;
  414. } else if (config_pair.first == "lease-database") {
  415. leases_parser = parser;
  416. } else if (config_pair.first == "option-data") {
  417. option_parser = parser;
  418. } else if (config_pair.first == "interfaces-config") {
  419. // The interface parser is independent from any other
  420. // parser and can be run here before any other parsers.
  421. iface_parser = parser;
  422. parser->build(config_pair.second);
  423. } else if (config_pair.first == "hooks-libraries") {
  424. // Executing commit will alter currently-loaded hooks
  425. // libraries. Check if the supplied libraries are valid,
  426. // but defer the commit until everything else has committed.
  427. hooks_parser = parser;
  428. parser->build(config_pair.second);
  429. } else {
  430. // Those parsers should be started before other
  431. // parsers so we can call build straight away.
  432. independent_parsers.push_back(parser);
  433. parser->build(config_pair.second);
  434. // The commit operation here may modify the global storage
  435. // but we need it so as the subnet6 parser can access the
  436. // parsed data.
  437. parser->commit();
  438. }
  439. }
  440. // The option values parser is the next one to be run.
  441. std::map<std::string, ConstElementPtr>::const_iterator option_config =
  442. values_map.find("option-data");
  443. if (option_config != values_map.end()) {
  444. config_pair.first = "option-data";
  445. option_parser->build(option_config->second);
  446. option_parser->commit();
  447. }
  448. // The subnet parser is the next one to be run.
  449. std::map<std::string, ConstElementPtr>::const_iterator subnet_config =
  450. values_map.find("subnet4");
  451. if (subnet_config != values_map.end()) {
  452. config_pair.first = "subnet4";
  453. subnet_parser->build(subnet_config->second);
  454. }
  455. // the leases database parser is the last to be run.
  456. std::map<std::string, ConstElementPtr>::const_iterator leases_config =
  457. values_map.find("lease-database");
  458. if (leases_config != values_map.end()) {
  459. config_pair.first = "lease-database";
  460. leases_parser->build(leases_config->second);
  461. leases_parser->commit();
  462. }
  463. } catch (const isc::Exception& ex) {
  464. LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
  465. .arg(config_pair.first).arg(ex.what());
  466. answer = isc::config::createAnswer(1, ex.what());
  467. // An error occurred, so make sure that we restore original data.
  468. rollback = true;
  469. } catch (...) {
  470. // For things like bad_cast in boost::lexical_cast
  471. LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
  472. answer = isc::config::createAnswer(1, "undefined configuration"
  473. " processing error");
  474. // An error occurred, so make sure that we restore original data.
  475. rollback = true;
  476. }
  477. // So far so good, there was no parsing error so let's commit the
  478. // configuration. This will add created subnets and option values into
  479. // the server's configuration.
  480. // This operation should be exception safe but let's make sure.
  481. if (!rollback) {
  482. try {
  483. // No need to commit interface names as this is handled by the
  484. // CfgMgr::commit() function.
  485. // Apply global options
  486. commitGlobalOptions();
  487. // This occurs last as if it succeeds, there is no easy way
  488. // revert it. As a result, the failure to commit a subsequent
  489. // change causes problems when trying to roll back.
  490. if (hooks_parser) {
  491. hooks_parser->commit();
  492. }
  493. }
  494. catch (const isc::Exception& ex) {
  495. LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
  496. answer = isc::config::createAnswer(2, ex.what());
  497. rollback = true;
  498. } catch (...) {
  499. // For things like bad_cast in boost::lexical_cast
  500. LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
  501. answer = isc::config::createAnswer(2, "undefined configuration"
  502. " parsing error");
  503. rollback = true;
  504. }
  505. }
  506. // Rollback changes as the configuration parsing failed.
  507. if (rollback) {
  508. globalContext().reset(new ParserContext(original_context));
  509. return (answer);
  510. }
  511. LOG_INFO(dhcp4_logger, DHCP4_CONFIG_COMPLETE)
  512. .arg(CfgMgr::instance().getStagingCfg()->
  513. getConfigSummary(SrvConfig::CFGSEL_ALL4));
  514. // Everything was fine. Configuration is successful.
  515. answer = isc::config::createAnswer(0, "Configuration successful.");
  516. return (answer);
  517. }
  518. ParserContextPtr& globalContext() {
  519. static ParserContextPtr global_context_ptr(new ParserContext(Option::V4));
  520. return (global_context_ptr);
  521. }
  522. }; // end of isc::dhcp namespace
  523. }; // end of isc namespace