summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_hosts.cc
diff options
context:
space:
mode:
authorMarcin Siodelski <marcin@isc.org>2014-12-22 14:13:18 +0100
committerMarcin Siodelski <marcin@isc.org>2014-12-22 14:13:18 +0100
commit7b192fe314c12e38622742b3b338e997934f862f (patch)
treeadfd23d88fd684cce6d395be0585885174d4bd32 /src/lib/dhcpsrv/cfg_hosts.cc
parent[master] Added ChangeLog for #3635. (diff)
parent[3564] Extended the configuration example with the in-pool reservation. (diff)
downloadkea-7b192fe314c12e38622742b3b338e997934f862f.tar.xz
kea-7b192fe314c12e38622742b3b338e997934f862f.zip
[master] Merge branch 'trac3564'
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_hosts.cc44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc
index 4b7936815d..f9d4911891 100644
--- a/src/lib/dhcpsrv/cfg_hosts.cc
+++ b/src/lib/dhcpsrv/cfg_hosts.cc
@@ -36,13 +36,17 @@ CfgHosts::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) {
}
ConstHostCollection
-CfgHosts::getAll4(const IOAddress&) const {
- isc_throw(isc::NotImplemented, "getAll4(address) const is not implemented");
+CfgHosts::getAll4(const IOAddress& address) const {
+ ConstHostCollection collection;
+ getAllInternal4<ConstHostCollection>(address, collection);
+ return (collection);
}
HostCollection
-CfgHosts::getAll4(const IOAddress&) {
- isc_throw(isc::NotImplemented, "getAll4(address) is not implemented");
+CfgHosts::getAll4(const IOAddress& address) {
+ HostCollection collection;
+ getAllInternal4<HostCollection>(address, collection);
+ return (collection);
}
template<typename Storage>
@@ -76,6 +80,25 @@ CfgHosts::getAllInternal(const HWAddrPtr& hwaddr, const DuidPtr& duid,
}
}
+template<typename Storage>
+void
+CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const {
+ // Must not specify address other than IPv4.
+ if (!address.isV4()) {
+ isc_throw(BadHostAddress, "must specify an IPv4 address when searching"
+ " for a host, specified address was " << address);
+ }
+ // Search for the Host using the reserved IPv4 address as a key.
+ const HostContainerIndex1& idx = hosts_.get<1>();
+ HostContainerIndex1Range r = idx.equal_range(address);
+ // Append each Host object to the storage.
+ for (HostContainerIndex1::iterator host = r.first; host != r.second;
+ ++host) {
+ storage.push_back(*host);
+ }
+}
+
+
ConstHostPtr
CfgHosts::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
const DuidPtr& duid) const {
@@ -91,6 +114,19 @@ CfgHosts::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
}
ConstHostPtr
+CfgHosts::get4(const SubnetID& subnet_id, const IOAddress& address) const {
+ ConstHostCollection hosts = getAll4(address);
+ for (ConstHostCollection::const_iterator host = hosts.begin();
+ host != hosts.end(); ++host) {
+ if ((*host)->getIPv4SubnetID() == subnet_id) {
+ return (*host);
+ }
+ }
+ return (ConstHostPtr());
+}
+
+
+ConstHostPtr
CfgHosts::get6(const SubnetID& subnet_id, const DuidPtr& duid,
const HWAddrPtr& hwaddr) const {
// The true value indicates that it is an IPv6 subnet.