From: Tomek Mrugalski Date: Fri, 14 Oct 2016 17:33:46 +0000 (+0200) Subject: [5023] Implementation in progress X-Git-Tag: trac4631b_base~4^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=690527d3e8a3c7375bf20b405d5facedd4f55c6e;p=thirdparty%2Fkea.git [5023] Implementation in progress --- diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 2f30470326..31cab47201 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -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. diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 909d01f780..5ca86f087d 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -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()); + + +} + }; diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index b96416cf4b..b5f4cf5a48 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -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 diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.h b/src/lib/dhcpsrv/parsers/dhcp_parsers.h index 67f62074c1..f6ea3d93b4 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.h +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.h @@ -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_; }; diff --git a/src/lib/dhcpsrv/pool.h b/src/lib/dhcpsrv/pool.h index 6a9747f255..ac88371ada 100644 --- a/src/lib/dhcpsrv/pool.h +++ b/src/lib/dhcpsrv/pool.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -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