json_config_parser.cc 23.7 KB
Newer Older
1
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15 16
#include <config.h>

17 18
#include <config/ccsession.h>
#include <dhcp4/dhcp4_log.h>
19 20
#include <dhcp/libdhcp++.h>
#include <dhcp/option_definition.h>
21
#include <dhcpsrv/cfg_option.h>
22
#include <dhcpsrv/cfgmgr.h>
23
#include <dhcp4/json_config_parser.h>
24
#include <dhcpsrv/option_space_container.h>
25 26
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
27 28
#include <dhcpsrv/parsers/host_reservation_parser.h>
#include <dhcpsrv/parsers/host_reservations_list_parser.h>
29
#include <dhcpsrv/parsers/ifaces_config_parser.h>
30
#include <util/encode/hex.h>
31
#include <util/strutil.h>
32

Tomek Mrugalski's avatar
Tomek Mrugalski committed
33 34 35
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
36

Tomek Mrugalski's avatar
Tomek Mrugalski committed
37
#include <limits>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
38 39 40 41
#include <iostream>
#include <vector>
#include <map>

42
using namespace std;
43 44
using namespace isc;
using namespace isc::dhcp;
45 46 47
using namespace isc::data;
using namespace isc::asiolink;

48 49
namespace {

50
/// @brief Parser for IPv4 pool definitions.
51
///
52 53 54
/// This is the IPv4 derivation of the PoolParser class and handles pool
/// definitions, i.e. a list of entries of one of two syntaxes: min-max and
/// prefix/len for IPv4 pools. Pool4 objects are created and stored in chosen
55
/// PoolStorage container.
56
///
57 58
/// It is useful for parsing Dhcp4/subnet4[X]/pool parameters.
class Pool4Parser : public PoolParser {
59 60
public:

61 62 63 64 65 66 67 68
    /// @brief Constructor.
    ///
    /// @param param_name name of the parameter. Note, it is passed through
    /// but unused, parameter is currently always "Dhcp4/subnet4[X]/pool"
    /// @param pools storage container in which to store the parsed pool
    /// upon "commit"
    Pool4Parser(const std::string& param_name,  PoolStoragePtr pools)
        :PoolParser(param_name, pools) {
69 70
    }

71 72
protected:
    /// @brief Creates a Pool4 object given a IPv4 prefix and the prefix length.
73
    ///
74 75
    /// @param addr is the IPv4 prefix of the pool.
    /// @param len is the prefix length.
76
    /// @param ignored dummy parameter to provide symmetry between the
77
    /// PoolParser derivations. The V6 derivation requires a third value.
78
    /// @return returns a PoolPtr to the new Pool4 object.
79
    PoolPtr poolMaker (IOAddress &addr, uint32_t len, int32_t) {
80 81
        return (PoolPtr(new Pool4(addr, len)));
    }
82

83 84 85 86
    /// @brief Creates a Pool4 object given starting and ending IPv4 addresses.
    ///
    /// @param min is the first IPv4 address in the pool.
    /// @param max is the last IPv4 address in the pool.
87
    /// @param ignored dummy parameter to provide symmetry between the
88
    /// PoolParser derivations. The V6 derivation requires a third value.
89
    /// @return returns a PoolPtr to the new Pool4 object.
90
    PoolPtr poolMaker (IOAddress &min, IOAddress &max, int32_t) {
91
        return (PoolPtr(new Pool4(min, max)));
92
    }
93
};
94

95 96 97 98 99 100 101 102 103 104 105 106
class Pools4ListParser : public PoolsListParser {
public:
    Pools4ListParser(const std::string& dummy, PoolStoragePtr pools)
        :PoolsListParser(dummy, pools) {
    }

protected:
    virtual ParserPtr poolParserMaker(PoolStoragePtr storage) {
        return (ParserPtr(new Pool4Parser("pool", storage)));
    }
};

107 108
/// @brief This class parses a single IPv4 subnet.
///
109 110
/// This is the IPv4 derivation of the SubnetConfigParser class and it parses
/// the whole subnet definition. It creates parsersfor received configuration
111 112 113 114
/// parameters as needed.
class Subnet4ConfigParser : public SubnetConfigParser {
public:
    /// @brief Constructor
115
    ///
116
    /// @param ignored first parameter
Francis Dupont's avatar
Francis Dupont committed
117
    /// stores global scope parameters, options, option definitions.
118
    Subnet4ConfigParser(const std::string&)
119
        :SubnetConfigParser("", globalContext(), IOAddress("0.0.0.0")) {
120
    }
121

122 123 124 125 126 127 128
    /// @brief Parses a single IPv4 subnet configuration and adds to the
    /// Configuration Manager.
    ///
    /// @param subnet A new subnet being configured.
    void build(ConstElementPtr subnet) {
        SubnetConfigParser::build(subnet);

129
        if (subnet_) {
130 131 132
            Subnet4Ptr sub4ptr = boost::dynamic_pointer_cast<Subnet4>(subnet_);
            if (!sub4ptr) {
                // If we hit this, it is a programming error.
133
                isc_throw(Unexpected,
134 135 136
                          "Invalid cast in Subnet4ConfigParser::commit");
            }

137 138
            // Set relay information if it was parsed
            if (relay_info_) {
139
                sub4ptr->setRelayInfo(*relay_info_);
140 141
            }

142 143 144 145
            // Adding a subnet to the Configuration Manager may fail if the
            // subnet id is invalid (duplicate). Thus, we catch exceptions
            // here to append a position in the configuration string.
            try {
146
                CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(sub4ptr);
147 148 149 150
            } catch (const std::exception& ex) {
                isc_throw(DhcpConfigError, ex.what() << " ("
                          << subnet->getPosition() << ")");
            }
151
        }
152 153 154 155 156 157 158 159

        // Parse Host Reservations for this subnet if any.
        ConstElementPtr reservations = subnet->get("reservations");
        if (reservations) {
            ParserPtr parser(new HostReservationsListParser<
                             HostReservationParser4>(subnet_->getID()));
            parser->build(reservations);
        }
160 161
    }

162 163 164 165 166 167
    /// @brief Commits subnet configuration.
    ///
    /// This function is currently no-op because subnet should already
    /// be added into the Config Manager in the build().
    void commit() { }

168
protected:
169

170
    /// @brief Creates parsers for entries in subnet definition.
171
    ///
172 173 174 175 176 177 178 179 180 181
    /// @param config_id name of the entry
    ///
    /// @return parser object for specified entry name. Note the caller is
    /// responsible for deleting the parser created.
    /// @throw isc::dhcp::DhcpConfigError if trying to create a parser
    /// for unknown config element
    DhcpConfigParser* createSubnetConfigParser(const std::string& config_id) {
        DhcpConfigParser* parser = NULL;
        if ((config_id.compare("valid-lifetime") == 0)  ||
            (config_id.compare("renew-timer") == 0)  ||
182 183
            (config_id.compare("rebind-timer") == 0) ||
            (config_id.compare("id") == 0)) {
184
            parser = new Uint32Parser(config_id, uint32_values_);
185
        } else if ((config_id.compare("subnet") == 0) ||
186
                   (config_id.compare("interface") == 0) ||
187
                   (config_id.compare("client-class") == 0) ||
188 189
                   (config_id.compare("next-server") == 0) ||
                   (config_id.compare("reservation-mode") == 0)) {
190
            parser = new StringParser(config_id, string_values_);
191 192
        } else if (config_id.compare("pools") == 0) {
            parser = new Pools4ListParser(config_id, pools_);
193
        } else if (config_id.compare("relay") == 0) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
194
            parser = new RelayInfoParser(config_id, relay_info_, Option::V4);
195
        } else if (config_id.compare("option-data") == 0) {
196
            parser = new OptionDataListParser(config_id, options_, AF_INET);
197
        } else {
198
            isc_throw(NotImplemented, "unsupported parameter: " << config_id);
199 200
        }

201
        return (parser);
202 203
    }

204
    /// @brief Issues a DHCP4 server specific warning regarding duplicate subnet
205 206
    /// options.
    ///
207
    /// @param code is the numeric option code of the duplicate option
208
    /// @param addr is the subnet address
209
    /// @todo a means to know the correct logger and perhaps a common
210
    /// message would allow this method to be emitted by the base class.
211 212 213 214 215
    virtual void duplicate_option_warning(uint32_t code,
                                         isc::asiolink::IOAddress& addr) {
        LOG_WARN(dhcp4_logger, DHCP4_CONFIG_OPTION_DUPLICATE)
            .arg(code).arg(addr.toText());
    }
216

217
    /// @brief Instantiates the IPv4 Subnet based on a given IPv4 address
218 219
    /// and prefix length.
    ///
220
    /// @param addr is IPv4 address of the subnet.
221
    /// @param len is the prefix length
222
    void initSubnet(isc::asiolink::IOAddress addr, uint8_t len) {
223 224 225 226 227 228 229 230
        // The renew-timer and rebind-timer are optional. If not set, the
        // option 58 and 59 will not be sent to a client. In this case the
        // client will use default values based on the valid-lifetime.
        Triplet<uint32_t> t1 = getOptionalParam("renew-timer");
        Triplet<uint32_t> t2 = getOptionalParam("rebind-timer");
        // The valid-lifetime is mandatory. It may be specified for a
        // particular subnet. If not, the global value should be present.
        // If there is no global value, exception is thrown.
231
        Triplet<uint32_t> valid = getParam("valid-lifetime");
232 233 234 235
        // Subnet ID is optional. If it is not supplied the value of 0 is used,
        // which means autogenerate.
        SubnetID subnet_id =
            static_cast<SubnetID>(uint32_values_->getOptionalParam("id", 0));
236

237 238 239 240 241 242 243 244 245 246
        stringstream s;
        s << addr << "/" << static_cast<int>(len) << " with params: ";
        // t1 and t2 are optional may be not specified.
        if (!t1.unspecified()) {
            s << "t1=" << t1 << ", ";
        }
        if (!t2.unspecified()) {
            s << "t2=" << t2 << ", ";
        }
        s <<"valid-lifetime=" << valid;
247

248
        LOG_INFO(dhcp4_logger, DHCP4_CONFIG_NEW_SUBNET).arg(s.str());
249

250
        Subnet4Ptr subnet4(new Subnet4(addr, len, t1, t2, valid, subnet_id));
Tomek Mrugalski's avatar
Tomek Mrugalski committed
251
        subnet_ = subnet4;
252 253 254 255

        // Try global value first
        try {
            string next_server = globalContext()->string_values_->getParam("next-server");
Tomek Mrugalski's avatar
Tomek Mrugalski committed
256 257 258
            if (!next_server.empty()) {
                subnet4->setSiaddr(IOAddress(next_server));
            }
259
        } catch (const DhcpConfigError&) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
260
            // Don't care. next_server is optional. We can live without it
261 262 263 264
        } catch (...) {
            isc_throw(DhcpConfigError, "invalid parameter next-server ("
                      << globalContext()->string_values_->getPosition("next-server")
                      << ")");
265 266 267 268 269
        }

