22#include <boost/algorithm/string/split.hpp>
23#include <boost/algorithm/string/classification.hpp>
29namespace flex_option {
187 vendor_id_ = vendor_id;
201 return (container_->getCode());
208 return (container_->getOptionDef());
215 return (container_->getClass());
222 container_action_ = action;
229 return (container_action_);
264 return (option_config_map_);
271 return (sub_option_config_map_);
286 template <
typename PktType>
288 PktType query, PktType response) {
293 if (!client_class.empty()) {
294 if (!query->inClass(client_class)) {
295 logClass(client_class, opt_cfg->getCode());
301 uint16_t code = opt_cfg->getCode();
304 switch (opt_cfg->getAction()) {
320 std::vector<std::string> split_vec =
322 opt = def->optionFactory(universe, code, split_vec);
324 buffer.assign(value.begin(), value.end());
329 response->addOption(opt);
341 std::vector<std::string> split_vec =
343 opt = def->optionFactory(universe, code,
346 buffer.assign(value.begin(), value.end());
352 while (response->getOption(code)) {
353 response->delOption(code);
356 response->addOption(opt);
369 while (response->getOption(code)) {
370 response->delOption(code);
378 for (
auto const& sub_pair : pair.second) {
380 uint16_t sub_code = sub_cfg->getCode();
381 uint16_t opt_code = sub_cfg->getContainerCode();
383 sub_cfg->getContainerClass();
384 if (!opt_class.empty()) {
385 if (!query->inClass(opt_class)) {
392 if (!sub_class.empty()) {
393 if (!query->inClass(sub_class)) {
403 uint32_t vendor_id = sub_cfg->getVendorId();
404 switch (sub_cfg->getAction()) {
409 if (!opt && (sub_cfg->getContainerAction() !=
ADD)) {
419 if (opt && vendor_id && !
checkVendor(opt, vendor_id)) {
423 if (opt && opt->getOption(sub_code)) {
428 std::vector<std::string> split_vec =
430 sub = def->optionFactory(universe, sub_code,
433 buffer.assign(value.begin(), value.end());
446 response->addOption(opt);
459 if (!opt && (sub_cfg->getContainerAction() !=
ADD)) {
469 if (opt && vendor_id && !
checkVendor(opt, vendor_id)) {
474 std::vector<std::string> split_vec =
476 sub = def->optionFactory(universe, sub_code,
479 buffer.assign(value.begin(), value.end());
485 while (opt->getOption(sub_code)) {
486 opt->delOption(sub_code);
498 response->addOption(opt);
514 sub = opt->getOption(sub_code);
524 if (opt && vendor_id && !
checkVendor(opt, vendor_id)) {
528 while (opt->getOption(sub_code)) {
529 opt->delOption(sub_code);
533 if ((sub_cfg->getContainerAction() ==
REMOVE) &&
534 opt->getOptions().empty()) {
535 response->delOption(opt_code);
558 const std::string& value);
565 static void logAction(
Action action, uint16_t code, uint32_t vendor_id);
573 uint16_t code, uint16_t container_code);
582 uint16_t container_code,
583 const std::string& value);
596 return (option_config_map_);
603 return (sub_option_config_map_);
Defines elements for storing the names of client classes.
This class represents vendor-specific information option.
Universe
defines option universe DHCPv4 or DHCPv6
Base option configuration.
virtual ~OptionConfig()
Destructor.
void setExpr(const isc::dhcp::ExpressionPtr &expr)
Set match expression.
const isc::dhcp::ExpressionPtr & getExpr() const
Get match expression.
uint16_t getCode() const
Return option code.
OptionConfig(uint16_t code, isc::dhcp::OptionDefinitionPtr def)
Constructor.
Action getAction() const
Return action.
const isc::dhcp::ClientClass & getClass() const
Get client class.
void setClass(const isc::dhcp::ClientClass &class_name)
Set client class.
isc::dhcp::OptionDefinitionPtr getOptionDef() const
Return option definition.
void setText(const std::string &text)
Set textual expression.
void setAction(Action action)
Set action.
const std::string & getText() const
Get textual expression.
Sub-option configuration.
isc::dhcp::OptionDefinitionPtr getContainerDef() const
Return container definition.
Action getContainerAction() const
Return action on the container.
SubOptionConfig(uint16_t code, isc::dhcp::OptionDefinitionPtr def, OptionConfigPtr container)
Constructor.
uint32_t getVendorId() const
Return vendor id.
void setVendorId(uint32_t vendor_id)
Set vendor id.
const isc::dhcp::ClientClass & getContainerClass() const
Return container client class.
void setContainerAction(Action action)
Set action on the container.
uint16_t getContainerCode() const
Return container code.
virtual ~SubOptionConfig()
Destructor.
Flex Option implementation.
void configure(isc::data::ConstElementPtr options)
Configure the Flex Option implementation.
std::map< uint16_t, OptionConfigList > OptionConfigMap
The type of the option config map.
const OptionConfigMap & getOptionConfigMap() const
Get the option config map.
~FlexOptionImpl()
Destructor.
static void logAction(Action action, uint16_t code, const std::string &value)
Log the action for option.
void process(isc::dhcp::Option::Universe universe, PktType query, PktType response)
Process a query / response pair.
boost::shared_ptr< SubOptionConfig > SubOptionConfigPtr
The type of shared pointers to sub-option config.
static void logSubClass(const isc::dhcp::ClientClass &client_class, uint16_t code, uint16_t container_code)
Log the client class for sub-option.
SubOptionConfigMapMap & getMutableSubOptionConfigMap()
Get a mutable reference to the sub-option config map of maps.
OptionConfigMap & getMutableOptionConfigMap()
Get a mutable reference to the option config map.
static void logSubAction(Action action, uint16_t code, uint16_t container_code, const std::string &value)
Log the action for sub-option.
std::list< OptionConfigPtr > OptionConfigList
The type of lists of shared pointers to option config.
FlexOptionImpl()
Constructor.
std::map< uint16_t, SubOptionConfigMap > SubOptionConfigMapMap
The type of the map of sub-option config maps.
boost::shared_ptr< OptionConfig > OptionConfigPtr
The type of shared pointers to option config.
std::map< uint16_t, SubOptionConfigPtr > SubOptionConfigMap
The type of the sub-option config map.
static bool checkVendor(isc::dhcp::OptionPtr opt, uint32_t vendor_id)
Check vendor option vendor id mismatch.
static void logClass(const isc::dhcp::ClientClass &client_class, uint16_t code)
Log the client class for option.
const SubOptionConfigMapMap & getSubOptionConfigMap() const
Get the sub-option config map of maps.
boost::shared_ptr< const Element > ConstElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
std::string ClientClass
Defines a single class name.
std::string evaluateString(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a string value.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Expression > ExpressionPtr
bool evaluateBool(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a true or false decision.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< FlexOptionImpl > FlexOptionImplPtr
The type of shared pointers to Flex Option implementations.
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
Defines the logger used by the top-level component of kea-lfc.