20#include <boost/foreach.hpp>
42 if (expression_cfg->getType() != Element::string) {
44 << expression_cfg->str() <<
"] must be a string, at ("
45 << expression_cfg->getPosition() <<
")");
51 expression_cfg->getValue(value);
58 }
catch (
const std::exception& ex) {
61 "expression: [" << value
62 <<
"] error: " << ex.
what() <<
" at ("
63 << expression_cfg->getPosition() <<
")");
73 bool append_error_position,
74 bool check_dependencies) {
76 std::string name =
getString(class_def_cfg,
"name");
79 "not empty parameter 'name' is required "
87 bool depend_on_known =
false;
91 [&class_dictionary, &depend_on_known, check_dependencies]
97 parser.
parse(match_expr, test_cfg, family, check_defined);
98 test = test_cfg->stringValue();
106 SimpleParser::setListDefaults(option_defs,
120 "Not allowed option definition for code '"
121 << def->getCode() <<
"' in space '"
122 << def->getOptionSpaceName() <<
"' at ("
123 << option_def->getPosition() <<
")");
127 }
catch (
const std::exception& ex) {
130 << option_def->getPosition() <<
")");
140 opts_parser.
parse(options, option_data);
147 bool required =
false;
148 if (class_def_cfg->contains(
"only-if-required")) {
149 required =
getBoolean(class_def_cfg,
"only-if-required");
154 if (class_def_cfg->contains(
"next-server")) {
155 std::string next_server_txt =
getString(class_def_cfg,
"next-server");
157 next_server =
IOAddress(next_server_txt);
160 "Invalid next-server value specified: '"
161 << next_server_txt <<
"' ("
162 <<
getPosition(
"next-server", class_def_cfg) <<
")");
165 if (next_server.
getFamily() != AF_INET) {
167 << next_server_txt <<
"', must be IPv4 address ("
168 <<
getPosition(
"next-server", class_def_cfg) <<
")");
173 << next_server_txt <<
"', must not be a broadcast ("
174 <<
getPosition(
"next-server", class_def_cfg) <<
")");
180 if (class_def_cfg->contains(
"server-hostname")) {
181 sname =
getString(class_def_cfg,
"server-hostname");
186 << sname.length() <<
" ("
187 <<
getPosition(
"server-hostname", class_def_cfg) <<
")");
192 std::string filename;
193 if (class_def_cfg->contains(
"boot-file-name")) {
194 filename =
getString(class_def_cfg,
"boot-file-name");
199 << filename.length() <<
" ("
200 <<
getPosition(
"boot-file-name", class_def_cfg) <<
")");
209 if (family != AF_INET) {
219 <<
"' only-if-required flag must be false");
223 <<
"' test expression must be empty");
229 if (name ==
"DROP") {
232 <<
"' only-if-required flag must be false");
239 class_dictionary->addClass(name, match_expr, test, required,
240 depend_on_known, options, defs,
241 user_context, next_server, sname, filename,
242 valid_lft, preferred_lft);
243 }
catch (
const std::exception& ex) {
244 std::ostringstream s;
245 s <<
"Can't add class: " << ex.what();
247 if (append_error_position) {
248 s <<
" (" << class_def_cfg->getPosition() <<
")";
256 const uint16_t family) {
258 if (!class_def_cfg || (class_def_cfg->getType() != Element::map)) {
263 static std::set<std::string> supported_params = {
"name",
269 "min-valid-lifetime",
270 "max-valid-lifetime" };
274 static std::set<std::string> supported_params_v4 = {
"option-def",
280 static std::set<std::string> supported_params_v6 = {
"preferred-lifetime",
281 "min-preferred-lifetime",
282 "max-preferred-lifetime" };
285 for (
auto name_value_pair : class_def_cfg->mapValue()) {
286 if ((supported_params.count(name_value_pair.first) > 0) ||
287 ((family == AF_INET) && (supported_params_v4.count(name_value_pair.first) > 0)) ||
288 ((family != AF_INET) && (supported_params_v6.count(name_value_pair.first) > 0))) {
292 << name_value_pair.first <<
"'");
302 uint16_t family,
bool check_dependencies) {
305 client_class_def_list->listValue()) {
307 parser.
parse(dictionary, client_class_def, family,
true, check_dependencies);
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The IOAddress class represents an IP addresses (version agnostic)
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
short getFamily() const
Returns the address family.
An exception that is thrown if an error occurs within the IO module.
const dhcp::Triplet< uint32_t > parseIntTriplet(const data::ConstElementPtr &scope, const std::string &name)
Parses an integer triplet.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
Represents option definitions used by the DHCP server.
Represents option data configuration for the DHCP server.
ClientClassDictionaryPtr parse(isc::data::ConstElementPtr class_def_list, uint16_t family, bool check_dependencies=true)
Parse configuration entries.
Parser for a single client class definition.
void parse(ClientClassDictionaryPtr &class_dictionary, isc::data::ConstElementPtr client_class_def, uint16_t family, bool append_error_position=true, bool check_dependencies=true)
Parses an entry that describes single client class definition.
void checkParametersSupported(const isc::data::ConstElementPtr &class_def_cfg, const uint16_t family)
Iterates over class parameters and checks if they are supported.
Maintains a list of ClientClassDef's.
To be removed. Please use ConfigError instead.
Parser for a logical expression.
void parse(ExpressionPtr &expression, isc::data::ConstElementPtr expression_cfg, uint16_t family, isc::eval::EvalContext::CheckDefined check_defined=isc::eval::EvalContext::acceptAll)
Parses an expression configuration element into an Expression.
static bool shouldDeferOptionUnpack(const std::string &space, const uint16_t code)
Checks if an option unpacking has to be deferred.
Parser for option data values within a subnet.
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list)
Parses a list of options, instantiates them and stores in cfg.
Parser for a single option definition.
OptionDefinitionPtr parse(isc::data::ConstElementPtr option_def)
Parses an entry that describes single option definition.
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
static const isc::data::SimpleDefaults OPTION4_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv4.
static const isc::data::SimpleDefaults OPTION6_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv6.
This template specifies a parameter value.
Evaluation context, an interface to the expression evaluation.
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
isc::dhcp::Expression expression
Parsed expression (output tokens are stored here)
Defines classes for storing client class definitions.
Parsers for client class definitions.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
std::string ClientClass
Defines a single class name.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Expression > ExpressionPtr
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
std::list< std::string > builtinNames
List of built-in client class names.
Defines the logger used by the top-level component of kea-lfc.