-// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
isc_throw(ToElementError, "invalid prefix range "
<< prefix.toText() << "-" << last.toText());
}
+ map->set("prefix-len", Element::create(prefix_len));
// Set delegated-len
uint8_t len = getLength();
uint8_t xlen = xopt->getExcludedPrefixLength();
map->set("excluded-prefix-len",
Element::create(static_cast<int>(xlen)));
- } else {
- map->set("excluded-prefix", Element::create(std::string("::")));
- map->set("excluded-prefix-len", Element::create(0));
}
+ // Let's not insert empty excluded-prefix values. If we ever
+ // decide to insert it after all, here's the code to do it:
+ // else {
+ // map->set("excluded-prefix",
+ // Element::create(std::string("::")));
+ // map->set("excluded-prefix-len", Element::create(0));
+ /// }
break;
}
-// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
ElementPtr pool_list = Element::createList();
for (PoolCollection::const_iterator pool = pools.cbegin();
pool != pools.cend(); ++pool) {
- // Prepare the map for a pool (@todo move this code to pool.cc)
- ElementPtr pool_map = Element::createMap();
- // Set user-context
- (*pool)->contextToElement(pool_map);
- // Set pool
- const IOAddress& first = (*pool)->getFirstAddress();
- const IOAddress& last = (*pool)->getLastAddress();
- std::string range = first.toText() + "-" + last.toText();
- // Try to output a prefix (vs a range)
- int prefix_len = prefixLengthFromRange(first, last);
- if (prefix_len >= 0) {
- std::ostringstream oss;
- oss << first.toText() << "/" << prefix_len;
- range = oss.str();
- }
- pool_map->set("pool", Element::create(range));
- // Set pool options
- ConstCfgOptionPtr opts = (*pool)->getCfgOption();
- pool_map->set("option-data", opts->toElement());
- // Set client-class
- const ClientClasses& cclasses = (*pool)->getClientClasses();
- if (cclasses.size() > 1) {
- isc_throw(ToElementError, "client-class has too many items: "
- << cclasses.size());
- } else if (!cclasses.empty()) {
- pool_map->set("client-class", Element::create(*cclasses.cbegin()));
- }
- // Push on the pool list
- pool_list->add(pool_map);
+ pool_list->add((*pool)->toElement());
}
map->set("pools", pool_list);
+
// Set pd-pools
const PoolCollection& pdpools = getPools(Lease::TYPE_PD);
ElementPtr pdpool_list = Element::createList();
for (PoolCollection::const_iterator pool = pdpools.cbegin();
pool != pdpools.cend(); ++pool) {
- // Get it as a Pool6 (@todo move this code to pool.cc)
- const Pool6* pdpool = dynamic_cast<Pool6*>(pool->get());
- if (!pdpool) {
- isc_throw(ToElementError, "invalid pd-pool pointer");
- }
- // Prepare the map for a pd-pool
- ElementPtr pool_map = Element::createMap();
- // Set user-context
- pdpool->contextToElement(pool_map);
- // Set prefix
- const IOAddress& prefix = pdpool->getFirstAddress();
- pool_map->set("prefix", Element::create(prefix.toText()));
- // Set prefix-len (get it from min - max)
- const IOAddress& last = pdpool->getLastAddress();
- int prefix_len = prefixLengthFromRange(prefix, last);
- if (prefix_len < 0) {
- // The pool is bad: give up
- isc_throw(ToElementError, "invalid prefix range "
- << prefix.toText() << "-" << last.toText());
- }
- pool_map->set("prefix-len", Element::create(prefix_len));
- // Set delegated-len
- uint8_t len = pdpool->getLength();
- pool_map->set("delegated-len",
- Element::create(static_cast<int>(len)));
-
- // Set excluded prefix
- const Option6PDExcludePtr& xopt =
- pdpool->getPrefixExcludeOption();
- if (xopt) {
- const IOAddress& xprefix =
- xopt->getExcludedPrefix(prefix, len);
- pool_map->set("excluded-prefix",
- Element::create(xprefix.toText()));
- uint8_t xlen = xopt->getExcludedPrefixLength();
- pool_map->set("excluded-prefix-len",
- Element::create(static_cast<int>(xlen)));
- }
-
- // Set pool options
- ConstCfgOptionPtr opts = pdpool->getCfgOption();
- pool_map->set("option-data", opts->toElement());
- // Set client-class
- const ClientClasses& cclasses = pdpool->getClientClasses();
- if (cclasses.size() > 1) {
- isc_throw(ToElementError, "client-class has too many items: "
- << cclasses.size());
- } else if (!cclasses.empty()) {
- pool_map->set("client-class", Element::create(*cclasses.cbegin()));
- }
- // Push on the pool list
- pdpool_list->add(pool_map);
+ pdpool_list->add((*pool)->toElement());
}
map->set("pd-pools", pdpool_list);