summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_hosts.cc
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2018-05-24 16:51:07 +0200
committerFrancis Dupont <fdupont@isc.org>2018-05-24 16:51:07 +0200
commite018f8e6c9ce3a13b6108b318216ede28c50ae37 (patch)
tree1f8456ca1303fec24868416604dd4952e3bf990a /src/lib/dhcpsrv/cfg_hosts.cc
parent[master] Added ChangeLog entry 1407 for #5626 (diff)
downloadkea-e018f8e6c9ce3a13b6108b318216ede28c50ae37.tar.xz
kea-e018f8e6c9ce3a13b6108b318216ede28c50ae37.zip
[5563] Changes done and compile
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_hosts.cc170
1 files changed, 37 insertions, 133 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc
index b7f52d405e..d673cdc3b1 100644
--- a/src/lib/dhcpsrv/cfg_hosts.cc
+++ b/src/lib/dhcpsrv/cfg_hosts.cc
@@ -1,10 +1,12 @@
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
+#include <dhcp/duid.h>
+#include <dhcp/hwaddr.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_hosts_util.h>
#include <dhcpsrv/hosts_log.h>
@@ -22,24 +24,6 @@ namespace isc {
namespace dhcp {
ConstHostCollection
-CfgHosts::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
- // Do not issue logging message here because it will be logged by
- // the getAllInternal method.
- ConstHostCollection collection;
- getAllInternal<ConstHostCollection>(hwaddr, duid, collection);
- return (collection);
-}
-
-HostCollection
-CfgHosts::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) {
- // Do not issue logging message here because it will be logged by
- // the getAllInternal method.
- HostCollection collection;
- getAllInternal<HostCollection>(hwaddr, duid, collection);
- return (collection);
-}
-
-ConstHostCollection
CfgHosts::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
@@ -139,26 +123,6 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type,
template<typename Storage>
void
-CfgHosts::getAllInternal(const HWAddrPtr& hwaddr, const DuidPtr& duid,
- Storage& storage) const {
- LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_HWADDR_DUID)
- .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
- .arg(duid ? duid->toText() : "(no-duid)");
-
- // Get hosts using HW address.
- if (hwaddr && !hwaddr->hwaddr_.empty()) {
- getAllInternal<Storage>(Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size(), storage);
- }
- // Get hosts using DUID.
- if (duid && !duid->getDuid().empty()) {
- getAllInternal<Storage>(Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size(), storage);
- }
-}
-
-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());
@@ -216,44 +180,6 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const {
}
ConstHostPtr
-CfgHosts::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
- // Do not log here because getHostInternal logs.
- // The false value indicates that it is an IPv4 subnet.
- HostPtr host;
- if (hwaddr && !hwaddr->hwaddr_.empty()) {
- host = getHostInternal(subnet_id, false, Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size());
- }
- if (!host && duid && !duid->getDuid().empty()) {
- host = getHostInternal(subnet_id, false, Host::IDENT_DUID,
- &duid->getDuid()[0],
- duid->getDuid().size());
- }
- return (host);
-}
-
-HostPtr
-CfgHosts::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) {
- // Do not log here because getHostInternal logs.
- // The false value indicates that it is an IPv4 subnet.
- HostPtr host;
- if (hwaddr && !hwaddr->hwaddr_.empty()) {
- host = getHostInternal(subnet_id, false, Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size());
- }
- if (!host && duid && !duid->getDuid().empty()) {
- host = getHostInternal(subnet_id, false, Host::IDENT_DUID,
- &duid->getDuid()[0],
- duid->getDuid().size());
- }
- return (host);
-}
-
-ConstHostPtr
CfgHosts::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
@@ -296,46 +222,6 @@ CfgHosts::get4(const SubnetID& subnet_id, const IOAddress& address) const {
ConstHostPtr
-CfgHosts::get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
- // Do not log here because getHostInternal logs.
- // The true value indicates that it is an IPv6 subnet.
- HostPtr host;
- if (duid && !duid->getDuid().empty()) {
- host = getHostInternal(subnet_id, true, Host::IDENT_DUID,
- &duid->getDuid()[0],
- duid->getDuid().size());
- }
- if (!host && hwaddr && !hwaddr->hwaddr_.empty()) {
- host = getHostInternal(subnet_id, true, Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size());
- }
-
- return (host);
-}
-
-HostPtr
-CfgHosts::get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr) {
- // Do not log here because getHostInternal logs.
- // The true value indicates that it is an IPv6 subnet.
- HostPtr host;
- if (duid && !duid->getDuid().empty()) {
- host = getHostInternal(subnet_id, true, Host::IDENT_DUID,
- &duid->getDuid()[0],
- duid->getDuid().size());
- }
- if (!host && hwaddr && !hwaddr->hwaddr_.empty()) {
- host = getHostInternal(subnet_id, true, Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size());
- }
-
- return (host);
-}
-
-ConstHostPtr
CfgHosts::get6(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
@@ -603,23 +489,41 @@ CfgHosts::add4(const HostPtr& host) {
}
// Check for duplicates for the specified IPv4 subnet.
- if ((host->getIPv4SubnetID() > 0) &&
- get4(host->getIPv4SubnetID(), hwaddr, duid)) {
- isc_throw(DuplicateHost, "failed to add new host using the HW"
- " address '" << (hwaddr ? hwaddr->toText(false) : "(null)")
- << " and DUID '" << (duid ? duid->toText() : "(null)")
- << "' to the IPv4 subnet id '" << host->getIPv4SubnetID()
- << "' as this host has already been added");
-
-
+ if (host->getIPv4SubnetID() > 0) {
+ if (hwaddr && !hwaddr->hwaddr_.empty() &&
+ get4(host->getIPv4SubnetID(), Host::IDENT_HWADDR,
+ &hwaddr->hwaddr_[0], hwaddr->hwaddr_.size())) {
+ isc_throw(DuplicateHost, "failed to add new host using the HW"
+ << " address '" << hwaddr->toText(false)
+ << "' to the IPv4 subnet id '" << host->getIPv4SubnetID()
+ << "' as this host has already been added");
+ }
+ if (duid && !duid->getDuid().empty() &&
+ get4(host->getIPv4SubnetID(), Host::IDENT_DUID,
+ &duid->getDuid()[0], duid->getDuid().size())) {
+ isc_throw(DuplicateHost, "failed to add new host using the "
+ << "DUID '" << duid->toText()
+ << "' to the IPv4 subnet id '" << host->getIPv4SubnetID()
+ << "' as this host has already been added");
+ }
// Check for duplicates for the specified IPv6 subnet.
- } else if (host->getIPv6SubnetID() &&
- get6(host->getIPv6SubnetID(), duid, hwaddr)) {
- isc_throw(DuplicateHost, "failed to add new host using the HW"
- " address '" << (hwaddr ? hwaddr->toText(false) : "(null)")
- << " and DUID '" << (duid ? duid->toText() : "(null)")
- << "' to the IPv6 subnet id '" << host->getIPv6SubnetID()
- << "' as this host has already been added");
+ } else if (host->getIPv6SubnetID()) {
+ if (duid && !duid->getDuid().empty() &&
+ get6(host->getIPv6SubnetID(), Host::IDENT_DUID,
+ &duid->getDuid()[0], duid->getDuid().size())) {
+ isc_throw(DuplicateHost, "failed to add new host using the "
+ << "DUID '" << duid->toText()
+ << "' to the IPv6 subnet id '" << host->getIPv6SubnetID()
+ << "' as this host has already been added");
+ }
+ if (hwaddr && !hwaddr->hwaddr_.empty() &&
+ get6(host->getIPv6SubnetID(), Host::IDENT_HWADDR,
+ &hwaddr->hwaddr_[0], hwaddr->hwaddr_.size())) {
+ isc_throw(DuplicateHost, "failed to add new host using the HW"
+ << " address '" << hwaddr->toText(false)
+ << "' to the IPv6 subnet id '" << host->getIPv6SubnetID()
+ << "' as this host has already been added");
+ }
}
// Check if the address is already reserved for the specified IPv4 subnet.