        // Try subnet specific value if it's available
        try {
            string next_server = string_values_->getParam("next-server");
Tomek Mrugalski's avatar
Tomek Mrugalski committed
270 271 272
            if (!next_server.empty()) {
                subnet4->setSiaddr(IOAddress(next_server));
            }
273
        } catch (const DhcpConfigError&) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
274
            // Don't care. next_server is optional. We can live without it
275 276 277 278
        } catch (...) {
            isc_throw(DhcpConfigError, "invalid parameter next-server ("
                      << string_values_->getPosition("next-server")
                      << ")");
279
        }
280

281

282 283 284 285 286 287 288
        // Try setting up client class (if specified)
        try {
            string client_class = string_values_->getParam("client-class");
            subnet4->allowClientClass(client_class);
        } catch (const DhcpConfigError&) {
            // That's ok if it fails. client-class is optional.
        }
289 290 291
    }
};

292
/// @brief this class parses list of DHCP4 subnets
293 294 295 296
///
/// This is a wrapper parser that handles the whole list of Subnet4
/// definitions. It iterates over all entries and creates Subnet4ConfigParser
/// for each entry.
297
class Subnets4ListConfigParser : public DhcpConfigParser {
298 299 300 301
public:

    /// @brief constructor
    ///
302
    /// @param dummy first argument, always ignored. All parsers accept a
303
    /// string parameter "name" as their first argument.
304 305 306 307 308 309 310 311 312 313 314
    Subnets4ListConfigParser(const std::string&) {
    }

