]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5023] Implementation in progress
authorTomek Mrugalski <tomasz@isc.org>
Fri, 14 Oct 2016 17:33:46 +0000 (19:33 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 14 Oct 2016 17:33:46 +0000 (19:33 +0200)
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/pool.h

index 2f304703260404de3974170f3cdbf7d41f935eaa..31cab4720105273ec89869e8aaa4a81752a70ff0 100644 (file)
@@ -187,7 +187,8 @@ public:
                                                                                options_,
                                                                                AF_INET6));
                 parser = option_parser;
-
+            } else if (entry == "user-context") {
+                user_context_ = param.second;
             } else {
                 isc_throw(DhcpConfigError, "unsupported parameter: " << entry
                           << " (" << param.second->getPosition() << ")");
@@ -216,6 +217,10 @@ public:
             isc_throw(isc::dhcp::DhcpConfigError, ex.what()
                       << " (" << pd_pool_->getPosition() << ")");
         }
+
+        if (user_context_) {
+            pool_->setUserContext(user_context_);
+        }
     }
 
     // @brief Commits the constructed local pool to the pool storage.
@@ -242,6 +247,8 @@ protected:
 
     /// A storage for pool specific option values.
     CfgOptionPtr options_;
+
+    isc::data::ConstElementPtr user_context_;
 };
 
 /// @brief Parser for a list of prefix delegation pools.
index 909d01f7800817c100d51084130b2084919f914b..5ca86f087d79ef5f24e5f10f9bd40373a2db7010 100644 (file)
@@ -55,6 +55,42 @@ using namespace std;
 
 namespace {
 
+const char* PARSER_CONFIGS[] = {
+    // CONFIGURATION 0:
+    // - basic timers, one subnet
+    "{"
+    "    \"inerfaces-config\": {"
+    "        \"interfaces\": [\"*\" ]"
+    "    },"
+    "    \"valid-lifetime\": 4000,"
+    "    \"rebind-timer\": 2000,"
+    "    \"renew-timer\": 1000,"
+    "    \"subnet6\": [ {"
+    "        \"pools\": [ "
+    "            { \"pool\":  \"2001:db8::/64\" }"
+    "        ],"
+    "        \"subnet\": \"2001:db8::/32\""
+    "     } ]"
+    "}",
+    "{"
+    "    \"inerfaces-config\": {"
+    "        \"interfaces\": [\"*\" ]"
+    "    },"
+    "    \"valid-lifetime\": 4000,"
+    "    \"rebind-timer\": 2000,"
+    "    \"renew-timer\": 1000,"
+    "    \"subnet6\": [ {"
+    "        \"pools\": [ "
+    "            { \"pool\":  \"2001:db8::/64\","
+    "                \"user-context\": {"
+    "                }"
+    "            }"
+    "        ],"
+    "        \"subnet\": \"2001:db8::/32\""
+    "     } ]"
+    "}"
+};
+
 std::string specfile(const std::string& name) {
     return (std::string(DHCP6_SRC_DIR) + "/" + name);
 }
@@ -4518,4 +4554,27 @@ TEST_F(Dhcp6ParserTest, invalidClientClassDictionary) {
     checkResult(status, 1);
 }
 
+TEST_F(Dhcp6ParserTest, PdPoolUserContextEmpty) {
+
+    ConstElementPtr status;
+    ElementPtr json = Element::fromJSON(string(PARSER_CONFIGS[0]));
+
+    EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
+    ASSERT_TRUE(status);
+    checkResult(status, 1);
+
+    ConstCfgSubnets6Ptr subnets6 = CfgMgr::instance().getStagingCfg()->getCfgSubnets6();
+    ASSERT_TRUE(subnets6);
+
+    const Subnet6Collection* subnets = subnets6->getAll();
+    ASSERT_TRUE(subnets);
+
+    ASSERT_EQ(1, subnets->size());
+
+    const PoolCollection pools = subnets->at(0)->getPools(Lease::TYPE_NA);
+    ASSERT_EQ(1, pools.size());
+    
+        
+}
+
 };
index b96416cf4b8790da547712322f75644fda3235f3..b5f4cf5a48c7a4b3295e53579ca61f8936d269f5 100644 (file)
@@ -1144,6 +1144,12 @@ PoolParser::build(ConstElementPtr pool_structure) {
                       << " (" << option_data->getPosition() << ")");
         }
     }
+
+    user_context_ = pool_structure->get("user-context");
+    if (user_context_ && user_context_->getType() != Element::map) {
+        isc_throw(isc::dhcp::DhcpConfigError, "User context has to be a map ("
+                  << user_context_->getPosition() << ")");
+    }
 }
 
 void
index 67f62074c1dce97d4cba9b4218d7d53c67e879ee..f6ea3d93b41455da6738aaaa7e95ce0967b0bcc7 100644 (file)
@@ -885,6 +885,9 @@ protected:
     /// A storage for pool specific option values.
     CfgOptionPtr options_;
 
+    /// A storage for user context.
+    isc::data::ConstElementPtr user_context_;
+
     /// @brief Address family: AF_INET (for DHCPv4) or AF_INET6 for DHCPv6.
     uint16_t address_family_;
 };
index 6a9747f255257caf2021ff93ba6a0d1c1d9cb7b1..ac88371adac3c10998981bf6c2d92b9dcaa25c12 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <asiolink/io_address.h>
 #include <boost/shared_ptr.hpp>
+#include <cc/data.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/lease.h>
 
@@ -92,6 +93,17 @@ public:
         return (cfg_option_);
     }
 
+    /// @brief Returns const pointer to the user context.
+    data::ConstElementPtr getContext() const {
+        return (user_context_);
+    }
+
+    /// @brief Sets user context.
+    /// @param ctx user context to be stored.
+    void setUserContext(const data::ConstElementPtr& ctx) {
+        user_context_ = ctx;
+    }
+
 protected:
 
     /// @brief protected constructor
@@ -144,6 +156,9 @@ protected:
 
     /// @brief Pointer to the option data configuration for this pool.
     CfgOptionPtr cfg_option_;
+
+    /// @brief Pointer to the user context (may be NULL)
+    data::ConstElementPtr user_context_;
 };
 
 /// @brief Pool information for IPv4 addresses