config_parser.cc 24.7 KB
Newer Older
1
// Copyright (C) 2012-2013 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
#include <asiolink/io_address.h>
16
#include <cc/data.h>
17
#include <config/ccsession.h>
18
#include <dhcp/libdhcp++.h>
19
#include <dhcp6/config_parser.h>
20
#include <dhcp6/dhcp6_log.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
21
#include <dhcp/iface_mgr.h>
22
#include <dhcpsrv/cfgmgr.h>
23
#include <dhcpsrv/dbaccess_parser.h>
24
#include <dhcpsrv/dhcp_config_parser.h>
25
#include <dhcpsrv/dhcp_parsers.h>
26 27 28 29 30
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/triplet.h>
#include <log/logger_support.h>
#include <util/encode/hex.h>
31
#include <util/strutil.h>
32 33 34 35 36 37 38 39 40 41 42 43

#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include <iostream>
#include <map>
#include <vector>

#include <stdint.h>
44 45

using namespace std;
46
using namespace isc;
47
using namespace isc::data;
48
using namespace isc::dhcp;
49 50
using namespace isc::asiolink;

51
namespace {
52

53 54 55 56 57
// Pointers to various parser objects.
typedef boost::shared_ptr<BooleanParser> BooleanParserPtr;
typedef boost::shared_ptr<StringParser> StringParserPtr;
typedef boost::shared_ptr<Uint32Parser> Uint32ParserPtr;

58
/// @brief Parser for DHCP6 option data value.
59 60
///
/// This parser parses configuration entries that specify value of
61 62 63
/// a single option specific to DHCP6.  It provides the DHCP6-specific
/// implementation of the abstract class OptionDataParser.
class Dhcp6OptionDataParser : public OptionDataParser {
64
public:
65 66
    /// @brief Constructor.
    ///
67 68 69
    /// @param dummy first param, option names are always "Dhcp6/option-data[n]"
    /// @param options is the option storage in which to store the parsed option
    /// upon "commit".
70
    /// @param global_context is a pointer to the global context which
71
    /// stores global scope parameters, options, option defintions.
72 73
    Dhcp6OptionDataParser(const std::string&, OptionStoragePtr options,
                         ParserContextPtr global_context)
74
        :OptionDataParser("", options, global_context) {
75 76
    }

77
    /// @brief static factory method for instantiating Dhcp4OptionDataParsers
78
    ///
79 80
    /// @param param_name name of the parameter to be parsed.
    /// @param options storage where the parameter value is to be stored.
81
    /// @param global_context is a pointer to the global context which
82 83 84 85 86 87
    /// stores global scope parameters, options, option defintions.
    /// @return returns a pointer to a new OptionDataParser. Caller is
    /// is responsible for deleting it when it is no longer needed.
    static OptionDataParser* factory(const std::string& param_name,
    OptionStoragePtr options, ParserContextPtr global_context) {
        return (new Dhcp6OptionDataParser(param_name, options, global_context));
88 89
    }

90 91 92

protected:
    /// @brief Finds an option definition within the server's option space
93 94
    ///
    /// Given an option space and an option code, find the correpsonding
95
    /// option defintion within the server's option defintion storage.
96
    ///
97 98 99
    /// @param option_space name of the parameter option space
    /// @param option_code numeric value of the parameter to find
    /// @return OptionDefintionPtr of the option defintion or an
100
    /// empty OptionDefinitionPtr if not found.
101 102
    /// @throw DhcpConfigError if the option space requested is not valid
    /// for this server.
103 104
    virtual OptionDefinitionPtr findServerSpaceOptionDefinition (
                            std::string& option_space, uint32_t option_code) {
105 106 107 108 109 110
        OptionDefinitionPtr def;
        if (option_space == "dhcp6" &&
            LibDHCP::isStandardOption(Option::V6, option_code)) {
            def = LibDHCP::getOptionDef(Option::V6, option_code);
        } else if (option_space == "dhcp4") {
            isc_throw(DhcpConfigError, "'dhcp4' option space name is reserved"
111
                     << " for DHCPv4 server");
112
        }
113

114
        return def;
115
    }
116 117
};

118
/// @brief Parser for IPv4 pool definitions.
119
///
120 121 122
/// This is the IPv6 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 IPv6 pools. Pool6 objects are created and stored in chosen
123
/// PoolStorage container.
124
///
125 126
/// It is useful for parsing Dhcp6/subnet6[X]/pool parameters.
class Pool6Parser : public PoolParser {
127 128 129 130
public:

    /// @brief Constructor.
    ///
131 132 133 134 135 136
    /// @param param_name name of the parameter. Note, it is passed through
    /// but unused, parameter is currently always "Dhcp6/subnet6[X]/pool"
    /// @param pools storage container in which to store the parsed pool
    /// upon "commit"
    Pool6Parser(const std::string& param_name,  PoolStoragePtr pools)
        :PoolParser(param_name, pools) {
137
    }
138

139 140
protected:
    /// @brief Creates a Pool6 object given a IPv6 prefix and the prefix length.
141
    ///
142 143
    /// @param addr is the IPv6 prefix of the pool.
    /// @param len is the prefix length.
144 145
    /// @param ptype is the type of IPv6 pool (Pool::PoolType). Note this is
    /// passed in as an int32_t and cast to PoolType to accommodate a
146
    /// polymorphic interface.
147
    /// @return returns a PoolPtr to the new Pool4 object.
148 149
    PoolPtr poolMaker (IOAddress &addr, uint32_t len, int32_t ptype)
    {
150
        return (PoolPtr(new Pool6(static_cast<isc::dhcp::Lease::Type>
151
                                  (ptype), addr, len)));
152 153
    }

154
    /// @brief Creates a Pool6 object given starting and ending IPv6 addresses.
155
    ///
156 157
    /// @param min is the first IPv6 address in the pool.
    /// @param max is the last IPv6 address in the pool.
158 159
    /// @param ptype is the type of IPv6 pool (Pool::PoolType). Note this is
    /// passed in as an int32_t and cast to PoolType to accommodate a
160
    /// polymorphic interface.
161
    /// @return returns a PoolPtr to the new Pool4 object.
162 163
    PoolPtr poolMaker (IOAddress &min, IOAddress &max, int32_t ptype)
    {
164
        return (PoolPtr(new Pool6(static_cast<isc::dhcp::Lease::Type>
165
                                  (ptype), min, max)));
166 167 168
    }
};

169
/// @brief This class parses a single IPv6 subnet.
170
///
171 172
/// This is the IPv6 derivation of the SubnetConfigParser class and it parses
/// the whole subnet definition. It creates parsersfor received configuration
173 174
/// parameters as needed.
class Subnet6ConfigParser : public SubnetConfigParser {
175 176
public:

177
    /// @brief Constructor
178
    ///
179 180
    /// @param ignored first parameter
    /// stores global scope parameters, options, option defintions.
181
    Subnet6ConfigParser(const std::string&)
182
        :SubnetConfigParser("", globalContext()) {
183 184
    }

185
    /// @brief Adds the created subnet to a server's configuration.
186
    /// @throw throws Unexpected if dynamic cast fails.
187
    void commit() {
188
        if (subnet_) {
189 190 191 192 193
            Subnet6Ptr sub6ptr = boost::dynamic_pointer_cast<Subnet6>(subnet_);
            if (!sub6ptr) {
                // If we hit this, it is a programming error.
                isc_throw(Unexpected,
                          "Invalid cast in Subnet4ConfigParser::commit");
194
            }
195
            isc::dhcp::CfgMgr::instance().addSubnet6(sub6ptr);
196 197 198
        }
    }

199
protected:
200

201
    /// @brief creates parsers for entries in subnet definition
202
    ///
203
    /// @param config_id name of the entry
204
    ///
205 206 207 208 209 210 211 212 213 214 215 216
    /// @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("preferred-lifetime") == 0)  ||
            (config_id.compare("valid-lifetime") == 0)  ||
            (config_id.compare("renew-timer") == 0)  ||
            (config_id.compare("rebind-timer") == 0))  {
            parser = new Uint32Parser(config_id, uint32_values_);
        } else if ((config_id.compare("subnet") == 0) ||
217 218
                   (config_id.compare("interface") == 0) ||
                   (config_id.compare("interface-id") == 0)) {
219 220 221 222
            parser = new StringParser(config_id, string_values_);
        } else if (config_id.compare("pool") == 0) {
            parser = new Pool6Parser(config_id, pools_);
        } else if (config_id.compare("option-data") == 0) {
223
           parser = new OptionDataListParser(config_id, options_,
224 225
                                             global_context_,
                                             Dhcp6OptionDataParser::factory);
226
        } else {
227 228
            isc_throw(NotImplemented,
                "parser error: Subnet6 parameter not supported: " << config_id);
229
        }
230

231
        return (parser);
232 233 234
    }