    /// @brief parses contents of the list
    ///
    /// Iterates over all entries on the list and creates Subnet4ConfigParser
    /// for each entry.
    ///
    /// @param subnets_list pointer to a list of IPv4 subnets
    void build(ConstElementPtr subnets_list) {
        BOOST_FOREACH(ConstElementPtr subnet, subnets_list->listValue()) {
315
            ParserPtr parser(new Subnet4ConfigParser("subnet"));
316 317 318 319 320 321
            parser->build(subnet);
        }
    }

    /// @brief commits subnets definitions.
    ///
322
    /// Does nothing.
323 324 325 326 327 328
    void commit() {
    }

    /// @brief Returns Subnet4ListConfigParser object
    /// @param param_name name of the parameter
    /// @return Subnets4ListConfigParser object
329
    static DhcpConfigParser* factory(const std::string& param_name) {
330 331 332 333
        return (new Subnets4ListConfigParser(param_name));
    }
};

334 335 336 337 338
} // anonymous namespace

namespace isc {
namespace dhcp {

339 340 341 342 343 344
/// @brief creates global parsers
///
/// This method creates global parsers that parse global parameters, i.e.
/// those that take format of Dhcp4/param1, Dhcp4/param2 and so forth.
///
/// @param config_id pointer to received global configuration entry
345
/// @param element pointer to the element to be parsed
346
/// @return parser for specified global DHCPv4 parameter
347
/// @throw NotImplemented if trying to create a parser for unknown
348
/// config element
349 350
    DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
                                                    ConstElementPtr element) {
351
    DhcpConfigParser* parser = NULL;
352 353 354
    if ((config_id.compare("valid-lifetime") == 0)  ||
        (config_id.compare("renew-timer") == 0)  ||
        (config_id.compare("rebind-timer") == 0))  {
355
        parser = new Uint32Parser(config_id,
356
                                 globalContext()->uint32_values_);
357
    } else if (config_id.compare("interfaces-config") == 0) {
358
        parser = new IfacesConfigParser4();
359
    } else if (config_id.compare("subnet4") == 0) {
360
        parser = new Subnets4ListConfigParser(config_id);
361
    } else if (config_id.compare("option-data") == 0) {
362
        parser = new OptionDataListParser(config_id, CfgOptionPtr(), AF_INET);
363
    } else if (config_id.compare("option-def") == 0) {
364
        parser  = new OptionDefListParser(config_id, globalContext());
365 366
    } else if ((config_id.compare("version") == 0) ||
               (config_id.compare("next-server") == 0)) {
367
        parser  = new StringParser(config_id,
368
                                    globalContext()->string_values_);
369
    } else if (config_id.compare("lease-database") == 0) {
370
        parser = new DbAccessParser(config_id, *globalContext());
371 372
    } else if (config_id.compare("hooks-libraries") == 0) {
        parser = new HooksLibrariesParser(config_id);
373 374
    } else if (config_id.compare("echo-client-id") == 0) {
        parser = new BooleanParser(config_id, globalContext()->boolean_values_);
375 376
    } else if (config_id.compare("dhcp-ddns") == 0) {
        parser = new D2ClientConfigParser(config_id);
377
    } else {
378 379 380
        isc_throw(DhcpConfigError,
                "unsupported global configuration parameter: "
                  << config_id << " (" << element->getPosition() << ")");
381
    }
382 383

    return (parser);
384 385
}

386
void commitGlobalOptions() {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
387 388
    // Although the function is modest for now, it is certain that the number
    // of global switches will increase over time, hence the name.
389 390 391 392 393 394 395 396 397 398 399

    // Set whether v4 server is supposed to echo back client-id (yes = RFC6842
    // compatible, no = backward compatibility)
    try {
        bool echo_client_id = globalContext()->boolean_values_->getParam("echo-client-id");
        CfgMgr::instance().echoClientId(echo_client_id);
    } catch (...) {
        // Ignore errors. This flag is optional
    }
}

400
isc::data::ConstElementPtr
401
configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
402
    if (!config_set) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
403 404 405
        ConstElementPtr answer = isc::config::createAnswer(1,
                                 string("Can't parse NULL config"));
        return (answer);
406 407
    }

