Commit e018f8e6 authored by Francis Dupont's avatar Francis Dupont

[5563] Changes done and compile

parent 4bfffff7
......@@ -4421,19 +4421,21 @@ TEST_F(Dhcp4ParserTest, reservations) {
// Let's create an object holding hardware address of the host having
// a reservation in the subnet having id of 234. For simplicity the
// address is a collection of numbers from 1 to 6.
std::vector<uint8_t> hwaddr_vec;
std::vector<uint8_t> hwaddr;
for (unsigned int i = 1; i < 7; ++i) {
hwaddr_vec.push_back(static_cast<uint8_t>(i));
hwaddr.push_back(static_cast<uint8_t>(i));
}
HWAddrPtr hwaddr(new HWAddr(hwaddr_vec, HTYPE_ETHER));
// Retrieve the reservation and sanity check the address reserved.
ConstHostPtr host = hosts_cfg->get4(234, hwaddr);
ConstHostPtr host = hosts_cfg->get4(234, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size());
ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.120", host->getIPv4Reservation().toText());
// This reservation should be solely assigned to the subnet 234,
// and not to other two.
EXPECT_FALSE(hosts_cfg->get4(123, hwaddr));
EXPECT_FALSE(hosts_cfg->get4(542, hwaddr));
EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
// Check that options are assigned correctly.
Option4AddrLstPtr opt_dns =
retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
......@@ -4447,16 +4449,15 @@ TEST_F(Dhcp4ParserTest, reservations) {
EXPECT_EQ(11, static_cast<int>(opt_ttl->getValue()));
// Do the same test for the DUID based reservation.
std::vector<uint8_t> duid_vec;
std::vector<uint8_t> duid;
for (unsigned int i = 1; i < 0xb; ++i) {
duid_vec.push_back(static_cast<uint8_t>(i));
duid.push_back(static_cast<uint8_t>(i));
}
DuidPtr duid(new DUID(duid_vec));
host = hosts_cfg->get4(234, HWAddrPtr(), duid);
host = hosts_cfg->get4(234, Host::IDENT_DUID, &duid[0], duid.size());
ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText());
EXPECT_FALSE(hosts_cfg->get4(123, HWAddrPtr(), duid));
EXPECT_FALSE(hosts_cfg->get4(542, HWAddrPtr(), duid));
EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size()));
EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size()));
// Check that options are assigned correctly.
opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
ASSERT_TRUE(opt_dns);
......@@ -4470,7 +4471,7 @@ TEST_F(Dhcp4ParserTest, reservations) {
// The circuit-id used for one of the reservations in the subnet 542
// consists of numbers from 6 to 1. So, let's just reverse the order
// of the address from the previous test.
std::vector<uint8_t> circuit_id(hwaddr_vec.rbegin(), hwaddr_vec.rend());
std::vector<uint8_t> circuit_id(hwaddr.rbegin(), hwaddr.rend());
host = hosts_cfg->get4(542, Host::IDENT_CIRCUIT_ID, &circuit_id[0],
circuit_id.size());
EXPECT_TRUE(host);
......@@ -4483,13 +4484,14 @@ TEST_F(Dhcp4ParserTest, reservations) {
// Repeat the test for the DUID based reservation in this subnet.
duid.reset(new DUID(std::vector<uint8_t>(duid_vec.rbegin(),
duid_vec.rend())));
host = hosts_cfg->get4(542, HWAddrPtr(), duid);
std::vector<uint8_t> duid_r(duid.rbegin(), duid.rend());
host = hosts_cfg->get4(542, Host::IDENT_DUID, &duid_r[0], duid_r.size());
ASSERT_TRUE(host);
EXPECT_EQ("192.0.4.101", host->getIPv4Reservation().toText());
EXPECT_FALSE(hosts_cfg->get4(123, HWAddrPtr(), duid));
EXPECT_FALSE(hosts_cfg->get4(234, HWAddrPtr(), duid));
EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID,
&duid_r[0], duid_r.size()));
EXPECT_FALSE(hosts_cfg->get4(234, Host::IDENT_DUID,
&duid_r[0], duid_r.size()));
// Check that options are assigned correctly.
opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
ASSERT_TRUE(opt_dns);
......@@ -4564,13 +4566,13 @@ TEST_F(Dhcp4ParserTest, reservationWithOptionDefinition) {
// Let's create an object holding DUID of the host. For simplicity the
// address is a collection of numbers from 1 to A.
std::vector<uint8_t> duid_vec;
std::vector<uint8_t> duid;
for (unsigned int i = 1; i < 0xB; ++i) {
duid_vec.push_back(static_cast<uint8_t>(i));
duid.push_back(static_cast<uint8_t>(i));
}
DuidPtr duid(new DUID(duid_vec));
// Retrieve the reservation and sanity check the address reserved.
ConstHostPtr host = hosts_cfg->get4(234, HWAddrPtr(), duid);
ConstHostPtr host =
hosts_cfg->get4(234, Host::IDENT_DUID, &duid[0], duid.size());
ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText());
......@@ -5992,9 +5994,9 @@ TEST_F(Dhcp4ParserTest, comments) {
// The subnet has a host reservation.
uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
HWAddrPtr hwaddr(new HWAddr(hw, sizeof(hw), HTYPE_ETHER));
ConstHostPtr host =
CfgMgr::instance().getStagingCfg()->getCfgHosts()->get4(100, hwaddr);
CfgMgr::instance().getStagingCfg()->getCfgHosts()->
get4(100, Host::IDENT_HWADDR, &hw[0], sizeof(hw));
ASSERT_TRUE(host);
EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType());
EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false));
......
// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-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
......@@ -4694,13 +4694,13 @@ TEST_F(Dhcp6ParserTest, reservations) {
// Let's create an object holding hardware address of the host having
// a reservation in the subnet having id of 234. For simplicity the
// address is a collection of numbers from 1 to 6.
std::vector<uint8_t> hwaddr_vec;
std::vector<uint8_t> hwaddr;
for (unsigned int i = 1; i < 7; ++i) {
hwaddr_vec.push_back(static_cast<uint8_t>(i));
hwaddr.push_back(static_cast<uint8_t>(i));
}
HWAddrPtr hwaddr(new HWAddr(hwaddr_vec, HTYPE_ETHER));
// Retrieve the reservation and sanity check the address reserved.
ConstHostPtr host = hosts_cfg->get6(234, DuidPtr(), hwaddr);
ConstHostPtr host = hosts_cfg->get6(234, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size());
ASSERT_TRUE(host);
IPv6ResrvRange resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
......@@ -4709,8 +4709,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
resrv));
// This reservation should be solely assigned to the subnet 234,
// and not to other two.
EXPECT_FALSE(hosts_cfg->get6(123, DuidPtr(), hwaddr));
EXPECT_FALSE(hosts_cfg->get6(542, DuidPtr(), hwaddr));
EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
EXPECT_FALSE(hosts_cfg->get6(542, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
// Check that options are assigned correctly.
Option6AddrLstPtr opt_dns =
retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
......@@ -4724,20 +4726,19 @@ TEST_F(Dhcp6ParserTest, reservations) {
EXPECT_EQ(25, static_cast<int>(opt_prf->getValue()));
// Do the same test for the DUID based reservation.
std::vector<uint8_t> duid_vec;
std::vector<uint8_t> duid;
for (unsigned int i = 1; i < 0xb; ++i) {
duid_vec.push_back(static_cast<uint8_t>(i));
duid.push_back(static_cast<uint8_t>(i));
}
DuidPtr duid(new DUID(duid_vec));
host = hosts_cfg->get6(234, duid);
host = hosts_cfg->get6(234, Host::IDENT_DUID, &duid[0], duid.size());
ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
IOAddress("2001:db8:2::1234")),
resrv));
EXPECT_FALSE(hosts_cfg->get6(123, duid));
EXPECT_FALSE(hosts_cfg->get6(542, duid));
EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_DUID, &duid[0], duid.size()));
EXPECT_FALSE(hosts_cfg->get6(542, Host::IDENT_DUID, &duid[0], duid.size()));
// Check that options are assigned correctly.
opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
ASSERT_TRUE(opt_dns);
......@@ -4752,9 +4753,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
// The HW address used for one of the reservations in the subnet 542
// consists of numbers from 6 to 1. So, let's just reverse the order
// of the address from the previous test.
hwaddr->hwaddr_.assign(hwaddr_vec.rbegin(), hwaddr_vec.rend());
host = hosts_cfg->get6(542, DuidPtr(), hwaddr);
EXPECT_TRUE(host);
std::vector<uint8_t> hwaddr_r(hwaddr.rbegin(), hwaddr.rend());
host = hosts_cfg->get6(542, Host::IDENT_HWADDR,
&hwaddr_r[0], hwaddr_r.size());
ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
......@@ -4762,13 +4764,14 @@ TEST_F(Dhcp6ParserTest, reservations) {
96), resrv));
// This reservation must not belong to other subnets.
EXPECT_FALSE(hosts_cfg->get6(123, DuidPtr(), hwaddr));
EXPECT_FALSE(hosts_cfg->get6(234, DuidPtr(), hwaddr));
EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_HWADDR,
&hwaddr_r[0], hwaddr_r.size()));
EXPECT_FALSE(hosts_cfg->get6(234, Host::IDENT_HWADDR,
&hwaddr_r[0], hwaddr_r.size()));
// Repeat the test for the DUID based reservation in this subnet.
duid.reset(new DUID(std::vector<uint8_t>(duid_vec.rbegin(),
duid_vec.rend())));
host = hosts_cfg->get6(542, duid);
std::vector<uint8_t> duid_r(duid.rbegin(), duid.rend());
host = hosts_cfg->get6(542, Host::IDENT_DUID, &duid_r[0], duid_r.size());
ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
......@@ -4776,8 +4779,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
IOAddress("2001:db8:3:2::"),
96), resrv));
EXPECT_FALSE(hosts_cfg->get6(123, duid));
EXPECT_FALSE(hosts_cfg->get6(234, duid));
EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_DUID,
&duid_r[0], duid_r.size()));
EXPECT_FALSE(hosts_cfg->get6(234, Host::IDENT_DUID,
&duid_r[0], duid_r.size()));
// Check that options are assigned correctly.
opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
ASSERT_TRUE(opt_dns);
......@@ -4842,13 +4847,13 @@ TEST_F(Dhcp6ParserTest, reservationWithOptionDefinition) {
// Let's create an object holding DUID of the host. For simplicity the
// address is a collection of numbers from 1 to A.
std::vector<uint8_t> duid_vec;
std::vector<uint8_t> duid;
for (unsigned int i = 1; i < 0xB; ++i) {
duid_vec.push_back(static_cast<uint8_t>(i));
duid.push_back(static_cast<uint8_t>(i));
}
DuidPtr duid(new DUID(duid_vec));
// Retrieve the reservation and sanity check the address reserved.
ConstHostPtr host = hosts_cfg->get6(234, duid);
ConstHostPtr host = hosts_cfg->get6(234, Host::IDENT_DUID,
&duid[0], duid.size());
ASSERT_TRUE(host);
// Check if the option has been parsed.
......@@ -6566,9 +6571,9 @@ TEST_F(Dhcp6ParserTest, comments) {
// The subnet has a host reservation.
uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
HWAddrPtr hwaddr(new HWAddr(hw, sizeof(hw), HTYPE_ETHER));
ConstHostPtr host =
CfgMgr::instance().getStagingCfg()->getCfgHosts()->get6(100, DuidPtr(), hwaddr);
CfgMgr::instance().getStagingCfg()->getCfgHosts()->
get6(100, Host::IDENT_HWADDR, &hw[0], sizeof(hw));
ASSERT_TRUE(host);
EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType());
EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false));
......
......@@ -8,8 +8,6 @@
#define BASE_HOST_DATA_SOURCE_H
#include <asiolink/io_address.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/host.h>
#include <exceptions/exceptions.h>
#include <boost/shared_ptr.hpp>
......@@ -76,30 +74,6 @@ public:
/// @brief Default destructor implementation.
virtual ~BaseHostDataSource() { }
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This method returns all @c Host objects which represent reservations
/// for the specified HW address or DUID. Note, that this method may
/// return multiple reservations because a particular client may have
/// reservations in multiple subnets and the same client may be identified
/// by HW address or DUID. The server is unable to verify that the specific
/// DUID and HW address belong to the same client, until the client sends
/// a DHCP message.
///
/// Specifying both hardware address and DUID is allowed for this method
/// and results in returning all objects that are associated with hardware
/// address OR duid. For example: if one host is associated with the
/// specified hardware address and another host is associated with the
/// specified DUID, two hosts will be returned.
///
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
///
/// @return Collection of const @c Host objects.
virtual ConstHostCollection
getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const = 0;
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
......@@ -129,25 +103,6 @@ public:
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const = 0;
/// @brief Returns a host connected to the IPv4 subnet.
///
/// Implementations of this method should guard against the case when
/// multiple instances of the @c Host are present, e.g. when two
/// @c Host objects are found, one for the DUID, another one for the
/// HW address. In such case, an implementation of this method
/// should throw an exception.
///
/// @param subnet_id Subnet identifier.
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid client id or NULL if not available.
///
/// @return Const @c Host object using a specified HW address or DUID.
virtual ConstHostPtr
get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
const DuidPtr& duid = DuidPtr()) const = 0;
/// @brief Returns a host connected to the IPv4 subnet.
///
/// @param subnet_id Subnet identifier.
......@@ -184,24 +139,6 @@ public:
get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const = 0;
/// @brief Returns a host connected to the IPv6 subnet.
///
/// Implementations of this method should guard against the case when
/// multiple instances of the @c Host are present, e.g. when two
/// @c Host objects are found, one for the DUID, another one for the
/// HW address. In such case, an implementation of this method
/// should throw an exception.
///
/// @param subnet_id Subnet identifier.
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid DUID or NULL if not available.
///
/// @return Const @c Host object using a specified HW address or DUID.
virtual ConstHostPtr
get6(const SubnetID& subnet_id, const DuidPtr& duid,
const HWAddrPtr& hwaddr = HWAddrPtr()) const = 0;
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
......@@ -223,7 +160,7 @@ public:
/// @param prefix IPv6 prefix for which the @c Host object is searched.
/// @param prefix_len IPv6 prefix length.
///
/// @return Const @c Host object using a specified HW address or DUID.
/// @return Const @c Host object using a specified IPv6 prefix.
virtual ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0;
......
// 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>
......@@ -21,24 +23,6 @@ using namespace isc::data;
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,
......@@ -137,26 +121,6 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type,
.arg(storage.size());
}
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 {
......@@ -215,44 +179,6 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const {
.arg(storage.size());
}
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,
......@@ -295,46 +221,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,
......@@ -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.
......
// 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
......@@ -9,8 +9,6 @@
#include <asiolink/io_address.h>
#include <cc/cfg_to_element.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/base_host_data_source.h>
#include <dhcpsrv/host.h>
#include <dhcpsrv/host_container.h>
......@@ -43,34 +41,6 @@ public:
/// @brief Destructor.
virtual ~CfgHosts() { }
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This method returns all @c Host objects which represent reservations
/// for the specified HW address or DUID. Note, that this method may
/// return multiple reservations because a particular client may have
/// reservations in multiple subnets and the same client may be identified
/// by HW address or DUID. The server is unable to verify that the specific
/// DUID and HW address belong to the same client, until the client sends
/// a DHCP message.
///
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
///
/// @return Collection of const @c Host objects.
virtual ConstHostCollection
getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
/// @brief Non-const version of the @c getAll const method.
///
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
///
/// @return Collection of non-const @c Host objects.
virtual HostCollection
getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr());
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
......@@ -149,36 +119,6 @@ public:
virtual HostCollection
getAll6(const asiolink::IOAddress& address);
/// @brief Returns a host connected to the IPv4 subnet and matching
/// specified identifiers.
///