summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_subnets6.cc
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2017-03-05 09:03:09 +0100
committerTomek Mrugalski <tomasz@isc.org>2017-03-07 13:42:58 +0100
commit0beffc6e25c8413b4f9439e9f5b02f38bc75a076 (patch)
tree8032a8364455d21b461c676662d6998721244a4c /src/lib/dhcpsrv/cfg_subnets6.cc
parent[master] Added (fixed) src/bin/agent to Doxyfile (diff)
downloadkea-0beffc6e25c8413b4f9439e9f5b02f38bc75a076.tar.xz
kea-0beffc6e25c8413b4f9439e9f5b02f38bc75a076.zip
[fdunparse2] Rebased, still reservations to do
Diffstat (limited to 'src/lib/dhcpsrv/cfg_subnets6.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_subnets6.cc181
1 files changed, 180 insertions, 1 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc
index 3136763f3c..b74e70e0e2 100644
--- a/src/lib/dhcpsrv/cfg_subnets6.cc
+++ b/src/lib/dhcpsrv/cfg_subnets6.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 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
@@ -9,9 +9,13 @@
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/subnet_id.h>
+#include <dhcpsrv/addr_utilities.h>
#include <stats/stats_mgr.h>
+#include <string.h>
+#include <sstream>
using namespace isc::asiolink;
+using namespace isc::data;
namespace isc {
namespace dhcp {
@@ -227,5 +231,180 @@ CfgSubnets6::updateStatistics() {
}
}
+ElementPtr
+CfgSubnets6::toElement() const {
+ ElementPtr result = Element::createList();
+ // Iterate subnets
+ for (Subnet6Collection::const_iterator subnet = subnets_.cbegin();
+ subnet != subnets_.cend(); ++subnet) {
+ // Prepare the map
+ ElementPtr map = Element::createMap();
+ // Set subnet id
+ SubnetID id = (*subnet)->getID();
+ map->set("id", Element::create(static_cast<long long>(id)));
+ // Set relay info
+ const Subnet::RelayInfo& relay_info = (*subnet)->getRelayInfo();
+ ElementPtr relay = Element::createMap();
+ relay->set("ip-address", Element::create(relay_info.addr_.toText()));
+ map->set("relay", relay);
+ // Set subnet
+ map->set("subnet", Element::create((*subnet)->toText()));
+ // Set interface
+ const std::string& iface = (*subnet)->getIface();
+ map->set("interface", Element::create(iface));
+ // Set interface-id
+ const OptionPtr& ifaceid = (*subnet)->getInterfaceId();
+ if (ifaceid) {
+ std::vector<uint8_t> bin = ifaceid->getData();
+ std::string ifid;
+ ifid.resize(bin.size());
+ if (!bin.empty()) {
+ std::memcpy(&ifid[0], &bin[0], bin.size());
+ }
+ map->set("interface-id", Element::create(ifid));
+ } else {
+ map->set("interface-id", Element::create(std::string()));
+ }
+ // Set renew-timer
+ map->set("renew-timer",
+ Element::create(static_cast<long long>
+ ((*subnet)->getT1().get())));
+ // Set rebind-timer
+ map->set("rebind-timer",
+ Element::create(static_cast<long long>
+ ((*subnet)->getT2().get())));
+ // Set preferred-lifetime
+ map->set("preferred-lifetime",
+ Element::create(static_cast<long long>
+ ((*subnet)->getPreferred().get())));
+ // Set valid-lifetime
+ map->set("valid-lifetime",
+ Element::create(static_cast<long long>
+ ((*subnet)->getValid().get())));
+ // Set rapid-commit
+ bool rapid_commit = (*subnet)->getRapidCommit();
+ map->set("rapid-commit", Element::create(rapid_commit));
+ // Set pools
+ const PoolCollection& pools = (*subnet)->getPools(Lease::TYPE_NA);
+ ElementPtr pool_list = Element::createList();
+ for (PoolCollection::const_iterator pool = pools.cbegin();
+ pool != pools.cend(); ++pool) {
+ // Prepare the map for a pool
+ ElementPtr pool_map = Element::createMap();
+ // 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 user-context
+ ConstElementPtr context = (*pool)->getContext();
+ if (!isNull(context)) {
+ pool_map->set("user-context", context);
+ }
+ // Set pool options
+ ConstCfgOptionPtr opts = (*pool)->getCfgOption();
+ pool_map->set("option-data", opts->toElement());
+ // Push on the pool list
+ pool_list->add(pool_map);
+ }
+ map->set("pools", pool_list);
+ // Set pd-pools
+ const PoolCollection& pdpools = (*subnet)->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
+ 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 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)));
+ } else {
+ pool_map->set("excluded-prefix",
+ Element::create(std::string("::")));
+ pool_map->set("excluded-prefix-len", Element::create(0));
+ }
+ // Set user-context
+ ConstElementPtr context = pdpool->getContext();
+ if (!isNull(context)) {
+ pool_map->set("user-context", context);
+ }
+ // Set pool options
+ ConstCfgOptionPtr opts = pdpool->getCfgOption();
+ pool_map->set("option-data", opts->toElement());
+ // Push on the pool list
+ pdpool_list->add(pool_map);
+ }
+ map->set("pd-pools", pdpool_list);
+ // Set host reservation-mode
+ Subnet::HRMode hrmode = (*subnet)->getHostReservationMode();
+ std::string mode;
+ switch (hrmode) {
+ case Subnet::HR_DISABLED:
+ mode = "disabled";
+ break;
+ case Subnet::HR_OUT_OF_POOL:
+ mode = "out-of-pool";
+ break;
+ case Subnet::HR_ALL:
+ mode = "all";
+ break;
+ default:
+ isc_throw(ToElementError,
+ "invalid host reservation mode: " << hrmode);
+ }
+ map->set("reservation-mode", Element::create(mode));
+ // Set client-class
+ const ClientClasses& cclasses = (*subnet)->getClientClasses();
+ if (cclasses.size() > 1) {
+ isc_throw(ToElementError, "client-classes has too many items: "
+ << cclasses.size());
+ } else if (!cclasses.empty()) {
+ map->set("client-class", Element::create(*cclasses.cbegin()));
+ }
+ // Set options
+ ConstCfgOptionPtr opts = (*subnet)->getCfgOption();
+ map->set("option-data", opts->toElement());
+ // Push on the list
+ result->add(map);
+ }
+ return (result);
+}
+
} // end of namespace isc::dhcp
} // end of namespace isc