235
    /// @brief Determines if the given option space name and code describe
236
    /// a standard option for the DHCP6 server.
237
    ///
238 239 240 241 242
    /// @param option_space is the name of the option space to consider
    /// @param code is the numeric option code to consider
    /// @return returns true if the space and code are part of the server's
    /// standard options.
    bool isServerStdOption(std::string option_space, uint32_t code) {
243
        return ((option_space.compare("dhcp6") == 0)
244
                && LibDHCP::isStandardOption(Option::V6, code));
245 246
    }

247 248 249 250 251 252
    /// @brief Returns the option definition for a given option code from
    /// the DHCP6 server's standard set of options.
    /// @param code is the numeric option code of the desired option definition.
    /// @return returns a pointer the option definition
    OptionDefinitionPtr getServerStdOptionDefinition (uint32_t code) {
        return (LibDHCP::getOptionDef(Option::V6, code));
253 254
    }

255
    /// @brief Issues a DHCP6 server specific warning regarding duplicate subnet
256 257
    /// options.
    ///
258 259 260 261
    /// @param code is the numeric option code of the duplicate option
    /// @param addr is the subnet address
    /// @todo A means to know the correct logger and perhaps a common
    /// message would allow this message to be emitted by the base class.
262
    virtual void duplicate_option_warning(uint32_t code,
263 264 265 266
                                         isc::asiolink::IOAddress& addr) {
        LOG_WARN(dhcp6_logger, DHCP6_CONFIG_OPTION_DUPLICATE)
            .arg(code).arg(addr.toText());
    }
267

268
    /// @brief Instantiates the IPv6 Subnet based on a given IPv6 address
269 270
    /// and prefix length.
    ///
271
    /// @param addr is IPv6 prefix of the subnet.
272
    /// @param len is the prefix length