408
    LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND,
409
              DHCP4_CONFIG_START).arg(config_set->str());
410

411 412 413 414
    // Before starting any subnet operations, let's reset the subnet-id counter,
    // so newly recreated configuration starts with first subnet-id equal 1.
    Subnet::resetSubnetID();

415
    // Some of the values specified in the configuration depend on
416 417 418
    // other values. Typically, the values in the subnet4 structure
    // depend on the global values. Also, option values configuration
    // must be performed after the option definitions configurations.
419
    // Thus we group parsers and will fire them in the right order:
420 421
    // all parsers other than: lease-database, subnet4 and option-data parser,
    // then: option-data parser, subnet4 parser, lease-database parser.
422
    // Please do not change this order!
423
    ParserCollection independent_parsers;
424 425
    ParserPtr subnet_parser;
    ParserPtr option_parser;
426
    ParserPtr iface_parser;
427
    ParserPtr leases_parser;
428

429 430
    // Some of the parsers alter the state of the system in a way that can't
    // easily be undone. (Or alter it in a way such that undoing the change has
431
    // the same risk of failure as doing the change.)
432
    ParserPtr hooks_parser;
433

434
    // The subnet parsers implement data inheritance by directly
435
    // accessing global storage. For this reason the global data
436
    // parsers must store the parsed data into global storages
