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) { ...@@ -4421,19 +4421,21 @@ TEST_F(Dhcp4ParserTest, reservations) {
// Let's create an object holding hardware address of the host having // Let's create an object holding hardware address of the host having
// a reservation in the subnet having id of 234. For simplicity the // a reservation in the subnet having id of 234. For simplicity the
// address is a collection of numbers from 1 to 6. // 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) { 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. // 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); ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.120", host->getIPv4Reservation().toText()); EXPECT_EQ("192.0.3.120", host->getIPv4Reservation().toText());
// This reservation should be solely assigned to the subnet 234, // This reservation should be solely assigned to the subnet 234,
// and not to other two. // and not to other two.
EXPECT_FALSE(hosts_cfg->get4(123, hwaddr)); EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_HWADDR,
EXPECT_FALSE(hosts_cfg->get4(542, hwaddr)); &hwaddr[0], hwaddr.size()));
EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
// Check that options are assigned correctly. // Check that options are assigned correctly.
Option4AddrLstPtr opt_dns = Option4AddrLstPtr opt_dns =
retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
...@@ -4447,16 +4449,15 @@ TEST_F(Dhcp4ParserTest, reservations) { ...@@ -4447,16 +4449,15 @@ TEST_F(Dhcp4ParserTest, reservations) {
EXPECT_EQ(11, static_cast<int>(opt_ttl->getValue())); EXPECT_EQ(11, static_cast<int>(opt_ttl->getValue()));
// Do the same test for the DUID based reservation. // 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) { 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, Host::IDENT_DUID, &duid[0], duid.size());
host = hosts_cfg->get4(234, HWAddrPtr(), duid);
ASSERT_TRUE(host); ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText()); EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText());
EXPECT_FALSE(hosts_cfg->get4(123, HWAddrPtr(), duid)); EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size()));
EXPECT_FALSE(hosts_cfg->get4(542, HWAddrPtr(), duid)); EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size()));
// Check that options are assigned correctly. // Check that options are assigned correctly.
opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
ASSERT_TRUE(opt_dns); ASSERT_TRUE(opt_dns);
...@@ -4470,7 +4471,7 @@ TEST_F(Dhcp4ParserTest, reservations) { ...@@ -4470,7 +4471,7 @@ TEST_F(Dhcp4ParserTest, reservations) {
// The circuit-id used for one of the reservations in the subnet 542 // 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 // consists of numbers from 6 to 1. So, let's just reverse the order
// of the address from the previous test. // 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], host = hosts_cfg->get4(542, Host::IDENT_CIRCUIT_ID, &circuit_id[0],
circuit_id.size()); circuit_id.size());
EXPECT_TRUE(host); EXPECT_TRUE(host);
...@@ -4483,13 +4484,14 @@ TEST_F(Dhcp4ParserTest, reservations) { ...@@ -4483,13 +4484,14 @@ TEST_F(Dhcp4ParserTest, reservations) {
// Repeat the test for the DUID based reservation in this subnet. // Repeat the test for the DUID based reservation in this subnet.
duid.reset(new DUID(std::vector<uint8_t>(duid_vec.rbegin(), std::vector<uint8_t> duid_r(duid.rbegin(), duid.rend());
duid_vec.rend()))); host = hosts_cfg->get4(542, Host::IDENT_DUID, &duid_r[0], duid_r.size());
host = hosts_cfg->get4(542, HWAddrPtr(), duid);
ASSERT_TRUE(host); ASSERT_TRUE(host);
EXPECT_EQ("192.0.4.101", host->getIPv4Reservation().toText()); EXPECT_EQ("192.0.4.101", host->getIPv4Reservation().toText());
EXPECT_FALSE(hosts_cfg->get4(123, HWAddrPtr(), duid)); EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID,
EXPECT_FALSE(hosts_cfg->get4(234, HWAddrPtr(), 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. // Check that options are assigned correctly.
opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS);
ASSERT_TRUE(opt_dns); ASSERT_TRUE(opt_dns);
...@@ -4564,13 +4566,13 @@ TEST_F(Dhcp4ParserTest, reservationWithOptionDefinition) { ...@@ -4564,13 +4566,13 @@ TEST_F(Dhcp4ParserTest, reservationWithOptionDefinition) {
// Let's create an object holding DUID of the host. For simplicity the // Let's create an object holding DUID of the host. For simplicity the
// address is a collection of numbers from 1 to A. // 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) { 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. // 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); ASSERT_TRUE(host);
EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText()); EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText());
...@@ -5992,9 +5994,9 @@ TEST_F(Dhcp4ParserTest, comments) { ...@@ -5992,9 +5994,9 @@ TEST_F(Dhcp4ParserTest, comments) {
// The subnet has a host reservation. // The subnet has a host reservation.
uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
HWAddrPtr hwaddr(new HWAddr(hw, sizeof(hw), HTYPE_ETHER));
ConstHostPtr host = 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); ASSERT_TRUE(host);
EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType()); EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType());
EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false)); 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 // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -4694,13 +4694,13 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4694,13 +4694,13 @@ TEST_F(Dhcp6ParserTest, reservations) {
// Let's create an object holding hardware address of the host having // Let's create an object holding hardware address of the host having
// a reservation in the subnet having id of 234. For simplicity the // a reservation in the subnet having id of 234. For simplicity the
// address is a collection of numbers from 1 to 6. // 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) { 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. // 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); ASSERT_TRUE(host);
IPv6ResrvRange resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA); IPv6ResrvRange resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second)); ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
...@@ -4709,8 +4709,10 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4709,8 +4709,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
resrv)); resrv));
// This reservation should be solely assigned to the subnet 234, // This reservation should be solely assigned to the subnet 234,
// and not to other two. // and not to other two.
EXPECT_FALSE(hosts_cfg->get6(123, DuidPtr(), hwaddr)); EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_HWADDR,
EXPECT_FALSE(hosts_cfg->get6(542, DuidPtr(), hwaddr)); &hwaddr[0], hwaddr.size()));
EXPECT_FALSE(hosts_cfg->get6(542, Host::IDENT_HWADDR,
&hwaddr[0], hwaddr.size()));
// Check that options are assigned correctly. // Check that options are assigned correctly.
Option6AddrLstPtr opt_dns = Option6AddrLstPtr opt_dns =
retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS); retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
...@@ -4724,20 +4726,19 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4724,20 +4726,19 @@ TEST_F(Dhcp6ParserTest, reservations) {
EXPECT_EQ(25, static_cast<int>(opt_prf->getValue())); EXPECT_EQ(25, static_cast<int>(opt_prf->getValue()));
// Do the same test for the DUID based reservation. // 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) { 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, Host::IDENT_DUID, &duid[0], duid.size());
host = hosts_cfg->get6(234, duid);
ASSERT_TRUE(host); ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA); resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second)); ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA, EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
IOAddress("2001:db8:2::1234")), IOAddress("2001:db8:2::1234")),
resrv)); resrv));
EXPECT_FALSE(hosts_cfg->get6(123, duid)); EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_DUID, &duid[0], duid.size()));
EXPECT_FALSE(hosts_cfg->get6(542, duid)); EXPECT_FALSE(hosts_cfg->get6(542, Host::IDENT_DUID, &duid[0], duid.size()));
// Check that options are assigned correctly. // Check that options are assigned correctly.
opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS); opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
ASSERT_TRUE(opt_dns); ASSERT_TRUE(opt_dns);
...@@ -4752,9 +4753,10 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4752,9 +4753,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
// The HW address used for one of the reservations in the subnet 542 // 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 // consists of numbers from 6 to 1. So, let's just reverse the order
// of the address from the previous test. // of the address from the previous test.
hwaddr->hwaddr_.assign(hwaddr_vec.rbegin(), hwaddr_vec.rend()); std::vector<uint8_t> hwaddr_r(hwaddr.rbegin(), hwaddr.rend());
host = hosts_cfg->get6(542, DuidPtr(), hwaddr); host = hosts_cfg->get6(542, Host::IDENT_HWADDR,
EXPECT_TRUE(host); &hwaddr_r[0], hwaddr_r.size());
ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD); resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second)); ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD, EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
...@@ -4762,13 +4764,14 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4762,13 +4764,14 @@ TEST_F(Dhcp6ParserTest, reservations) {
96), resrv)); 96), resrv));
// This reservation must not belong to other subnets. // This reservation must not belong to other subnets.
EXPECT_FALSE(hosts_cfg->get6(123, DuidPtr(), hwaddr)); EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_HWADDR,
EXPECT_FALSE(hosts_cfg->get6(234, DuidPtr(), 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. // Repeat the test for the DUID based reservation in this subnet.
duid.reset(new DUID(std::vector<uint8_t>(duid_vec.rbegin(), std::vector<uint8_t> duid_r(duid.rbegin(), duid.rend());
duid_vec.rend()))); host = hosts_cfg->get6(542, Host::IDENT_DUID, &duid_r[0], duid_r.size());
host = hosts_cfg->get6(542, duid);
ASSERT_TRUE(host); ASSERT_TRUE(host);
resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD); resrv = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
ASSERT_EQ(1, std::distance(resrv.first, resrv.second)); ASSERT_EQ(1, std::distance(resrv.first, resrv.second));
...@@ -4776,8 +4779,10 @@ TEST_F(Dhcp6ParserTest, reservations) { ...@@ -4776,8 +4779,10 @@ TEST_F(Dhcp6ParserTest, reservations) {
IOAddress("2001:db8:3:2::"), IOAddress("2001:db8:3:2::"),
96), resrv)); 96), resrv));
EXPECT_FALSE(hosts_cfg->get6(123, duid)); EXPECT_FALSE(hosts_cfg->get6(123, Host::IDENT_DUID,
EXPECT_FALSE(hosts_cfg->get6(234, 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. // Check that options are assigned correctly.
opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS); opt_dns = retrieveOption<Option6AddrLstPtr>(*host, D6O_NAME_SERVERS);
ASSERT_TRUE(opt_dns); ASSERT_TRUE(opt_dns);
...@@ -4842,13 +4847,13 @@ TEST_F(Dhcp6ParserTest, reservationWithOptionDefinition) { ...@@ -4842,13 +4847,13 @@ TEST_F(Dhcp6ParserTest, reservationWithOptionDefinition) {
// Let's create an object holding DUID of the host. For simplicity the // Let's create an object holding DUID of the host. For simplicity the
// address is a collection of numbers from 1 to A. // 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) { 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. // 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); ASSERT_TRUE(host);
// Check if the option has been parsed. // Check if the option has been parsed.
...@@ -6566,9 +6571,9 @@ TEST_F(Dhcp6ParserTest, comments) { ...@@ -6566,9 +6571,9 @@ TEST_F(Dhcp6ParserTest, comments) {
// The subnet has a host reservation. // The subnet has a host reservation.
uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
HWAddrPtr hwaddr(new HWAddr(hw, sizeof(hw), HTYPE_ETHER));
ConstHostPtr host = 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); ASSERT_TRUE(host);
EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType()); EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType());
EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false)); EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false));
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#define BASE_HOST_DATA_SOURCE_H #define BASE_HOST_DATA_SOURCE_H
#include <asiolink/io_address.h> #include <asiolink/io_address.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/host.h> #include <dhcpsrv/host.h>
#include <exceptions/exceptions.h> #include <exceptions/exceptions.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
...@@ -76,30 +74,6 @@ public: ...@@ -76,30 +74,6 @@ public:
/// @brief Default destructor implementation. /// @brief Default destructor implementation.
virtual ~BaseHostDataSource() { } 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 /// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier. /// have been made using a specified identifier.
/// ///
...@@ -129,25 +103,6 @@ public: ...@@ -129,25 +103,6 @@ public:
virtual ConstHostCollection virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const = 0; 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. /// @brief Returns a host connected to the IPv4 subnet.
/// ///
/// @param subnet_id Subnet identifier. /// @param subnet_id Subnet identifier.
...@@ -184,24 +139,6 @@ public: ...@@ -184,24 +139,6 @@ public:
get4(const SubnetID& subnet_id, get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const = 0; 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. /// @brief Returns a host connected to the IPv6 subnet.
/// ///
/// @param subnet_id Subnet identifier. /// @param subnet_id Subnet identifier.
...@@ -223,7 +160,7 @@ public: ...@@ -223,7 +160,7 @@ public:
/// @param prefix IPv6 prefix for which the @c Host object is searched. /// @param prefix IPv6 prefix for which the @c Host object is searched.
/// @param prefix_len IPv6 prefix length. /// @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 virtual ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0; 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 // 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 // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h> #include <config.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/cfg_hosts.h> #include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_hosts_util.h> #include <dhcpsrv/cfg_hosts_util.h>
#include <dhcpsrv/hosts_log.h> #include <dhcpsrv/hosts_log.h>
...@@ -21,24 +23,6 @@ using namespace isc::data; ...@@ -21,24 +23,6 @@ using namespace isc::data;
namespace isc { namespace isc {
namespace dhcp { 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 ConstHostCollection
CfgHosts::getAll(const Host::IdentifierType& identifier_type, CfgHosts::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const uint8_t* identifier_begin,
...@@ -137,26 +121,6 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type, ...@@ -137,26 +121,6 @@ CfgHosts::getAllInternal(const Host::IdentifierType& identifier_type,
.arg(storage.size()); .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> template<typename Storage>
void void
CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const { CfgHosts::getAllInternal4(const IOAddress& address, Storage& storage) const {
...@@ -215,44 +179,6 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const { ...@@ -215,44 +179,6 @@ CfgHosts::getAllInternal6(const IOAddress& address, Storage& storage) const {
.arg(storage.size()); .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 ConstHostPtr
CfgHosts::get4(const SubnetID& subnet_id,