From: Francis Dupont Date: Thu, 17 Mar 2022 19:30:22 +0000 (+0100) Subject: [#2314] Checkpoint: sub-option definitions X-Git-Tag: Kea-2.1.4~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=734525295cb68aebbf3c1bd372f4d96194a003d6;p=thirdparty%2Fkea.git [#2314] Checkpoint: sub-option definitions --- diff --git a/src/hooks/dhcp/flex_option/flex_option.cc b/src/hooks/dhcp/flex_option/flex_option.cc index 87daff7acd..e2d53697cd 100644 --- a/src/hooks/dhcp/flex_option/flex_option.cc +++ b/src/hooks/dhcp/flex_option/flex_option.cc @@ -71,15 +71,30 @@ namespace isc { namespace flex_option { const SimpleKeywords FlexOptionImpl::OPTION_PARAMETERS = { - { "code", Element::integer }, - { "name", Element::string }, - { "space", Element::string }, - { "csv-format", Element::boolean }, - { "add", Element::string }, - { "supersede", Element::string }, - { "remove", Element::string }, - { "client-class", Element::string }, - { "comment", Element::string } + { "code", Element::integer }, + { "name", Element::string }, + { "space", Element::string }, + { "csv-format", Element::boolean }, + { "add", Element::string }, + { "supersede", Element::string }, + { "remove", Element::string }, + { "sub-options", Element::list }, + { "client-class", Element::string }, + { "comment", Element::string } +}; + +const SimpleKeywords FlexOptionImpl::SUB_OPTION_PARAMETERS = { + { "code", Element::integer }, + { "name", Element::string }, + { "space", Element::string }, + { "csv-format", Element::boolean }, + { "add", Element::string }, + { "supersede", Element::string }, + { "remove", Element::string }, + { "container-add", Element::boolean }, + { "container-remove", Element::boolean }, + { "client-class", Element::string }, + { "comment", Element::string } }; FlexOptionImpl::OptionConfig::OptionConfig(uint16_t code, @@ -90,10 +105,25 @@ FlexOptionImpl::OptionConfig::OptionConfig(uint16_t code, FlexOptionImpl::OptionConfig::~OptionConfig() { } +FlexOptionImpl::SubOptionConfig::SubOptionConfig(uint16_t code, + OptionDefinitionPtr def, + OptionConfigPtr container) + : OptionConfig(code, def), container_(container), vendor_id_(0), + container_action_(NONE) { + if (!container) { + isc_throw(Unexpected, "null container?"); + } +} + +FlexOptionImpl::SubOptionConfig::~SubOptionConfig() { + container_.reset(); +} + FlexOptionImpl::FlexOptionImpl() { } FlexOptionImpl::~FlexOptionImpl() { + sub_option_config_map_.clear(); option_config_map_.clear(); } @@ -273,7 +303,7 @@ FlexOptionImpl::logClass(const ClientClass& client_class, uint16_t code) { void FlexOptionImpl::logAction(Action action, uint16_t code, const string& value) const { - if (action == NONE) { + if ((action == NONE) || (action == SUB_OPTIONS)) { return; } if (action == REMOVE) { diff --git a/src/hooks/dhcp/flex_option/flex_option.h b/src/hooks/dhcp/flex_option/flex_option.h index a651ca32f6..993304a346 100644 --- a/src/hooks/dhcp/flex_option/flex_option.h +++ b/src/hooks/dhcp/flex_option/flex_option.h @@ -42,14 +42,16 @@ public: /// - add (if not already existing) /// - supersede (as add but also when already existing) /// - remove + /// - sub-options enum Action { NONE, ADD, SUPERSEDE, - REMOVE + REMOVE, + SUB_OPTIONS }; - /// @brief Option configuration. + /// @brief Base option configuration. /// /// Per option configuration. class OptionConfig { @@ -163,6 +165,86 @@ public: /// @brief The type of the option config map. typedef std::map OptionConfigMap; + /// @brief Sub-option configuration. + /// + /// Per sub-option configuration. + class SubOptionConfig : public OptionConfig { + public: + /// @brief Constructor. + /// + /// @param code the sub-option code. + /// @param def the sub-option definition. + /// @param container pointer to the container option. + SubOptionConfig(uint16_t code, isc::dhcp::OptionDefinitionPtr def, + OptionConfigPtr container); + + /// @brief Destructor. + virtual ~SubOptionConfig(); + + /// @brief Set vendor id. + /// + /// @param vendor_id the vendor id. + void setVendorId(uint32_t vendor_id) { + vendor_id_ = vendor_id; + } + + /// @brief Return vendor id. + /// + /// @return vendor id. + uint32_t getVendorId() const { + return (vendor_id_); + } + + /// @brief Return container code. + /// + /// @return container code. + uint16_t getContainerCode() const { + return (container_->getCode()); + } + + /// @brief Return container definition. + /// + /// @return container definition. + isc::dhcp::OptionDefinitionPtr getContainerDef() const { + return (container_->getOptionDef()); + } + + /// @brief Set action on the container. + /// + /// @param action the action. + void setContainerAction(Action action) { + container_action_ = action; + } + + /// @brief Return action on the container. + /// + /// @return action on the container. + Action getContainerAction() const { + return (container_action_); + } + + private: + /// @brief Pointer to the container option configuration. + OptionConfigPtr container_; + + /// @brief Vendor id (0 when the container is not a vendor one). + uint32_t vendor_id_; + + /// @brief The action on the container. + Action container_action_; + }; + + /// @brief The type of shared pointers to sub-option config. + typedef boost::shared_ptr SubOptionConfigPtr; + + /// @brief The type of the sub-option config map. + /// @note the index is the sub-option code. + typedef std::map SubOptionConfigMap; + + /// @brief The type of the map of sub-option config maps. + /// @note the index is the container option code. + typedef std::map SubOptionConfigMapMap; + /// @brief Constructor. FlexOptionImpl(); @@ -279,6 +361,10 @@ public: } logAction(REMOVE, opt_cfg->getCode(), ""); break; + case SUB_OPTIONS: + /////// todo! + logAction(SUB_OPTIONS, opt_cfg->getCode(), ""); + break; } } } @@ -309,9 +395,15 @@ private: /// @brief Option parameters. static const data::SimpleKeywords OPTION_PARAMETERS; + /// @brief Sub-option parameters. + static const data::SimpleKeywords SUB_OPTION_PARAMETERS; + /// @brief The option config map (code and pointer to option config). OptionConfigMap option_config_map_; + /// @brief The sub-option config map of map. + SubOptionConfigMapMap sub_option_config_map_; + /// @brief Parse an option config. /// /// @param option The element with option config.