2013-01-04 14:15:40 +01:00
|
|
|
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
|
2012-09-25 18:26:37 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2012-09-28 20:39:13 +02:00
|
|
|
#include <asiolink/io_address.h>
|
2012-09-25 18:26:37 +02:00
|
|
|
#include <cc/data.h>
|
2012-09-27 19:33:20 +02:00
|
|
|
#include <config/ccsession.h>
|
2012-11-02 20:10:10 +01:00
|
|
|
#include <dhcp/libdhcp++.h>
|
2012-09-28 20:39:13 +02:00
|
|
|
#include <dhcp6/config_parser.h>
|
2012-09-27 19:33:20 +02:00
|
|
|
#include <dhcp6/dhcp6_log.h>
|
2013-01-17 17:14:38 +01:00
|
|
|
#include <dhcp/iface_mgr.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
2013-01-10 13:16:22 +00:00
|
|
|
#include <dhcpsrv/dbaccess_parser.h>
|
2013-01-04 14:15:40 +01:00
|
|
|
#include <dhcpsrv/dhcp_config_parser.h>
|
2013-04-10 17:02:10 -04:00
|
|
|
#include <dhcpsrv/dhcp_parsers.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
#include <dhcpsrv/pool.h>
|
|
|
|
#include <dhcpsrv/subnet.h>
|
|
|
|
#include <dhcpsrv/triplet.h>
|
|
|
|
#include <log/logger_support.h>
|
|
|
|
#include <util/encode/hex.h>
|
2012-12-20 12:22:16 +01:00
|
|
|
#include <util/strutil.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
|
|
|
|
#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>
|
2012-09-25 18:26:37 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2013-01-10 10:21:59 +01:00
|
|
|
using namespace isc;
|
2012-09-25 18:26:37 +02:00
|
|
|
using namespace isc::data;
|
2013-01-04 12:58:23 +01:00
|
|
|
using namespace isc::dhcp;
|
2012-09-25 18:26:37 +02:00
|
|
|
using namespace isc::asiolink;
|
|
|
|
|
2012-12-20 12:22:16 +01:00
|
|
|
namespace {
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2013-01-10 10:21:59 +01:00
|
|
|
// Pointers to various parser objects.
|
|
|
|
typedef boost::shared_ptr<BooleanParser> BooleanParserPtr;
|
|
|
|
typedef boost::shared_ptr<StringParser> StringParserPtr;
|
|
|
|
typedef boost::shared_ptr<Uint32Parser> Uint32ParserPtr;
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
/// @brief Collection of address pools.
|
2012-10-01 16:47:31 +02:00
|
|
|
///
|
2012-11-13 10:19:54 +01:00
|
|
|
/// This type is used as intermediate storage, when pools are parsed, but there is
|
2012-10-01 16:47:31 +02:00
|
|
|
/// no subnet object created yet to store them.
|
2012-12-20 12:22:16 +01:00
|
|
|
typedef std::vector<isc::dhcp::Pool6Ptr> PoolStorage;
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-10-01 16:47:31 +02:00
|
|
|
/// @brief Global uint32 parameters that will be used as defaults.
|
|
|
|
Uint32Storage uint32_defaults;
|
|
|
|
|
|
|
|
/// @brief global string parameters that will be used as defaults.
|
|
|
|
StringStorage string_defaults;
|
|
|
|
|
2012-10-29 12:53:17 +01:00
|
|
|
/// @brief Global storage for options that will be used as defaults.
|
|
|
|
OptionStorage option_defaults;
|
|
|
|
|
2013-01-10 21:22:44 +01:00
|
|
|
/// @brief Global storage for option definitions.
|
2013-01-14 12:25:01 +01:00
|
|
|
OptionDefStorage option_def_intermediate;
|
2013-01-10 21:22:44 +01:00
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief parser for pool definition
|
|
|
|
///
|
|
|
|
/// This parser handles pool definitions, i.e. a list of entries of one
|
|
|
|
/// of two syntaxes: min-max and prefix/len. Pool6 objects are created
|
|
|
|
/// and stored in chosen PoolStorage container.
|
|
|
|
///
|
|
|
|
/// As there are no default values for pool, setStorage() must be called
|
2012-11-13 10:19:54 +01:00
|
|
|
/// before build(). Otherwise an exception will be thrown.
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
|
|
|
/// It is useful for parsing Dhcp6/subnet6[X]/pool parameters.
|
2012-10-09 19:13:29 +02:00
|
|
|
class PoolParser : public DhcpConfigParser {
|
2012-09-25 18:26:37 +02:00
|
|
|
public:
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// @brief constructor.
|
2012-09-25 18:26:37 +02:00
|
|
|
PoolParser(const std::string& /*param_name*/)
|
2012-12-21 00:12:03 +01:00
|
|
|
: pools_(NULL) {
|
2012-09-25 18:26:37 +02:00
|
|
|
// ignore parameter name, it is always Dhcp6/subnet6[X]/pool
|
|
|
|
}
|
2012-10-01 18:56:55 +02:00
|
|
|
|
2013-04-10 17:02:10 -04:00
|
|
|
/// @brief constructor.
|
|
|
|
PoolParser(const std::string& /*param_name*/, PoolStorage* pools)
|
|
|
|
:pools_(pools) {
|
|
|
|
// ignore parameter name, it is always Dhcp6/subnet6[X]/pool
|
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief parses the actual list
|
|
|
|
///
|
|
|
|
/// This method parses the actual list of interfaces.
|
|
|
|
/// No validation is done at this stage, everything is interpreted as
|
|
|
|
/// interface name.
|
2012-12-05 15:22:05 +01:00
|
|
|
/// @param pools_list list of pools defined for a subnet
|
2012-12-21 00:12:03 +01:00
|
|
|
/// @throw isc::InvalidOperation if storage was not specified
|
|
|
|
/// (setStorage() not called)
|
2012-09-25 18:26:37 +02:00
|
|
|
void build(ConstElementPtr pools_list) {
|
2012-12-21 00:12:03 +01:00
|
|
|
|
2012-09-25 18:26:37 +02:00
|
|
|
// setStorage() should have been called before build
|
|
|
|
if (!pools_) {
|
2012-12-21 00:12:03 +01:00
|
|
|
isc_throw(isc::InvalidOperation, "parser logic error: no pool storage set,"
|
2012-10-09 19:13:29 +02:00
|
|
|
" but pool parser asked to parse pools");
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(ConstElementPtr text_pool, pools_list->listValue()) {
|
|
|
|
|
|
|
|
// That should be a single pool representation. It should contain
|
2012-11-13 10:19:54 +01:00
|
|
|
// text in the form prefix/len or first - last. Note that spaces
|
2012-09-25 18:26:37 +02:00
|
|
|
// are allowed
|
|
|
|
string txt = text_pool->stringValue();
|
|
|
|
|
2012-10-11 14:30:28 +02:00
|
|
|
// first let's remove any whitespaces
|
|
|
|
boost::erase_all(txt, " "); // space
|
|
|
|
boost::erase_all(txt, "\t"); // tabulation
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-09-27 19:33:20 +02:00
|
|
|
// Is this prefix/len notation?
|
2012-09-25 18:26:37 +02:00
|
|
|
size_t pos = txt.find("/");
|
|
|
|
if (pos != string::npos) {
|
|
|
|
IOAddress addr("::");
|
|
|
|
uint8_t len = 0;
|
|
|
|
try {
|
|
|
|
addr = IOAddress(txt.substr(0, pos));
|
|
|
|
|
2012-10-11 14:30:28 +02:00
|
|
|
// start with the first character after /
|
2012-10-09 19:13:29 +02:00
|
|
|
string prefix_len = txt.substr(pos + 1);
|
|
|
|
|
2012-11-13 10:19:54 +01:00
|
|
|
// It is lexically cast to int and then downcast to uint8_t.
|
2012-10-09 19:13:29 +02:00
|
|
|
// Direct cast to uint8_t (which is really an unsigned char)
|
2012-09-25 18:26:37 +02:00
|
|
|
// will result in interpreting the first digit as output
|
2012-10-09 19:13:29 +02:00
|
|
|
// value and throwing exception if length is written on two
|
|
|
|
// digits (because there are extra characters left over).
|
|
|
|
|
|
|
|
// No checks for values over 128. Range correctness will
|
|
|
|
// be checked in Pool6 constructor.
|
|
|
|
len = boost::lexical_cast<int>(prefix_len);
|
2012-09-25 18:26:37 +02:00
|
|
|
} catch (...) {
|
2013-01-08 20:49:32 +01:00
|
|
|
isc_throw(DhcpConfigError, "failed to parse pool "
|
2012-09-25 18:26:37 +02:00
|
|
|
"definition: " << text_pool->stringValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
Pool6Ptr pool(new Pool6(Pool6::TYPE_IA, addr, len));
|
2012-12-21 00:12:03 +01:00
|
|
|
local_pools_.push_back(pool);
|
2012-09-25 18:26:37 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-27 19:33:20 +02:00
|
|
|
// Is this min-max notation?
|
2012-09-25 18:26:37 +02:00
|
|
|
pos = txt.find("-");
|
|
|
|
if (pos != string::npos) {
|
2012-09-27 19:33:20 +02:00
|
|
|
// using min-max notation
|
2012-12-13 11:38:21 +00:00
|
|
|
IOAddress min(txt.substr(0, pos));
|
2012-10-09 19:13:29 +02:00
|
|
|
IOAddress max(txt.substr(pos + 1));
|
2012-09-25 18:26:37 +02:00
|
|
|
|
|
|
|
Pool6Ptr pool(new Pool6(Pool6::TYPE_IA, min, max));
|
|
|
|
|
2012-12-21 00:12:03 +01:00
|
|
|
local_pools_.push_back(pool);
|
2012-09-25 18:26:37 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-08 20:49:32 +01:00
|
|
|
isc_throw(DhcpConfigError, "failed to parse pool definition:"
|
2012-09-25 18:26:37 +02:00
|
|
|
<< text_pool->stringValue() <<
|
|
|
|
". Does not contain - (for min-max) nor / (prefix/len)");
|
|
|
|
}
|
|
|
|
}
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// @brief sets storage for value of this parameter
|
|
|
|
///
|
2012-12-21 00:12:03 +01:00
|
|
|
/// See @ref dhcpv6ConfigInherit for details.
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
|
|
|
/// @param storage pointer to the storage container
|
2012-09-25 18:26:37 +02:00
|
|
|
void setStorage(PoolStorage* storage) {
|
|
|
|
pools_ = storage;
|
|
|
|
}
|
|
|
|
|
2012-12-21 00:12:03 +01:00
|
|
|
/// @brief Stores the parsed values in a storage provided
|
|
|
|
/// by an upper level parser.
|
|
|
|
virtual void commit() {
|
|
|
|
if (pools_) {
|
2012-12-21 09:34:21 +01:00
|
|
|
// local_pools_ holds the values produced by the build function.
|
|
|
|
// At this point parsing should have completed successfuly so
|
|
|
|
// we can append new data to the supplied storage.
|
2012-12-21 00:12:03 +01:00
|
|
|
pools_->insert(pools_->end(), local_pools_.begin(),
|
|
|
|
local_pools_.end());
|
|
|
|
}
|
|
|
|
}
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief factory that constructs PoolParser objects
|
|
|
|
///
|
|
|
|
/// @param param_name name of the parameter to be parsed
|
2013-01-04 13:47:37 +01:00
|
|
|
static DhcpConfigParser* factory(const std::string& param_name) {
|
2012-09-25 18:26:37 +02:00
|
|
|
return (new PoolParser(param_name));
|
|
|
|
}
|
|
|
|
|
2012-12-05 15:38:14 +01:00
|
|
|
private:
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief pointer to the actual Pools storage
|
|
|
|
///
|
2012-11-13 10:19:54 +01:00
|
|
|
/// This is typically a storage somewhere in Subnet parser
|
2012-10-01 18:56:55 +02:00
|
|
|
/// (an upper level parser).
|
2012-10-09 19:13:29 +02:00
|
|
|
PoolStorage* pools_;
|
2012-12-21 00:12:03 +01:00
|
|
|
/// A temporary storage for pools configuration. It is a
|
|
|
|
/// storage where pools are stored by build function.
|
|
|
|
PoolStorage local_pools_;
|
2012-09-25 18:26:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief this class parses a single subnet
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
|
|
|
/// This class parses the whole subnet definition. It creates parsers
|
|
|
|
/// for received configuration parameters as needed.
|
2012-10-09 19:13:29 +02:00
|
|
|
class Subnet6ConfigParser : public DhcpConfigParser {
|
2012-09-25 18:26:37 +02:00
|
|
|
public:
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// @brief constructor
|
|
|
|
Subnet6ConfigParser(const std::string& ) {
|
2012-11-13 10:19:54 +01:00
|
|
|
// The parameter should always be "subnet", but we don't check
|
|
|
|
// against that here in case some wants to reuse this parser somewhere.
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief parses parameter value
|
|
|
|
///
|
|
|
|
/// @param subnet pointer to the content of subnet definition
|
2012-12-21 09:34:21 +01:00
|
|
|
///
|
2013-01-08 20:49:32 +01:00
|
|
|
/// @throw isc::DhcpConfigError if subnet configuration parsing failed.
|
2012-09-25 18:26:37 +02:00
|
|
|
void build(ConstElementPtr subnet) {
|
|
|
|
|
|
|
|
BOOST_FOREACH(ConfigPair param, subnet->mapValue()) {
|
|
|
|
ParserPtr parser(createSubnet6ConfigParser(param.first));
|
2013-04-10 17:02:10 -04:00
|
|
|
parser->build(param.second);
|
|
|
|
parsers_.push_back(parser);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-12-21 00:12:03 +01:00
|
|
|
// In order to create new subnet we need to get the data out
|
|
|
|
// of the child parsers first. The only way to do it is to
|
|
|
|
// invoke commit on them because it will make them write
|
|
|
|
// parsed data into storages we have supplied.
|
|
|
|
// Note that triggering commits on child parsers does not
|
|
|
|
// affect global data because we supplied pointers to storages
|
|
|
|
// local to this object. Thus, even if this method fails
|
|
|
|
// later on, the configuration remains consistent.
|
2012-11-07 18:26:21 +01:00
|
|
|
BOOST_FOREACH(ParserPtr parser, parsers_) {
|
|
|
|
parser->commit();
|
|
|
|
}
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-12-21 00:12:03 +01:00
|
|
|
// Create a subnet.
|
2012-12-21 09:34:21 +01:00
|
|
|
createSubnet();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Adds the created subnet to a server's configuration.
|
|
|
|
void commit() {
|
|
|
|
if (subnet_) {
|
|
|
|
isc::dhcp::CfgMgr::instance().addSubnet6(subnet_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-01-11 18:39:35 +01:00
|
|
|
/// @brief Append sub-options to an option.
|
|
|
|
///
|
|
|
|
/// @param option_space a name of the encapsulated option space.
|
|
|
|
/// @param option option instance to append sub-options to.
|
|
|
|
void appendSubOptions(const std::string& option_space, OptionPtr& option) {
|
2013-01-21 18:31:01 +01:00
|
|
|
// Only non-NULL options are stored in option container.
|
|
|
|
// If this option pointer is NULL this is a serious error.
|
|
|
|
assert(option);
|
2013-01-15 15:33:55 +01:00
|
|
|
|
|
|
|
OptionDefinitionPtr def;
|
|
|
|
if (option_space == "dhcp6" &&
|
|
|
|
LibDHCP::isStandardOption(Option::V6, option->getType())) {
|
|
|
|
def = LibDHCP::getOptionDef(Option::V6, option->getType());
|
|
|
|
// Definitions for some of the standard options hasn't been
|
|
|
|
// implemented so it is ok to leave here.
|
|
|
|
if (!def) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const OptionDefContainerPtr defs =
|
|
|
|
option_def_intermediate.getItems(option_space);
|
|
|
|
const OptionDefContainerTypeIndex& idx = defs->get<1>();
|
|
|
|
const OptionDefContainerTypeRange& range =
|
|
|
|
idx.equal_range(option->getType());
|
|
|
|
// There is no definition so we have to leave.
|
|
|
|
if (std::distance(range.first, range.second) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = *range.first;
|
|
|
|
|
|
|
|
// If the definition exists, it must be non-NULL.
|
|
|
|
// Otherwise it is a programming error.
|
|
|
|
assert(def);
|
|
|
|
}
|
|
|
|
|
2013-01-21 18:31:01 +01:00
|
|
|
// We need to get option definition for the particular option space
|
2013-01-11 18:39:35 +01:00
|
|
|
// and code. This definition holds the information whether our
|
|
|
|
// option encapsulates any option space.
|
|
|
|
// Get the encapsulated option space name.
|
2013-01-15 15:33:55 +01:00
|
|
|
std::string encapsulated_space = def->getEncapsulatedSpace();
|
2013-01-11 18:39:35 +01:00
|
|
|
// If option space name is empty it means that our option does not
|
|
|
|
// encapsulate any option space (does not include sub-options).
|
|
|
|
if (!encapsulated_space.empty()) {
|
|
|
|
// Get the sub-options that belong to the encapsulated
|
|
|
|
// option space.
|
|
|
|
const Subnet::OptionContainerPtr sub_opts =
|
|
|
|
option_defaults.getItems(encapsulated_space);
|
|
|
|
// Append sub-options to the option.
|
|
|
|
BOOST_FOREACH(Subnet::OptionDescriptor desc, *sub_opts) {
|
|
|
|
if (desc.option) {
|
|
|
|
option->addOption(desc.option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
/// @brief Create a new subnet using a data from child parsers.
|
|
|
|
///
|
2013-01-08 20:49:32 +01:00
|
|
|
/// @throw isc::dhcp::DhcpConfigError if subnet configuration parsing failed.
|
2012-12-21 09:34:21 +01:00
|
|
|
void createSubnet() {
|
2013-04-01 11:19:24 -04:00
|
|
|
std::string subnet_txt;
|
|
|
|
try {
|
|
|
|
subnet_txt = string_values_.getParam("subnet");
|
|
|
|
} catch (DhcpConfigError) {
|
|
|
|
// rethrow with precise error
|
2013-01-08 20:49:32 +01:00
|
|
|
isc_throw(DhcpConfigError,
|
2012-09-25 18:26:37 +02:00
|
|
|
"Mandatory subnet definition in subnet missing");
|
|
|
|
}
|
2013-04-01 11:19:24 -04:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Remove any spaces or tabs.
|
2012-09-25 18:26:37 +02:00
|
|
|
boost::erase_all(subnet_txt, " ");
|
|
|
|
boost::erase_all(subnet_txt, "\t");
|
2013-04-01 11:19:24 -04:00
|
|
|
|
2013-01-04 13:47:37 +01:00
|
|
|
// The subnet format is prefix/len. We are going to extract
|
|
|
|
// the prefix portion of a subnet string to create IOAddress
|
|
|
|
// object from it. IOAddress will be passed to the Subnet's
|
|
|
|
// constructor later on. In order to extract the prefix we
|
|
|
|
// need to get all characters preceding "/".
|
2012-09-25 18:26:37 +02:00
|
|
|
size_t pos = subnet_txt.find("/");
|
|
|
|
if (pos == string::npos) {
|
2013-01-08 20:49:32 +01:00
|
|
|
isc_throw(DhcpConfigError,
|
2013-04-01 11:19:24 -04:00
|
|
|
"Invalid subnet syntax (prefix/len expected):" << subnet_txt);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2012-12-21 00:12:03 +01:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Try to create the address object. It also validates that
|
|
|
|
// the address syntax is ok.
|
2012-09-25 18:26:37 +02:00
|
|
|
IOAddress addr(subnet_txt.substr(0, pos));
|
|
|
|
uint8_t len = boost::lexical_cast<unsigned int>(subnet_txt.substr(pos + 1));
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Get all 'time' parameters using inheritance.
|
|
|
|
// If the subnet-specific value is defined then use it, else
|
2013-01-04 13:47:37 +01:00
|
|
|
// use the global value. The global value must always be
|
|
|
|
// present. If it is not, it is an internal error and exception
|
|
|
|
// is thrown.
|
2012-09-25 18:26:37 +02:00
|
|
|
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");
|
|
|
|
|
2013-01-15 16:05:33 +01:00
|
|
|
// Get interface name. If it is defined, then the subnet is available
|
|
|
|
// directly over specified network interface.
|
2013-04-01 11:19:24 -04:00
|
|
|
std::string iface;
|
|
|
|
try {
|
|
|
|
iface = string_values_.getParam("interface");
|
|
|
|
} catch (DhcpConfigError) {
|
|
|
|
// iface not mandatory so swallow the exception
|
2013-01-15 16:05:33 +01:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:33:20 +02:00
|
|
|
/// @todo: Convert this to logger once the parser is working reliably
|
2012-09-28 20:39:13 +02:00
|
|
|
stringstream tmp;
|
|
|
|
tmp << addr.toText() << "/" << (int)len
|
|
|
|
<< " with params t1=" << t1 << ", t2=" << t2 << ", pref="
|
|
|
|
<< pref << ", valid=" << valid;
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-09-28 20:39:13 +02:00
|
|
|
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_NEW_SUBNET).arg(tmp.str());
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Create a new subnet.
|
2012-12-21 00:12:03 +01:00
|
|
|
subnet_.reset(new Subnet6(addr, len, t1, t2, pref, valid));
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Add pools to it.
|
2012-09-28 20:39:13 +02:00
|
|
|
for (PoolStorage::iterator it = pools_.begin(); it != pools_.end(); ++it) {
|
2013-01-10 16:32:24 +01:00
|
|
|
subnet_->addPool(*it);
|
2012-09-28 20:39:13 +02:00
|
|
|
}
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2013-01-15 16:05:33 +01:00
|
|
|
// Configure interface, if defined
|
2013-01-17 17:14:38 +01:00
|
|
|
if (!iface.empty()) {
|
|
|
|
if (!IfaceMgr::instance().getIface(iface)) {
|
2013-01-18 16:52:38 +01:00
|
|
|
isc_throw(DhcpConfigError, "Specified interface name " << iface
|
2013-01-17 17:14:38 +01:00
|
|
|
<< " for subnet " << subnet_->toText() << " is not present"
|
|
|
|
<< " in the system.");
|
|
|
|
}
|
2012-10-30 18:42:16 +01:00
|
|
|
|
2013-01-15 16:05:33 +01:00
|
|
|
subnet_->setIface(iface);
|
|
|
|
}
|
|
|
|
|
2013-01-10 21:22:44 +01:00
|
|
|
// We are going to move configured options to the Subnet object.
|
|
|
|
// Configured options reside in the container where options
|
|
|
|
// are grouped by space names. Thus we need to get all space names
|
|
|
|
// and iterate over all options that belong to them.
|
2013-01-16 10:09:46 +01:00
|
|
|
std::list<std::string> space_names = options_.getOptionSpaceNames();
|
|
|
|
BOOST_FOREACH(std::string option_space, space_names) {
|
2013-01-10 21:22:44 +01:00
|
|
|
// Get all options within a particular option space.
|
|
|
|
BOOST_FOREACH(Subnet::OptionDescriptor desc,
|
|
|
|
*options_.getItems(option_space)) {
|
2013-01-14 12:25:01 +01:00
|
|
|
// The pointer should be non-NULL. The validation is expected
|
|
|
|
// to be performed by the OptionDataParser before adding an
|
|
|
|
// option descriptor to the container.
|
2013-01-10 21:22:44 +01:00
|
|
|
assert(desc.option);
|
|
|
|
// We want to check whether an option with the particular
|
|
|
|
// option code has been already added. If so, we want
|
|
|
|
// to issue a warning.
|
|
|
|
Subnet::OptionDescriptor existing_desc =
|
|
|
|
subnet_->getOptionDescriptor("option_space",
|
|
|
|
desc.option->getType());
|
|
|
|
if (existing_desc.option) {
|
|
|
|
LOG_WARN(dhcp6_logger, DHCP6_CONFIG_OPTION_DUPLICATE)
|
|
|
|
.arg(desc.option->getType()).arg(addr.toText());
|
|
|
|
}
|
2013-01-11 18:39:35 +01:00
|
|
|
// Add sub-options (if any).
|
|
|
|
appendSubOptions(option_space, desc.option);
|
2013-01-10 21:22:44 +01:00
|
|
|
// In any case, we add the option to the subnet.
|
|
|
|
subnet_->addOption(desc.option, false, option_space);
|
2012-10-30 10:21:08 +01:00
|
|
|
}
|
2012-10-24 20:38:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-29 12:53:17 +01:00
|
|
|
// Check all global options and add them to the subnet object if
|
|
|
|
// they have been configured in the global scope. If they have been
|
|
|
|
// configured in the subnet scope we don't add global option because
|
2012-11-07 18:26:21 +01:00
|
|
|
// the one configured in the subnet scope always takes precedence.
|
2013-01-16 10:09:46 +01:00
|
|
|
space_names = option_defaults.getOptionSpaceNames();
|
|
|
|
BOOST_FOREACH(std::string option_space, space_names) {
|
2013-01-10 21:22:44 +01:00
|
|
|
// Get all global options for the particular option space.
|
|
|
|
BOOST_FOREACH(Subnet::OptionDescriptor desc,
|
|
|
|
*option_defaults.getItems(option_space)) {
|
2013-01-14 12:25:01 +01:00
|
|
|
// The pointer should be non-NULL. The validation is expected
|
|
|
|
// to be performed by the OptionDataParser before adding an
|
|
|
|
// option descriptor to the container.
|
2013-01-10 21:22:44 +01:00
|
|
|
assert(desc.option);
|
|
|
|
// Check if the particular option has been already added.
|
|
|
|
// This would mean that it has been configured in the
|
|
|
|
// subnet scope. Since option values configured in the
|
|
|
|
// subnet scope take precedence over globally configured
|
|
|
|
// values we don't add option from the global storage
|
|
|
|
// if there is one already.
|
|
|
|
Subnet::OptionDescriptor existing_desc =
|
|
|
|
subnet_->getOptionDescriptor(option_space, desc.option->getType());
|
|
|
|
if (!existing_desc.option) {
|
2013-01-11 18:39:35 +01:00
|
|
|
// Add sub-options (if any).
|
|
|
|
appendSubOptions(option_space, desc.option);
|
|
|
|
|
2013-01-10 21:22:44 +01:00
|
|
|
subnet_->addOption(desc.option, false, option_space);
|
|
|
|
}
|
2012-10-29 12:53:17 +01:00
|
|
|
}
|
|
|
|
}
|
2012-10-30 10:21:08 +01:00
|
|
|
}
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// @brief creates parsers for entries in subnet definition
|
|
|
|
///
|
|
|
|
/// @param config_id name od the entry
|
2012-12-21 09:34:21 +01:00
|
|
|
///
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @return parser object for specified entry name
|
2013-01-08 20:49:32 +01:00
|
|
|
/// @throw isc::dhcp::DhcpConfigError if trying to create a parser
|
2012-12-21 09:34:21 +01:00
|
|
|
/// for unknown config element
|
2012-10-09 19:13:29 +02:00
|
|
|
DhcpConfigParser* createSubnet6ConfigParser(const std::string& config_id) {
|
2013-04-10 17:02:10 -04:00
|
|
|
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) ||
|
|
|
|
(config_id.compare("interface") == 0)) {
|
|
|
|
parser = new StringParser(config_id, &string_values_);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("pool") == 0) {
|
|
|
|
parser = new PoolParser(config_id, &pools_);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("option-data") == 0) {
|
|
|
|
parser = new OptionDataListParser(config_id, &options_,
|
|
|
|
&option_def_intermediate,
|
|
|
|
Dhcp6OptionDataParser::factory);
|
|
|
|
} else {
|
|
|
|
isc_throw(NotImplemented,
|
|
|
|
"parser error: Subnet6 parameter not supported: " << config_id);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2013-04-10 17:02:10 -04:00
|
|
|
|
|
|
|
return (parser);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
/// @brief Returns value for a given parameter (after using inheritance)
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
2012-11-13 10:19:54 +01:00
|
|
|
/// This method implements inheritance. For a given parameter name, it first
|
2012-10-01 18:56:55 +02:00
|
|
|
/// checks if there is a global value for it and overwrites it with specific
|
|
|
|
/// value if such value was defined in subnet.
|
|
|
|
///
|
|
|
|
/// @param name name of the parameter
|
|
|
|
/// @return triplet with the parameter name
|
2013-01-08 20:49:32 +01:00
|
|
|
/// @throw DhcpConfigError when requested parameter is not present
|
2012-12-21 09:34:21 +01:00
|
|
|
isc::dhcp::Triplet<uint32_t> getParam(const std::string& name) {
|
2012-09-25 18:26:37 +02:00
|
|
|
uint32_t value = 0;
|
2013-04-01 11:19:24 -04:00
|
|
|
try {
|
|
|
|
// look for local value
|
|
|
|
value = uint32_values_.getParam(name);
|
|
|
|
} catch (DhcpConfigError) {
|
|
|
|
try {
|
|
|
|
// no local, use global value
|
|
|
|
value = uint32_defaults.getParam(name);
|
|
|
|
} catch (DhcpConfigError) {
|
|
|
|
isc_throw(DhcpConfigError, "Mandatory parameter " << name
|
2012-09-25 18:26:37 +02:00
|
|
|
<< " missing (no global default and no subnet-"
|
|
|
|
<< "specific value)");
|
2013-04-01 11:19:24 -04:00
|
|
|
}
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2013-04-01 11:19:24 -04:00
|
|
|
|
|
|
|
return (Triplet<uint32_t>(value));
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// storage for subnet-specific uint32 values
|
2012-09-25 18:26:37 +02:00
|
|
|
Uint32Storage uint32_values_;
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// storage for subnet-specific integer values
|
2012-09-25 18:26:37 +02:00
|
|
|
StringStorage string_values_;
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// storage for pools belonging to this subnet
|
2012-09-25 18:26:37 +02:00
|
|
|
PoolStorage pools_;
|
2012-10-01 18:56:55 +02:00
|
|
|
|
2012-10-24 20:38:58 +02:00
|
|
|
/// storage for options belonging to this subnet
|
|
|
|
OptionStorage options_;
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// parsers are stored here
|
2012-09-25 18:26:37 +02:00
|
|
|
ParserCollection parsers_;
|
2012-12-21 00:12:03 +01:00
|
|
|
|
|
|
|
/// Pointer to the created subnet object.
|
2012-12-21 09:34:21 +01:00
|
|
|
isc::dhcp::Subnet6Ptr subnet_;
|
2012-09-25 18:26:37 +02:00
|
|
|
};
|
|
|
|
|
2012-11-13 10:19:54 +01:00
|
|
|
/// @brief this class parses a list of subnets
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
|
|
|
/// This is a wrapper parser that handles the whole list of Subnet6
|
|
|
|
/// definitions. It iterates over all entries and creates Subnet6ConfigParser
|
|
|
|
/// for each entry.
|
2012-10-09 19:13:29 +02:00
|
|
|
class Subnets6ListConfigParser : public DhcpConfigParser {
|
2012-09-25 18:26:37 +02:00
|
|
|
public:
|
2012-10-01 18:56:55 +02:00
|
|
|
|
|
|
|
/// @brief constructor
|
|
|
|
///
|
|
|
|
Subnets6ListConfigParser(const std::string&) {
|
|
|
|
/// parameter name is ignored
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief parses contents of the list
|
|
|
|
///
|
2012-11-13 10:19:54 +01:00
|
|
|
/// Iterates over all entries on the list and creates a Subnet6ConfigParser
|
2012-10-01 18:56:55 +02:00
|
|
|
/// for each entry.
|
|
|
|
///
|
|
|
|
/// @param subnets_list pointer to a list of IPv6 subnets
|
2012-09-25 18:26:37 +02:00
|
|
|
void build(ConstElementPtr subnets_list) {
|
|
|
|
|
|
|
|
// No need to define FactoryMap here. There's only one type
|
|
|
|
// used: Subnet6ConfigParser
|
|
|
|
|
|
|
|
BOOST_FOREACH(ConstElementPtr subnet, subnets_list->listValue()) {
|
|
|
|
|
|
|
|
ParserPtr parser(new Subnet6ConfigParser("subnet"));
|
|
|
|
parser->build(subnet);
|
|
|
|
subnets_.push_back(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief commits subnets definitions.
|
|
|
|
///
|
|
|
|
/// Iterates over all Subnet6 parsers. Each parser contains definitions
|
|
|
|
/// of a single subnet and its parameters and commits each subnet separately.
|
2012-09-25 18:26:37 +02:00
|
|
|
void commit() {
|
2012-09-28 20:39:13 +02:00
|
|
|
// @todo: Implement more subtle reconfiguration than toss
|
|
|
|
// the old one and replace with the new one.
|
|
|
|
|
|
|
|
// remove old subnets
|
2012-12-21 09:34:21 +01:00
|
|
|
isc::dhcp::CfgMgr::instance().deleteSubnets6();
|
2012-09-28 20:39:13 +02:00
|
|
|
|
2012-09-25 18:26:37 +02:00
|
|
|
BOOST_FOREACH(ParserPtr subnet, subnets_) {
|
|
|
|
subnet->commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief Returns Subnet6ListConfigParser object
|
|
|
|
/// @param param_name name of the parameter
|
|
|
|
/// @return Subnets6ListConfigParser object
|
2013-01-04 13:47:37 +01:00
|
|
|
static DhcpConfigParser* factory(const std::string& param_name) {
|
2012-09-25 18:26:37 +02:00
|
|
|
return (new Subnets6ListConfigParser(param_name));
|
|
|
|
}
|
|
|
|
|
2012-10-01 18:56:55 +02:00
|
|
|
/// @brief collection of subnet parsers.
|
2012-09-25 18:26:37 +02:00
|
|
|
ParserCollection subnets_;
|
|
|
|
};
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace isc {
|
|
|
|
namespace dhcp {
|
|
|
|
|
2013-04-10 17:02:10 -04:00
|
|
|
//************** Dhcp6OptionDataParser methods ****************************
|
|
|
|
|
|
|
|
Dhcp6OptionDataParser::Dhcp6OptionDataParser(const std::string& param_name,
|
|
|
|
OptionStorage *options, OptionDefStorage *option_defs)
|
|
|
|
:OptionDataParser(param_name, options, option_defs, Option::V6) {
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionDataParser* Dhcp6OptionDataParser::factory(const std::string& param_name,
|
|
|
|
OptionStorage *options, OptionDefStorage *option_defs) {
|
|
|
|
return new Dhcp6OptionDataParser(param_name, options, option_defs);
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionDefinitionPtr Dhcp6OptionDataParser::findServerSpaceOptionDefinition (
|
|
|
|
std::string& option_space, uint32_t option_code) {
|
|
|
|
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"
|
|
|
|
<< " for DHCPv4 server");
|
|
|
|
}
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2012-09-25 18:26:37 +02:00
|
|
|
/// @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.
|
2012-10-01 18:56:55 +02:00
|
|
|
///
|
|
|
|
/// @param config_id pointer to received global configuration entry
|
|
|
|
/// @return parser for specified global DHCPv6 parameter
|
2012-12-05 15:22:05 +01:00
|
|
|
/// @throw NotImplemented if trying to create a parser for unknown config element
|
2012-10-09 19:13:29 +02:00
|
|
|
DhcpConfigParser* createGlobalDhcpConfigParser(const std::string& config_id) {
|
2013-04-10 17:02:10 -04:00
|
|
|
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_defaults);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("interface") == 0) {
|
|
|
|
parser = new InterfaceListConfigParser(config_id);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("subnet6") == 0) {
|
|
|
|
parser = new Subnets6ListConfigParser(config_id);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("option-data") == 0) {
|
|
|
|
parser = new OptionDataListParser(config_id, &option_defaults,
|
|
|
|
&option_def_intermediate,
|
|
|
|
Dhcp6OptionDataParser::factory);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("option-def") == 0) {
|
|
|
|
parser = new OptionDefListParser(config_id, &option_def_intermediate);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("version") == 0) {
|
|
|
|
parser = new StringParser(config_id, &string_defaults);
|
|
|
|
}
|
|
|
|
else if (config_id.compare("lease-database") == 0) {
|
|
|
|
parser = new DbAccessParser(config_id);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-25 18:26:37 +02:00
|
|
|
isc_throw(NotImplemented,
|
2013-04-10 17:02:10 -04:00
|
|
|
"Parser error: Global configuration parameter not supported: "
|
|
|
|
<< config_id);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2013-04-10 17:02:10 -04:00
|
|
|
|
|
|
|
return (parser);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:33:20 +02:00
|
|
|
ConstElementPtr
|
2013-01-15 10:34:40 +01:00
|
|
|
configureDhcp6Server(Dhcpv6Srv&, ConstElementPtr config_set) {
|
2012-09-25 18:26:37 +02:00
|
|
|
if (!config_set) {
|
2012-12-05 15:23:34 +01:00
|
|
|
ConstElementPtr answer = isc::config::createAnswer(1,
|
|
|
|
string("Can't parse NULL config"));
|
|
|
|
return (answer);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:33:20 +02:00
|
|
|
/// @todo: append most essential info here (like "2 new subnets configured")
|
|
|
|
string config_details;
|
|
|
|
|
|
|
|
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_START).arg(config_set->str());
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Some of the values specified in the configuration depend on
|
2013-01-10 21:22:44 +01:00
|
|
|
// 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.
|
2013-01-14 12:25:01 +01:00
|
|
|
// Thus we group parsers and will fire them in the right order:
|
|
|
|
// all parsers other than subnet4 and option-data parser,
|
|
|
|
// option-data parser, subnet4 parser.
|
2012-12-21 00:12:03 +01:00
|
|
|
ParserCollection independent_parsers;
|
2013-01-10 21:22:44 +01:00
|
|
|
ParserPtr subnet_parser;
|
|
|
|
ParserPtr option_parser;
|
2012-12-21 00:12:03 +01:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// The subnet parsers implement data inheritance by directly
|
2013-01-10 21:22:44 +01:00
|
|
|
// accessing global storage. For this reason the global data
|
2012-12-21 09:34:21 +01:00
|
|
|
// parsers must store the parsed data into global storages
|
2013-01-04 13:47:37 +01:00
|
|
|
// 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.
|
2012-12-21 00:12:03 +01:00
|
|
|
Uint32Storage uint32_local(uint32_defaults);
|
|
|
|
StringStorage string_local(string_defaults);
|
|
|
|
OptionStorage option_local(option_defaults);
|
2013-01-14 12:25:01 +01:00
|
|
|
OptionDefStorage option_def_local(option_def_intermediate);
|
2012-12-21 09:34:21 +01:00
|
|
|
|
|
|
|
// answer will hold the result.
|
2012-12-21 00:12:03 +01:00
|
|
|
ConstElementPtr answer;
|
2012-12-21 09:34:21 +01:00
|
|
|
// rollback informs whether error occured and original data
|
|
|
|
// have to be restored to global storages.
|
2012-12-21 00:12:03 +01:00
|
|
|
bool rollback = false;
|
2013-01-21 20:57:57 +00:00
|
|
|
// 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.
|
2013-01-18 12:05:12 +00:00
|
|
|
ConfigPair config_pair;
|
2012-09-25 18:26:37 +02:00
|
|
|
try {
|
2013-01-10 21:22:44 +01:00
|
|
|
|
|
|
|
// Make parsers grouping.
|
|
|
|
const std::map<std::string, ConstElementPtr>& values_map =
|
|
|
|
config_set->mapValue();
|
2013-01-21 20:57:57 +00:00
|
|
|
BOOST_FOREACH(config_pair, values_map) {
|
2013-01-10 21:22:44 +01:00
|
|
|
ParserPtr parser(createGlobalDhcpConfigParser(config_pair.first));
|
2013-01-21 20:57:57 +00:00
|
|
|
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
|
|
|
|
.arg(config_pair.first);
|
2013-01-10 21:22:44 +01:00
|
|
|
if (config_pair.first == "subnet6") {
|
|
|
|
subnet_parser = parser;
|
|
|
|
|
|
|
|
} else if (config_pair.first == "option-data") {
|
|
|
|
option_parser = parser;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Those parsers should be started before other
|
|
|
|
// parsers so we can call build straight away.
|
2012-12-21 00:12:03 +01:00
|
|
|
independent_parsers.push_back(parser);
|
|
|
|
parser->build(config_pair.second);
|
2012-12-21 09:34:21 +01:00
|
|
|
// The commit operation here may modify the global storage
|
|
|
|
// but we need it so as the subnet6 parser can access the
|
|
|
|
// parsed data.
|
2012-12-21 00:12:03 +01:00
|
|
|
parser->commit();
|
|
|
|
}
|
|
|
|
}
|
2012-09-25 18:26:37 +02:00
|
|
|
|
2013-01-10 21:22:44 +01:00
|
|
|
// 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);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2012-12-21 00:12:03 +01:00
|
|
|
|
2012-09-25 18:26:37 +02:00
|
|
|
} catch (const isc::Exception& ex) {
|
2013-01-21 22:01:48 +00:00
|
|
|
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
|
2013-01-18 12:05:12 +00:00
|
|
|
.arg(config_pair.first).arg(ex.what());
|
|
|
|
answer = isc::config::createAnswer(1,
|
|
|
|
string("Configuration parsing failed: ") + ex.what());
|
2012-12-21 09:34:21 +01:00
|
|
|
// An error occured, so make sure that we restore original data.
|
2012-12-21 00:12:03 +01:00
|
|
|
rollback = true;
|
|
|
|
|
2012-09-28 20:39:13 +02:00
|
|
|
} catch (...) {
|
|
|
|
// for things like bad_cast in boost::lexical_cast
|
2013-01-21 22:01:48 +00:00
|
|
|
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(config_pair.first);
|
2013-01-18 12:05:12 +00:00
|
|
|
answer = isc::config::createAnswer(1,
|
|
|
|
string("Configuration parsing failed"));
|
2012-12-21 09:34:21 +01:00
|
|
|
// An error occured, so make sure that we restore original data.
|
2012-12-21 00:12:03 +01:00
|
|
|
rollback = true;
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// 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.
|
2012-12-21 00:12:03 +01:00
|
|
|
if (!rollback) {
|
|
|
|
try {
|
2013-01-10 21:22:44 +01:00
|
|
|
if (subnet_parser) {
|
|
|
|
subnet_parser->commit();
|
2012-12-21 00:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const isc::Exception& ex) {
|
2013-01-10 15:30:10 +00:00
|
|
|
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
|
2013-01-21 20:57:57 +00:00
|
|
|
answer = isc::config::createAnswer(2,
|
|
|
|
string("Configuration commit failed:") + ex.what());
|
2012-12-21 09:34:21 +01:00
|
|
|
// An error occured, so make sure to restore the original data.
|
2012-12-21 00:12:03 +01:00
|
|
|
rollback = true;
|
|
|
|
} catch (...) {
|
|
|
|
// for things like bad_cast in boost::lexical_cast
|
2013-01-10 15:30:10 +00:00
|
|
|
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
|
2013-01-21 20:57:57 +00:00
|
|
|
answer = isc::config::createAnswer(2,
|
|
|
|
string("Configuration commit failed"));
|
2012-12-21 09:34:21 +01:00
|
|
|
// An error occured, so make sure to restore the original data.
|
2012-12-21 00:12:03 +01:00
|
|
|
rollback = true;
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2012-09-28 20:39:13 +02:00
|
|
|
}
|
2012-12-21 00:12:03 +01:00
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Rollback changes as the configuration parsing failed.
|
2012-12-21 00:12:03 +01:00
|
|
|
if (rollback) {
|
|
|
|
std::swap(uint32_defaults, uint32_local);
|
|
|
|
std::swap(string_defaults, string_local);
|
|
|
|
std::swap(option_defaults, option_local);
|
2013-01-14 12:25:01 +01:00
|
|
|
std::swap(option_def_intermediate, option_def_local);
|
2012-09-28 20:39:13 +02:00
|
|
|
return (answer);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
2012-09-27 19:33:20 +02:00
|
|
|
|
|
|
|
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_COMPLETE).arg(config_details);
|
|
|
|
|
2012-12-21 09:34:21 +01:00
|
|
|
// Everything was fine. Configuration is successful.
|
2013-01-30 11:47:57 +01:00
|
|
|
answer = isc::config::createAnswer(0, "Configuration committed.");
|
2012-09-27 19:33:20 +02:00
|
|
|
return (answer);
|
2012-09-25 18:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // end of isc::dhcp namespace
|
|
|
|
}; // end of isc namespace
|