47 if (elem->getType() != Element::string) {
51 string expr_text = elem->stringValue();
52 if (expr_text.empty()) {
58 opt_cfg->setAction(action);
59 opt_cfg->setText(expr_text);
62 eval_ctx.parseString(expr_text, parser_type);
64 opt_cfg->setExpr(expr);
65 }
catch (
const std::exception& ex) {
67 << expr_text <<
"] error: " << ex.
what());
75namespace flex_option {
89 option_config_map_.clear();
97 if (options->getType() != Element::list) {
100 if (options->empty()) {
103 for (
auto option : options->listValue()) {
104 parseOptionConfig(option);
110 uint16_t family = CfgMgr::instance().getFamily();
114 if (option->getType() != Element::map) {
121 if (!code_elem && !name_elem) {
127 if (family == AF_INET) {
129 universe = Option::V4;
132 universe = Option::V6;
136 if (code_elem->getType() != Element::integer) {
138 << code_elem->str());
140 int64_t value = code_elem->intValue();
142 if (family == AF_INET) {
143 max_code = numeric_limits<uint8_t>::max();
145 max_code = numeric_limits<uint16_t>::max();
147 if ((value < 0) || (value > max_code)) {
149 <<
" not in [0.." << max_code <<
"]");
151 if (family == AF_INET) {
154 "invalid 'code' value 0: reserved for PAD");
157 "invalid 'code' value 255: reserved for END");
164 code =
static_cast<uint16_t
>(value);
167 if (name_elem->getType() != Element::string) {
169 << name_elem->str());
171 string name = name_elem->stringValue();
175 def = LibDHCP::getOptionDef(space, name);
177 def = LibDHCP::getRuntimeOptionDef(space, name);
180 def = LibDHCP::getLastResortOptionDef(space, name);
184 << space <<
"' space");
186 if (code_elem && (def->getCode() != code)) {
188 << def->getCode() <<
", not the specified code: "
191 code = def->getCode();
193 if (option_config_map_.count(code)) {
197 bool csv_format =
false;
198 if (csv_format_elem) {
199 if (csv_format_elem->getType() != Element::boolean) {
201 << csv_format_elem->str());
203 csv_format = csv_format_elem->boolValue();
222 <<
"' in '" << space <<
"' space");
229 parseAction(option, opt_cfg, universe,
230 "add",
ADD, EvalContext::PARSER_STRING);
231 parseAction(option, opt_cfg, universe,
232 "supersede",
SUPERSEDE, EvalContext::PARSER_STRING);
233 parseAction(option, opt_cfg, universe,
234 "remove",
REMOVE, EvalContext::PARSER_BOOL);
236 if (opt_cfg->getAction() ==
NONE) {
240 option_config_map_[code] = opt_cfg;
245 const string& value)
const {
246 if (action ==
NONE) {
257 repr <<
"'" << value <<
"'";
260 for (
const char& ch : value) {
261 repr << setw(2) << setfill('0') << static_cast<unsigned>(ch);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
Universe
defines option universe DHCPv4 or DHCPv6
Evaluation context, an interface to the expression evaluation.
ParserType
Specifies what type of expression the parser is expected to see.
virtual ~OptionConfig()
Destructor.
OptionConfig(uint16_t code, isc::dhcp::OptionDefinitionPtr def)
Constructor.
void configure(isc::data::ConstElementPtr options)
Configure the Flex Option implementation.
boost::shared_ptr< OptionConfig > OptionConfigPtr
The type of shared pointers to option config.
~FlexOptionImpl()
Destructor.
void logAction(Action action, uint16_t code, const std::string &value) const
Log the action.
FlexOptionImpl()
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const isc::log::MessageID FLEX_OPTION_PROCESS_ADD
const isc::log::MessageID FLEX_OPTION_PROCESS_REMOVE
const isc::log::MessageID FLEX_OPTION_PROCESS_SUPERSEDE
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Expression > ExpressionPtr
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
isc::log::Logger flex_option_logger("flex-option-hooks")
const int DBGLVL_TRACE_BASIC
Trace basic operations.
bool isPrintable(const std::string &content)
Check if a string is printable.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE