summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_subnets4.cc
diff options
context:
space:
mode:
authorMarcin Siodelski <marcin@isc.org>2017-07-19 23:22:30 +0200
committerMarcin Siodelski <marcin@isc.org>2017-07-19 23:22:30 +0200
commit62d94947c2068583c66d894c2066d0bacc1f6608 (patch)
tree6b69e8afd9fd6eb2adf7bfbe0deb9ab7f0614693 /src/lib/dhcpsrv/cfg_subnets4.cc
parent[master] Added ChangeLog for #5330. (diff)
downloadkea-62d94947c2068583c66d894c2066d0bacc1f6608.tar.xz
kea-62d94947c2068583c66d894c2066d0bacc1f6608.zip
[5314] Subnet to Element conversion moved to SubnetX classes.
Diffstat (limited to 'src/lib/dhcpsrv/cfg_subnets4.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_subnets4.cc101
1 files changed, 1 insertions, 100 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc
index 136f213d45..e86580e351 100644
--- a/src/lib/dhcpsrv/cfg_subnets4.cc
+++ b/src/lib/dhcpsrv/cfg_subnets4.cc
@@ -284,106 +284,7 @@ CfgSubnets4::toElement() const {
// Iterate subnets
for (Subnet4Collection::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 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 valid-lifetime
- map->set("valid-lifetime",
- Element::create(static_cast<long long>
- ((*subnet)->getValid().get())));
- // Set pools
- const PoolCollection& pools = (*subnet)->getPools(Lease::TYPE_V4);
- 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 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 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 match-client-id
- map->set("match-client-id",
- Element::create((*subnet)->getMatchClientId()));
- // Set next-server
- map->set("next-server",
- Element::create((*subnet)->getSiaddr().toText()));
- // Set DHCP4o6
- const Cfg4o6& d4o6 = (*subnet)->get4o6();
- isc::data::merge(map, d4o6.toElement());
- // Set client-class
- const ClientClasses& cclasses = (*subnet)->getClientClasses();
- if (cclasses.size() > 1) {
- isc_throw(ToElementError, "client-class 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());
- // Not supported: interface-id
- // Not supported: rapid-commit
- // Push on the list
- result->add(map);
+ result->add((*subnet)->toElement());
}
return (result);
}