summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_hosts.cc
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2019-01-11 16:48:30 +0100
committerFrancis Dupont <fdupont@isc.org>2019-01-29 10:49:05 +0100
commit2a5750c931866bb27e7f8e5b8bcfb30d4cf532ac (patch)
treea35c76bba6455e26beb3220dbd233f3d47779c55 /src/lib/dhcpsrv/cfg_hosts.cc
parentimproved error trace in case ./configure cannot find mysql dependencies (diff)
downloadkea-2a5750c931866bb27e7f8e5b8bcfb30d4cf532ac.tar.xz
kea-2a5750c931866bb27e7f8e5b8bcfb30d4cf532ac.zip
[313-return-a-list-of-all-reservations-by-subnet-id] Added getAll[46] by subnet - checkpoint of the day
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_hosts.cc97
1 files changed, 95 insertions, 2 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc
index b07fe152ed..386bc2888e 100644
--- a/src/lib/dhcpsrv/cfg_hosts.cc
+++ b/src/lib/dhcpsrv/cfg_hosts.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2019 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
@@ -47,6 +47,42 @@ CfgHosts::getAll(const Host::IdentifierType& identifier_type,
}
ConstHostCollection
+CfgHosts::getAll4(const SubnetID& subnet_id) const {
+ // Do not issue logging message here because it will be logged by
+ // the getAllInternal method.
+ ConstHostCollection collection;
+ getAllInternal4<ConstHostCollection>(subnet_id, collection);
+ return (collection);
+}
+
+HostCollection
+CfgHosts::getAll4(const SubnetID& subnet_id) {
+ // Do not issue logging message here because it will be logged by
+ // the getAllInternal method.
+ HostCollection collection;
+ getAllInternal4<HostCollection>(subnet_id, collection);
+ return (collection);
+}
+
+ConstHostCollection
+CfgHosts::getAll6(const SubnetID& subnet_id) const {
+ // Do not issue logging message here because it will be logged by
+ // the getAllInternal method.
+ ConstHostCollection collection;
+ getAllInternal6<ConstHostCollection>(subnet_id, collection);
+ return (collection);
+}
+
+HostCollection
+CfgHosts::getAll6(const SubnetID& subnet_id) {
+ // Do not issue logging message here because it will be logged by
+ // the getAllInternal method.
+ HostCollection collection;
+ getAllInternal6<HostCollection>(subnet_id, collection);
+ return (collection);
+}
+
+ConstHostCollection
CfgHosts::getAll4(const IOAddress& address) const {
// Do not issue logging message here because it will be logged by
// the getAllInternal4 method.
@@ -123,6 +159,63 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type,
template<typename Storage>
void
+CfgHosts::getAllInternal4(const SubnetID& subnet_id,
+ Storage& storage) const {
+
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_SUBNET_ID4)
+ .arg(subnet_id);
+
+ // Use try DHCPv4 subnet id.
+ const HostContainerIndex2& idx = hosts_.get<2>();
+
+ // Append each Host object to the storage.
+ for (HostContainerIndex2::iterator host = idx.lower_bound(subnet_id);
+ host != idx.upper_bound(subnet_id);
+ ++host) {
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA,
+ HOSTS_CFG_GET_ALL_SUBNET_ID4_HOST)
+ .arg(subnet_id)
+ .arg((*host)->toText());
+ storage.push_back(*host);
+ }
+
+ // Log how many hosts have been found.
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_SUBNET_ID4_COUNT)
+ .arg(subnet_id)
+ .arg(storage.size());
+}
+
+template<typename Storage>
+void
+CfgHosts::getAllInternal6(const SubnetID& subnet_id,
+ Storage& storage) const {
+
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_SUBNET_ID6)
+ .arg(subnet_id);
+
+ // Use try DHCPv6 subnet id.
+ const HostContainerIndex3& idx = hosts_.get<3>();
+
+ // Append each Host object to the storage.
+ for (HostContainerIndex3::iterator host = idx.lower_bound(subnet_id);
+ host != idx.upper_bound(subnet_id);
+ ++host) {
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE_DETAIL_DATA,
+ HOSTS_CFG_GET_ALL_SUBNET_ID6_HOST)
+ .arg(subnet_id)
+ .arg((*host)->toText());
+ storage.push_back(*host);
+ }
+
+ // Log how many hosts have been found.
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_RESULTS, HOSTS_CFG_GET_ALL_SUBNET_ID6_COUNT)
+ .arg(subnet_id)
+ .arg(storage.size());
+}
+
+
+template<typename Storage>
+void
CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const {
LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_ADDRESS4)
.arg(address.toText());
@@ -447,7 +540,7 @@ CfgHosts::add(const HostPtr& host) {
}
// At least one subnet ID must be used
- if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
+ if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
host->getIPv6SubnetID() == SUBNET_ID_UNUSED) {
isc_throw(BadValue, "must not use both IPv4 and IPv6 subnet ids of"
" 0 when adding new host reservation");