+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2018 Deutsche Telekom AG.
//
// Authors: Razvan Becheriu <razvan.becheriu@qualitance.com>
Lease4Collection
CqlLeaseMgr::getLeases4(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv4 address.
+ if (!lower_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected IPv4 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
if (page_size.page_size_ == 0) {
isc_throw(OutOfRange, "page size of retrieved leases must not be 0");
}
Lease4Collection
CqlLeaseMgr::getLeases4(const IOAddress& lower_bound_address,
const IOAddress& upper_bound_address) const {
+ // Expecting two IPv4 addresses.
+ if (!lower_bound_address.isV4() || !upper_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv4 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
<< " is lower than lower bound address " << lower_bound_address);
Lease6Collection
CqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv6 address.
+ if (!lower_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected IPv6 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
if (page_size.page_size_ == 0) {
isc_throw(OutOfRange, "page size of retrieved leases must not be 0");
}
isc::Exception(file, line, what) {}
};
+/// @brief Invalid address family used as input to Lease Manager.
+class InvalidAddressFamily : public Exception {
+public:
+ InvalidAddressFamily(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what) {}
+};
+
} // namespace isc
} // namespace dhcp
Lease4Collection
Memfile_LeaseMgr::getLeases4(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv4 address.
+ if (!lower_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected IPv4 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_PAGE4)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease4Collection
Memfile_LeaseMgr::getLeases4(const IOAddress& lower_bound_address,
const IOAddress& upper_bound_address) const {
+ // Expecting two IPv4 addresses.
+ if (!lower_bound_address.isV4() || !upper_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv4 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
// Check if the range boundaries aren't swapped.
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
Lease6Collection
Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv6 address.
+ if (!lower_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected IPv6 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_PAGE6)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease6Collection
Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const asiolink::IOAddress& upper_bound_address) const {
+ // Expecting two IPv6 addresses.
+ if (!lower_bound_address.isV6() || !upper_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv6 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
// Check if the range boundaries aren't swapped.
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
Lease4Collection
MySqlLeaseMgr::getLeases4(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv4 address.
+ if (!lower_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected IPv4 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_PAGE4)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease4Collection
MySqlLeaseMgr::getLeases4(const IOAddress& lower_bound_address,
const IOAddress& upper_bound_address) const {
+ // Expecting two IPv4 addresses.
+ if (!lower_bound_address.isV4() || !upper_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv4 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
<< " is lower than lower bound address " << lower_bound_address);
Lease6Collection
MySqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv6 address.
+ if (!lower_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected IPv6 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_PAGE6)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease6Collection
MySqlLeaseMgr::getLeases6(const IOAddress& lower_bound_address,
const IOAddress& upper_bound_address) const {
+ // Expecting two IPv6 addresses.
+ if (!lower_bound_address.isV6() || !upper_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv6 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
<< " is lower than lower bound address " << lower_bound_address);
Lease4Collection
PgSqlLeaseMgr::getLeases4(const asiolink::IOAddress& lower_bound_address,
- const LeasePageSize& page_size) const {
+ const LeasePageSize& page_size) const {
+ // Expecting IPv4 address.
+ if (!lower_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected IPv4 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_PAGE4)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease4Collection
PgSqlLeaseMgr::getLeases4(const IOAddress& lower_bound_address,
const IOAddress& upper_bound_address) const {
+ // Expecting two IPv4 addresses.
+ if (!lower_bound_address.isV4() || !upper_bound_address.isV4()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv4 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
<< " is lower than lower bound address " << lower_bound_address);
Lease6Collection
PgSqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
+ // Expecting IPv6 address.
+ if (!lower_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected IPv6 address while "
+ "retrieving leases from the lease database, got "
+ << lower_bound_address);
+ }
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_PAGE6)
.arg(page_size.page_size_)
.arg(lower_bound_address.toText());
Lease6Collection
PgSqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const asiolink::IOAddress& upper_bound_address) const {
+ // Expecting two IPv6 addresses.
+ if (!lower_bound_address.isV6() || !upper_bound_address.isV6()) {
+ isc_throw(InvalidAddressFamily, "expected two IPv6 addresses for "
+ "retrieving a range of leases, got "
+ << lower_bound_address << " and " << upper_bound_address);
+ }
+
if (upper_bound_address < lower_bound_address) {
isc_throw(InvalidRange, "upper bound address " << upper_bound_address
<< " is lower than lower bound address " << lower_bound_address);
#include <exceptions/exceptions.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/database_connection.h>
+#include <dhcpsrv/db_exceptions.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
#include <dhcpsrv/tests/test_utils.h>
// Zero page size is illegal too.
EXPECT_THROW(lease_page_size.reset(new LeasePageSize(0)), OutOfRange);
+
+ // Only IPv4 address can be used.
+ EXPECT_THROW(lmptr_->getLeases4(IOAddress("2001:db8::1"), LeasePageSize(3)),
+ InvalidAddressFamily);
}
void
// Swapping the lower bound and upper bound should cause an error.
EXPECT_THROW(lmptr_->getLeases4(IOAddress("192.0.2.8"), IOAddress("192.0.2.1")),
InvalidRange);
+
+ // Both must be IPv4 addresses.
+ EXPECT_THROW(lmptr_->getLeases4(IOAddress("192.0.2.3"), IOAddress("2001:db8::8")),
+ InvalidAddressFamily);
+
+ EXPECT_THROW(lmptr_->getLeases4(IOAddress("2001:db8::2"), IOAddress("192.0.2.7")),
+ InvalidAddressFamily);
}
void
EXPECT_TRUE(found) << "lease for address " << lease->addr_.toText()
<< " was not returned in any of the pages";
}
+
+ // Only IPv6 address can be used.
+ EXPECT_THROW(lmptr_->getLeases6(IOAddress("192.0.2.0"), LeasePageSize(3)),
+ InvalidAddressFamily);
+
}
void
// Swapping the lower bound and upper bound should cause an error.
EXPECT_THROW(lmptr_->getLeases6(IOAddress("2001:db8::8"), IOAddress("2001:db8::1")),
InvalidRange);
+
+ // Both must be IPv6 addresses.
+ EXPECT_THROW(lmptr_->getLeases6(IOAddress("192.0.2.3"), IOAddress("2001:db8::8")),
+ InvalidAddressFamily);
+
+ EXPECT_THROW(lmptr_->getLeases6(IOAddress("2001:db8::2"), IOAddress("192.0.2.7")),
+ InvalidAddressFamily);
}
void