437 438 439 440
    // immediately. This may cause data inconsistency if the
    // parsing operation fails after the global storage has been
    // modified. We need to preserve the original global data here
    // so as we can rollback changes when an error occurs.
441
    ParserContext original_context(*globalContext());
442

443
    // Answer will hold the result.
444
    ConstElementPtr answer;
Francis Dupont's avatar
Francis Dupont committed
445
    // Rollback informs whether error occurred and original data
446 447
    // have to be restored to global storages.
    bool rollback = false;
448
    // config_pair holds the details of the current parser when iterating over
449 450
    // the parsers.  It is declared outside the loops so in case of an error,
    // the name of the failing parser can be retrieved in the "catch" clause.
451
    ConfigPair config_pair;
452
    try {
453
        // Make parsers grouping.
454
        const std::map<std::string, ConstElementPtr>& values_map =
455
                                                        config_set->mapValue();
456
        BOOST_FOREACH(config_pair, values_map) {
457 458
            ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
                                                           config_pair.second));
459 460
            LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
                      .arg(config_pair.first);
461 462
            if (config_pair.first == "subnet4") {
                subnet_parser = parser;
463 464
            } else if (config_pair.first == "lease-database") {
                leases_parser = parser;
465 466
            } else if (config_pair.first == "option-data") {
                option_parser = parser;
467
            } else if (config_pair.first == "interfaces-config") {
468 469 470 471
                // 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);
472 473 474 475
            } else if (config_pair.first == "hooks-libraries") {
                // Executing commit will alter currently-loaded hooks
                // libraries.  Check if the supplied libraries are valid,
                // but defer the commit until everything else has committed.
476
                hooks_parser = parser;
477
                parser->build(config_pair.second);
478
            } else {
479 480
                // Those parsers should be started before other
                // parsers so we can call build straight away.
481 482 483 484 485 486 487 488
                independent_parsers.push_back(parser);
                parser->build(config_pair.second);
                // The commit operation here may modify the global storage
                // but we need it so as the subnet6 parser can access the
                // parsed data.
                parser->commit();
            }
        }
