]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2314] Checkpoint: sub-option definitions
authorFrancis Dupont <fdupont@isc.org>
Thu, 17 Mar 2022 19:30:22 +0000 (20:30 +0100)
committerRazvan Becheriu <razvan@isc.org>
Wed, 23 Mar 2022 07:50:03 +0000 (09:50 +0200)
src/hooks/dhcp/flex_option/flex_option.cc
src/hooks/dhcp/flex_option/flex_option.h

index 87daff7acd4896c0e4584e90c818e7c1ec5b1ba8..e2d53697cd6747b8090d980f290b1a2320898da1 100644 (file)
@@ -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) {
index a651ca32f6a9cdc0e894876afadf5ebf0029ff72..993304a34605d586a0ec30d4666dd5da279177e7 100644 (file)
@@ -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<uint16_t, OptionConfigList> 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<SubOptionConfig> SubOptionConfigPtr;
+
+    /// @brief The type of the sub-option config map.
+    /// @note the index is the sub-option code.
+    typedef std::map<uint16_t, SubOptionConfigPtr> SubOptionConfigMap;
+
+    /// @brief The type of the map of sub-option config maps.
+    /// @note the index is the container option code.
+    typedef std::map<uint16_t, SubOptionConfigMap> 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.