273
    void initSubnet(isc::asiolink::IOAddress addr, uint8_t len) {
274 275
        // Get all 'time' parameters using inheritance.
        // If the subnet-specific value is defined then use it, else
276 277 278
        // use the global value. The global value must always be
        // present. If it is not, it is an internal error and exception
        // is thrown.
279 280 281 282 283
        Triplet<uint32_t> t1 = getParam("renew-timer");
        Triplet<uint32_t> t2 = getParam("rebind-timer");
        Triplet<uint32_t> pref = getParam("preferred-lifetime");
        Triplet<uint32_t> valid = getParam("valid-lifetime");

284 285 286 287
        // Get interface-id option content. For now we support string
        // represenation only
        std::string ifaceid;
        try {
288 289
            ifaceid = string_values_->getParam("interface-id");
        } catch (const DhcpConfigError &) {
290 291 292
            // interface-id is not mandatory
        }

293 294
        // Specifying both interface for locally reachable subnets and
        // interface id for relays is mutually exclusive. Need to test for
295
        // this condition.
296 297 298 299 300
        if (!ifaceid.empty()) {
            std::string iface;
            try {
                iface = string_values_->getParam("interface");
            } catch (const DhcpConfigError &) {
301
                // iface not mandatory
302 303 304 305
            }

            if (!iface.empty()) {
                isc_throw(isc::dhcp::DhcpConfigError,
306 307 308 309
                      "parser error: interface (defined for locally reachable "
                      "subnets) and interface-id (defined for subnets reachable"
                      " via relays) cannot be defined at the same time for "
                      "subnet " << addr.toText() << "/" << (int)len);
310
            }
311 312
        }

313
        stringstream tmp;
314
        tmp << addr.toText() << "/" << static_cast<int>(len)
315 316
            << " with params t1=" << t1 << ", t2=" << t2 << ", pref="
            << pref << ", valid=" << valid;
317

318
        LOG_INFO(dhcp6_logger, DHCP6_CONFIG_NEW_SUBNET).arg(tmp.str());
319

320
        // Create a new subnet.
321
        Subnet6* subnet6 = new Subnet6(addr, len, t1, t2, pref, valid);
322

323 324 325 326
        // Configure interface-id for remote interfaces, if defined
        if (!ifaceid.empty()) {
            OptionBuffer tmp(ifaceid.begin(), ifaceid.end());
            OptionPtr opt(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
327
            subnet6->setInterfaceId(opt);
328 329
        }

330
        subnet_.reset(subnet6);
331
    }
332

333 334
};

335 336

/// @brief this class parses a list of DHCP6 subnets
337 338 339 340
///
/// This is a wrapper parser that handles the whole list of Subnet6
/// definitions. It iterates over all entries and creates Subnet6ConfigParser
/// for each entry.
341
class Subnets6ListConfigParser : public DhcpConfigParser {
342
public:
343 344 345

    /// @brief constructor
    ///
346
    /// @param dummy first argument, always ignored. All parsers accept a
347
    /// string parameter "name" as their first argument.
348
    Subnets6ListConfigParser(const std::string&) {
349 350
    }

351 352
    /// @brief parses contents of the list
    ///
353
    /// Iterates over all entries on the list and creates a Subnet6ConfigParser
354 355 356
    /// for each entry.
    ///
    /// @param subnets_list pointer to a list of IPv6 subnets
357 358 359 360 361 362 363 364 365
    void build(ConstElementPtr subnets_list) {
        BOOST_FOREACH(ConstElementPtr subnet, subnets_list->listValue()) {
            ParserPtr parser(new Subnet6ConfigParser("subnet"));
            parser->build(subnet);
            subnets_.push_back(parser);
        }

    }

366 367
    /// @brief commits subnets definitions.
    ///
368 369
    /// Iterates over all Subnet6 parsers. Each parser contains definitions of
    /// a single subnet and its parameters and commits each subnet separately.
370
    void commit() {
371 372 373 374
        // @todo: Implement more subtle reconfiguration than toss
        // the old one and replace with the new one.

        // remove old subnets
375
        isc::dhcp::CfgMgr::instance().deleteSubnets6();
376

377 378 379 380 381 382
        BOOST_FOREACH(ParserPtr subnet, subnets_) {
            subnet->commit();
        }

    }

383 384 385
    /// @brief Returns Subnet6ListConfigParser object
    /// @param param_name name of the parameter
    /// @return Subnets6ListConfigParser object
386
    static DhcpConfigParser* factory(const std::string& param_name) {
387 388 389
        return (new Subnets6ListConfigParser(param_name));
    }

390
    /// @brief collection of subnet parsers.
391 392 393
    ParserCollection subnets_;
};

394 395 396 397 398
} // anonymous namespace

