From: Marcin Siodelski Date: Thu, 24 Apr 2014 17:02:19 +0000 (+0200) Subject: [3409] The DHCPv4 config parser logs positions of the elements in config. X-Git-Tag: trac3434_base~43^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7137b4a408c63b84a636329c19658dbed15f7186;p=thirdparty%2Fkea.git [3409] The DHCPv4 config parser logs positions of the elements in config. --- diff --git a/src/bin/dhcp4/config_parser.cc b/src/bin/dhcp4/config_parser.cc index 5e9e9d60ae..813f6afff0 100644 --- a/src/bin/dhcp4/config_parser.cc +++ b/src/bin/dhcp4/config_parser.cc @@ -218,8 +218,7 @@ protected: global_context_, Dhcp4OptionDataParser::factory); } else { - isc_throw(NotImplemented, - "parser error: Subnet4 parameter not supported: " << config_id); + isc_throw(NotImplemented, "unsupported parameter: " << config_id); } return (parser); diff --git a/src/lib/dhcpsrv/dhcp_parsers.cc b/src/lib/dhcpsrv/dhcp_parsers.cc index 2d868230e8..38b299548a 100644 --- a/src/lib/dhcpsrv/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/dhcp_parsers.cc @@ -455,15 +455,25 @@ OptionDataParser::createOption() { isc_throw(DhcpConfigError, "invalid option space name '" << option_space << "' specified for option '" << option_name << "', code '" << option_code - << "' (" << string_values_->getPosition("name") << ")"); + << "' (" << string_values_->getPosition("space") << ")"); } const bool csv_format = boolean_values_->getParam("csv-format"); // Find the Option Definition for the option by its option code. // findOptionDefinition will throw if not found, no need to test. + // Find the definition for the option by its code. This function + // may throw so we catch exceptions to log the culprit line of the + // configuration. OptionDefinitionPtr def; - if (!(def = findServerSpaceOptionDefinition(option_space, option_code))) { + try { + def = findServerSpaceOptionDefinition(option_space, option_code); + + } catch (const std::exception& ex) { + isc_throw(DhcpConfigError, ex.what() + << " (" << string_values_->getPosition("space") << ")"); + } + if (!def) { // If we are not dealing with a standard option then we // need to search for its definition among user-configured // options. They are expected to be in the global storage @@ -1011,7 +1021,16 @@ SubnetConfigParser::SubnetConfigParser(const std::string&, void SubnetConfigParser::build(ConstElementPtr subnet) { BOOST_FOREACH(ConfigPair param, subnet->mapValue()) { - ParserPtr parser(createSubnetConfigParser(param.first)); + ParserPtr parser; + // When unsupported parameter is specified, the function called + // below will thrown an exception. We have to catch this exception + // to append the line number where the parameter is. + try { + parser = (createSubnetConfigParser(param.first)); + } catch (const std::exception& ex) { + isc_throw(DhcpConfigError, ex.what() << " (" + << param.second->getPosition() << ")"); + } parser->build(param.second); parsers_.push_back(parser); } @@ -1029,7 +1048,13 @@ SubnetConfigParser::build(ConstElementPtr subnet) { } // Create a subnet. - createSubnet(); + try { + createSubnet(); + } catch (const std::exception& ex) { + isc_throw(DhcpConfigError, + "subnet configuration failed (" << subnet->getPosition() + << "): " << ex.what()); + } } void