summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_hosts.cc
diff options
context:
space:
mode:
authorTomek Mrugalski <tomasz@isc.org>2017-04-22 12:28:53 +0200
committerTomek Mrugalski <tomasz@isc.org>2017-04-22 12:28:53 +0200
commit7d00bc89e740d3f6ebbb552b5a085b6fdfecf598 (patch)
tree73e68fbc768c1ccd201ddcc8ef1fd6595b203fd0 /src/lib/dhcpsrv/cfg_hosts.cc
parent[5208a] setTestHostDataSource() added. (diff)
downloadkea-7d00bc89e740d3f6ebbb552b5a085b6fdfecf598.tar.xz
kea-7d00bc89e740d3f6ebbb552b5a085b6fdfecf598.zip
[5208a] toElement() moved from CfgHosts to Host
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_hosts.cc118
1 files changed, 10 insertions, 108 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc
index 4453c92d58..c493c77edb 100644
--- a/src/lib/dhcpsrv/cfg_hosts.cc
+++ b/src/lib/dhcpsrv/cfg_hosts.cc
@@ -708,60 +708,12 @@ CfgHosts::toElement4() const {
const HostContainerIndex0& idx = hosts_.get<0>();
for (HostContainerIndex0::const_iterator host = idx.begin();
host != idx.end(); ++host) {
- // Get the subnet ID
+
+ // Convert host to element representation
+ ElementPtr map = (*host)->toElement4();
+
+ // Push it on the list
SubnetID subnet_id = (*host)->getIPv4SubnetID();
- // Prepare the map
- ElementPtr map = Element::createMap();
- // Set the identifier
- Host::IdentifierType id_type = (*host)->getIdentifierType();
- if (id_type == Host::IDENT_HWADDR) {
- HWAddrPtr hwaddr = (*host)->getHWAddress();
- map->set("hw-address", Element::create(hwaddr->toText(false)));
- } else if (id_type == Host::IDENT_DUID) {
- DuidPtr duid = (*host)->getDuid();
- map->set("duid", Element::create(duid->toText()));
- } else if (id_type == Host::IDENT_CIRCUIT_ID) {
- const std::vector<uint8_t>& bin = (*host)->getIdentifier();
- std::string circuit_id = util::encode::encodeHex(bin);
- map->set("circuit-id", Element::create(circuit_id));
- } else if (id_type == Host::IDENT_CLIENT_ID) {
- const std::vector<uint8_t>& bin = (*host)->getIdentifier();
- std::string client_id = util::encode::encodeHex(bin);
- map->set("client-id", Element::create(client_id));
- } else if (id_type == Host::IDENT_FLEX) {
- const std::vector<uint8_t>& bin = (*host)->getIdentifier();
- std::string flex = util::encode::encodeHex(bin);
- map->set("flex-id", Element::create(flex));
- } else {
- isc_throw(ToElementError, "invalid identifier type: " << id_type);
- }
- // Set the reservation
- const IOAddress& address = (*host)->getIPv4Reservation();
- map->set("ip-address", Element::create(address.toText()));
- // Set the hostname
- const std::string& hostname = (*host)->getHostname();
- map->set("hostname", Element::create(hostname));
- // Set next-server
- const IOAddress& next_server = (*host)->getNextServer();
- map->set("next-server", Element::create(next_server.toText()));
- // Set server-hostname
- const std::string& server_hostname = (*host)->getServerHostname();
- map->set("server-hostname", Element::create(server_hostname));
- // Set boot-file-name
- const std::string& boot_file_name = (*host)->getBootFileName();
- map->set("boot-file-name", Element::create(boot_file_name));
- // Set client-classes
- const ClientClasses& cclasses = (*host)->getClientClasses4();
- ElementPtr classes = Element::createList();
- for (ClientClasses::const_iterator cclass = cclasses.cbegin();
- cclass != cclasses.end(); ++cclass) {
- classes->add(Element::create(*cclass));
- }
- map->set("client-classes", classes);
- // Set option-data
- ConstCfgOptionPtr opts = (*host)->getCfgOption4();
- map->set("option-data", opts->toElement());
- // Push the map on the list
result.add(subnet_id, map);
}
return (result.externalize());
@@ -774,62 +726,12 @@ CfgHosts::toElement6() const {
const HostContainerIndex0& idx = hosts_.get<0>();
for (HostContainerIndex0::const_iterator host = idx.begin();
host != idx.end(); ++host) {
- // Get the subnet ID
+
+ // Convert host to Element representation
+ ElementPtr map = (*host)->toElement6();
+
+ // Push it on the list
SubnetID subnet_id = (*host)->getIPv6SubnetID();
- // Prepare the map
- ElementPtr map = Element::createMap();
- // Set the identifier
- Host::IdentifierType id_type = (*host)->getIdentifierType();
- if (id_type == Host::IDENT_HWADDR) {
- HWAddrPtr hwaddr = (*host)->getHWAddress();
- map->set("hw-address", Element::create(hwaddr->toText(false)));
- } else if (id_type == Host::IDENT_DUID) {
- DuidPtr duid = (*host)->getDuid();
- map->set("duid", Element::create(duid->toText()));
- } else if (id_type == Host::IDENT_CIRCUIT_ID) {
- isc_throw(ToElementError, "unexpected circuit-id DUID type");
- } else if (id_type == Host::IDENT_CLIENT_ID) {
- isc_throw(ToElementError, "unexpected client-id DUID type");
- } else if (id_type == Host::IDENT_FLEX) {
- const std::vector<uint8_t>& bin = (*host)->getIdentifier();
- std::string flex = util::encode::encodeHex(bin);
- map->set("flex-id", Element::create(flex));
- } else {
- isc_throw(ToElementError, "invalid DUID type: " << id_type);
- }
- // Set reservations (ip-addresses)
- IPv6ResrvRange na_resv =
- (*host)->getIPv6Reservations(IPv6Resrv::TYPE_NA);
- ElementPtr resvs = Element::createList();
- for (IPv6ResrvIterator resv = na_resv.first;
- resv != na_resv.second; ++resv) {
- resvs->add(Element::create(resv->second.toText()));
- }
- map->set("ip-addresses", resvs);
- // Set reservations (prefixes)
- IPv6ResrvRange pd_resv =
- (*host)->getIPv6Reservations(IPv6Resrv::TYPE_PD);
- resvs = Element::createList();
- for (IPv6ResrvIterator resv = pd_resv.first;
- resv != pd_resv.second; ++resv) {
- resvs->add(Element::create(resv->second.toText()));
- }
- map->set("prefixes", resvs);
- // Set the hostname
- const std::string& hostname = (*host)->getHostname();
- map->set("hostname", Element::create(hostname));
- // Set client-classes
- const ClientClasses& cclasses = (*host)->getClientClasses6();
- ElementPtr classes = Element::createList();
- for (ClientClasses::const_iterator cclass = cclasses.cbegin();
- cclass != cclasses.end(); ++cclass) {
- classes->add(Element::create(*cclass));
- }
- map->set("client-classes", classes);
- // Set option-data
- ConstCfgOptionPtr opts = (*host)->getCfgOption6();
- map->set("option-data", opts->toElement());
- // Push the map on the list
result.add(subnet_id, map);
}
return (result.externalize());