diff options
author | Marcin Siodelski <marcin@isc.org> | 2014-12-11 16:59:22 +0100 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2014-12-11 17:03:24 +0100 |
commit | e29eee4fa7a0bcff002aa1d2d47c8cdd6eafd414 (patch) | |
tree | ee4a4160a2ce8a68bcc20eaeb55ab25f0a4eb540 /src/lib/dhcpsrv/cfg_hosts.cc | |
parent | [3564] Updated allocateLease4 in allocation engine to use reservations. (diff) | |
download | kea-e29eee4fa7a0bcff002aa1d2d47c8cdd6eafd414.tar.xz kea-e29eee4fa7a0bcff002aa1d2d47c8cdd6eafd414.zip |
[3564] Resolve conflicts with the reserved addresses in allocation engine.
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r-- | src/lib/dhcpsrv/cfg_hosts.cc | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc index 8bb17f3cc3..4c2b8b3d85 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. |