namespace isc {
namespace dhcp {

399 400 401 402
/// @brief creates global parsers
///
/// This method creates global parsers that parse global parameters, i.e.
/// those that take format of Dhcp6/param1, Dhcp6/param2 and so forth.
403 404 405
///
/// @param config_id pointer to received global configuration entry
/// @return parser for specified global DHCPv6 parameter
406
/// @throw NotImplemented if trying to create a parser for unknown config
407 408 409
/// element
DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id) {
    DhcpConfigParser* parser = NULL;
410 411 412 413
    if ((config_id.compare("preferred-lifetime") == 0)  ||
        (config_id.compare("valid-lifetime") == 0)  ||
        (config_id.compare("renew-timer") == 0)  ||
        (config_id.compare("rebind-timer") == 0))  {
414
        parser = new Uint32Parser(config_id,
415
                                 globalContext()->uint32_values_);
416
    } else if (config_id.compare("interfaces") == 0) {
417
        parser = new InterfaceListConfigParser(config_id);
418
    } else if (config_id.compare("subnet6") == 0) {
419
        parser = new Subnets6ListConfigParser(config_id);
420
    } else if (config_id.compare("option-data") == 0) {
421 422
        parser = new OptionDataListParser(config_id,
                                          globalContext()->options_,
423
                                          globalContext(),
424
                                          Dhcp6OptionDataParser::factory);
425
    } else if (config_id.compare("option-def") == 0) {
426
        parser  = new OptionDefListParser(config_id,
427
                                          globalContext()->option_defs_);
428
    } else if (config_id.compare("version") == 0) {
429
        parser  = new StringParser(config_id,
430
                                   globalContext()->string_values_);
431
    } else if (config_id.compare("lease-database") == 0) {
432
        parser = new DbAccessParser(config_id);
433 434
    } else if (config_id.compare("hooks-libraries") == 0) {
        parser = new HooksLibrariesParser(config_id);
435
    } else {
436
        isc_throw(NotImplemented,
437 438
                "Parser error: Global configuration parameter not supported: "
                << config_id);
439
    }
440 441

    return (parser);
442 443
}

444 445
isc::data::ConstElementPtr
configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
446
    if (!config_set) {
447 448 449
        ConstElementPtr answer = isc::config::createAnswer(1,
                                 string("Can't parse NULL config"));
        return (answer);
450 451
    }

452
    /// @todo: Append most essential info here (like "2 new subnets configured")
453 454
    string config_details;

455
    LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND,
456
              DHCP6_CONFIG_START).arg(config_set->str());
457

458
    // Some of the values specified in the configuration depend on
459
    // other values. Typically, the values in the subnet6 structure
460 461
    // depend on the global values. Also, option values configuration
    // must be performed after the option definitions configurations.
462
    // Thus we group parsers and will fire them in the right order:
463 464
    // all parsers other than subnet6 and option-data parser,
    // option-data parser, subnet6 parser.
465
    ParserCollection independent_parsers;
466 467
    ParserPtr subnet_parser;
    ParserPtr option_parser;
468
    ParserPtr iface_parser;
469

470 471 472 473 474
    // Some of the parsers alter state of the system that can't easily
    // be undone. (Or alter it in a way such that undoing the change
    // has the same risk of failure as doing the change.)
    ParserPtr hooks_parser;

475
    // The subnet parsers implement data inheritance by directly
476
    // accessing global storage. For this reason the global data
477
    // parsers must store the parsed data into global storages
478 479 480 481
    // 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.
482
    ParserContext original_context(*globalContext());
483 484

    // answer will hold the result.
485
    ConstElementPtr answer;
486 487
    // rollback informs whether error occured and original data
    // have to be restored to global storages.
488
    bool rollback = false;
489 490 491
    // config_pair holds ther details of the current parser when iterating over
    // the parsers.  It is declared outside the loop so in case of error, the
    // name of the failing parser can be retrieved within the "catch" clause.
492
    ConfigPair config_pair;
493
    try {
494 495 496 497

        // Make parsers grouping.
        const std::map<std::string, ConstElementPtr>& values_map =
            config_set->mapValue();
498
        BOOST_FOREACH(config_pair, values_map) {
499
            ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first));
500 501
            LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
                      .arg(config_pair.first);
