summaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorMarcin Siodelski <marcin@isc.org>2016-10-27 20:20:25 +0200
committerMarcin Siodelski <marcin@isc.org>2016-10-27 20:20:25 +0200
commit3e7fa856b7e896c38e64f7d85d89f07db2aa06ea (patch)
tree9a06401f7c0ce93f30a82e30548bd5c63f6b69e3 /src/bin
parent[5016] Option6PDExclude holds subnet id rather than entire prefix. (diff)
downloadkea-3e7fa856b7e896c38e64f7d85d89f07db2aa06ea.tar.xz
kea-3e7fa856b7e896c38e64f7d85d89f07db2aa06ea.zip
[5016] Update server code and tests to properly use exclude option.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc44
-rw-r--r--src/bin/dhcp6/dhcp6_srv.h9
-rw-r--r--src/bin/dhcp6/tests/renew_unittest.cc4
-rw-r--r--src/bin/dhcp6/tests/sarr_unittest.cc2
4 files changed, 33 insertions, 26 deletions
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 1c8ffdcc43..e6ab1be386 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -893,26 +893,7 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
// Get the list of options that client requested.
const std::vector<uint16_t>& requested_opts = option_oro->getValues();
- if (co_list.empty()) {
- // If there are no options configured, we at least have to check if
- // the client has requested PD exclude, which is configured as
- // part of the pool configuration.
- ctx.pd_exclude_requested_ = (std::find(requested_opts.begin(),
- requested_opts.end(),
- D6O_PD_EXCLUDE) !=
- requested_opts.end());
- return;
- }
-
BOOST_FOREACH(uint16_t opt, requested_opts) {
- // Prefix Exclude option requires special handling, as it can
- // be configured as part of the pool configuration.
- if (opt == D6O_PD_EXCLUDE) {
- ctx.pd_exclude_requested_ = true;
- // Prefix Exclude can only be included in the IA Prefix option
- // of IA_PD. Thus there is nothing more to do here.
- continue;
- }
// Iterate on the configured option list
for (CfgOptionList::const_iterator copts = co_list.begin();
copts != co_list.end(); ++copts) {
@@ -1576,6 +1557,8 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& answer,
ia_rsp->setT1(subnet->getT1());
ia_rsp->setT2(subnet->getT2());
+ const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
+
for (Lease6Collection::iterator l = leases.begin();
l != leases.end(); ++l) {
@@ -1594,14 +1577,12 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& answer,
(*l)->valid_lft_));
ia_rsp->addOption(addr);
- if (ctx.pd_exclude_requested_) {
+ if (pd_exclude_requested) {
// PD exclude option has been requested via ORO, thus we need to
// include it if the pool configuration specifies this option.
Pool6Ptr pool = boost::dynamic_pointer_cast<
Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_));
if (pool && pool->getExcludedPrefixLength() > 0) {
- std::cout << pool->getExcludedPrefix() << "/"
- << (unsigned)pool->getExcludedPrefixLength() << std::endl;
OptionPtr opt(new Option6PDExclude((*l)->addr_,
(*l)->prefixlen_,
pool->getExcludedPrefix(),
@@ -1877,6 +1858,8 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query,
// into temporary container.
AllocEngine::HintContainer hints = ctx.currentIA().hints_;
+ const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
+
// For all the leases we have now, add the IAPPREFIX with non-zero lifetimes
for (Lease6Collection::const_iterator l = leases.begin(); l != leases.end(); ++l) {
@@ -1885,7 +1868,8 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query,
(*l)->preferred_lft_, (*l)->valid_lft_));
ia_rsp->addOption(prf);
- if (ctx.pd_exclude_requested_) {
+
+ if (pd_exclude_requested) {
// PD exclude option has been requested via ORO, thus we need to
// include it if the pool configuration specifies this option.
Pool6Ptr pool = boost::dynamic_pointer_cast<
@@ -3288,5 +3272,19 @@ int Dhcpv6Srv::getHookIndexBuffer6Send() {
return (Hooks.hook_index_buffer6_send_);
}
+bool
+Dhcpv6Srv::requestedInORO(const Pkt6Ptr& query, const uint16_t code) const {
+ OptionUint16ArrayPtr oro =
+ boost::dynamic_pointer_cast<OptionUint16Array>(query->getOption(D6O_ORO));
+
+ if (oro) {
+ const std::vector<uint16_t>& codes = oro->getValues();
+ return (std::find(codes.begin(), codes.end(), code) != codes.end());
+ }
+
+ return (false);
+}
+
+
};
};
diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h
index 63e0397ec2..7c3f907ac0 100644
--- a/src/bin/dhcp6/dhcp6_srv.h
+++ b/src/bin/dhcp6/dhcp6_srv.h
@@ -805,6 +805,15 @@ private:
/// @param query packet received
static void processStatsReceived(const Pkt6Ptr& query);
+ /// @brief Checks if the specified option code has been requested using
+ /// the Option Request option.
+ ///
+ /// @param query Pointer to the client's query.
+ /// @parma code Option code.
+ ///
+ /// @return true if option has been requested in the ORO.
+ bool requestedInORO(const Pkt6Ptr& query, const uint16_t code) const;
+
/// UDP port number on which server listens.
uint16_t port_;
diff --git a/src/bin/dhcp6/tests/renew_unittest.cc b/src/bin/dhcp6/tests/renew_unittest.cc
index 07324f2433..c61066fcd8 100644
--- a/src/bin/dhcp6/tests/renew_unittest.cc
+++ b/src/bin/dhcp6/tests/renew_unittest.cc
@@ -218,7 +218,7 @@ const char* RENEW_CONFIGS[] = {
" \"interface-id\": \"\","
" \"interface\": \"eth0\""
" } ],"
- "\"valid-lifetime\": 4000 }
+ "\"valid-lifetime\": 4000 }"
};
/// @brief Test fixture class for testing Renew.
@@ -352,7 +352,7 @@ TEST_F(RenewTest, renewWithExcludedPrefix) {
ASSERT_FALSE(option);
// Reconfigure the server to use the prefix pool with excluded prefix.
- configure(RENEW_CONFIGS[4], *client.getServer());
+ configure(RENEW_CONFIGS[5], *client.getServer());
// Send Renew message to the server, including IA_NA and IA_PD.
ASSERT_NO_THROW(client.doRenew());
diff --git a/src/bin/dhcp6/tests/sarr_unittest.cc b/src/bin/dhcp6/tests/sarr_unittest.cc
index 1a085f802f..d053bd3b2a 100644
--- a/src/bin/dhcp6/tests/sarr_unittest.cc
+++ b/src/bin/dhcp6/tests/sarr_unittest.cc
@@ -339,7 +339,7 @@ TEST_F(SARRTest, directClientExcludedPrefix) {
// Configure client to request IA_PD.
client.requestPrefix();
client.requestOption(D6O_PD_EXCLUDE);
- configure(CONFIGS[2], *client.getServer());
+ configure(CONFIGS[3], *client.getServer());
// Make sure we ended-up having expected number of subnets configured.
const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
getCfgSubnets6()->getAll();