489

490
        // The option values parser is the next one to be run.
491 492 493
        std::map<std::string, ConstElementPtr>::const_iterator option_config =
            values_map.find("option-data");
        if (option_config != values_map.end()) {
494
            config_pair.first = "option-data";
495 496 497 498
            option_parser->build(option_config->second);
            option_parser->commit();
        }

499
        // The subnet parser is the next one to be run.
500 501 502
        std::map<std::string, ConstElementPtr>::const_iterator subnet_config =
            values_map.find("subnet4");
        if (subnet_config != values_map.end()) {
503
            config_pair.first = "subnet4";
504
            subnet_parser->build(subnet_config->second);
505
        }
506

507 508 509 510 511 512 513 514 515
        // the leases database parser is the last to be run.
        std::map<std::string, ConstElementPtr>::const_iterator leases_config =
            values_map.find("lease-database");
        if (leases_config != values_map.end()) {
            config_pair.first = "lease-database";
            leases_parser->build(leases_config->second);
            leases_parser->commit();
        }

516
    } catch (const isc::Exception& ex) {
517
        LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
518
                  .arg(config_pair.first).arg(ex.what());
519
        answer = isc::config::createAnswer(1, ex.what());
520

Francis Dupont's avatar
Francis Dupont committed
521
        // An error occurred, so make sure that we restore original data.
522 523
        rollback = true;

524
    } catch (...) {
525
        // For things like bad_cast in boost::lexical_cast
526
        LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
527 528
        answer = isc::config::createAnswer(1, "undefined configuration"
                                           " processing error");
529

Francis Dupont's avatar
Francis Dupont committed
530
        // An error occurred, so make sure that we restore original data.
531
        rollback = true;
532 533
    }

534 535 536 537 538 539
    // So far so good, there was no parsing error so let's commit the
    // configuration. This will add created subnets and option values into
    // the server's configuration.
    // This operation should be exception safe but let's make sure.
    if (!rollback) {
        try {
540 541
            // No need to commit interface names as this is handled by the
            // CfgMgr::commit() function.
542

543 544 545
            // Apply global options
            commitGlobalOptions();

546 547 548
            // This occurs last as if it succeeds, there is no easy way
            // revert it.  As a result, the failure to commit a subsequent
            // change causes problems when trying to roll back.
549 550
            if (hooks_parser) {
                hooks_parser->commit();
551
            }
552 553
        }
        catch (const isc::Exception& ex) {
554
            LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
555
            answer = isc::config::createAnswer(2, ex.what());
556 557
            rollback = true;
        } catch (...) {
558
            // For things like bad_cast in boost::lexical_cast
559
            LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
560 561
            answer = isc::config::createAnswer(2, "undefined configuration"
                                               " parsing error");
562
            rollback = true;
563 564
        }
    }
565 566 567

    // Rollback changes as the configuration parsing failed.
    if (rollback) {
568
        globalContext().reset(new ParserContext(original_context));
569 570 571
        return (answer);
    }

572
    LOG_INFO(dhcp4_logger, DHCP4_CONFIG_COMPLETE)
573
        .arg(CfgMgr::instance().getStagingCfg()->
574
             getConfigSummary(SrvConfig::CFGSEL_ALL4));
575

576
    // Everything was fine. Configuration is successful.
577
    answer = isc::config::createAnswer(0, "Configuration successful.");
578 579 580
    return (answer);
}

581
ParserContextPtr& globalContext() {
582 583
    static ParserContextPtr global_context_ptr(new ParserContext(Option::V4));
    return (global_context_ptr);
584 585
}

586 587


588 589
}; // end of isc::dhcp namespace
}; // end of isc namespace