502 503 504 505
            if (config_pair.first == "subnet6") {
                subnet_parser = parser;
            } else if (config_pair.first == "option-data") {
                option_parser = parser;
506 507 508 509 510 511 512
            } else if (config_pair.first == "hooks-libraries") {
                // Executing the commit will alter currently loaded hooks
                // libraries. Check if the supplied libraries are valid,
                // but defer the commit until after everything else has
                // committed.
                hooks_parser = parser;
                hooks_parser->build(config_pair.second);
513 514 515 516 517
            } else if (config_pair.first == "interfaces") {
                // The interface parser is independent from any other parser and
                // can be run here before other parsers.
                parser->build(config_pair.second);
                iface_parser = parser;
518 519 520
            } else {
                // Those parsers should be started before other
                // parsers so we can call build straight away.
521 522
                independent_parsers.push_back(parser);
                parser->build(config_pair.second);
523 524 525
                // The commit operation here may modify the global storage
                // but we need it so as the subnet6 parser can access the
                // parsed data.
526 527 528
                parser->commit();
            }
        }
529

530 531 532 533 534 535 536 537 538 539 540 541 542
        // The option values parser is the next one to be run.
        std::map<std::string, ConstElementPtr>::const_iterator option_config =
            values_map.find("option-data");
        if (option_config != values_map.end()) {
            option_parser->build(option_config->second);
            option_parser->commit();
        }

        // The subnet parser is the last one to be run.
        std::map<std::string, ConstElementPtr>::const_iterator subnet_config =
            values_map.find("subnet6");
        if (subnet_config != values_map.end()) {
            subnet_parser->build(subnet_config->second);
543
        }
544

545
    } catch (const isc::Exception& ex) {
546
        LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
547 548 549
                  .arg(config_pair.first).arg(ex.what());
        answer = isc::config::createAnswer(1,
                     string("Configuration parsing failed: ") + ex.what());
550
        // An error occured, so make sure that we restore original data.
551 552
        rollback = true;

553 554
    } catch (...) {
        // for things like bad_cast in boost::lexical_cast
555
        LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(config_pair.first);
556 557
        answer = isc::config::createAnswer(1,
                     string("Configuration parsing failed"));
558
        // An error occured, so make sure that we restore original data.
559
        rollback = true;
560 561
    }

562 563 564 565
    // 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.
566 567
    if (!rollback) {
        try {
568 569
            if (subnet_parser) {
                subnet_parser->commit();
570
            }
571 572 573 574

            if (iface_parser) {
                iface_parser->commit();
            }
575 576 577 578 579 580 581

            // This occurs last as if it succeeds, there is no easy way to
            // revert it.  As a result, the failure to commit a subsequent
            // change causes problems when trying to roll back.
            if (hooks_parser) {
                hooks_parser->commit();
            }
582 583
        }
        catch (const isc::Exception& ex) {
584
            LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
585 586
            answer = isc::config::createAnswer(2,
                         string("Configuration commit failed:") + ex.what());
587
            // An error occured, so make sure to restore the original data.
588 589 590
            rollback = true;
        } catch (...) {
            // for things like bad_cast in boost::lexical_cast
591
            LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
592 593
            answer = isc::config::createAnswer(2,
                         string("Configuration commit failed"));
594
            // An error occured, so make sure to restore the original data.
595
            rollback = true;
596
        }
597
    }
598

599
    // Rollback changes as the configuration parsing failed.
600
    if (rollback) {
601
        globalContext().reset(new ParserContext(original_context));
602
        return (answer);
603
    }
604 605 606

    LOG_INFO(dhcp6_logger, DHCP6_CONFIG_COMPLETE).arg(config_details);

607
    // Everything was fine. Configuration is successful.
Shane Kerr's avatar
Shane Kerr committed
608
    answer = isc::config::createAnswer(0, "Configuration committed.");
609
    return (answer);
610 611
}

612
ParserContextPtr& globalContext() {
613 614
    static ParserContextPtr global_context_ptr(new ParserContext(Option::V6));
    return (global_context_ptr);
615 616
}

617 618
}; // end of isc::dhcp namespace
}; // end of isc namespace