45 << expression_cfg->str() <<
"] must be a string, at ("
46 << expression_cfg->getPosition() <<
")");
52 expression_cfg->getValue(value);
56 << expression_cfg->getPosition() <<
")");
65 }
catch (
const std::exception& ex) {
68 "expression: [" << value
69 <<
"] error: " << ex.what() <<
" at ("
70 << expression_cfg->getPosition() <<
")");
80 bool append_error_position,
81 bool check_dependencies) {
83 std::string name =
getString(class_def_cfg,
"name");
86 "not empty parameter 'name' is required "
91 if (escaped != name) {
101 bool is_template =
false;
106 ConstElementPtr template_test_cfg = class_def_cfg->get(
"template-test");
107 if (test_cfg && template_test_cfg) {
109 << test_cfg->getPosition() <<
") and ("
110 << template_test_cfg->getPosition() <<
")");
113 bool depend_on_known =
false;
115 if (template_test_cfg) {
116 test_cfg = template_test_cfg;
123 check_defined = [&depend_on_known](
const ClientClass& cclass) {
125 if ((cclass ==
"KNOWN") || (cclass ==
"UNKNOWN")) {
126 depend_on_known =
true;
133 [&class_dictionary, &depend_on_known, check_dependencies](
const ClientClass& cclass) {
135 depend_on_known, cclass));
141 parser.
parse(match_expr, test_cfg, family, check_defined, parser_type);
142 test = test_cfg->stringValue();
156 for (
auto const& option_def : option_defs->listValue()) {
164 "Not allowed option definition for code '"
165 << def->getCode() <<
"' in space '"
166 << def->getOptionSpaceName() <<
"' at ("
167 << option_def->getPosition() <<
")");
171 }
catch (
const std::exception& ex) {
174 << option_def->getPosition() <<
")");
184 opts_parser->parse(options, option_data);
192 << user_context->getPosition() <<
")");
197 auto required_elem = class_def_cfg->get(
"only-if-required");
198 auto additional_elem = class_def_cfg->get(
"only-in-additional-list");
200 if (!additional_elem) {
202 additional_elem = required_elem;
205 "cannot specify both 'only-if-required' and "
206 "'only-in-additional-list'. Use only the latter.");
210 bool additional =
false;
211 if (additional_elem) {
213 additional = additional_elem->boolValue();
216 "'only-in-additional-list' must be boolean"
217 << additional_elem->getPosition());
223 if (class_def_cfg->contains(
"next-server")) {
224 std::string next_server_txt =
getString(class_def_cfg,
"next-server");
226 next_server =
IOAddress(next_server_txt);
229 "Invalid next-server value specified: '"
230 << next_server_txt <<
"' ("
231 <<
getPosition(
"next-server", class_def_cfg) <<
")");
234 if (next_server.
getFamily() != AF_INET) {
236 << next_server_txt <<
"', must be IPv4 address ("
237 <<
getPosition(
"next-server", class_def_cfg) <<
")");
242 << next_server_txt <<
"', must not be a broadcast ("
243 <<
getPosition(
"next-server", class_def_cfg) <<
")");
249 if (class_def_cfg->contains(
"server-hostname")) {
250 sname =
getString(class_def_cfg,
"server-hostname");
255 << sname.length() <<
" ("
256 <<
getPosition(
"server-hostname", class_def_cfg) <<
")");
261 std::string filename;
262 if (class_def_cfg->contains(
"boot-file-name")) {
263 filename =
getString(class_def_cfg,
"boot-file-name");
268 << filename.length() <<
" ("
269 <<
getPosition(
"boot-file-name", class_def_cfg) <<
")");
274 if (class_def_cfg->contains(
"offer-lifetime")) {
275 auto value =
getInteger(class_def_cfg,
"offer-lifetime");
278 << value <<
"' must be a positive number ("
279 <<
getPosition(
"offer-lifetime", class_def_cfg) <<
")");
289 if (family != AF_INET) {
299 <<
"' only-in-additional-list flag must be false");
303 <<
"' test expression must be empty");
309 if ((name ==
"DROP") || (name ==
"REJECT")) {
312 <<
"' only-in-additional-list flag must be false");
327 class_dictionary->addClass(name, match_expr,
test, additional,
328 depend_on_known, options, defs,
329 user_context, next_server, sname, filename,
330 valid_lft, preferred_lft, is_template, offer_lft);
331 }
catch (
const std::exception& ex) {
332 std::ostringstream s;
333 s <<
"Can't add class: " << ex.what();
335 if (append_error_position) {
336 s <<
" (" << class_def_cfg->getPosition() <<
")";
344 const uint16_t family) {
346 if (!class_def_cfg || (class_def_cfg->getType() !=
Element::map)) {
351 static std::set<std::string> supported_params = {
"name",
356 "only-in-additional-list",
358 "min-valid-lifetime",
359 "max-valid-lifetime",
363 static std::set<std::string> supported_params_v4 = {
"option-def",
369 static std::set<std::string> supported_params_v6 = {
"preferred-lifetime",
370 "min-preferred-lifetime",
371 "max-preferred-lifetime" };
374 for (
auto const& name_value_pair : class_def_cfg->mapValue()) {
375 if ((supported_params.count(name_value_pair.first) > 0) ||
376 ((family == AF_INET) && (supported_params_v4.count(name_value_pair.first) > 0)) ||
377 ((family != AF_INET) && (supported_params_v6.count(name_value_pair.first) > 0))) {
381 << name_value_pair.first <<
"'");
386boost::shared_ptr<OptionDataListParser>
389 auto parser = boost::make_shared<OptionDataListParser>(address_family, cfg_option_def);
397 uint16_t family,
bool check_dependencies) {
399 for (
auto const& client_class_def : client_class_def_list->listValue()) {
401 parser.
parse(dictionary, client_class_def, family,
true, check_dependencies);
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.
static size_t setListDefaults(isc::data::ConstElementPtr list, const SimpleDefaults &default_values)
Sets the default values for all entries in a list.
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.
const isc::util::Triplet< uint32_t > parseIntTriplet(const data::ConstElementPtr &scope, const std::string &name)
Parses an integer triplet.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer 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.
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def) const
Returns an instance of the OptionDataListParser to be used in parsing the option-data structure.
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.
static std::string escape(const std::string &name, bool escape_escape=true)
Escape a client class name.
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, isc::eval::EvalContext::ParserType parser_type=isc::eval::EvalContext::PARSER_BOOL)
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 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.
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.
ParserType
Specifies what type of expression the parser is expected to see.
@ PARSER_BOOL
expression is expected to evaluate to bool
@ PARSER_STRING
expression is expected to evaluate to string
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
isc::dhcp::Expression expression_
Parsed expression (output tokens are stored here).
A template representing an optional value.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
This template specifies a parameter value.
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.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
std::string ClientClass
Defines a single class name.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
const isc::log::MessageID DHCPSRV_CLASS_WITH_ADDITIONAL_AND_LIFETIMES
const isc::log::MessageID DHCPSRV_CLASS_BAD_NAME
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.
const isc::log::MessageID DHCPSRV_ONLY_IF_REQUIRED_DEPRECATED
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
std::list< std::string > builtinNames
List of classes for which test expressions cannot be defined.
Defines the logger used by the top-level component of kea-lfc.