// 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);
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);
// 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);
// 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);
// 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());
// 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
// 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));
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);
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);
// 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,
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));
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);
// 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.
// 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));
#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>
/// @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.
///
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.
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.
/// @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>
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,
.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 {
.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,
}
-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,
}
// 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
#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>
/// @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.
///
virtual HostCollection
getAll6(const asiolink::IOAddress& address);
- /// @brief Returns a host connected to the IPv4 subnet and matching
- /// specified identifiers.
- ///
- /// @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.
- /// @throw isc::dhcp::DuplicateHost if more than one candidate host has
- /// been found.
- virtual ConstHostPtr
- get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const;
-
- /// @brief Returns a host connected to the IPv4 subnet and matching
- /// specified identifiers.
- ///
- /// @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 Non-const @c Host object using a specified HW address or DUID.
- /// @throw isc::dhcp::DuplicateHost if more than one candidate host has
- /// been found.
- virtual HostPtr
- get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr());
-
/// @brief Returns a host connected to the IPv4 subnet.
///
/// @param subnet_id Subnet identifier.
virtual ConstHostPtr
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @brief Returns a host connected to the IPv6 subnet and matching
- /// the specified identifiers.
- ///
- /// @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.
- /// @throw isc::dhcp::DuplicateHost if more than one candidate host has
- /// been found.
- virtual ConstHostPtr
- get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr()) const;
-
- /// @brief Returns a host connected to the IPv6 subnet and matching the
- /// specified identifiers.
- ///
- /// @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 Non-const @c Host object using a specified HW address or DUID.
- /// @throw isc::dhcp::DuplicateHost if more than one candidate host has
- /// been found.
- virtual HostPtr
- get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr());
-
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
const size_t identifier_len,
Storage& storage) const;
- /// @brief Returns @c Host objects for the specified HW address or DUID.
- ///
- /// This private method is called by the @c CfgHosts::getAll methods to
- /// retrieve the @c Host objects using HW address or DUID. The retrieved
- /// objects are appended to the @c storage container.
- ///
- /// @param hwaddr HW address identifying a host.
- /// @param duid DUID identifying a host.
- /// @param [out] storage Container to which the retrieved objects are
- /// appended.
- /// @tparam One of the @c ConstHostCollection or @c HostCollection.
- template<typename Storage>
- void getAllInternal(const HWAddrPtr& hwaddr, const DuidPtr& duid,
- Storage& storage) const;
-
/// @brief Returns @c Host objects for the specified IPv4 address.
///
/// This private method is called by the @c CfgHosts::getAll4 methods
#include <dhcpsrv/cql_host_data_source.h>
+#include <dhcp/duid.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option.h>
#include <dhcp/option_definition.h>
virtual ConstHostPtr get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const;
- /// @brief Implementation of @ref CqlHostDataSource::get4()
- ///
- /// See @ref CqlHostDataSource::get4() for parameter details.
- /// Either hwaddr or DUID must be specified, not both.
- ///
- /// @param subnet_id Id of the subnet to look into
- /// @param hwaddr hardware address
- /// @param duid DUID of the client
- virtual ConstHostPtr get4(const SubnetID& subnet_id,
- const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const;
-
/// @brief Implementation of @ref CqlHostDataSource::get4()
///
/// See @ref CqlHostDataSource::get4() for parameter details.
virtual ConstHostPtr get6(const asiolink::IOAddress& prefix,
const uint8_t prefix_len) const;
- /// @brief Retrieves a host by DUID or hardware address.
- ///
- /// Only one of DUID or hwaddr must be specified, not both.
- /// See @ref CqlHostDataSource::get6() for parameter details.
- ///
- /// @param subnet_id Id of the subnet to look into
- /// @param duid Searched DUID
- /// @param hwaddr Searched hwaddr
- virtual ConstHostPtr get6(const SubnetID& subnet_id,
- const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr()) const;
-
/// @brief Implementation of @ref CqlHostDataSource::get6()
///
/// See @ref CqlHostDataSource::get6() for parameter details.
virtual ConstHostPtr get6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const;
- /// @brief Implementation of @ref CqlHostDataSource::getAll()
- ///
- /// Returns reservations in all subnets for a given host.
- /// See @ref CqlHostDataSource::getAll() for parameter details.
- ///
- /// Only one of DUID or hwaddr must be specified, not both.
- /// See @ref CqlHostDataSource::get6() for parameter details.
- ///
- /// @param hwaddr
- /// @param duid
- virtual ConstHostCollection getAll(const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const;
-
/// @brief Implementation of @ref CqlHostDataSource::getAll()
///
/// See @ref CqlHostDataSource::getAll() for parameter details.
return (result);
}
-ConstHostPtr
-CqlHostDataSourceImpl::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
- /// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "CqlHostDataSource::get4(3) called with both "
- "hwaddr and duid, only one of them is allowed");
- } else if (!hwaddr && !duid) {
- isc_throw(BadValue, "CqlHostDataSource::get4(3) called with neither "
- "hwaddr or duid specified, one of them is "
- "required");
- }
-
- const HostIdentifier* host_identifier;
- Host::IdentifierType host_identifier_type;
- if (duid) {
- host_identifier = &duid->getDuid();
- host_identifier_type = Host::IDENT_DUID;
- } else if (hwaddr) {
- host_identifier = &hwaddr->hwaddr_;
- host_identifier_type = Host::IDENT_HWADDR;
- } else {
- return (ConstHostPtr());
- }
-
- // Delegate to get4(4).
- ConstHostPtr result = get4(subnet_id, host_identifier_type, host_identifier->data(),
- host_identifier->size());
-
- return (result);
-}
-
ConstHostPtr
CqlHostDataSourceImpl::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (result);
}
-ConstHostPtr
-CqlHostDataSourceImpl::get6(const SubnetID& subnet_id,
- const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
- /// @todo: Rethink the logic in BaseHostDataSource::get6(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "CqlHostDataSource::get6(3): both hardware address "
- "and DUID are specified, only one of them is "
- "allowed");
- } else if (!hwaddr && !duid) {
- isc_throw(BadValue, "CqlHostDataSource::get6(3): both hardware address "
- "and DUID are specified, one of them is required");
- }
-
- const HostIdentifier* host_identifier;
- Host::IdentifierType host_identifier_type;
- if (duid) {
- host_identifier = &duid->getDuid();
- host_identifier_type = Host::IDENT_DUID;
- } else if (hwaddr) {
- host_identifier = &hwaddr->hwaddr_;
- host_identifier_type = Host::IDENT_HWADDR;
- } else {
- return (ConstHostPtr());
- }
-
- // Delegate to get6(4).
- ConstHostPtr result = get6(subnet_id, host_identifier_type, host_identifier->data(),
- host_identifier->size());
-
- return (result);
-}
-
ConstHostPtr
CqlHostDataSourceImpl::get6(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (result);
}
-ConstHostCollection
-CqlHostDataSourceImpl::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
- if (!duid && !hwaddr) {
- return (ConstHostCollection());
- }
-
- // Convert to CQL data types.
- cass_int32_t host_identifier_type;
- CassBlob host_identifier;
- if (duid) {
- HostIdentifier duid_vector = duid->getDuid();
- host_identifier = CassBlob(duid_vector.begin(), duid_vector.end());
- host_identifier_type = static_cast<cass_int32_t>(Host::IDENT_DUID);
- } else if (hwaddr) {
- host_identifier = CassBlob(hwaddr->hwaddr_.begin(), hwaddr->hwaddr_.end());
- host_identifier_type = static_cast<cass_int32_t>(Host::IDENT_HWADDR);
- }
-
- // Bind to array.
- AnyArray where_values;
- where_values.add(&host_identifier);
- where_values.add(&host_identifier_type);
-
- // Run statement.
- ConstHostCollection result = getHostCollection(CqlHostExchange::GET_HOST_BY_HOST_ID,
- where_values);
-
- return (result);
-}
-
ConstHostCollection
CqlHostDataSourceImpl::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
return (impl_->insertOrDelete(host, false));
}
-ConstHostCollection
-CqlHostDataSource::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_HOST_GET_ALL);
-
- return (impl_->getAll(hwaddr, duid));
-}
-
ConstHostCollection
CqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
return (impl_->getAll4(address));
}
-ConstHostPtr
-CqlHostDataSource::get4(const SubnetID& subnet_id,
- const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_HOST_GET4);
-
- return (impl_->get4(subnet_id, hwaddr, duid));
-}
-
ConstHostPtr
CqlHostDataSource::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (impl_->get4(subnet_id, address));
}
-ConstHostPtr
-CqlHostDataSource::get6(const SubnetID& subnet_id,
- const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_HOST_GET6);
-
- return (impl_->get6(subnet_id, duid, hwaddr));
-}
-
ConstHostPtr
CqlHostDataSource::get6(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) override;
- /// @brief Return all @ref Host objects for the specified @ref HWAddr or
- /// @ref DUID.
- ///
- /// Returns all @ref 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 @ref HWAddr and @ref DUID is allowed for this method
- /// and results in returning all objects that are associated with hardware
- /// address OR duid. For example: if one @ref Host is associated with the
- /// specified @ref HWAddr and another @ref Host is associated with the
- /// specified @ref 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 @ref Host objects.
- virtual ConstHostCollection
- getAll(const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const override;
-
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const override;
- /// @brief Retrieves a single @ref Host connected to an IPv4 subnet.
- ///
- /// Implementations of this method should guard against the case when
- /// multiple instances of the @ref Host are present, e.g. when two @ref
- /// Host objects are found, one for the @ref DUID, another one for the @ref
- /// HWAddr. In such case, throw a @ref MultipleRecords exception.
- ///
- /// @param subnet_id subnet identifier to filter by
- /// @param hwaddr hardware address of the client to filter by or NULL if not
- /// available
- /// @param duid client identifier to filter by or NULL if not available
- ///
- /// @return @ref ConstHostPtr to a @ref Host object using a specified @ref
- /// HWAddr or @ref DUID
- ///
- /// @throw BadValue if both or neither of subnet_id and duid are specified
- virtual ConstHostPtr get4(const SubnetID& subnet_id,
- const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const override;
-
/// @brief Retrieves a @ref Host connected to an IPv4 subnet.
///
/// The host is identified by specific identifier.
get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const override;
- /// @brief Retrieves a @ref Host connected to an IPv6 subnet.
- ///
- /// Implementations of this method should guard against the case when
- /// multiple instances of the @ref Host are present, e.g. when two
- /// @ref Host objects are found, one for the @ref DUID, another one for the
- /// @ref HWAddr. In such case, throw a @ref MultipleRecords exception.
- ///
- /// @param subnet_id subnet identifier to filter by
- /// @param hwaddr hardware address of the client to filter by or NULL if not
- /// available
- /// @param duid client identifier to filter by or NULL if not available
- ///
- /// @return @ref Host object using a specified @ref HWAddr or @ref DUID
- ///
- /// @throw BadValue if both or neither of subnet_id and duid are specified
- virtual ConstHostPtr
- get6(const SubnetID& subnet_id,
- const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr()) const override;
-
/// @brief Returns a @ref Host connected to an IPv6 subnet.
///
/// @param subnet_id subnet identifier to filter by
/// @param prefix IPv6 prefix for which the @ref Host object is searched.
/// @param prefix_len IPv6 prefix length.
///
- /// @return Const @ref Host object using a specified HW address or DUID.
+ /// @return Const @ref Host object using a specified IPv6 prefix.
///
/// @throw MultipleRecords if two or more rows are returned from the
/// Cassandra database
return (*host_mgr_ptr);
}
-ConstHostCollection
-HostMgr::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
- ConstHostCollection hosts = getCfgHosts()->getAll(hwaddr, duid);
- for (auto source : alternate_sources_) {
- ConstHostCollection hosts_plus = source->getAll(hwaddr, duid);
- hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
- }
- return (hosts);
-}
-
ConstHostCollection
HostMgr::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
return (hosts);
}
-ConstHostPtr
-HostMgr::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
- ConstHostPtr host = getCfgHosts()->get4(subnet_id, hwaddr, duid);
- if (host || alternate_sources_.empty()) {
- return (host);
- }
- LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
- HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_HWADDR_DUID)
- .arg(subnet_id)
- .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
- .arg(duid ? duid->toText() : "(duid)");
- for (auto source : alternate_sources_) {
- if (hwaddr) {
- host = source->get4(subnet_id, hwaddr, DuidPtr());
- }
- if (!host && duid) {
- host = source->get4(subnet_id, HWAddrPtr(), duid);
- }
- if (host && host->getNegative()) {
- return (ConstHostPtr());
- }
- if (host && (source != cache_ptr_)) {
- cache(host);
- }
- if (host) {
- return (host);
- }
- }
- return (ConstHostPtr());
-}
-
ConstHostPtr
HostMgr::get4Any(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
}
-ConstHostPtr
-HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
- ConstHostPtr host = getCfgHosts()->get6(subnet_id, duid, hwaddr);
- if (host || alternate_sources_.empty()) {
- return (host);
- }
- LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
- HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_DUID_HWADDR)
- .arg(subnet_id)
- .arg(duid ? duid->toText() : "(duid)")
- .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)");
-
- for (auto source : alternate_sources_) {
- if (duid) {
- host = source->get6(subnet_id, duid, HWAddrPtr());
- }
- if (!host && hwaddr) {
- host = source->get6(subnet_id, DuidPtr(), hwaddr);
- }
- if (host && host->getNegative()) {
- return (ConstHostPtr());
- }
- if (host && source != cache_ptr_) {
- cache(host);
- }
- if (host) {
- return (host);
- }
- }
- return (ConstHostPtr());
-}
-
ConstHostPtr
HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len) const {
ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
#ifndef HOST_MGR_H
#define HOST_MGR_H
-#include <dhcp/duid.h>
-#include <dhcp/hwaddr.h>
#include <dhcpsrv/base_host_data_source.h>
#include <dhcpsrv/cache_host_data_source.h>
#include <dhcpsrv/database_connection.h>
/// manager to not use the alternate host data source.
static HostMgr& instance();
- /// @brief Returns all hosts for the specified HW address or DUID.
- ///
- /// This method returns all @c Host objects representing reservations for
- /// the specified HW address or/and DUID as documented in the
- /// @c BaseHostDataSource::getAll.
- ///
- /// It retrieves reservations from both primary and alternate host data
- /// source as a single collection of @c Host objects, i.e. if matching
- /// reservations are in both sources, all of them are returned. The
- /// reservations from the primary data source are placed before the
- /// reservations from the alternate source.
- ///
- /// Note that returned collection may contain duplicates. It is the
- /// caller's responsibility to check for duplicates.
- ///
- /// @param hwaddr HW address of the client or NULL if no HW address
- /// available.
- /// @param duid client id or NULL of not available.
- ///
- /// @return Collection of const @c Host objects.
- virtual ConstHostCollection
- getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
-
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
- /// @brief Returns a host connected to the IPv4 subnet.
- ///
- /// This method returns a single reservation for the particular host
- /// (identified by the HW address or DUID) as documented in the
- /// @c BaseHostDataSource::get4.
- ///
- /// @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;
-
/// @brief Returns any host connected to the IPv4 subnet.
///
/// This method returns a single reservation for a particular host as
virtual ConstHostPtr
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @brief Returns a host connected to the IPv6 subnet.
- ///
- /// This method returns a host connected to the IPv6 subnet and identified
- /// by the HW address or DUID, as described in the
- /// @c BaseHostDataSource::get6.
- ///
- /// @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;
-
/// @brief Returns any host connected to the IPv6 subnet.
///
/// This method returns a host connected to the IPv6 subnet as described
/// @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;
for the specified IPv6 address. The arguments specify the IPv6 address
and the detailed description of the host found.
-% HOSTS_CFG_GET_ALL_HWADDR_DUID get all hosts with reservations for HWADDR %1 and DUID %2
-This debug message is issued when starting to retrieve reservations for all hosts
-using specific HW address or DUID. The arguments specify the HW address and
-DUID respectively. The argument specify the HW address and DUID respectively.
-
% HOSTS_CFG_GET_ALL_IDENTIFIER get all hosts with reservations using identifier: %1
This debug message is issued when starting to retrieve reservations for all hosts
identified by HW address or DUID. The argument holds both the identifier
the specific IPv4 address, and it is starting to search for this host
in alternate host data sources.
-% HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_HWADDR_DUID trying alternate sources for host using subnet id %1, HWADDR %2, DUID%3
-This debug message is issued when the Host Manager doesn't find the
-host connected to the specific subnet and identified by the HW address
-or DUID, and it is starting to search for this host in alternate
-host data sources.
-
% HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER get one host with IPv4 reservation for subnet id %1, identified by %2
This debug message is issued when starting to retrieve a host holding
IPv4 reservation, which is connected to a specific subnet and
the specified IPv6 address, and it is starting to search for this
host in alternate host data sources.
-% HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_DUID_HWADDR trying alternate sources for host using subnet id %1, DUID %2, HWADDR %3
-This debug message is issued when the Host Manager doesn't find the
-host connected to the specific subnet and identified by the specified
-DUID or HW Address, and it is starting to search for this host in
-alternate host data sources.
-
% HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER get one host with IPv6 reservation for subnet id %1, identified by %2
This debug message is issued when starting to retrieve a host holding
IPv4 reservation, which is connected to a specific subnet and
-// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-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
return (impl_->delStatement(MySqlHostDataSourceImpl::DEL_HOST_SUBID6_ID, inbind));
}
-ConstHostCollection
-MySqlHostDataSource::getAll(const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
-
- if (duid) {
- return (getAll(Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
-
- } else if (hwaddr) {
- return (getAll(Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
- }
-
- return (ConstHostCollection());
-}
-
ConstHostCollection
MySqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
return (result);
}
-ConstHostPtr
-MySqlHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
-
- /// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "MySQL host data source get4() called with both"
- " hwaddr and duid, only one of them is allowed");
- }
- if (!hwaddr && !duid) {
- isc_throw(BadValue, "MySQL host data source get4() called with "
- "neither hwaddr or duid specified, one of them is required");
- }
-
- // Choosing one of the identifiers
- if (hwaddr) {
- return (get4(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
-
- } else if (duid) {
- return (get4(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
- }
-
- return (ConstHostPtr());
-}
-
ConstHostPtr
MySqlHostDataSource::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (result);
}
-ConstHostPtr
-MySqlHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
-
- /// @todo: Rethink the logic in BaseHostDataSource::get6(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "MySQL host data source get6() called with both"
- " hwaddr and duid, only one of them is allowed");
- }
- if (!hwaddr && !duid) {
- isc_throw(BadValue, "MySQL host data source get6() called with "
- "neither hwaddr or duid specified, one of them is required");
- }
-
- // Choosing one of the identifiers
- if (hwaddr) {
- return (get6(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
- } else if (duid) {
- return (get6(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
- }
-
- return (ConstHostPtr());
-}
-
ConstHostPtr
MySqlHostDataSource::get6(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
-// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-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
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len);
- /// @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;
-
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
- /// @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 MultipleRecords 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;
-
/// @brief Returns a host connected to the IPv4 subnet.
///
/// @param subnet_id Subnet identifier.
virtual ConstHostPtr
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @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 MultipleRecords 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;
-
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
/// @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;
bind_array));
}
-ConstHostCollection
-PgSqlHostDataSource::getAll(const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
-
- if (duid){
- return (getAll(Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
-
- } else if (hwaddr) {
- return (getAll(Host::IDENT_HWADDR,
- &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
- }
-
- return (ConstHostCollection());
-}
-
ConstHostCollection
PgSqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
return (result);
}
-ConstHostPtr
-PgSqlHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid) const {
-
- /// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "PgSQL host data source get4() called with both"
- " hwaddr and duid, only one of them is allowed");
- }
- if (!hwaddr && !duid) {
- isc_throw(BadValue, "PgSQL host data source get4() called with "
- "neither hwaddr or duid specified, one of them is required");
- }
-
- // Choosing one of the identifiers
- if (hwaddr) {
- return (get4(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
-
- } else if (duid) {
- return (get4(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
- }
-
- return (ConstHostPtr());
-}
-
ConstHostPtr
PgSqlHostDataSource::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (result);
}
-ConstHostPtr
-PgSqlHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr) const {
-
- /// @todo: Rethink the logic in BaseHostDataSource::get6(subnet, hwaddr, duid)
- if (hwaddr && duid) {
- isc_throw(BadValue, "PgSQL host data source get6() called with both"
- " hwaddr and duid, only one of them is allowed");
- }
- if (!hwaddr && !duid) {
- isc_throw(BadValue, "PgSQL host data source get6() called with "
- "neither hwaddr or duid specified, one of them is required");
- }
-
- // Choosing one of the identifiers
- if (hwaddr) {
- return (get6(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
- hwaddr->hwaddr_.size()));
- } else if (duid) {
- return (get6(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
- duid->getDuid().size()));
- }
-
- return (ConstHostPtr());
-}
-
ConstHostPtr
PgSqlHostDataSource::get6(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len);
- /// @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;
-
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
- /// @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 MultipleRecords 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;
-
/// @brief Returns a host connected to the IPv4 subnet.
///
/// @param subnet_id Subnet identifier.
virtual ConstHostPtr
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @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 MultipleRecords 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;
-
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
/// @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;
-// 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
// Verify that hosts can be retrieved.
for (unsigned i = 0; i < 25; ++i) {
- // Get host by HW address. The DUID is non-null but the reservation
- // should be returned for the HW address because there are no
- // reservations for the DUIDs from the range of 25 to 49.
- HostCollection hosts = cfg.getAll(hwaddrs_[i], duids_[i + 25]);
+ // Get host by HW address.
+ HostCollection hosts = cfg.getAll(Host::IDENT_HWADDR,
+ &hwaddrs_[i]->hwaddr_[0],
+ hwaddrs_[i]->hwaddr_.size());
ASSERT_EQ(2, hosts.size());
EXPECT_EQ(1, hosts[0]->getIPv4SubnetID());
EXPECT_EQ(addressesa_[i], hosts[0]->getIPv4Reservation().toText());
EXPECT_EQ(2, hosts[1]->getIPv4SubnetID());
EXPECT_EQ(addressesb_[i], hosts[1]->getIPv4Reservation().toText());
- // Get host by DUID. The HW address is non-null but the reservation
- // should be returned for the DUID because there are no
- // reservations for the HW addresses from the range of 25 to 49.
- hosts = cfg.getAll(hwaddrs_[i + 25], duids_[i]);
- ASSERT_EQ(2, hosts.size());
- EXPECT_EQ(1, hosts[0]->getIPv4SubnetID());
- EXPECT_EQ(2, hosts[1]->getIPv4SubnetID());
- }
+ // The HW address is non-null but there are no reservations
+ // for the HW addresses from the range of 25 to 49.
+ hosts = cfg.getAll(Host::IDENT_HWADDR,
+ &hwaddrs_[i + 25]->hwaddr_[0],
+ hwaddrs_[i + 25]->hwaddr_.size());
+ EXPECT_TRUE(hosts.empty());
+
+ // Get host by DUID.
+ hosts = cfg.getAll(Host::IDENT_DUID,
+ &duids_[i]->getDuid()[0],
+ duids_[i]->getDuid().size());
- // The getAll function should return empty containers for the HW addresses
- // and DUIDs for which the reservations haven't been added.
- for (int i = 25; i < 50; ++i) {
- EXPECT_TRUE(cfg.getAll(hwaddrs_[i]).empty());
- EXPECT_TRUE(cfg.getAll(HWAddrPtr(), duids_[i]).empty());
+ // The DUID is non-null but there are no reservations
+ // for the DUIDs from the range of 25 to 49.
+ hosts = cfg.getAll(Host::IDENT_DUID,
+ &duids_[i + 25]->getDuid()[0],
+ duids_[i + 25]->getDuid().size());
+ EXPECT_TRUE(hosts.empty());
}
}
/// Destructor
virtual ~TestOneBackend() { }
- ConstHostCollection getAll(const HWAddrPtr&, const DuidPtr&) const {
- return (getCollection());
- }
-
ConstHostCollection getAll(const Host::IdentifierType&, const uint8_t*,
const size_t) const {
return (getCollection());
return (getCollection());
}
- ConstHostPtr get4(const SubnetID&, const HWAddrPtr&,
- const DuidPtr&) const {
- return (getOne());
- }
-
ConstHostPtr get4(const SubnetID&, const Host::IdentifierType&,
const uint8_t*, const size_t) const {
return (getOne());
return (getOne());
}
- ConstHostPtr get6(const SubnetID&, const DuidPtr&,
- const HWAddrPtr&) const {
- return (getOne());
- }
-
ConstHostPtr get6(const SubnetID&, const Host::IdentifierType&,
const uint8_t*, const size_t) const {
return (getOne());
// Verifies getAll* return a collection with it.
ConstHostCollection hosts;
- ASSERT_NO_THROW(hosts =
- HostMgr::instance().getAll(host->getHWAddress(), DuidPtr()));
- ASSERT_EQ(1, hosts.size());
- EXPECT_EQ(host, hosts[0]);
-
ASSERT_NO_THROW(hosts =
HostMgr::instance().getAll(host->getIdentifierType(),
&host->getIdentifier()[0],
// Verifies get4 overloads return a null pointer.
ConstHostPtr got;
- ASSERT_NO_THROW(got =
- HostMgr::instance().get4(host->getIPv4SubnetID(),
- host->getHWAddress(), DuidPtr()));
- EXPECT_FALSE(got);
-
ASSERT_NO_THROW(got =
HostMgr::instance().get4(host->getIPv4SubnetID(),
host->getIdentifierType(),
// Verifies get6 overloads return a null pointer.
ConstHostPtr got;
- ASSERT_NO_THROW(got =
- HostMgr::instance().get6(host->getIPv6SubnetID(),
- host->getDuid(),
- HWAddrPtr()));
- EXPECT_FALSE(got);
-
ASSERT_NO_THROW(got =
HostMgr::instance().get6(host->getIPv6SubnetID(),
host->getIdentifierType(),
HostMgrTest::testGetAll(BaseHostDataSource& data_source1,
BaseHostDataSource& data_source2) {
// Initially, no reservations should be present.
- ConstHostCollection hosts = HostMgr::instance().getAll(hwaddrs_[0]);
+ ConstHostCollection hosts =
+ HostMgr::instance().getAll(Host::IDENT_HWADDR,
+ &hwaddrs_[1]->hwaddr_[0],
+ hwaddrs_[1]->hwaddr_.size());
ASSERT_TRUE(hosts.empty());
// Add two reservations for the same HW address. They differ by the IP
void
HostMgrTest::testGet4(BaseHostDataSource& data_source) {
// Initially, no host should be present.
- ConstHostPtr host = HostMgr::instance().get4(SubnetID(1), hwaddrs_[0]);
+ ConstHostPtr host =
+ HostMgr::instance().get4(SubnetID(1), Host::IDENT_HWADDR,
+ &hwaddrs_[0]->hwaddr_[0],
+ hwaddrs_[0]->hwaddr_.size());
ASSERT_FALSE(host);
// Add new host to the database.
void
HostMgrTest::testGet6(BaseHostDataSource& data_source) {
// Initially, no host should be present.
- ConstHostPtr host = HostMgr::instance().get6(SubnetID(2), duids_[0]);
+ ConstHostPtr host =
+ HostMgr::instance().get6(SubnetID(2), Host::IDENT_DUID,
+ &duids_[0]->getDuid()[0],
+ duids_[0]->getDuid().size());
ASSERT_FALSE(host);
// Add new host to the database.
-// 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
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(10, hosts[0]->getIPv4SubnetID());
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(hwaddr_));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_HWADDR,
+ &hwaddr_->hwaddr_[0],
+ hwaddr_->hwaddr_.size()));
ASSERT_EQ(1, hosts.size());
const ClientClasses& classes = hosts[0]->getClientClasses4();
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(10, hosts[0]->getIPv4SubnetID());
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(hwaddr_, DuidPtr()));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_HWADDR,
+ &hwaddr_->hwaddr_[0],
+ hwaddr_->hwaddr_.size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(0, hosts[0]->getIPv4SubnetID());
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(0, hosts[0]->getIPv4SubnetID());
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
-
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(0, hosts[0]->getIPv4SubnetID());
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(hwaddr_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_HWADDR,
+ &hwaddr_->hwaddr_[0],
+ hwaddr_->hwaddr_.size()));
ASSERT_EQ(1, hosts.size());
// Retrieve and sanity check name servers.
ASSERT_NO_THROW(cfg_hosts->add(host));
HostCollection hosts;
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
// Retrieve and sanity check DNS servers option.
-// 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
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
// Get the first reservation for the host identified by the HW address.
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(hwaddr_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_HWADDR,
+ &hwaddr_->hwaddr_[0],
+ hwaddr_->hwaddr_.size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(1, hosts[0]->getIPv4SubnetID());
EXPECT_EQ("foo.example.com", hosts[0]->getHostname());
// Get the second reservation for the host identified by the DUID.
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(1, hosts[0]->getIPv4SubnetID());
CfgHostsPtr cfg_hosts = CfgMgr::instance().getStagingCfg()->getCfgHosts();
// Get the reservation for the host identified by the HW address.
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(hwaddr_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_HWADDR,
+ &hwaddr_->hwaddr_[0],
+ hwaddr_->hwaddr_.size()));
ASSERT_EQ(1, hosts.size());
// Make sure it belongs to a valid subnet.
EXPECT_EQ(128, prefixes.first->second.getPrefixLen());
// Validate the second reservation.
- ASSERT_NO_THROW(hosts = cfg_hosts->getAll(HWAddrPtr(), duid_));
+ ASSERT_NO_THROW(hosts = cfg_hosts->getAll(Host::IDENT_DUID,
+ &duid_->getDuid()[0],
+ duid_->getDuid().size()));
ASSERT_EQ(1, hosts.size());
EXPECT_EQ(0, hosts[0]->getIPv4SubnetID());
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv4SubnetID();
- // Fetch the host via:
- // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
- ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
- ASSERT_EQ(1, hosts_by_id.size());
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
-
// Fetch the host via:
// getAll(const Host::IdentifierType, const uint8_t* identifier_begin,
// const size_t identifier_len) const;
- hosts_by_id =
+ ConstHostCollection hosts_by_id =
hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
host->getIdentifier().size());
ASSERT_EQ(1, hosts_by_id.size());
ASSERT_EQ(1, hosts_by_id.size());
ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
- // Fetch the host via
- // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- // const DuidPtr& duid = DuidPtr()) const;
- ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress());
- ASSERT_TRUE(from_hds);
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
-
// Fetch the host via
// get4(const SubnetID& subnet_id, const Host::IdentifierType&
// identifier_type,
// const uint8_t* identifier_begin, const size_t identifier_len) const;
- from_hds =
+ ConstHostPtr from_hds =
hdsptr_->get4(subnet_id, host->getIdentifierType(),
&host->getIdentifier()[0], host->getIdentifier().size());
ASSERT_TRUE(from_hds);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv6SubnetID();
- // Fetch the host via:
- // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
- ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
- ASSERT_EQ(1, hosts_by_id.size());
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
-
// getAll(const Host::IdentifierType& identifier_type,
// const uint8_t* identifier_begin,
// const size_t identifier_len) const;
- hosts_by_id =
+ ConstHostCollection hosts_by_id =
hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
host->getIdentifier().size());
ASSERT_EQ(1, hosts_by_id.size());
ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
- // get6(const SubnetID& subnet_id, const DuidPtr& duid,
- // const HWAddrPtr& hwaddr = HWAddrPtr()) const;
- ConstHostPtr from_hds =
- hdsptr_->get6(subnet_id, DuidPtr(), host->getHWAddress());
- ASSERT_TRUE(from_hds);
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
-
// Fetch the host via:
// get6(const SubnetID& subnet_id, const Host::IdentifierType&
// identifier_type,
// const uint8_t* identifier_begin, const size_t identifier_len) const;
- from_hds =
+ ConstHostPtr from_hds =
hdsptr_->get6(subnet_id, Host::IDENT_HWADDR, &host->getIdentifier()[0],
host->getIdentifier().size());
ASSERT_TRUE(from_hds);
// Subnet id will be used in queries to the database.
SubnetID subnet_id = host->getIPv4SubnetID();
- // Fetch the host via:
- // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
- ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
- ASSERT_EQ(1, hosts_by_id.size());
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
-
// Fetch the host via:
// getAll(const Host::IdentifierType, const uint8_t* identifier_begin,
// const size_t identifier_len) const;
- hosts_by_id =
+ ConstHostCollection hosts_by_id =
hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
host->getIdentifier().size());
ASSERT_EQ(1, hosts_by_id.size());
ASSERT_EQ(1, hosts_by_id.size());
ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
- // Fetch the host via
- // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- // const DuidPtr& duid = DuidPtr()) const;
- ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress());
- ASSERT_TRUE(from_hds);
- ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
-
// Fetch the host via
// get4(const SubnetID& subnet_id, const Host::IdentifierType&
// identifier_type,
// const uint8_t* identifier_begin, const size_t identifier_len) const;
- from_hds =
+ ConstHostPtr from_hds =
hdsptr_->get4(subnet_id, host->getIdentifierType(),
&host->getIdentifier()[0], host->getIdentifier().size());
ASSERT_TRUE(from_hds);
namespace dhcp {
namespace test {
-ConstHostCollection
-MemHostDataSource::getAll(const HWAddrPtr& /*hwaddr*/,
- const DuidPtr& /*duid*/) const {
- return (ConstHostCollection());
-}
-
ConstHostCollection
MemHostDataSource::getAll(const Host::IdentifierType& /*identifier_type*/,
const uint8_t* /*identifier_begin*/,
return (ConstHostCollection());
}
-ConstHostPtr
-MemHostDataSource::get4(const SubnetID& /*subnet_id*/,
- const HWAddrPtr& /*hwaddr*/,
- const DuidPtr& /*duid*/) const {
- return (ConstHostPtr());
-}
-
ConstHostPtr
MemHostDataSource::get4(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
return (ConstHostPtr());
}
-ConstHostPtr
-MemHostDataSource::get6(const SubnetID& /*subnet_id*/,
- const DuidPtr& /*duid*/,
- const HWAddrPtr& /*hwaddr*/) const {
- return (ConstHostPtr());
-}
-
ConstHostPtr
MemHostDataSource::get6(const asiolink::IOAddress& /*prefix*/,
const uint8_t /*prefix_len*/) const {
/// BaseHostDataSource methods.
- /// @brief Return all hosts for the specified HW address or DUID.
- ///
- /// This may return hosts from multiple subnets.
- ///
- /// Currently not implemented.
- ///
- /// @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 Empty collection of const @c Host objects.
- virtual ConstHostCollection
- getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
-
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
- /// @brief Returns a host connected to the IPv4 subnet.
- ///
- /// Currently not implemented.
- ///
- /// @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;
-
/// @brief Returns a host connected to the IPv4 subnet.
///
get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const;
- /// @brief Returns a host connected to the IPv6 subnet.
- ///
- /// Currently not implemented.
- ///
- /// @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;
-
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
///
/// @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;
-// 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
/// @brief Default destructor implementation.
virtual ~WritableHostDataSource() { }
- /// @brief Non-const version of the @c getAll const method.
- ///
- /// 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 non-const @c Host objects.
- virtual HostCollection
- getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) = 0;
-
/// @brief Non-const version of the @c getAll const method.
///
/// This method returns all @c Host objects which represent reservations
virtual HostCollection
getAll4(const asiolink::IOAddress& address) = 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 Non-const @c Host object using a specified HW address or DUID.
- virtual HostPtr
- get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) = 0;
-
/// @brief Returns a host connected to the IPv4 subnet.
///
/// @param subnet_id Subnet identifier.
get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len) = 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 Non-const @c Host object using a specified HW address or DUID.
- virtual HostPtr
- get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr()) = 0;
-
/// @brief Returns a host connected to the IPv6 subnet.
///
/// @param subnet_id Subnet identifier.
/// @param prefix IPv6 prefix for which the @c Host object is searched.
/// @param prefix_len IPv6 prefix length.
///
- /// @return Non-const @c Host object using a specified HW address or DUID.
+ /// @return Non-const @c Host object using a specified IPv6 prefix.
virtual HostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) = 0;