#include <dhcp/libdhcp++.h>
#include <dhcp/option_definition.h>
#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/dbaccess_parser.h>
#include <dhcpsrv/dhcp_config_parser.h>
+ #include <dhcpsrv/option_space_container.h>
#include <util/encode/hex.h>
#include <util/strutil.h>
#include <boost/foreach.hpp>
namespace {
-/// @brief auxiliary type used for storing element name and its parser
-typedef pair<string, ConstElementPtr> ConfigPair;
-
+ // Forward declarations of some of the parser classes.
+ // They are used to define pointer types for these classes.
+ class BooleanParser;
+ class StringParser;
+ class Uint32Parser;
+
+ // Pointers to various parser objects.
+ typedef boost::shared_ptr<BooleanParser> BooleanParserPtr;
+ typedef boost::shared_ptr<StringParser> StringParserPtr;
+ typedef boost::shared_ptr<Uint32Parser> Uint32ParserPtr;
+
/// @brief a factory method that will create a parser for a given element name
typedef isc::dhcp::DhcpConfigParser* ParserFactory(const std::string& config_id);
factories["interface"] = InterfaceListConfigParser::factory;
factories["subnet4"] = Subnets4ListConfigParser::factory;
factories["option-data"] = OptionDataListParser::factory;
+ factories["option-def"] = OptionDefListParser::factory;
factories["version"] = StringParser::factory;
+ factories["lease-database"] = DbAccessParser::factory;
FactoryMap::iterator f = factories.find(config_id);
if (f == factories.end()) {
// rollback informs whether error occured and original data
// have to be restored to global storages.
bool rollback = false;
-
+ // config_pair holds the details of the current parser when iterating over
- // parser. 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.
++ // 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.
+ ConfigPair config_pair;
try {
- BOOST_FOREACH(ConfigPair config_pair, values_map) {
+ // Make parsers grouping.
+ const std::map<std::string, ConstElementPtr>& values_map =
+ config_set->mapValue();
++ BOOST_FOREACH(config_pair, values_map) {
+ ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first));
++ LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
++ .arg(config_pair.first);
+ if (config_pair.first == "subnet4") {
+ subnet_parser = parser;
- // Iterate over all independent parsers first (all but subnet4)
- // and try to parse the data.
- BOOST_FOREACH(config_pair, config_set->mapValue()) {
- if (config_pair.first != "subnet4") {
- ParserPtr parser(createGlobalDhcp4ConfigParser(
- config_pair.first));
- LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED1)
- .arg(config_pair.first);
+ } 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.
independent_parsers.push_back(parser);
parser->build(config_pair.second);
// The commit operation here may modify the global storage
}
} catch (const isc::Exception& ex) {
- answer =
- isc::config::createAnswer(1, string("Configuration parsing failed: ") + ex.what());
+ LOG_ERROR(dhcp4_logger, DHCP4_PARSER_CREATE_FAIL)
+ .arg(config_pair.first).arg(ex.what());
+ answer = isc::config::createAnswer(1,
+ string("Configuration parsing failed: ") + ex.what());
+
// An error occured, so make sure that we restore original data.
rollback = true;
} catch (...) {
// for things like bad_cast in boost::lexical_cast
- answer =
- isc::config::createAnswer(1, string("Configuration parsing failed"));
+ LOG_ERROR(dhcp4_logger, DHCP4_PARSER_CREATE_EXCEPTION)
+ .arg(config_pair.first);
+ answer = isc::config::createAnswer(1,
+ string("Configuration parsing failed"));
+
// An error occured, so make sure that we restore original data.
rollback = true;
}
}
}
catch (const isc::Exception& ex) {
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed: ") + ex.what());
+ LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed: ") + ex.what());
++ answer = isc::config::createAnswer(2,
++ string("Configuration commit failed: ") + ex.what());
rollback = true;
} catch (...) {
// for things like bad_cast in boost::lexical_cast
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed"));
+ LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed"));
++ answer = isc::config::createAnswer(2,
++ string("Configuration commit failed"));
rollback = true;
}
returned to the client into a valid packet. The cause is most likely
to be a programming error: please raise a bug report.
- % DHCP4_PARSER_CREATED1 created parser for configuration element %1
- A debug message output during a configuration update of the IPv4 DHCP
- server, notifying that the parser for the specified configuration element
- has been successfully created in the first pass through creating parsers
-
- % DHCP4_PARSER_CREATED2 created parser for configuration element %1
+% DHCP4_PARSER_COMMIT_EXCEPTION parser failed to commit changes
+On receipt of message containing details to a change of the IPv4 DHCP
+server configuration, a set of parsers were successfully created, but one
+of them failed to commit its changes due to a low-level system exception
+being raised. Additional messages may be output indicating the reason.
+
+% DHCP4_PARSER_COMMIT_FAIL parser failed to commit changes: %1
+On receipt of message containing details to a change of the IPv4 DHCP
+server configuration, a set of parsers were successfully created, but
+one of them failed to commit its changes. The reason for the failure
+is given in the message.
+
- has been successfully created in the second pass through creating parsers
++% DHCP4_PARSER_CREATED created parser for configuration element %1
+A debug message output during a configuration update of the IPv4 DHCP
+server, notifying that the parser for the specified configuration element
++has been successfully created.
+
+% DHCP4_PARSER_CREATE_FAIL failed to create parser for configuration element %1: %2
+On receipt of message containing details to a change of its configuration,
+the IPv4 DHCP server failed to create a parser to decode the contents of the
+named configuration element. The reason for the failure is given in the
+message.
+
+% DHCP4_PARSER_CREATE_EXCEPTION failed to create parser for configuration element %1
+On receipt of message containing details to a change of its configuration,
+the IPv4 DHCP server failed to create a parser to decode the contents
+of the named configuration element. The message has been output in
+response to a non-BIND 10 exception being raised. Additional messages
+may give further information.
+
% DHCP4_QUERY_DATA received packet type %1, data is <%2>
A debug message listing the data received from the client.
#include <dhcp/libdhcp++.h>
#include <dhcp6/config_parser.h>
#include <dhcp6/dhcp6_log.h>
+ #include <dhcp/iface_mgr.h>
#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/dbaccess_parser.h>
#include <dhcpsrv/dhcp_config_parser.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
namespace {
-/// @brief Auxiliary type used for storing an element name and its parser.
-typedef pair<string, ConstElementPtr> ConfigPair;
-
+ // Forward declarations of some of the parser classes.
+ // They are used to define pointer types for these classes.
+ class BooleanParser;
+ class StringParser;
+ class Uint32Parser;
+
+ // Pointers to various parser objects.
+ typedef boost::shared_ptr<BooleanParser> BooleanParserPtr;
+ typedef boost::shared_ptr<StringParser> StringParserPtr;
+ typedef boost::shared_ptr<Uint32Parser> Uint32ParserPtr;
+
/// @brief Factory method that will create a parser for a given element name
typedef isc::dhcp::DhcpConfigParser* ParserFactory(const std::string& config_id);
factories["interface"] = InterfaceListConfigParser::factory;
factories["subnet6"] = Subnets6ListConfigParser::factory;
factories["option-data"] = OptionDataListParser::factory;
+ factories["option-def"] = OptionDefListParser::factory;
factories["version"] = StringParser::factory;
+ factories["lease-database"] = DbAccessParser::factory;
FactoryMap::iterator f = factories.find(config_id);
if (f == factories.end()) {
// rollback informs whether error occured and original data
// have to be restored to global storages.
bool rollback = false;
- // config_pair holds the details of the current parser when iterating over
- // parser. 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.
++ // 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.
+ ConfigPair config_pair;
try {
- // Iterate over all independent parsers first (all but subnet6)
- // and try to parse the data.
- BOOST_FOREACH(config_pair, config_set->mapValue()) {
- if (config_pair.first != "subnet6") {
- ParserPtr parser(createGlobalDhcpConfigParser(
- config_pair.first));
- LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED1)
- .arg(config_pair.first);
+
+ // Make parsers grouping.
+ const std::map<std::string, ConstElementPtr>& values_map =
+ config_set->mapValue();
- BOOST_FOREACH(ConfigPair config_pair, values_map) {
++ BOOST_FOREACH(config_pair, values_map) {
+ ParserPtr parser(createGlobalDhcpConfigParser(config_pair.first));
++ LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
++ .arg(config_pair.first);
+ 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.
independent_parsers.push_back(parser);
parser->build(config_pair.second);
// The commit operation here may modify the global storage
}
}
catch (const isc::Exception& ex) {
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed:")
- + ex.what());
+ LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed:")
- + ex.what());
++ answer = isc::config::createAnswer(2,
++ string("Configuration commit failed:") + ex.what());
// An error occured, so make sure to restore the original data.
rollback = true;
} catch (...) {
// for things like bad_cast in boost::lexical_cast
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed"));
+ LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
- answer =
- isc::config::createAnswer(2, string("Configuration commit failed"));
++ answer = isc::config::createAnswer(2,
++ string("Configuration commit failed"));
// An error occured, so make sure to restore the original data.
rollback = true;
}
returned to the client into a valid packet. The reason is most likely
to be to a programming error: please raise a bug report.
- % DHCP6_PARSER_CREATED1 created parser for configuration element %1
+% DHCP6_PARSER_COMMIT_EXCEPTION parser failed to commit changes
+On receipt of message containing details to a change of the IPv6 DHCP
+server configuration, a set of parsers were successfully created, but one
+of them failed to commit its changes due to a low-level system exception
+being raised. Additional messages may be output indicating the reason.
+
+% DHCP6_PARSER_COMMIT_FAIL parser failed to commit changes: %1
+On receipt of message containing details to a change of the IPv6 DHCP
+server configuration, a set of parsers were successfully created, but
+one of them failed to commit its changes. The reason for the failure
+is given in the message.
+
- has been successfully created in the first pass through creating parsers
-
- % DHCP6_PARSER_CREATED2 created parser for configuration element %1
- A debug message output during a configuration update of the IPv6 DHCP
- server, notifying that the parser for the specified configuration element
- has been successfully created in the second pass through creating parsers
++% DHCP6_PARSER_CREATED created parser for configuration element %1
+A debug message output during a configuration update of the IPv6 DHCP
+server, notifying that the parser for the specified configuration element
++has been successfully created.
+
+% DHCP6_PARSER_CREATE_FAIL failed to create parser for configuration element %1: %2
+On receipt of message containing details to a change of its configuration,
+the IPv6 DHCP server failed to create a parser to decode the contents of the
+named configuration element. The reason for the failure is given in the
+message.
+
+% DHCP6_PARSER_CREATE_EXCEPTION failed to create parser for configuration element %1
+On receipt of message containing details to a change of its configuration,
+the IPv6 DHCP server failed to create a parser to decode the contents
+of the named configuration element. The message has been output in
+response to a non-BIND 10 exception being raised. Additional messages
+may give further information.
+
+The most likely cause of this is that the specification file for the server
+(which details the allowable contents of the configuration) is not correct for
+this version of BIND 10. This former may be the result of an interrupted
+installation of an update to BIND 10.
+
% DHCP6_PROCESS_IA_NA_REQUEST server is processing IA_NA option (duid=%1, iaid=%2, hint=%3)
This is a debug message that indicates a processing of received IA_NA
option. It may optionally contain an address that may be used by the server
IfaceMgr::instance().openSockets6(port);
}
- setServerID();
+ string duid_file = CfgMgr::instance().getDataDir() + "/" + string(SERVER_DUID_FILE);
+ if (loadServerID(duid_file)) {
+ LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_SERVERID_LOADED)
+ .arg(duid_file);
+ } else {
+ generateServerID();
+ LOG_INFO(dhcp6_logger, DHCP6_SERVERID_GENERATED)
+ .arg(duidToString(getServerID()))
+ .arg(duid_file);
+
+ if (!writeServerID(duid_file)) {
+ LOG_WARN(dhcp6_logger, DHCP6_SERVERID_WRITE_FAIL)
+ .arg(duid_file);
+ }
+
+ }
- // Instantiate LeaseMgr
- LeaseMgrFactory::create(dbconfig);
- LOG_INFO(dhcp6_logger, DHCP6_DB_BACKEND_STARTED)
- .arg(LeaseMgrFactory::instance().getType())
- .arg(LeaseMgrFactory::instance().getName());
-
// Instantiate allocation engine
alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
returned the specified IPv6 subnet when given the address hint specified
as the address is within the subnet.
-This is a debug message reporting that the DHCP configuration manager has
-returned the specified IPv6 subnet for a packet received over given interface.
-This particular subnet was selected, because it was specified as being directly
-reachable over given interface. (see 'interface' parameter in subnet6 definition).
+ % DHCPSRV_CFGMGR_SUBNET6_IFACE selected subnet %1 for packet received over interface %2
++This is a debug message reporting that the DHCP configuration manager
++has returned the specified IPv6 subnet for a packet received over
++given interface. This particular subnet was selected, because it
++was specified as being directly reachable over given interface. (see
++'interface' parameter in subnet6 definition).
++
+% DHCPSRV_CLOSE_DB closing currently open %1 database
+This is a debug message, issued when the DHCP server closes the currently
+open lease database. It is issued at program shutdown and whenever
+the database access parameters are changed: in the latter case, the
+server closes the currently open database, and opens a database using
+the new parameters.
% DHCPSRV_INVALID_ACCESS invalid database access string: %1
This is logged when an attempt has been made to parse a database access string
libdhcpsrv_unittests_SOURCES += addr_utilities_unittest.cc
libdhcpsrv_unittests_SOURCES += alloc_engine_unittest.cc
libdhcpsrv_unittests_SOURCES += cfgmgr_unittest.cc
- libdhcpsrv_unittests_SOURCES += hwaddr_unittest.cc
+libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
libdhcpsrv_unittests_SOURCES += lease_mgr_factory_unittest.cc
libdhcpsrv_unittests_SOURCES += lease_mgr_unittest.cc
libdhcpsrv_unittests_SOURCES += memfile_lease_mgr_unittest.cc