BIND 10 master, updated. b25d6802e2236e06c9eb83a9508cb9bfca048563 [master] ChangeLog for trac2546
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 13 13:27:09 UTC 2012
The branch, master has been updated
via b25d6802e2236e06c9eb83a9508cb9bfca048563 (commit)
via 0140368ed066c722e5d11d7f9cf1c01462cf7e13 (commit)
via fecfe82bdfc93fedc24263a8f1bbdcedf59a7b71 (commit)
via 52d965040ccb6e919a34abd95240fee3718c0247 (commit)
via a69ebe7341bfbbc01037e71e66b0c6e7121ca6cd (commit)
via 4f17a81c04b1364a0835e9a9b9c26adc6c159cd3 (commit)
via 7942b605f69740f853100f36abad05e9a98d1e90 (commit)
via e4e8de317591b5ac9fec818693fb2cdc5ce9e2a3 (commit)
via 03b92733bfd3c13bc86c8f878b274cf33740ef15 (commit)
via d87597de14b3c81e481b51ea6de8b3273305487a (commit)
via 084a16684541f0d19e99998a2a29a92619ee0b94 (commit)
from ce492ecf70bdd3fe483a7f4282e98443f72b6989 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b25d6802e2236e06c9eb83a9508cb9bfca048563
Author: Stephen Morris <stephen at isc.org>
Date: Thu Dec 13 13:26:36 2012 +0000
[master] ChangeLog for trac2546
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 6 ++
doc/devel/02-dhcp.dox | 4 +-
doc/devel/mainpage.dox | 14 +--
src/bin/dhcp4/config_parser.cc | 10 +-
src/bin/dhcp4/ctrl_dhcp4_srv.cc | 2 +-
src/bin/dhcp4/ctrl_dhcp4_srv.h | 4 +-
src/bin/dhcp4/dhcp4.dox | 10 +-
src/bin/dhcp4/dhcp4_srv.h | 4 +-
src/bin/dhcp6/config_parser.cc | 14 +--
src/bin/dhcp6/ctrl_dhcp6_srv.cc | 1 -
src/bin/dhcp6/ctrl_dhcp6_srv.h | 4 +-
src/bin/dhcp6/dhcp6.dox | 6 +-
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc | 6 +-
src/lib/dhcp/duid.h | 3 +
src/lib/dhcp/option.h | 2 +-
src/lib/dhcp/option4_addrlst.h | 4 +-
src/lib/dhcp/option6_addrlst.h | 4 +-
src/lib/dhcp/option_custom.h | 3 +-
src/lib/dhcp/pkt4.cc | 57 +++++++-----
src/lib/dhcp/pkt4.h | 22 ++---
src/lib/dhcp/pkt6.h | 12 ++-
src/lib/dhcp/tests/pkt4_unittest.cc | 11 ++-
src/lib/dhcpsrv/addr_utilities.h | 8 +-
src/lib/dhcpsrv/alloc_engine.cc | 2 +-
src/lib/dhcpsrv/cfgmgr.h | 3 +
src/lib/dhcpsrv/database_backends.dox | 2 +-
src/lib/dhcpsrv/lease_mgr.h | 96 ++++++++------------
src/lib/dhcpsrv/memfile_lease_mgr.cc | 28 +++---
src/lib/dhcpsrv/memfile_lease_mgr.h | 22 +----
src/lib/dhcpsrv/mysql_lease_mgr.cc | 71 +++++----------
src/lib/dhcpsrv/mysql_lease_mgr.h | 40 +-------
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc | 24 +----
.../dhcpsrv/tests/memfile_lease_mgr_unittest.cc | 4 +-
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc | 89 ++++++------------
src/lib/dhcpsrv/triplet.h | 2 +-
35 files changed, 245 insertions(+), 349 deletions(-)
-----------------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index 9164587..eb15baf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+526. [bug] syephen
+ Miscellaneous fixes to DHCP code including rationalisation of
+ some methods in LeaseMgr and resolving some Doxygen/cppcheck
+ issues.
+ (Trac #2546, git 0140368ed066c722e5d11d7f9cf1c01462cf7e13)
+
525. [func] tomek
b10-dhcp4: DHCPv4 server is now able to parse configuration. It
is possible to specify IPv4 subnets with dynamic pools within
diff --git a/doc/devel/02-dhcp.dox b/doc/devel/02-dhcp.dox
index 5c59daa..b98920f 100644
--- a/doc/devel/02-dhcp.dox
+++ b/doc/devel/02-dhcp.dox
@@ -19,7 +19,7 @@
*
* @section dhcpv4Session BIND10 message queue integration
*
- * DHCPv4 server component is now integrated with BIND10 message queue.
+ * DHCPv4 server component is now integrated with the BIND10 message queue.
* The integration is performed by establishSession() and disconnectSession()
* functions in isc::dhcp::ControlledDhcpv4Srv class. main() method deifined
* in the src/bin/dhcp4/main.cc file instantiates isc::dhcp::ControlledDhcpv4Srv
@@ -57,4 +57,4 @@
* that does not support msgq. That is useful for embedded environments.
* It may also be useful in validation.
*
- */
\ No newline at end of file
+ */
diff --git a/doc/devel/mainpage.dox b/doc/devel/mainpage.dox
index 407723e..295fd03 100644
--- a/doc/devel/mainpage.dox
+++ b/doc/devel/mainpage.dox
@@ -21,13 +21,13 @@
*
* @section DHCP
* - @subpage dhcp4
- * - @subpage dhcp4-session
- * - @subpage dhcp4-config-parser
- * - @subpage dhcp4-config-inherit
+ * - @subpage dhcpv4Session
+ * - @subpage dhcpv4ConfigParser
+ * - @subpage dhcpv4ConfigInherit
* - @subpage dhcp6
- * - @subpage dhcp6-session
- * - @subpage dhcp6-config-parser
- * - @subpage dhcp6-config-inherit
+ * - @subpage dhcpv6Session
+ * - @subpage dhcpv6ConfigParser
+ * - @subpage dhcpv6ConfigInherit
* - @subpage libdhcp
* - @subpage libdhcpIntro
* - @subpage libdhcpIfaceMgr
@@ -35,7 +35,7 @@
* - @subpage leasemgr
* - @subpage cfgmgr
* - @subpage allocengine
- * - @subpage dhcp-database-backends
+ * - @subpage dhcpDatabaseBackends
* - @subpage perfdhcpInternals
*
* @section misc Miscellaneous topics
diff --git a/src/bin/dhcp4/config_parser.cc b/src/bin/dhcp4/config_parser.cc
index aa2fa4f..08d16f8 100644
--- a/src/bin/dhcp4/config_parser.cc
+++ b/src/bin/dhcp4/config_parser.cc
@@ -120,7 +120,7 @@ private:
/// in its base class, \ref Dhcp4ConfigParser.
///
/// For overview of usability of this generic purpose parser, see
-/// \ref dhcp4-config-inherit page.
+/// \ref dhcpv4ConfigInherit page.
class Uint32Parser : public Dhcp4ConfigParser {
public:
@@ -181,7 +181,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp4-config-inherit for details.
+ /// See \ref dhcpv4ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(Uint32Storage* storage) {
@@ -209,7 +209,7 @@ private:
/// in its base class, \ref Dhcp4ConfigParser.
///
/// For overview of usability of this generic purpose parser, see
-/// \ref dhcp4-config-inherit page.
+/// \ref dhcpv4ConfigInherit page.
class StringParser : public Dhcp4ConfigParser {
public:
@@ -252,7 +252,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp4-config-inherit for details.
+ /// See \ref dhcpv4ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(StringStorage* storage) {
@@ -422,7 +422,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp4-config-inherit for details.
+ /// See \ref dhcpv4ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(PoolStorage* storage) {
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
index 20eedeb..eb5d482 100644
--- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc
+++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
@@ -127,7 +127,7 @@ void ControlledDhcpv4Srv::establishSession() {
/// Integrate the asynchronous I/O model of BIND 10 configuration
/// control with the "select" model of the DHCP server. This is
- /// fully explained in \ref dhcp4-session.
+ /// fully explained in \ref dhcpv4Session.
int ctrl_socket = cc_session_->getSocketDesc();
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_CCSESSION_STARTED)
.arg(ctrl_socket);
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.h b/src/bin/dhcp4/ctrl_dhcp4_srv.h
index c1a26cc..9bd261c 100644
--- a/src/bin/dhcp4/ctrl_dhcp4_srv.h
+++ b/src/bin/dhcp4/ctrl_dhcp4_srv.h
@@ -34,7 +34,7 @@ namespace dhcp {
/// embedded environments.
///
/// For detailed explanation or relations between main(), ControlledDhcpv4Srv,
-/// Dhcpv4Srv and other classes, see \ref dhcp4-session.
+/// Dhcpv4Srv and other classes, see \ref dhcpv4Session.
class ControlledDhcpv4Srv : public isc::dhcp::Dhcpv4Srv {
public:
@@ -66,6 +66,8 @@ public:
/// @brief Session callback, processes received commands.
///
+ /// @param command Text represenation of the command (e.g. "shutdown")
+ /// @param args Optional parameters
/// @param command text represenation of the command (e.g. "shutdown")
/// @param args optional parameters
///
diff --git a/src/bin/dhcp4/dhcp4.dox b/src/bin/dhcp4/dhcp4.dox
index 54f2bd3..05f1670 100644
--- a/src/bin/dhcp4/dhcp4.dox
+++ b/src/bin/dhcp4/dhcp4.dox
@@ -15,7 +15,7 @@ DHCPv4 server component does not support direct traffic (relayed
only), as support for transmission to hosts without IPv4 address
assigned is not implemented in IfaceMgr yet.
- at section dhcp4-session BIND10 message queue integration
+ at section dhcpv4Session BIND10 message queue integration
DHCPv4 server component is now integrated with BIND10 message queue.
The integration is performed by establishSession() and disconnectSession()
@@ -55,14 +55,14 @@ possible to instantiate Dhcpv4Srv object directly, thus getting a server
that does not support msgq. That is useful for embedded environments.
It may also be useful in validation.
- at section dhcp4-config-parser Configuration Parser in DHCPv4
+ at section dhcpv4ConfigParser Configuration Parser in DHCPv4
This parser follows exactly the same logic as its DHCPv6 counterpart.
-See \ref dhcp6-config-parser.
+See \ref dhcpv6ConfigParser.
- at section dhcp4-config-inherit DHCPv4 configuration inheritance
+ at section dhcpv4ConfigInherit DHCPv4 configuration inheritance
Configuration inheritance in DHCPv4 follows exactly the same logic as its DHCPv6
-counterpart. See \ref dhcp6-config-inherit.
+counterpart. See \ref dhcpv6ConfigInherit.
*/
diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h
index 724b351..db4b4bc 100644
--- a/src/bin/dhcp4/dhcp4_srv.h
+++ b/src/bin/dhcp4/dhcp4_srv.h
@@ -36,11 +36,11 @@ namespace dhcp {
/// appropriate responses.
///
/// This class does not support any controlling mechanisms directly.
-/// See derived \ref ControlledDhcpv4Srv class for support for
+/// See the derived \ref ControlledDhcpv4Srv class for support for
/// command and configuration updates over msgq.
///
/// For detailed explanation or relations between main(), ControlledDhcpv4Srv,
-/// Dhcpv4Srv and other classes, see \ref dhcp4-session.
+/// Dhcpv4Srv and other classes, see \ref dhcpv4Session.
class Dhcpv4Srv : public boost::noncopyable {
public:
diff --git a/src/bin/dhcp6/config_parser.cc b/src/bin/dhcp6/config_parser.cc
index 3db6aec..4c6fab1 100644
--- a/src/bin/dhcp6/config_parser.cc
+++ b/src/bin/dhcp6/config_parser.cc
@@ -147,7 +147,7 @@ private:
/// in its base class, \ref DhcpConfigParser.
///
/// For overview of usability of this generic purpose parser, see
-/// \ref dhcp6-config-inherit page.
+/// \ref dhcpv6ConfigInherit page.
///
/// @todo this class should be turned into the template class which
/// will handle all uintX_types of data (see ticket #2415).
@@ -222,7 +222,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp6-config-inherit for details.
+ /// See \ref dhcpv6ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(Uint32Storage* storage) {
@@ -250,7 +250,7 @@ private:
/// in its base class, \ref DhcpConfigParser.
///
/// For overview of usability of this generic purpose parser, see
-/// \ref dhcp6-config-inherit page.
+/// \ref dhcpv6ConfigInherit page.
class StringParser : public DhcpConfigParser {
public:
@@ -294,7 +294,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp6-config-inherit for details.
+ /// See \ref dhcpv6ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(StringStorage* storage) {
@@ -341,7 +341,7 @@ public:
/// @brief parses parameters value
///
/// Parses configuration entry (list of parameters) and stores it in
- /// storage. See \ref setStorage() for details.
+ /// storage.
///
/// @param value pointer to the content of parsed values
virtual void build(ConstElementPtr value) {
@@ -446,7 +446,7 @@ public:
pos = txt.find("-");
if (pos != string::npos) {
// using min-max notation
- IOAddress min(txt.substr(0,pos));
+ IOAddress min(txt.substr(0, pos));
IOAddress max(txt.substr(pos + 1));
Pool6Ptr pool(new Pool6(Pool6::TYPE_IA, min, max));
@@ -463,7 +463,7 @@ public:
/// @brief sets storage for value of this parameter
///
- /// See \ref dhcp6-config-inherit for details.
+ /// See \ref dhcpv6ConfigInherit for details.
///
/// @param storage pointer to the storage container
void setStorage(PoolStorage* storage) {
diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc
index 5d4d990..8611365 100644
--- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc
+++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc
@@ -17,7 +17,6 @@
#include <asiolink/asiolink.h>
#include <cc/data.h>
#include <cc/session.h>
-#include <cc/session.h>
#include <config/ccsession.h>
#include <dhcp/iface_mgr.h>
#include <dhcp6/config_parser.h>
diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.h b/src/bin/dhcp6/ctrl_dhcp6_srv.h
index 22cb3b6..ef1acab 100644
--- a/src/bin/dhcp6/ctrl_dhcp6_srv.h
+++ b/src/bin/dhcp6/ctrl_dhcp6_srv.h
@@ -68,8 +68,8 @@ public:
/// @brief Session callback, processes received commands.
///
- /// @param command_id text represenation of the command (e.g. "shutdown")
- /// @param args optional parameters
+ /// @param command Text represenation of the command (e.g. "shutdown")
+ /// @param args Optional parameters
///
/// @return status of the command
static isc::data::ConstElementPtr
diff --git a/src/bin/dhcp6/dhcp6.dox b/src/bin/dhcp6/dhcp6.dox
index 7e9204a..5350fd8 100644
--- a/src/bin/dhcp6/dhcp6.dox
+++ b/src/bin/dhcp6/dhcp6.dox
@@ -16,13 +16,13 @@
DHCPv6 server component does not use BIND10 logging yet.
- @section dhcp6-session BIND10 message queue integration
+ @section dhcpv6Session BIND10 message queue integration
DHCPv4 server component is now integrated with BIND10 message queue.
It follows the same principle as DHCPv4. See \ref dhcpv4Session for
details.
- @section dhcp6-config-parser Configuration Parser in DHCPv6
+ @section dhcpv6ConfigParser Configuration Parser in DHCPv6
b10-dhcp6 component uses BIND10 cfgmgr for commands and configuration. During
initial configuration (See \ref
@@ -49,7 +49,7 @@
elements and creates parsers for a given scope. This process may be repeated
(sort of) recursively.
- @section dhcp6-config-inherit DHCPv6 Configuration Inheritance
+ @section dhcpv6ConfigInherit DHCPv6 Configuration Inheritance
One notable useful feature of DHCP configuration is its parameter inheritance.
For example, renew-timer value may be specified at a global scope and it then
diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
index 03bf309..de0dc28 100644
--- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
+++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
@@ -706,7 +706,7 @@ TEST_F(Dhcpv6SrvTest, RequestBasic) {
// check that the lease is really in the database
Lease6Ptr l = checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
EXPECT_TRUE(l);
- LeaseMgrFactory::instance().deleteLease6(addr->getAddress());
+ LeaseMgrFactory::instance().deleteLease(addr->getAddress());
}
// This test checks that the server is offering different addresses to different
@@ -876,7 +876,7 @@ TEST_F(Dhcpv6SrvTest, RenewBasic) {
// equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected));
- EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease6(addr_opt->getAddress()));
+ EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress()));
}
// This test verifies that incoming (invalid) RENEW can be handled properly.
@@ -986,7 +986,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
// Verify that the lease was not updated.
EXPECT_EQ(123, lease->cltt_);
- EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease6(addr));
+ EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr));
}
// This test verifies if the status code option is generated properly.
diff --git a/src/lib/dhcp/duid.h b/src/lib/dhcp/duid.h
index 1b75f73..60b9706 100644
--- a/src/lib/dhcp/duid.h
+++ b/src/lib/dhcp/duid.h
@@ -114,6 +114,9 @@ public:
bool operator!=(const ClientId& other) const;
};
+/// @brief Shared pointer to a Client ID.
+typedef boost::shared_ptr<ClientId> ClientIdPtr;
+
}; // end of isc::dhcp namespace
}; // end of isc namespace
diff --git a/src/lib/dhcp/option.h b/src/lib/dhcp/option.h
index 29f0f01..3c7799f 100644
--- a/src/lib/dhcp/option.h
+++ b/src/lib/dhcp/option.h
@@ -152,7 +152,7 @@ public:
/// @brief returns option universe (V4 or V6)
///
/// @return universe type
- Universe getUniverse() { return universe_; };
+ Universe getUniverse() const { return universe_; };
/// @brief Writes option in wire-format to a buffer.
///
diff --git a/src/lib/dhcp/option4_addrlst.h b/src/lib/dhcp/option4_addrlst.h
index b266cbf..927f75b 100644
--- a/src/lib/dhcp/option4_addrlst.h
+++ b/src/lib/dhcp/option4_addrlst.h
@@ -111,10 +111,10 @@ public:
/// We return a copy of our list. Although this includes overhead,
/// it also makes this list safe to use after this option object
/// is no longer available. As options are expected to hold only
- /// a couple (1-3) addresses, the overhead is not that big.
+ /// a few (1-3) addresses, the overhead is not that big.
///
/// @return address container with addresses
- AddressContainer getAddresses() { return addrs_; };
+ AddressContainer getAddresses() const { return addrs_; };
/// @brief Sets addresses list.
///
diff --git a/src/lib/dhcp/option6_addrlst.h b/src/lib/dhcp/option6_addrlst.h
index b9c0deb..8327201 100644
--- a/src/lib/dhcp/option6_addrlst.h
+++ b/src/lib/dhcp/option6_addrlst.h
@@ -82,10 +82,10 @@ public:
/// We return a copy of our list. Although this includes overhead,
/// it also makes this list safe to use after this option object
/// is no longer available. As options are expected to hold only
- /// a couple (1-3) addresses, the overhead is not that big.
+ /// a few (1-3) addresses, the overhead is not that big.
///
/// @return address container with addresses
- AddressContainer getAddresses() { return addrs_; };
+ AddressContainer getAddresses() const { return addrs_; };
// returns data length (data length + DHCPv4/DHCPv6 option header)
virtual uint16_t len();
diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h
index d9a4c18..0ee4688 100644
--- a/src/lib/dhcp/option_custom.h
+++ b/src/lib/dhcp/option_custom.h
@@ -174,7 +174,6 @@ public:
/// @brief Read a buffer as FQDN.
///
/// @param index buffer index.
- /// @param [out] len number of bytes read from a buffer.
///
/// @throw isc::OutOfRange if buffer index is out of range.
/// @throw isc::dhcp::BadDataTypeCast if a buffer being read
@@ -246,7 +245,7 @@ public:
/// @brief Write a string value into a buffer.
///
/// @param text the string value to be written.
- /// @param buffer index.
+ /// @param index buffer index.
void writeString(const std::string& text,
const uint32_t index = 0);
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index 5be8211..15c885c 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -18,6 +18,7 @@
#include <dhcp/pkt4.h>
#include <exceptions/exceptions.h>
+#include <algorithm>
#include <iostream>
#include <sstream>
@@ -78,6 +79,9 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len
<< ") received, at least " << DHCPV4_PKT_HDR_LEN
<< " is expected.");
+
+ } else if (data == NULL) {
+ isc_throw(InvalidParameter, "data buffer passed to Pkt4 is NULL");
}
data_.resize(len);
@@ -158,7 +162,7 @@ Pkt4::unpack() {
// this is *NOT* DHCP packet. It does not have any DHCPv4 options. In
// particular, it does not have magic cookie, a 4 byte sequence that
// differentiates between DHCP and BOOTP packets.
- isc_throw(InvalidOperation, "Recevied BOOTP packet. BOOTP is not supported.");
+ isc_throw(InvalidOperation, "Received BOOTP packet. BOOTP is not supported.");
}
if (bufferIn.getLength() - bufferIn.getPosition() < 4) {
@@ -178,8 +182,8 @@ Pkt4::unpack() {
bufferIn.readVector(optsBuffer, opts_len);
LibDHCP::unpackOptions4(optsBuffer, options_);
- // TODO: check will need to be called separately, so hooks can be called after
- // packet is parsed, but before its content is verified
+ // @todo check will need to be called separately, so hooks can be called
+ // after the packet is parsed, but before its content is verified
check();
}
@@ -187,8 +191,9 @@ void Pkt4::check() {
boost::shared_ptr<Option> typeOpt = getOption(DHO_DHCP_MESSAGE_TYPE);
if (typeOpt) {
uint8_t msg_type = typeOpt->getUint8();
- if (msg_type>DHCPLEASEACTIVE) {
- isc_throw(BadValue, "Invalid DHCP message type received:" << msg_type);
+ if (msg_type > DHCPLEASEACTIVE) {
+ isc_throw(BadValue, "Invalid DHCP message type received: "
+ << msg_type);
}
msg_type_ = msg_type;
@@ -221,21 +226,21 @@ Pkt4::toText() {
void
Pkt4::setHWAddr(uint8_t hType, uint8_t hlen,
- const std::vector<uint8_t>& macAddr) {
- /// TODO Rewrite this once support for client-identifier option
+ const std::vector<uint8_t>& mac_addr) {
+ /// @todo Rewrite this once support for client-identifier option
/// is implemented (ticket 1228?)
- if (hlen>MAX_CHADDR_LEN) {
+ if (hlen > MAX_CHADDR_LEN) {
isc_throw(OutOfRange, "Hardware address (len=" << hlen
<< " too long. Max " << MAX_CHADDR_LEN << " supported.");
- }
- if ( (macAddr.size() == 0) && (hlen > 0) ) {
+
+ } else if (mac_addr.empty() && (hlen > 0) ) {
isc_throw(OutOfRange, "Invalid HW Address specified");
}
htype_ = hType;
hlen_ = hlen;
- memset(chaddr_, 0, MAX_CHADDR_LEN);
- memcpy(chaddr_, &macAddr[0], hlen);
+ std::copy(&mac_addr[0], &mac_addr[hlen], &chaddr_[0]);
+ std::fill(&chaddr_[hlen], &chaddr_[MAX_CHADDR_LEN], 0);
}
void
@@ -243,11 +248,15 @@ Pkt4::setSname(const uint8_t* sname, size_t snameLen /*= MAX_SNAME_LEN*/) {
if (snameLen > MAX_SNAME_LEN) {
isc_throw(OutOfRange, "sname field (len=" << snameLen
<< ") too long, Max " << MAX_SNAME_LEN << " supported.");
+
+ } else if (sname == NULL) {
+ isc_throw(InvalidParameter, "Invalid sname specified");
}
- memset(sname_, 0, MAX_SNAME_LEN);
- memcpy(sname_, sname, snameLen);
- // no need to store snameLen as any empty space is filled with 0s
+ std::copy(&sname[0], &sname[snameLen], &sname_[0]);
+ std::fill(&sname_[snameLen], &sname_[MAX_SNAME_LEN], 0);
+
+ // No need to store snameLen as any empty space is filled with 0s
}
void
@@ -255,11 +264,15 @@ Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
if (fileLen > MAX_FILE_LEN) {
isc_throw(OutOfRange, "file field (len=" << fileLen
<< ") too long, Max " << MAX_FILE_LEN << " supported.");
+
+ } else if (file == NULL) {
+ isc_throw(InvalidParameter, "Invalid file name specified");
}
- memset(file_, 0, MAX_FILE_LEN);
- memcpy(file_, file, fileLen);
- // no need to store fileLen as any empty space is filled with 0s
+ std::copy(&file[0], &file[fileLen], &file_[0]);
+ std::fill(&file_[fileLen], &file_[MAX_FILE_LEN], 0);
+
+ // No need to store fileLen as any empty space is filled with 0s
}
uint8_t
@@ -272,6 +285,7 @@ Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
case DHCPINFORM:
case DHCPLEASEQUERY:
return (BOOTREQUEST);
+
case DHCPACK:
case DHCPNAK:
case DHCPOFFER:
@@ -279,6 +293,7 @@ Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
case DHCPLEASEUNKNOWN:
case DHCPLEASEACTIVE:
return (BOOTREPLY);
+
default:
isc_throw(OutOfRange, "Invalid message type: "
<< static_cast<int>(dhcpType) );
@@ -287,7 +302,7 @@ Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
void
Pkt4::addOption(boost::shared_ptr<Option> opt) {
- // check for uniqueness (DHCPv4 options must be unique)
+ // Check for uniqueness (DHCPv4 options must be unique)
if (getOption(opt->getType())) {
isc_throw(BadValue, "Option " << opt->getType()
<< " already present in this message.");
@@ -298,7 +313,7 @@ Pkt4::addOption(boost::shared_ptr<Option> opt) {
boost::shared_ptr<isc::dhcp::Option>
Pkt4::getOption(uint8_t type) {
Option::OptionCollection::const_iterator x = options_.find(type);
- if (x!=options_.end()) {
+ if (x != options_.end()) {
return (*x).second;
}
return boost::shared_ptr<isc::dhcp::Option>(); // NULL
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index e09069c..5139458 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -89,7 +89,7 @@ public:
/// reasonable value. This method is expected to grow significantly.
/// It makes sense to separate unpack() and check() for testing purposes.
///
- /// TODO: It is called from unpack() directly. It should be separated.
+ /// @todo It is called from unpack() directly. It should be separated.
///
/// Method will throw exception if anomaly is found.
void check();
@@ -262,16 +262,16 @@ public:
/// @brief Sets hardware address.
///
/// Sets parameters of hardware address. hlen specifies
- /// length of macAddr buffer. Content of macAddr buffer
+ /// length of mac_addr buffer. Content of mac_addr buffer
/// will be copied to appropriate field.
///
- /// Note: macAddr must be a buffer of at least hlen bytes.
+ /// Note: mac_addr must be a buffer of at least hlen bytes.
///
/// @param hType hardware type (will be sent in htype field)
/// @param hlen hardware length (will be sent in hlen field)
- /// @param macAddr pointer to hardware address
+ /// @param mac_addr pointer to hardware address
void setHWAddr(uint8_t hType, uint8_t hlen,
- const std::vector<uint8_t>& macAddr);
+ const std::vector<uint8_t>& mac_addr);
/// Returns htype field
///
@@ -367,7 +367,7 @@ public:
/// @brief Returns remote address
///
/// @return remote address
- const isc::asiolink::IOAddress& getRemoteAddr() {
+ const isc::asiolink::IOAddress& getRemoteAddr() const {
return (remote_addr_);
}
@@ -381,7 +381,7 @@ public:
/// @brief Returns local address.
///
/// @return local address
- const isc::asiolink::IOAddress& getLocalAddr() {
+ const isc::asiolink::IOAddress& getLocalAddr() const {
return (local_addr_);
}
@@ -393,7 +393,7 @@ public:
/// @brief Returns local port.
///
/// @return local port
- uint16_t getLocalPort() { return (local_port_); }
+ uint16_t getLocalPort() const { return (local_port_); }
/// @brief Sets remote port.
///
@@ -403,7 +403,7 @@ public:
/// @brief Returns remote port.
///
/// @return remote port
- uint16_t getRemotePort() { return (remote_port_); }
+ uint16_t getRemotePort() const { return (remote_port_); }
/// @brief Update packet timestamp.
///
@@ -519,13 +519,13 @@ protected:
std::vector<uint8_t> data_;
/// message type (e.g. 1=DHCPDISCOVER)
- /// TODO: this will eventually be replaced with DHCP Message Type
+ /// @todo this will eventually be replaced with DHCP Message Type
/// option (option 53)
uint8_t msg_type_;
/// collection of options present in this message
///
- /// @warnig This protected member is accessed by derived
+ /// @warning This protected member is accessed by derived
/// classes directly. One of such derived classes is
/// @ref perfdhcp::PerfPkt4. The impact on derived clasess'
/// behavior must be taken into consideration before making
diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h
index 0542df9..6ffea2b 100644
--- a/src/lib/dhcp/pkt6.h
+++ b/src/lib/dhcp/pkt6.h
@@ -189,7 +189,9 @@ public:
/// @brief Returns remote address
///
/// @return remote address
- const isc::asiolink::IOAddress& getRemoteAddr() { return (remote_addr_); }
+ const isc::asiolink::IOAddress& getRemoteAddr() const {
+ return (remote_addr_);
+ }
/// @brief Sets local address.
///
@@ -199,7 +201,9 @@ public:
/// @brief Returns local address.
///
/// @return local address
- const isc::asiolink::IOAddress& getLocalAddr() { return (local_addr_); }
+ const isc::asiolink::IOAddress& getLocalAddr() const {
+ return (local_addr_);
+ }
/// @brief Sets local port.
///
@@ -209,7 +213,7 @@ public:
/// @brief Returns local port.
///
/// @return local port
- uint16_t getLocalPort() { return (local_port_); }
+ uint16_t getLocalPort() const { return (local_port_); }
/// @brief Sets remote port.
///
@@ -219,7 +223,7 @@ public:
/// @brief Returns remote port.
///
/// @return remote port
- uint16_t getRemotePort() { return (remote_port_); }
+ uint16_t getRemotePort() const { return (remote_port_); }
/// @brief Sets interface index.
///
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index 37af9c6..2ef982a 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -416,6 +416,11 @@ TEST(Pkt4Test, sname) {
delete pkt;
}
+
+ // Check that a null argument generates an exception.
+ Pkt4 pkt4(DHCPOFFER, 1234);
+ EXPECT_THROW(pkt4.setSname(NULL, Pkt4::MAX_SNAME_LEN), InvalidParameter);
+ EXPECT_THROW(pkt4.setSname(NULL, 0), InvalidParameter);
}
TEST(Pkt4Test, file) {
@@ -451,6 +456,10 @@ TEST(Pkt4Test, file) {
delete pkt;
}
+ // Check that a null argument generates an exception.
+ Pkt4 pkt4(DHCPOFFER, 1234);
+ EXPECT_THROW(pkt4.setFile(NULL, Pkt4::MAX_FILE_LEN), InvalidParameter);
+ EXPECT_THROW(pkt4.setFile(NULL, 0), InvalidParameter);
}
static uint8_t v4Opts[] = {
diff --git a/src/lib/dhcpsrv/addr_utilities.h b/src/lib/dhcpsrv/addr_utilities.h
index a1d856c..784aeab 100644
--- a/src/lib/dhcpsrv/addr_utilities.h
+++ b/src/lib/dhcpsrv/addr_utilities.h
@@ -26,8 +26,8 @@ namespace dhcp {
/// @brief returns a first address in a given prefix
///
-/// Example: For 2001:db8:1::deaf:beef and length /120 the function will return
-/// 2001:db8:1::dead:be00. See also @ref lastAddrInPrefix.
+/// Example: For 2001:db8:1\::deaf:beef and length /120 the function will return
+/// 2001:db8:1\::dead:be00. See also @ref lastAddrInPrefix.
///
/// @todo It currently works for v6 only and will throw if v4 address is passed.
///
@@ -40,8 +40,8 @@ isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefi
/// @brief returns a last address in a given prefix
///
-/// Example: For 2001:db8:1::deaf:beef and length /112 the function will return
-/// 2001:db8:1::dead:ffff. See also @ref firstAddrInPrefix.
+/// Example: For 2001:db8:1\::deaf:beef and length /112 the function will return
+/// 2001:db8:1\::dead:ffff. See also @ref firstAddrInPrefix.
///
/// @todo It currently works for v6 only and will throw if v4 address is passed.
///
diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc
index 3a53887..77a2df4 100644
--- a/src/lib/dhcpsrv/alloc_engine.cc
+++ b/src/lib/dhcpsrv/alloc_engine.cc
@@ -67,7 +67,7 @@ AllocEngine::IterativeAllocator::pickAddress(const Subnet6Ptr& subnet,
const Pool6Collection& pools = subnet->getPools();
- if (pools.size() == 0) {
+ if (pools.empty()) {
isc_throw(AllocFailed, "No pools defined in selected subnet");
}
diff --git a/src/lib/dhcpsrv/cfgmgr.h b/src/lib/dhcpsrv/cfgmgr.h
index db2bfd5..ac1b3f5 100644
--- a/src/lib/dhcpsrv/cfgmgr.h
+++ b/src/lib/dhcpsrv/cfgmgr.h
@@ -43,6 +43,7 @@ namespace dhcp {
/// Below is a sketch of configuration inheritance (not implemented yet).
/// Let's investigate the following configuration:
///
+/// @code
/// preferred-lifetime 500;
/// valid-lifetime 1000;
/// subnet6 2001:db8:1::/48 {
@@ -52,6 +53,8 @@ namespace dhcp {
/// valid-lifetime 2000;
/// pool6 2001::db8:2::1 - 2001::db8:2::ff;
/// };
+/// @endcode
+///
/// Parameters defined in a global scope are applicable to everything until
/// they are overwritten in a smaller scope, in this case subnet6.
/// In the example above, the first subnet6 has preferred lifetime of 500s
diff --git a/src/lib/dhcpsrv/database_backends.dox b/src/lib/dhcpsrv/database_backends.dox
index f954bed..a3b3b0c 100644
--- a/src/lib/dhcpsrv/database_backends.dox
+++ b/src/lib/dhcpsrv/database_backends.dox
@@ -1,5 +1,5 @@
/**
- @page dhcp-database-backends DHCP Database Back-Ends
+ @page dhcpDatabaseBackends DHCP Database Back-Ends
All DHCP lease data is stored in some form of database, the interface
to this being through the Lease Manager.
diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h
index a264743..7865e11 100644
--- a/src/lib/dhcpsrv/lease_mgr.h
+++ b/src/lib/dhcpsrv/lease_mgr.h
@@ -30,7 +30,7 @@
#include <utility>
#include <vector>
-/// @file dhcp/lease_mgr.h
+/// @file lease_mgr.h
/// @brief An abstract API for lease database
///
/// This file contains declarations of Lease4, Lease6 and LeaseMgr classes.
@@ -118,32 +118,6 @@ struct Lease4 {
/// @brief Maximum size of a hardware address
static const size_t HWADDR_MAX = 20;
- /// @brief Constructor
- ///
- /// @param addr IPv4 address as unsigned 32-bit integer in network byte
- /// order.
- /// @param hwaddr Hardware address buffer
- /// @param hwaddr_len Length of hardware address buffer
- /// @param clientid Client identification buffer
- /// @param clientid_len Length of client identification buffer
- /// @param valid_lft Lifetime of the lease
- /// @param cltt Client last transmission time
- /// @param subnet_id Subnet identification
- Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len,
- const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
- time_t cltt, uint32_t subnet_id)
- : addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len),
- client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0),
- valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id),
- fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false),
- comments_()
- {}
-
- /// @brief Default Constructor
- ///
- /// Initialize fields that don't have a default constructor.
- Lease4() : addr_(0) {}
-
/// IPv4 address
isc::asiolink::IOAddress addr_;
@@ -165,7 +139,7 @@ struct Lease4 {
///
/// @todo Should this be a pointer to a client ID or the ID itself?
/// Compare with the DUID in the Lease6 structure.
- boost::shared_ptr<ClientId> client_id_;
+ ClientIdPtr client_id_;
/// @brief Renewal timer
///
@@ -227,6 +201,33 @@ struct Lease4 {
/// system administrator.
std::string comments_;
+ /// @brief Constructor
+ ///
+ /// @param addr IPv4 address as unsigned 32-bit integer in network byte
+ /// order.
+ /// @param hwaddr Hardware address buffer
+ /// @param hwaddr_len Length of hardware address buffer
+ /// @param clientid Client identification buffer
+ /// @param clientid_len Length of client identification buffer
+ /// @param valid_lft Lifetime of the lease
+ /// @param cltt Client last transmission time
+ /// @param subnet_id Subnet identification
+ Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len,
+ const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
+ time_t cltt, uint32_t subnet_id)
+ : addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len),
+ client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0),
+ valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id),
+ fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false),
+ comments_()
+ {}
+
+ /// @brief Default Constructor
+ ///
+ /// Initialize fields that don't have a default constructor.
+ Lease4() : addr_(0), fixed_(false), fqdn_fwd_(false), fqdn_rev_(false)
+ {}
+
/// @brief Compare two leases for equality
///
/// @param other lease6 object with which to compare
@@ -265,11 +266,6 @@ struct Lease6 {
LEASE_IA_PD /// the lease contains IPv6 prefix (for prefix delegation)
} LeaseType;
- /// @brief Constructor
- Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
- uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
- uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
-
/// @brief IPv6 address
///
/// IPv6 address or, in the case of a prefix delegation, the prefix.
@@ -367,9 +363,16 @@ struct Lease6 {
/// @todo: Add DHCPv6 failover related fields here
/// @brief Constructor
+ Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
+ uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
+ uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
+
+ /// @brief Constructor
///
/// Initialize fields that don't have a default constructor.
- Lease6() : addr_("::") {}
+ Lease6() : addr_("::"), type_(LEASE_IA_NA), fixed_(false), fqdn_fwd_(false),
+ fqdn_rev_(false)
+ {}
/// @brief Convert Lease6 to Printable Form
///
@@ -443,19 +446,6 @@ public:
/// with the same address was already there).
virtual bool addLease(const Lease6Ptr& lease) = 0;
- /// @brief Returns IPv4 lease for specified IPv4 address and subnet_id
- ///
- /// This method is used to get a lease for specific subnet_id. There can be
- /// at most one lease for any given subnet, so this method returns a single
- /// pointer.
- ///
- /// @param addr address of the searched lease
- /// @param subnet_id ID of the subnet the lease must belong to
- ///
- /// @return smart pointer to the lease (or NULL if a lease is not found)
- virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr,
- SubnetID subnet_id) const = 0;
-
/// @brief Returns an IPv4 lease for specified IPv4 address
///
/// This method return a lease that is associated with a given address.
@@ -568,17 +558,11 @@ public:
/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr) = 0;
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv6 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be IPv4 or
+ /// IPv6.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress& addr) = 0;
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0;
/// @brief Return backend type
///
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc
index 8a59b73..b71b166 100644
--- a/src/lib/dhcpsrv/memfile_lease_mgr.cc
+++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc
@@ -49,11 +49,6 @@ Lease4Collection Memfile_LeaseMgr::getLease4(const HWAddr& ) const {
return (Lease4Collection());
}
-Lease4Ptr Memfile_LeaseMgr::getLease4(const isc::asiolink::IOAddress&,
- SubnetID) const {
- return (Lease4Ptr());
-}
-
Lease4Ptr Memfile_LeaseMgr::getLease4(const HWAddr&,
SubnetID) const {
return (Lease4Ptr());
@@ -102,18 +97,21 @@ void Memfile_LeaseMgr::updateLease6(const Lease6Ptr& ) {
}
-bool Memfile_LeaseMgr::deleteLease4(const isc::asiolink::IOAddress&) {
- return (false);
-}
-
-bool Memfile_LeaseMgr::deleteLease6(const isc::asiolink::IOAddress& addr) {
- Lease6Storage::iterator l = storage6_.find(addr);
- if (l == storage6_.end()) {
- // no such lease
+bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
+ if (addr.isV4()) {
+ // V4 not implemented yet
return (false);
+
} else {
- storage6_.erase(l);
- return (true);
+ // V6 lease
+ Lease6Storage::iterator l = storage6_.find(addr);
+ if (l == storage6_.end()) {
+ // No such lease
+ return (false);
+ } else {
+ storage6_.erase(l);
+ return (true);
+ }
}
}
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h
index 3f54edc..268b722 100644
--- a/src/lib/dhcpsrv/memfile_lease_mgr.h
+++ b/src/lib/dhcpsrv/memfile_lease_mgr.h
@@ -68,16 +68,6 @@ public:
/// @return a collection of leases
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const;
- /// @brief Returns existing IPv4 lease for specific address and subnet
- ///
- /// @todo Not implemented yet
- /// @param addr address of the searched lease
- /// @param subnet_id ID of the subnet the lease must belong to
- ///
- /// @return smart pointer to the lease (or NULL if a lease is not found)
- virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr,
- SubnetID subnet_id) const;
-
/// @brief Returns existing IPv4 leases for specified hardware address.
///
/// @todo Not implemented yet
@@ -176,17 +166,11 @@ public:
/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv4 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be IPv4 or
+ /// IPv6.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress& addr);
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
/// @brief Return backend type
///
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index 73289ad..ad6e66c 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -1274,24 +1274,6 @@ MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
}
-Lease4Ptr
-MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr,
- SubnetID subnet_id) const {
-
- // As the address is the unique primary key of the lease4 table, there can
- // only be one lease with a given address. Therefore we will get that
- // lease and do the filtering on subnet ID here.
- Lease4Ptr result = getLease4(addr);
- if (result && (result->subnet_id_ != subnet_id)) {
-
- // Lease found but IDs do not match. Return null pointer
- result.reset();
- }
-
- return (result);
-}
-
-
Lease4Collection
MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
// Set up the WHERE clause value
@@ -1573,12 +1555,13 @@ MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
updateLeaseCommon(stindex, &bind[0], lease);
}
-// Delete lease methods. As with other groups of methods, these comprise
-// a per-type method that sets up the relevant MYSQL_BIND array and a
-// common method than handles the common processing.
+// Delete lease methods. Similar to other groups of methods, these comprise
+// a per-type method that sets up the relevant MYSQL_BIND array (in this
+// case, a single method for both V4 and V6 addresses) and a common method that
+// handles the common processing.
bool
-MySqlLeaseMgr::deleteLease(StatementIndex stindex, MYSQL_BIND* bind) {
+MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind) {
// Bind the input parameters to the statement
int status = mysql_stmt_bind_param(statements_[stindex], bind);
@@ -1595,42 +1578,34 @@ MySqlLeaseMgr::deleteLease(StatementIndex stindex, MYSQL_BIND* bind) {
bool
-MySqlLeaseMgr::deleteLease4(const isc::asiolink::IOAddress& addr) {
+MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
- uint32_t addr4 = static_cast<uint32_t>(addr);
+ if (addr.isV4()) {
+ uint32_t addr4 = static_cast<uint32_t>(addr);
- // See the earlier description of the use of "const_cast" when accessing
- // the address for an explanation of the reason.
- inbind[0].buffer_type = MYSQL_TYPE_LONG;
- inbind[0].buffer = reinterpret_cast<char*>(&addr4);
- inbind[0].is_unsigned = MLM_TRUE;
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
+ inbind[0].buffer = reinterpret_cast<char*>(&addr4);
+ inbind[0].is_unsigned = MLM_TRUE;
- return (deleteLease(DELETE_LEASE4, inbind));
-}
+ return (deleteLeaseCommon(DELETE_LEASE4, inbind));
+ } else {
+ std::string addr6 = addr.toText();
+ unsigned long addr6_length = addr6.size();
-bool
-MySqlLeaseMgr::deleteLease6(const isc::asiolink::IOAddress& addr) {
-
- // Set up the WHERE clause value
- MYSQL_BIND inbind[1];
- memset(inbind, 0, sizeof(inbind));
-
- std::string addr6 = addr.toText();
- unsigned long addr6_length = addr6.size();
-
- // See the earlier description of the use of "const_cast" when accessing
- // the address for an explanation of the reason.
- inbind[0].buffer_type = MYSQL_TYPE_STRING;
- inbind[0].buffer = const_cast<char*>(addr6.c_str());
- inbind[0].buffer_length = addr6_length;
- inbind[0].length = &addr6_length;
+ // See the earlier description of the use of "const_cast" when accessing
+ // the address for an explanation of the reason.
+ inbind[0].buffer_type = MYSQL_TYPE_STRING;
+ inbind[0].buffer = const_cast<char*>(addr6.c_str());
+ inbind[0].buffer_length = addr6_length;
+ inbind[0].length = &addr6_length;
- return (deleteLease(DELETE_LEASE6, inbind));
+ return (deleteLeaseCommon(DELETE_LEASE6, inbind));
+ }
}
// Miscellaneous database methods.
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h
index 8a97fc0..68b0e1c 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.h
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.h
@@ -94,19 +94,6 @@ public:
/// failed.
virtual bool addLease(const Lease6Ptr& lease);
- /// @brief Return IPv4 lease for specified IPv4 address and subnet_id
- ///
- /// This method is used to get a lease for specific subnet_id. There can be
- /// at most one lease for any given subnet, so this method returns a single
- /// pointer.
- ///
- /// @param addr address of the sought lease
- /// @param subnet_id ID of the subnet the lease must belong to
- ///
- /// @return smart pointer to the lease (or NULL if a lease is not found)
- virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr,
- SubnetID subnet_id) const;
-
/// @brief Returns an IPv4 lease for specified IPv4 address
///
/// This method return a lease that is associated with a given address.
@@ -286,33 +273,16 @@ public:
/// failed.
virtual void updateLease6(const Lease6Ptr& lease6);
- /// @brief Deletes an IPv4 lease.
- ///
- /// @todo Merge with deleteLease6: it is possible to determine whether
- /// an address is V4 or V6 from the IOAddress argument, so there
- /// is no need for separate V4 or V6 methods.
- ///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- ///
- /// @throw isc::dhcp::DbOperationError An operation on the open database has
- /// failed.
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
-
- /// @brief Deletes an IPv6 lease.
- ///
- /// @todo Merge with deleteLease4: it is possible to determine whether
- /// an address is V4 or V6 from the IOAddress argument, so there
- /// is no need for separate V4 or V6 methods.
+ /// @brief Deletes a lease.
///
- /// @param addr IPv6 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. This can be an IPv4
+ /// address or an IPv6 address.
///
/// @return true if deletion was successful, false if no such lease exists
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
- virtual bool deleteLease6(const isc::asiolink::IOAddress& addr);
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
/// @brief Return backend type
///
@@ -613,7 +583,7 @@ private:
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
- bool deleteLease(StatementIndex stindex, MYSQL_BIND* bind);
+ bool deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind);
/// @brief Check Error and Throw Exception
///
diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
index 6384c1c..a812811 100644
--- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
@@ -73,16 +73,6 @@ public:
return (Lease4Ptr());
}
- /// @brief Returns existing IPv4 lease for specific address and subnet
- /// @param addr address of the searched lease
- /// @param subnet_id ID of the subnet the lease must belong to
- ///
- /// @return smart pointer to the lease (or NULL if a lease is not found)
- virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress&,
- SubnetID) const {
- return (Lease4Ptr());
- }
-
/// @brief Returns existing IPv4 leases for specified hardware address.
///
/// Although in the usual case there will be only one lease, for mobile
@@ -179,19 +169,11 @@ public:
/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress&) {
- return (false);
- }
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv4 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be either
+ /// a V4 address or a V6 address.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress&) {
+ virtual bool deleteLease(const isc::asiolink::IOAddress&) {
return (false);
}
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
index b3f504f..08186dc 100644
--- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
@@ -120,10 +120,10 @@ TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
EXPECT_FALSE(y);
// should return false - there's no such address
- EXPECT_FALSE(lease_mgr->deleteLease6(IOAddress("2001:db8:1::789")));
+ EXPECT_FALSE(lease_mgr->deleteLease(IOAddress("2001:db8:1::789")));
// this one should succeed
- EXPECT_TRUE(lease_mgr->deleteLease6(IOAddress("2001:db8:1::456")));
+ EXPECT_TRUE(lease_mgr->deleteLease(IOAddress("2001:db8:1::456")));
// after the lease is deleted, it should really be gone
x = lease_mgr->getLease6(IOAddress("2001:db8:1::456"));
diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
index d7487b5..746ef00 100644
--- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
@@ -230,8 +230,8 @@ public:
///
/// @param address Address to use for the initialization
///
- /// @return Lease4Ptr. This will not point to anything if the initialization
- /// failed (e.g. unknown address).
+ /// @return Lease4Ptr. This will not point to anything if the
+ /// initialization failed (e.g. unknown address).
Lease4Ptr initializeLease4(std::string address) {
Lease4Ptr lease(new Lease4());
@@ -251,7 +251,7 @@ public:
// Set other parameters. For historical reasons, address 0 is not used.
if (address == straddress4_[0]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x08);
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x42)));
lease->valid_lft_ = 8677;
lease->cltt_ = 168256;
@@ -259,7 +259,7 @@ public:
} else if (address == straddress4_[1]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x19);
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x53)));
lease->valid_lft_ = 3677;
lease->cltt_ = 123456;
@@ -267,7 +267,7 @@ public:
} else if (address == straddress4_[2]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x2a);
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x64)));
lease->valid_lft_ = 5412;
lease->cltt_ = 234567;
@@ -275,7 +275,7 @@ public:
} else if (address == straddress4_[3]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x19); // Same as lease 1
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x75)));
// The times used in the next tests are deliberately restricted - we
@@ -289,7 +289,7 @@ public:
} else if (address == straddress4_[4]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x4c);
// Same ClientId as straddr4_[1]
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x53))); // Same as lease 1
lease->valid_lft_ = 7736;
lease->cltt_ = 222456;
@@ -298,7 +298,7 @@ public:
} else if (address == straddress4_[5]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x19); // Same as lease 1
// Same ClientId and IAID as straddress4_1
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x53))); // Same as lease 1
lease->valid_lft_ = 7832;
lease->cltt_ = 227476;
@@ -307,7 +307,7 @@ public:
} else if (address == straddress4_[6]) {
lease->hwaddr_ = vector<uint8_t>(6, 0x6e);
// Same ClientId as straddress4_1
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>(8, 0x53))); // Same as lease 1
lease->valid_lft_ = 1832;
lease->cltt_ = 627476;
@@ -315,7 +315,7 @@ public:
} else if (address == straddress4_[7]) {
lease->hwaddr_ = vector<uint8_t>(); // Empty
- lease->client_id_ = boost::shared_ptr<ClientId>(
+ lease->client_id_ = ClientIdPtr(
new ClientId(vector<uint8_t>())); // Empty
lease->valid_lft_ = 7975;
lease->cltt_ = 213876;
@@ -708,7 +708,8 @@ TEST_F(MySqlLeaseMgrTest, checkVersion) {
/// @brief Basic Lease4 Checks
///
-/// Checks that the addLease, getLease4 (by address) and deleteLease4 works.
+/// Checks that the addLease, getLease4 (by address) and deleteLease (with an
+/// IPv4 address) works.
TEST_F(MySqlLeaseMgrTest, basicLease4) {
// Get the leases to be used for the test.
vector<Lease4Ptr> leases = createLeases4();
@@ -740,10 +741,10 @@ TEST_F(MySqlLeaseMgrTest, basicLease4) {
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
- EXPECT_TRUE(lmptr_->deleteLease4(ioaddress4_[1]));
+ EXPECT_TRUE(lmptr_->deleteLease(ioaddress4_[1]));
l_returned = lmptr_->getLease4(ioaddress4_[1]);
EXPECT_FALSE(l_returned);
- EXPECT_FALSE(lmptr_->deleteLease4(ioaddress4_[1]));
+ EXPECT_FALSE(lmptr_->deleteLease(ioaddress4_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease4(ioaddress4_[2]);
@@ -753,7 +754,8 @@ TEST_F(MySqlLeaseMgrTest, basicLease4) {
/// @brief Basic Lease6 Checks
///
-/// Checks that the addLease, getLease6 (by address) and deleteLease6 works.
+/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
+/// IPv6 address) works.
TEST_F(MySqlLeaseMgrTest, basicLease6) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
@@ -785,10 +787,10 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
- EXPECT_TRUE(lmptr_->deleteLease6(ioaddress6_[1]));
+ EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1]));
l_returned = lmptr_->getLease6(ioaddress6_[1]);
EXPECT_FALSE(l_returned);
- EXPECT_FALSE(lmptr_->deleteLease6(ioaddress6_[1]));
+ EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease6(ioaddress6_[2]);
@@ -796,45 +798,6 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
detailCompareLease(leases[2], l_returned);
}
-/// @brief Check GetLease4 methods - access by Address and SubnetID
-///
-/// Adds leases to the database and checks that they can be accessed via
-/// a the hardware address
-TEST_F(MySqlLeaseMgrTest, getLease4AddressSubnetId) {
- // Get the leases to be used for the test.
- vector<Lease4Ptr> leases = createLeases4();
- const SubnetID lease1_subnetid = leases[1]->subnet_id_;
-
- // Generate a Subnet ID known to be invalid - one more than the maximum
- // Subnet ID in all the leases.
- SubnetID invalid_subnetid = 0;
- for (int i = 0; i < leases.size(); ++i) {
- invalid_subnetid = max(invalid_subnetid, leases[i]->subnet_id_);
- }
- ++invalid_subnetid;
-
-
- // Add just one to the database.
- EXPECT_TRUE(lmptr_->addLease(leases[1]));
-
- // Look for a known lease with a valid Subnet ID
- Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1], lease1_subnetid);
- ASSERT_TRUE(l_returned);
- detailCompareLease(leases[1], l_returned);
-
- // Look for a lease known to be in the database with an invalid Subnet ID
- l_returned = lmptr_->getLease4(ioaddress4_[1], invalid_subnetid);
- EXPECT_FALSE(l_returned);
-
- // Look for a lease known not to be in the database with a valid Subnet ID
- l_returned = lmptr_->getLease4(ioaddress4_[2], lease1_subnetid);
- EXPECT_FALSE(l_returned);
-
- // Look for a lease known not to be in the database with and invalid
- l_returned = lmptr_->getLease4(ioaddress4_[2], invalid_subnetid);
- EXPECT_FALSE(l_returned);
-}
-
/// @brief Check GetLease4 methods - access by Hardware Address
///
/// Adds leases to the database and checks that they can be accessed via
@@ -896,7 +859,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSize) {
Lease4Collection returned = lmptr_->getLease4(leases[1]->hwaddr_);
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Expect some problem when accessing a lease that had too long a hardware
@@ -954,7 +917,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
// "multiple records" exception. (We expect there to be only one record
// with that combination, so getting them via getLeaseX() (as opposed
// to getLeaseXCollection() should throw an exception.)
- EXPECT_TRUE(lmptr_->deleteLease4(leases[2]->addr_));
+ EXPECT_TRUE(lmptr_->deleteLease(leases[2]->addr_));
leases[1]->addr_ = leases[2]->addr_;
EXPECT_TRUE(lmptr_->addLease(leases[1]));
EXPECT_THROW(returned = lmptr_->getLease4(leases[1]->hwaddr_,
@@ -964,7 +927,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
// Delete all leases in the database
for (int i = 0; ADDRESS4[i] != NULL; ++i) {
IOAddress addr(ADDRESS4[i]);
- (void) lmptr_->deleteLease4(addr);
+ (void) lmptr_->deleteLease(addr);
}
}
@@ -986,7 +949,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetIdSize) {
leases[1]->subnet_id_);
ASSERT_TRUE(returned);
detailCompareLease(leases[1], returned);
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Expect some error when getting a lease with too long a hardware
@@ -1069,7 +1032,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSize) {
Lease4Collection returned = lmptr_->getLease4(*leases[1]->client_id_);
ASSERT_TRUE(returned.size() == 1);
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check client IDs longer than the maximum -
@@ -1179,7 +1142,7 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSize) {
leases[1]->iaid_);
EXPECT_EQ(1, returned.size());
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease6(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check DUIDs longer than the maximum - these cannot be
@@ -1245,7 +1208,7 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
leases[1]->subnet_id_);
ASSERT_TRUE(returned);
detailCompareLease(leases[1], returned);
- (void) lmptr_->deleteLease6(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check DUIDs longer than the maximum - these cannot be
@@ -1293,7 +1256,7 @@ TEST_F(MySqlLeaseMgrTest, updateLease4) {
detailCompareLease(leases[1], l_returned);
// Try updating a lease not in the database.
- lmptr_->deleteLease4(ioaddress4_[2]);
+ lmptr_->deleteLease(ioaddress4_[2]);
EXPECT_THROW(lmptr_->updateLease4(leases[2]), isc::dhcp::NoSuchLease);
}
diff --git a/src/lib/dhcpsrv/triplet.h b/src/lib/dhcpsrv/triplet.h
index d9388fe..c7b8156 100644
--- a/src/lib/dhcpsrv/triplet.h
+++ b/src/lib/dhcpsrv/triplet.h
@@ -37,7 +37,7 @@ public:
///
/// Typically: uint32_t to Triplet assignment. It is very convenient
/// to be able to simply write Triplet<uint32_t> x = 7;
- Triplet<T> operator=(T other) {
+ Triplet<T>& operator=(T other) {
min_ = other;
default_ = other;
max_ = other;
More information about the bind10-changes
mailing list