]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Added global and option def
authorFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 07:09:49 +0000 (08:09 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 07:09:49 +0000 (08:09 +0100)
22 files changed:
src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/shared_network_unittest.cc
src/bin/dhcp6/dhcp6_lexer.ll
src/bin/dhcp6/dhcp6_parser.yy
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/cc/Makefile.am
src/lib/cc/user_context.cc [moved from src/lib/dhcpsrv/user_context.cc with 96% similarity]
src/lib/cc/user_context.h [moved from src/lib/dhcpsrv/user_context.h with 100% similarity]
src/lib/dhcp/option_definition.h
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_option_def.cc
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/pool.h
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc

index 34e68a1eefd127c7ab2496d2d5123af247ea64ef..823d87f6e3911b134ddc93c42a790a0fda0aed6a 100644 (file)
@@ -578,9 +578,11 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 
 \"user-context\" {
     switch(driver.ctx_) {
+    case isc::dhcp::Parser4Context::DHCP4:
     case isc::dhcp::Parser4Context::SUBNET4:
     case isc::dhcp::Parser4Context::POOLS:
     case isc::dhcp::Parser4Context::SHARED_NETWORK:
+    case isc::dhcp::Parser4Context::OPTION_DEF:
         return isc::dhcp::Dhcp4Parser::make_USER_CONTEXT(driver.loc_);
     default:
         return isc::dhcp::Dhcp4Parser::make_STRING("user-context", driver.loc_);
@@ -589,9 +591,11 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 
 \"comment\" {
     switch(driver.ctx_) {
+    case isc::dhcp::Parser4Context::DHCP4:
     case isc::dhcp::Parser4Context::SUBNET4:
     case isc::dhcp::Parser4Context::POOLS:
     case isc::dhcp::Parser4Context::SHARED_NETWORK:
+    case isc::dhcp::Parser4Context::OPTION_DEF:
         return isc::dhcp::Dhcp4Parser::make_COMMENT(driver.loc_);
     default:
         return isc::dhcp::Dhcp4Parser::make_STRING("comment", driver.loc_);
index cd174dc4d9c86b4e1d5b8c6b553fae0529f08f51..5b65a7bfa20f7b78f05e10ed8279f026fe855a99 100644 (file)
@@ -433,6 +433,8 @@ global_param: valid_lifetime
             | next_server
             | server_hostname
             | boot_file_name
+            | user_context
+            | comment
             | unknown_map_entry
             ;
 
@@ -1136,6 +1138,8 @@ option_def_param: option_def_name
                 | option_def_space
                 | option_def_encapsulate
                 | option_def_array
+                | user_context
+                | comment
                 | unknown_map_entry
                 ;
 
index 31ce8ec87bf510c00257afdb8c0e6ef4d50d8f7a..d0cf070db3d7d5e18dddc291bcedf1c19969a35e 100644 (file)
@@ -69,6 +69,7 @@ public:
     /// - echo-client-id
     /// - decline-probation-period
     /// - dhcp4o6-port
+    /// - user-context
     ///
     /// @throw DhcpConfigError if parameters are missing or
     /// or having incorrect values.
@@ -87,6 +88,12 @@ public:
         // Set the DHCPv4-over-DHCPv6 interserver port.
         uint16_t dhcp4o6_port = getUint16(global, "dhcp4o6-port");
         cfg->setDhcp4o6Port(dhcp4o6_port);
+
+        // Set the global user context.
+        ConstElementPtr user_context = global->get("user-context");
+        if (user_context) {
+            cfg->setContext(user_context);
+        }
     }
 
     /// @brief Copies subnets from shared networks to regular subnets container
@@ -445,8 +452,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
 
             // Timers are not used in the global scope. Their values are derived
             // to specific subnets (see SimpleParser6::deriveParameters).
-            // decline-probation-period, dhcp4o6-port, echo-client-id are
-            // handled in global_parser.parse() which sets global parameters.
+            // decline-probation-period, dhcp4o6-port, echo-client-id,
+            // user-context are handled in global_parser.parse() which
+            // sets global parameters.
             // match-client-id is derived to subnet scope level.
             if ( (config_pair.first == "renew-timer") ||
                  (config_pair.first == "rebind-timer") ||
@@ -454,6 +462,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
                  (config_pair.first == "decline-probation-period") ||
                  (config_pair.first == "dhcp4o6-port") ||
                  (config_pair.first == "echo-client-id") ||
+                 (config_pair.first == "user-context") ||
                  (config_pair.first == "match-client-id") ||
                  (config_pair.first == "next-server") ||
                  (config_pair.first == "server-hostname") ||
index 1a8cb35ee44c52ab7030da3b61f3a1787b8ea81e..fcea2b5b0057a14ecde929fd65f8d13ca414e165 100644 (file)
@@ -5611,9 +5611,17 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDeriveClientClass) {
 TEST_F(Dhcp4ParserTest, comments) {
 
     string config = "{\n"
+        "\"comment\": \"A DHCPv4 server\",\n"
+        "\"option-def\": [ {\n"
+        "    \"name\": \"foo\",\n"
+        "    \"code\": 100,\n"
+        "    \"comment\": \"An option definition\",\n"
+        "    \"type\": \"ipv4-address\",\n"
+        "    \"space\": \"isc\"\n"
+        " } ],\n"
         "\"shared-networks\": [ {\n"
         "    \"name\": \"foo\"\n,"
-        "    \"comment\": \"A shared-network\"\n,"
+        "    \"comment\": \"A shared network\"\n,"
         "    \"subnet4\": [\n"
         "    { \n"
         "        \"subnet\": \"192.0.1.0/24\",\n"
@@ -5632,6 +5640,32 @@ TEST_F(Dhcp4ParserTest, comments) {
     extractConfig(config);
     configure(config, CONTROL_RESULT_SUCCESS, "");
 
+    // Check global user context.
+    ConstElementPtr ctx = CfgMgr::instance().getStagingCfg()->getContext();
+    ASSERT_TRUE(ctx);
+    ASSERT_EQ(1, ctx->size());
+    ASSERT_TRUE(ctx->get("comment"));
+    EXPECT_EQ("\"A DHCPv4 server\"", ctx->get("comment")->str());
+
+    // Make the option definition available.
+    LibDHCP::commitRuntimeOptionDefs();
+
+    // Get and verify the option definition.
+    OptionDefinitionPtr opt_def = LibDHCP::getRuntimeOptionDef("isc", 100);
+    ASSERT_TRUE(opt_def);
+    EXPECT_EQ("foo", opt_def->getName());
+    EXPECT_EQ(1, opt_def->getCode());
+    EXPECT_FALSE(opt_def->getArrayType());
+    EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, opt_def->getType());
+    EXPECT_TRUE(opt_def->getEncapsulatedSpace().empty());
+
+    // Check option definition user context
+    ConstElementPtr ctx_opt_def = opt_def->getContext();
+    ASSERT_TRUE(ctx_opt_def);
+    ASSERT_EQ(1, ctx_opt_def->size());
+    ASSERT_TRUE(ctx_opt_def->get("comment"));
+    EXPECT_EQ("\"An option definition\"", ctx_opt_def->get("comment")->str());
+
     // Now verify that the shared network was indeed configured.
     CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg()
         ->getCfgSharedNetworks4();
@@ -5647,7 +5681,7 @@ TEST_F(Dhcp4ParserTest, comments) {
     ASSERT_TRUE(ctx_net);
     ASSERT_EQ(1, ctx_net->size());
     ASSERT_TRUE(ctx_net->get("comment"));
-    EXPECT_EQ("\"A shared-network\"", ctx_net->get("comment")->str());
+    EXPECT_EQ("\"A shared network\"", ctx_net->get("comment")->str());
 
     // The shared network has a subnet.
     const Subnet4Collection * subs = net->getAllSubnets();
index 58dae250986a5c02629d04e799b7c7cc5ff8f276..c5c47007dad177816dbad2bf3654bead8826a384 100644 (file)
@@ -1081,9 +1081,9 @@ TEST_F(Dhcpv4SharedNetworkTest, parse) {
     ConstElementPtr comment = config::parseAnswer(rcode, status);
     ASSERT_EQ(0, rcode);
     ASSERT_NO_THROW( {
-       CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
-       cfg_db->setAppendedParameters("universe=4");
-       cfg_db->createManagers();
+        CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
+        cfg_db->setAppendedParameters("universe=4");
+        cfg_db->createManagers();
     } );
     CfgMgr::instance().commit();
 
index bd6421250b6343ea4a79240ea269e388e065bb1b..785481fa2e94af095b2484dcb35977cec654e26a 100644 (file)
@@ -808,10 +808,12 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 
 \"user-context\" {
     switch(driver.ctx_) {
+    case isc::dhcp::Parser6Context::DHCP6:
     case isc::dhcp::Parser6Context::POOLS:
     case isc::dhcp::Parser6Context::PD_POOLS:
     case isc::dhcp::Parser6Context::SUBNET6:
     case isc::dhcp::Parser6Context::SHARED_NETWORK:
+    case isc::dhcp::Parser6Context::OPTION_DEF:
         return isc::dhcp::Dhcp6Parser::make_USER_CONTEXT(driver.loc_);
     default:
         return isc::dhcp::Dhcp6Parser::make_STRING("user-context", driver.loc_);
@@ -820,10 +822,12 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 
 \"comment\" {
     switch(driver.ctx_) {
+    case isc::dhcp::Parser6Context::DHCP6:
     case isc::dhcp::Parser6Context::POOLS:
     case isc::dhcp::Parser6Context::PD_POOLS:
     case isc::dhcp::Parser6Context::SUBNET6:
     case isc::dhcp::Parser6Context::SHARED_NETWORK:
+    case isc::dhcp::Parser6Context::OPTION_DEF:
         return isc::dhcp::Dhcp6Parser::make_COMMENT(driver.loc_);
     default:
         return isc::dhcp::Dhcp6Parser::make_STRING("comment", driver.loc_);
index 2cec6de1ceb7320ca1d919a555b8540fe74e7c9d..4ed697666c00b62fbe486e5139e6464d8dacd626 100644 (file)
@@ -435,6 +435,8 @@ global_param: preferred_lifetime
             | dhcp4o6_port
             | control_socket
             | dhcp_ddns
+            | user_context
+            | comment
             | unknown_map_entry
             ;
 
@@ -1100,6 +1102,8 @@ option_def_param: option_def_name
                 | option_def_space
                 | option_def_encapsulate
                 | option_def_array
+                | user_context
+                | comment
                 | unknown_map_entry
                 ;
 
index f536154c99d2e5532d199b2edaffea665086ebc7..d74dab56cf7b03e72939cca8bd60ad2d1d6a173a 100644 (file)
@@ -144,6 +144,7 @@ public:
     ///
     /// - decline-probation-period
     /// - dhcp4o6-port
+    /// - user-context
     ///
     /// @throw DhcpConfigError if parameters are missing or
     /// or having incorrect values.
@@ -157,6 +158,12 @@ public:
         // Set the DHCPv4-over-DHCPv6 interserver port.
         uint16_t dhcp4o6_port = getUint16(global, "dhcp4o6-port");
         srv_config->setDhcp4o6Port(dhcp4o6_port);
+
+        // Set the global user context.
+        ConstElementPtr user_context = global->get("user-context");
+        if (user_context) {
+            srv_config->setContext(user_context);
+        }
     }
 
     /// @brief Copies subnets from shared networks to regular subnets container
@@ -557,14 +564,16 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
 
             // Timers are not used in the global scope. Their values are derived
             // to specific subnets (see SimpleParser6::deriveParameters).
-            // decline-probation-period and dhcp4o6-port are handled in the
-            // global_parser.parse() which sets global parameters.
+            // decline-probation-period, dhcp4o6-port and user-context
+            // are handled in the global_parser.parse() which sets
+            // global parameters.
             if ( (config_pair.first == "renew-timer") ||
                  (config_pair.first == "rebind-timer") ||
                  (config_pair.first == "preferred-lifetime") ||
                  (config_pair.first == "valid-lifetime") ||
                  (config_pair.first == "decline-probation-period") ||
-                 (config_pair.first == "dhcp4o6-port")) {
+                 (config_pair.first == "dhcp4o6-port") ||
+                 (config_pair.first == "user-context")) {
                 continue;
             }
 
index d6f9073d06d62279b439998bef89b0550b5c5f0e..03ac7fdd40fa0d697d99399b97789282664cc58f 100644 (file)
@@ -6053,9 +6053,17 @@ TEST_F(Dhcp6ParserTest, sharedNetworksRapidCommitMix) {
 TEST_F(Dhcp6ParserTest, comments) {
 
     string config = "{\n"
+        "\"comment\": \"A DHCPv6 server\",\n"
+        "\"option-def\": [ {\n"
+        "    \"name\": \"foo\",\n"
+        "    \"code\": 100,\n"
+        "    \"comment\": \"An option definition\",\n"
+        "    \"type\": \"ipv6-address\",\n"
+        "    \"space\": \"isc\"\n"
+        " } ],\n"
         "\"shared-networks\": [ {\n"
         "    \"name\": \"foo\"\n,"
-        "    \"comment\": \"A shared-network\"\n,"
+        "    \"comment\": \"A shared network\"\n,"
         "    \"subnet6\": [\n"
         "    { \n"
         "        \"subnet\": \"2001:db1::/48\",\n"
@@ -6082,6 +6090,32 @@ TEST_F(Dhcp6ParserTest, comments) {
     extractConfig(config);
     configure(config, CONTROL_RESULT_SUCCESS, "");
 
+    // Check global user context
+    ConstElementPtr ctx = CfgMgr::instance().getStagingCfg()->getContext();
+    ASSERT_TRUE(ctx);
+    ASSERT_EQ(1, ctx->size());
+    ASSERT_TRUE(ctx->get("comment"));
+    EXPECT_EQ("\"A DHCPv6 server\"", ctx->get("comment")->str());
+
+    // Make the option definition available.
+    LibDHCP::commitRuntimeOptionDefs();
+
+    // Get and verify the option definition.
+    OptionDefinitionPtr opt_def = LibDHCP::getRuntimeOptionDef("isc", 100);
+    ASSERT_TRUE(opt_def);
+    EXPECT_EQ("foo", opt_def->getName());
+    EXPECT_EQ(1, opt_def->getCode());
+    EXPECT_FALSE(opt_def->getArrayType());
+    EXPECT_EQ(OPT_IPV6_ADDRESS_TYPE, opt_def->getType());
+    EXPECT_TRUE(opt_def->getEncapsulatedSpace().empty());
+
+    // Check option definition user context
+    ConstElementPtr ctx_opt_def = opt_def->getContext();
+    ASSERT_TRUE(ctx_opt_def);
+    ASSERT_EQ(1, ctx_opt_def->size());
+    ASSERT_TRUE(ctx_opt_def->get("comment"));
+    EXPECT_EQ("\"An option definition\"", ctx_opt_def->get("comment")->str());
+
     // Now verify that the shared network was indeed configured.
     CfgSharedNetworks6Ptr cfg_net = CfgMgr::instance().getStagingCfg()
         ->getCfgSharedNetworks6();
@@ -6097,7 +6131,7 @@ TEST_F(Dhcp6ParserTest, comments) {
     ASSERT_TRUE(ctx_net);
     ASSERT_EQ(1, ctx_net->size());
     ASSERT_TRUE(ctx_net->get("comment"));
-    EXPECT_EQ("\"A shared-network\"", ctx_net->get("comment")->str());
+    EXPECT_EQ("\"A shared network\"", ctx_net->get("comment")->str());
 
     // The shared network has a subnet.
     const Subnet6Collection * subs = net->getAllSubnets();
index 7031653e736525ecc4c5fb8e79d96ff8bdab300e..5a0f5789591d43d3d1552b17316eb9adee476f7d 100644 (file)
@@ -10,6 +10,7 @@ libkea_cc_la_SOURCES += cfg_to_element.h dhcp_config_error.h
 libkea_cc_la_SOURCES += command_interpreter.cc command_interpreter.h
 libkea_cc_la_SOURCES += json_feed.cc json_feed.h
 libkea_cc_la_SOURCES += simple_parser.cc simple_parser.h
+libkea_cc_la_SOURCES += user_context.cc user_context.h
 
 libkea_cc_la_LIBADD  = $(top_builddir)/src/lib/util/libkea-util.la
 libkea_cc_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
@@ -26,8 +27,8 @@ libkea_cc_include_HEADERS = \
        data.h \
        dhcp_config_error.h \
        json_feed.h \
-       simple_parser.h
-
+       simple_parser.h \
+       user_context.h
 
 EXTRA_DIST = cc.dox
 
similarity index 96%
rename from src/lib/dhcpsrv/user_context.cc
rename to src/lib/cc/user_context.cc
index f6d273c506c6cce64bd75736fdc6dd27317459ed..e7086d4f4af9d518da361dfe0dcec7e43ad79de4 100644 (file)
@@ -4,7 +4,7 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-#include <dhcpsrv/user_context.h>
+#include <cc/user_context.h>
 
 using namespace isc::data;
 
index affe5397d4f9ef5df66de09d89255d74d9aedf6d..02e49f7c1579f1427157246e28beb0c4a121e085 100644 (file)
@@ -10,6 +10,7 @@
 #include <dhcp/option.h>
 #include <dhcp/option_data_types.h>
 #include <dhcp/option_space_container.h>
+#include <cc/user_context.h>
 
 #include <boost/multi_index/hashed_index.hpp>
 #include <boost/multi_index/mem_fun.hpp>
@@ -131,6 +132,7 @@ class OptionIntArray;
 /// @todo Extend the comment to describe "generic factories".
 /// @todo Extend this class to use custom namespaces.
 /// @todo Extend this class with more factory functions.
+/// @todo Derive from UserContext without breaking the multi index.
 class OptionDefinition {
 public:
 
@@ -284,6 +286,27 @@ public:
     /// @return option data type.
     OptionDataType getType() const { return (type_); };
 
+    /// @brief Returns const pointer to the user context
+    data::ConstElementPtr getContext() const {
+        return (user_context_.getContext());
+    }
+
+    /// @brief Sets user context.
+    /// @param ctx user context to be stored.
+    void setContext(const data::ConstElementPtr& ctx) {
+        user_context_.setContext(ctx);
+    }
+
+    /// @brief Merge unparse a user_context object.
+    ///
+    /// Add user-context to map, but only if defined. Omit if it was not.
+    /// Extract comment so it will be pretty-printed first.
+    ///
+    /// @param map A pointer to map where the user context will be unparsed.
+    void contextToElement(data::ElementPtr map) const {
+        user_context_.contextToElement(map);
+    }
+
     /// @brief Check if the option definition is valid.
     ///
     /// Note that it is a responsibility of the code that created
@@ -708,6 +731,8 @@ private:
     std::string encapsulated_space_;
     /// Collection of data fields within the record.
     RecordFieldsCollection record_fields_;
+    /// User context
+    UserContext user_context_;
 };
 
 
index 82197774f63ca3a33985773066f3564345f79396..cc3e14863405fd9639dbbbe44758be064cde7223 100644 (file)
@@ -159,7 +159,6 @@ libkea_dhcpsrv_la_SOURCES += subnet_id.h
 libkea_dhcpsrv_la_SOURCES += subnet_selector.h
 libkea_dhcpsrv_la_SOURCES += timer_mgr.cc timer_mgr.h
 libkea_dhcpsrv_la_SOURCES += triplet.h
-libkea_dhcpsrv_la_SOURCES += user_context.cc user_context.h
 libkea_dhcpsrv_la_SOURCES += utils.h
 libkea_dhcpsrv_la_SOURCES += writable_host_data_source.h
 
@@ -296,7 +295,6 @@ libkea_dhcpsrv_include_HEADERS = \
        subnet_selector.h \
        timer_mgr.h \
        triplet.h \
-       user_context.h \
        utils.h \
        writable_host_data_source.h
 
index 3a61bb1ef68de3beb83b41ffac9549aadb8a36c9..42a92267677ece2ae848033711f360fd0178e7d4 100644 (file)
@@ -166,7 +166,9 @@ CfgOptionDef::toElement() const {
              def != defs->end(); ++def) {
             // Get and fill the map for this definition
             ElementPtr map = Element::createMap();
-            // First set space from parent iterator
+            // Set user context
+            (*def)->contextToElement(map);
+            // Set space from parent iterator
             map->set("space", Element::create(*name));
             // Set required items: name, code and type
             map->set("name", Element::create((*def)->getName()));
@@ -204,6 +206,5 @@ CfgOptionDef::toElement() const {
     return (result);
 }
 
-
 } // end of namespace isc::dhcp
 } // end of namespace isc
index bd211ae1f60018851b58352b029160fdbe473d4b..11cd5264bb2d74970774ac673bbfd7995560a916 100644 (file)
 #include <asiolink/io_address.h>
 #include <cc/cfg_to_element.h>
 #include <cc/data.h>
+#include <cc/user_context.h>
 #include <dhcp/classify.h>
 #include <dhcp/option.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfg_4o6.h>
 #include <dhcpsrv/triplet.h>
-#include <dhcpsrv/user_context.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 #include <cstdint>
index a2926ecf06134a1167a8b2268a3dbf3ecdeedfbe..06b97e4858b963bfe64c7bbdfaa7299eedd2d0fe 100644 (file)
@@ -84,12 +84,6 @@ void ControlSocketParser::parse(SrvConfig& srv_cfg, isc::data::ConstElementPtr v
     srv_cfg.setControlSocketInfo(value);
 }
 
-
-
-
-
-
-
 template<typename SearchKey>
 OptionDefinitionPtr
 OptionDataParser::findOptionDefinition(const std::string& option_space,
@@ -132,6 +126,7 @@ OptionDefParser::parse(ConstElementPtr option_def) {
     std::string record_types = getString(option_def, "record-types");
     std::string space = getString(option_def, "space");
     std::string encapsulates = getString(option_def, "encapsulate");
+    ConstElementPtr user_context = option_def->get("user-context");
 
     if (!OptionSpace::validateName(space)) {
         isc_throw(DhcpConfigError, "invalid option space name '"
@@ -168,6 +163,10 @@ OptionDefParser::parse(ConstElementPtr option_def) {
 
     }
 
+    if (user_context) {
+        def->setContext(user_context);
+    }
+
     // Split the list of record types into tokens.
     std::vector<std::string> record_tokens =
     isc::util::str::tokens(record_types, ",");
index 55d4235fe335f88649c70e3d6c159d66ca76dd8b..5bdefceccb5713eb82f7ee7041f1a6e0197e3bd6 100644 (file)
@@ -11,9 +11,9 @@
 #include <dhcp/option6_pdexclude.h>
 #include <boost/shared_ptr.hpp>
 #include <cc/data.h>
+#include <cc/user_context.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/lease.h>
-#include <dhcpsrv/user_context.h>
 #include <boost/shared_ptr.hpp>
 
 #include <vector>
index f155c9c5d4642e65297ff438c4e2ab49f66ac1c2..da3d1e2ef9aa5763f36284bc72c8af46f3fd8e9e 100644 (file)
@@ -214,6 +214,8 @@ SrvConfig::toElement() const {
     ElementPtr result = Element::createMap();
     // DhcpX global map
     ElementPtr dhcp = Element::createMap();
+    // Set user-context
+    contextToElement(dhcp);
     // Set decline-probation-period
     dhcp->set("decline-probation-period",
               Element::create(static_cast<long long>(decline_timer_)));
index 35a08eea55957e578f44b4bd194bc55d98d38dea..5ca75aefbc60daf6ec8f906edb7f8ee6db70bc8f 100644 (file)
@@ -26,6 +26,7 @@
 #include <dhcpsrv/logging_info.h>
 #include <hooks/hooks_config.h>
 #include <cc/data.h>
+#include <cc/user_context.h>
 #include <boost/shared_ptr.hpp>
 #include <vector>
 #include <stdint.h>
@@ -39,7 +40,7 @@ class CfgMgr;
 /// @brief Specifies current DHCP configuration
 ///
 /// @todo Migrate all other configuration parameters from cfgmgr.h here
-class SrvConfig : public isc::data::CfgToElement {
+class SrvConfig : public UserContext, public isc::data::CfgToElement {
 public:
     /// @name Constants for selection of parameters returned by @c getConfigSummary
     ///
index d22e3ae12b5e7420cd964dfa069c4383c055477c..ed556988990be082ab61e06b29bd692a91f39c65 100644 (file)
@@ -9,13 +9,13 @@
 
 #include <asiolink/io_address.h>
 #include <cc/data.h>
+#include <cc/user_context.h>
 #include <dhcp/option_space_container.h>
 #include <dhcpsrv/assignable_network.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet_id.h>
 #include <dhcpsrv/triplet.h>
-#include <dhcpsrv/user_context.h>
 
 #include <boost/multi_index/mem_fun.hpp>
 #include <boost/multi_index/indexed_by.hpp>
index 99fd3d69f213fc2b528f46d2a170f87b676af673..e595f4103f61f34e5ec7e68fb600acaed1a89ac3 100644 (file)
@@ -257,6 +257,8 @@ TEST(CfgOptionDefTest, unparse) {
     cfg.add(OptionDefinitionPtr(new
         OptionDefinition("option-baz", 6, "uint16", "dns")), "isc");
     OptionDefinitionPtr rec(new OptionDefinition("option-rec", 6, "record"));
+    std::string json = "{ \"comment\": \"foo\" }";
+    rec->setContext(data::Element::fromJSON(json));
     rec->addRecordField("uint16");
     rec->addRecordField("uint16");
     cfg.add(rec, "dns");
@@ -274,6 +276,7 @@ TEST(CfgOptionDefTest, unparse) {
         "},{\n"
         "    \"name\": \"option-rec\",\n"
         "    \"code\": 6,\n"
+        "    \"comment\": \"foo\",\n"
         "    \"type\": \"record\",\n"
         "    \"array\": false,\n"
         "    \"record-types\": \"uint16, uint16\",\n"