BIND 10 trac1955, updated. ce911b68e171ddced13c91ced5e7a1d417ad62ca [1955] Check for null options pointers.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 8 16:10:33 UTC 2012
The branch, trac1955 has been updated
via ce911b68e171ddced13c91ced5e7a1d417ad62ca (commit)
via fa56b67ff11e54e7eed6331c4470d37bcbc2c5bb (commit)
via 6fc0bdf0ad2a49f5e98c1d78aadf7334c954a5a3 (commit)
via 5496d551ef264130bb017a99906410fa27045cd9 (commit)
via 652738d33dd4a62c676b3bcb26996d646253191c (commit)
via 56951dcff8366dd0bccf09ae233ea90f8c90dbca (commit)
from be57f66a715103218b56b77536807d5c5714cbab (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 ce911b68e171ddced13c91ced5e7a1d417ad62ca
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 18:09:54 2012 +0200
[1955] Check for null options pointers.
commit fa56b67ff11e54e7eed6331c4470d37bcbc2c5bb
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 17:47:27 2012 +0200
[1955] Using named constants for offsets and transaction id in unit tests.
commit 6fc0bdf0ad2a49f5e98c1d78aadf7334c954a5a3
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 16:35:34 2012 +0200
[1955] Using OutputBuffer::writeUint8At to avoid OutputBuffer::clear().
commit 5496d551ef264130bb017a99906410fa27045cd9
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 13:55:34 2012 +0200
[1955] Access perf_pktN and pktN class members via getters and setters.
Some of the pktN protected variables are still accessed directly in derived
classes thus warnings have been added in libs.
commit 652738d33dd4a62c676b3bcb26996d646253191c
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 12:09:02 2012 +0200
[1955] Removed redundant constructors, used default values instead.
commit 56951dcff8366dd0bccf09ae233ea90f8c90dbca
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Jun 8 10:47:48 2012 +0200
[1955] Updated dates in perfdhcp copyright headers.
-----------------------------------------------------------------------
Summary of changes:
doc/Doxyfile | 2 +-
src/lib/dhcp/pkt4.h | 26 ++++++
src/lib/dhcp/pkt6.h | 26 ++++++
tests/tools/perfdhcp/command_options.cc | 2 +-
tests/tools/perfdhcp/command_options.h | 2 +-
tests/tools/perfdhcp/localized_option.h | 2 +-
tests/tools/perfdhcp/perf_pkt4.cc | 33 ++++----
tests/tools/perfdhcp/perf_pkt4.h | 62 ++++-----------
tests/tools/perfdhcp/perf_pkt6.cc | 33 +++-----
tests/tools/perfdhcp/perf_pkt6.h | 56 +++----------
tests/tools/perfdhcp/perfdhcp.cc | 2 +-
tests/tools/perfdhcp/pkt_transform.cc | 65 +++++++--------
tests/tools/perfdhcp/pkt_transform.h | 4 +-
.../perfdhcp/tests/command_options_unittest.cc | 2 +-
.../perfdhcp/tests/localized_option_unittest.cc | 2 +-
tests/tools/perfdhcp/tests/perf_pkt4_unittest.cc | 83 +++++++++++++-------
tests/tools/perfdhcp/tests/perf_pkt6_unittest.cc | 61 ++++++++------
17 files changed, 237 insertions(+), 226 deletions(-)
-----------------------------------------------------------------------
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 8730ae4..6d91bf2 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -579,7 +579,7 @@ INPUT = ../src/lib/exceptions ../src/lib/cc \
../src/lib/testutils ../src/lib/cache ../src/lib/server_common/ \
../src/bin/sockcreator/ ../src/lib/util/ ../src/lib/util/io/ \
../src/lib/resolve ../src/lib/acl ../src/bin/dhcp6 ../src/lib/dhcp \
- ../src/bin/dhcp4 devel
+ ../src/bin/dhcp4 ../tests/tools/perfdhcp devel
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index c36f5bf..b72c03e 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -204,6 +204,11 @@ public:
void
setGiaddr(const isc::asiolink::IOAddress& giaddr) { giaddr_ = giaddr; };
+ /// @brief Sets transaction-id value
+ ///
+ /// @param transid transaction-id to be set.
+ void setTransid(uint32_t transid) { transid_ = transid; }
+
/// @brief Returns value of transaction-id field.
///
/// @return transaction-id
@@ -488,12 +493,26 @@ protected:
// end of real DHCPv4 fields
/// output buffer (used during message transmission)
+ ///
+ /// @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
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
isc::util::OutputBuffer bufferOut_;
/// that's the data of input buffer used in RX packet. Note that
/// InputBuffer does not store the data itself, but just expects that
/// data will be valid for the whole life of InputBuffer. Therefore we
/// need to keep the data around.
+ ///
+ /// @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
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
std::vector<uint8_t> data_;
/// message type (e.g. 1=DHCPDISCOVER)
@@ -502,6 +521,13 @@ protected:
uint8_t msg_type_;
/// collection of options present in this message
+ ///
+ /// @warnig 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
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
isc::dhcp::Option::OptionCollection options_;
/// packet timestamp
diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h
index 6cca573..2612f27 100644
--- a/src/lib/dhcp/pkt6.h
+++ b/src/lib/dhcp/pkt6.h
@@ -131,6 +131,11 @@ public:
/// @param type message type to be set
void setType(uint8_t type) { msg_type_=type; };
+ /// @brief Sets transaction-id value
+ ///
+ /// @param transid transaction-id to be set.
+ void setTransid(uint32_t transid) { transid_ = transid; }
+
/// Returns value of transaction-id field
///
/// @return transaction-id
@@ -241,6 +246,13 @@ public:
/// TODO Need to implement getOptions() as well
/// collection of options present in this message
+ ///
+ /// @warning This protected member is accessed by derived
+ /// classes directly. One of such derived classes is
+ /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
+ /// behavior must be taken into consideration before making
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
isc::dhcp::Option::OptionCollection options_;
/// @brief Update packet timestamp.
@@ -296,6 +308,13 @@ protected:
uint32_t transid_;
/// unparsed data (in received packets)
+ ///
+ /// @warning This protected member is accessed by derived
+ /// classes directly. One of such derived classes is
+ /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
+ /// behavior must be taken into consideration before making
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
OptionBuffer data_;
/// name of the network interface the packet was received/to be sent over
@@ -322,6 +341,13 @@ protected:
uint16_t remote_port_;
/// output buffer (used during message transmission)
+ ///
+ /// @warning This protected member is accessed by derived
+ /// classes directly. One of such derived classes is
+ /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
+ /// behavior must be taken into consideration before making
+ /// changes to this member such as access scope restriction or
+ /// data format change etc.
isc::util::OutputBuffer bufferOut_;
/// packet timestamp
diff --git a/tests/tools/perfdhcp/command_options.cc b/tests/tools/perfdhcp/command_options.cc
index 7b62076..5b4f424 100644
--- a/tests/tools/perfdhcp/command_options.cc
+++ b/tests/tools/perfdhcp/command_options.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
diff --git a/tests/tools/perfdhcp/command_options.h b/tests/tools/perfdhcp/command_options.h
index 033d29a..9196857 100644
--- a/tests/tools/perfdhcp/command_options.h
+++ b/tests/tools/perfdhcp/command_options.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
diff --git a/tests/tools/perfdhcp/localized_option.h b/tests/tools/perfdhcp/localized_option.h
index a6e4155..5374684 100644
--- a/tests/tools/perfdhcp/localized_option.h
+++ b/tests/tools/perfdhcp/localized_option.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
diff --git a/tests/tools/perfdhcp/perf_pkt4.cc b/tests/tools/perfdhcp/perf_pkt4.cc
index 6f09f29..3f733af 100644
--- a/tests/tools/perfdhcp/perf_pkt4.cc
+++ b/tests/tools/perfdhcp/perf_pkt4.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -25,23 +25,13 @@ using namespace dhcp;
namespace isc {
namespace perfdhcp {
-PerfPkt4::PerfPkt4(const uint8_t* buf, size_t len) :
- Pkt4(buf, len),
- transid_offset_(1) {
-}
-
PerfPkt4::PerfPkt4(const uint8_t* buf,
size_t len,
size_t transid_offset,
uint32_t transid) :
Pkt4(buf, len),
transid_offset_(transid_offset) {
- transid_ = transid;
-}
-
-PerfPkt4::PerfPkt4(const uint8_t* buf, size_t len, size_t transid_offset) :
- Pkt4(buf, len),
- transid_offset_(transid_offset) {
+ setTransid(transid);
}
bool
@@ -49,18 +39,23 @@ PerfPkt4::rawPack() {
return (PktTransform::pack(dhcp::Option::V4,
data_,
options_,
- transid_offset_,
- transid_,
+ getTransidOffset(),
+ getTransid(),
bufferOut_));
}
bool
PerfPkt4::rawUnpack() {
- return (PktTransform::unpack(dhcp::Option::V4,
- data_,
- options_,
- transid_offset_,
- transid_));
+ uint32_t transid = getTransid();
+ bool res = PktTransform::unpack(dhcp::Option::V4,
+ data_,
+ options_,
+ getTransidOffset(),
+ transid);
+ if (res) {
+ setTransid(transid);
+ }
+ return (res);
}
} // namespace perfdhcp
diff --git a/tests/tools/perfdhcp/perf_pkt4.h b/tests/tools/perfdhcp/perf_pkt4.h
index 99a6116..f4cc440 100644
--- a/tests/tools/perfdhcp/perf_pkt4.h
+++ b/tests/tools/perfdhcp/perf_pkt4.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -50,65 +50,31 @@ public:
/// Localized option pointer type.
typedef boost::shared_ptr<LocalizedOption> LocalizedOptionPtr;
- /// \brief Constructor, used for outgoing and incoming messages
+ /// \brief Constructor, used to create messages from packet
+ /// template files.
///
- /// This constructor initializes the transaction ID and
- /// transaction id offset of the packet with default
- /// values.
- ///
- /// \param buf buffer holding contents of the message.
- /// \param len length of the data in the buffer.
- PerfPkt4(const uint8_t* buf, size_t len);
-
- /// \brief Constructor, used for outgoing DHCP messages.
- ///
- /// Creates new DHCPv4 message using the provided buffer. The
- /// transaction ID and its offset are specified via this
- /// constructor. The transaction ID is stored in the outgoing message
- /// when the client class calls \ref PerfPkt4::rawPack.
- ///
- /// \note This constructor should be used only for outgoing
- /// messages that are created from template files.
+ /// Creates a new DHCPv4 message using the provided buffer.
+ /// The transaction ID and its offset are specified via this
+ /// constructor. The transaction ID is stored in outgoing message
+ /// when client class calls \ref PerfPkt4::rawPack. Transaction id
+ /// offset value is used for incoming and outgoing messages to
+ /// identify transaction ID field's position in incoming and outgoing
+ /// messages.
///
/// \param buf buffer holding contents of the message (this can
/// be directly read from template file).
/// \param len length of the data in the buffer.
- /// \param transid_offset transaction id offset in outgoing message.
- /// \param transid transaction id to be stored in outgoing message.
- PerfPkt4(const uint8_t* buf,
- size_t len,
- size_t transid_offset,
- uint32_t transid);
-
- /// Constructor, used for incoming DHCP messages.
- ///
- /// Creates new DHCPv4 message using the provided buffer.
- /// The client class may indicate which options are to be read
- /// from the buffer. Such options should be added to the
- /// options collection using \ref dhcp::Pkt4::addOption: these
- /// options should be of \ref LocalizedOption class.
- ///
- /// The transaction ID offset points to the location where the
- /// transaction ID field is stored. The transaction ID will
- /// be read from this location when \ref PerfPkt4::rawUnpack is
- /// called. The transid_ class member will be updated accordingly.
- ///
- /// \note Use this constructor only in the case where you want to create
- /// an incoming DHCPv4 object from the raw buffer
- /// and you know the options offsets. The options offsets are
- /// specified on the perfdhcp command line by the user.
- ///
- /// \param buf pointer to a buffer of received packet content.
- /// \param len size of buffer of packet content.
/// \param transid_offset transaction id offset in a message.
+ /// \param transid transaction id to be stored in outgoing message.
PerfPkt4(const uint8_t* buf,
size_t len,
- size_t transid_offset);
+ size_t transid_offset = 1,
+ uint32_t transid = 0);
/// \brief Returns transaction id offset in packet buffer
///
/// \return Transaction ID offset in packet buffer
- size_t getTransIdOffset() const { return transid_offset_; };
+ size_t getTransidOffset() const { return transid_offset_; };
/// \brief Prepares on-wire format from raw buffer.
///
diff --git a/tests/tools/perfdhcp/perf_pkt6.cc b/tests/tools/perfdhcp/perf_pkt6.cc
index 17dbf3a..24cfb93 100644
--- a/tests/tools/perfdhcp/perf_pkt6.cc
+++ b/tests/tools/perfdhcp/perf_pkt6.cc
@@ -27,25 +27,13 @@ using namespace dhcp;
namespace isc {
namespace perfdhcp {
-PerfPkt6::PerfPkt6(const uint8_t* buf, size_t len) :
- Pkt6(buf, len),
- transid_offset_(1) {
-}
-
PerfPkt6::PerfPkt6(const uint8_t* buf,
size_t len,
size_t transid_offset,
uint32_t transid) :
Pkt6(buf, len, Pkt6::UDP),
transid_offset_(transid_offset) {
- transid_ = transid;
-}
-
-PerfPkt6::PerfPkt6(const uint8_t* buf,
- size_t len,
- size_t transid_offset) :
- Pkt6(buf, len, Pkt6::UDP),
- transid_offset_(transid_offset) {
+ setTransid(transid);
}
bool
@@ -53,18 +41,23 @@ PerfPkt6::rawPack() {
return (PktTransform::pack(dhcp::Option::V6,
data_,
options_,
- transid_offset_,
- transid_,
+ getTransidOffset(),
+ getTransid(),
bufferOut_));
}
bool
PerfPkt6::rawUnpack() {
- return (PktTransform::unpack(dhcp::Option::V6,
- data_,
- options_,
- transid_offset_,
- transid_));
+ uint32_t transid = getTransid();
+ bool res = PktTransform::unpack(dhcp::Option::V6,
+ data_,
+ options_,
+ getTransidOffset(),
+ transid);
+ if (res) {
+ setTransid(transid);
+ }
+ return (res);
}
} // namespace perfdhcp
diff --git a/tests/tools/perfdhcp/perf_pkt6.h b/tests/tools/perfdhcp/perf_pkt6.h
index 73cb825..94fe47b 100644
--- a/tests/tools/perfdhcp/perf_pkt6.h
+++ b/tests/tools/perfdhcp/perf_pkt6.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -50,65 +50,31 @@ public:
/// Localized option pointer type.
typedef boost::shared_ptr<LocalizedOption> LocalizedOptionPtr;
- /// \brief Constructor, used for outgoing and incoming messages
- ///
- /// This constructor initializes the transaction ID and the
- /// transaction ID offset of the packet with default
- /// values.
- ///
- /// \param buf buffer holding contents of the message.
- /// \param len length of the data in the buffer.
- PerfPkt6(const uint8_t* buf, size_t len);
-
- /// \brief Constructor, used for outgoing DHCP messages.
+ /// \brief Constructor, used to create messages from packet
+ /// template files.
///
/// Creates a new DHCPv6 message using the provided buffer.
/// The transaction ID and its offset are specified via this
/// constructor. The transaction ID is stored in outgoing message
- /// when client class calls \ref PerfPkt6::rawPack.
- ///
- /// \note This constructor should be used only for outgoing
- /// messages that are created from template files.
+ /// when client class calls \ref PerfPkt6::rawPack. Transaction id
+ /// offset value is used for incoming and outgoing messages to
+ /// identify transaction ID field's position in incoming and outgoing
+ /// messages.
///
/// \param buf buffer holding contents of the message (this can
/// be directly read from template file).
/// \param len length of the data in the buffer.
- /// \param transid_offset transaction id offset in outgoing message.
- /// \param transid transaction id to be stored in outgoing message.
- PerfPkt6(const uint8_t* buf,
- size_t len,
- size_t transid_offset,
- uint32_t transid);
-
- /// Constructor, used for incoming DHCP messages.
- ///
- /// Creates a new DHCPv6 message using the provided buffer. The
- /// client class may indicate which options are to be read
- /// from the buffer. Such options should be added to the
- /// options collection using \ref dhcp::Pkt4::addOption. The
- /// options should be of \ref LocalizedOption class.
- ///
- /// The transaction ID offset points to location where the
- /// transaction ID field is stored. The transaction ID will
- /// be read from this location when \ref PerfPkt4::rawUnpack is
- /// called. The transid_ class member will be updated accordingly.
- ///
- /// \note Use this constructor only in the case where you want to create
- /// incoming DHCPv4 object from the raw buffer
- /// and you know the options offsets. Options offsets are
- /// specified on the perfdhcp command line by the user.
- ///
- /// \param buf pointer to a buffer of received packet content.
- /// \param len size of buffer of packet content.
/// \param transid_offset transaction id offset in a message.
+ /// \param transid transaction id to be stored in outgoing message.
PerfPkt6(const uint8_t* buf,
size_t len,
- size_t transid_offset);
+ size_t transid_offset = 1,
+ uint32_t transid = 0);
/// \brief Returns transaction id offset in packet buffer
///
/// \return Transaction ID offset in the packet buffer.
- size_t getTransIdOffset() const { return transid_offset_; };
+ size_t getTransidOffset() const { return transid_offset_; };
/// \brief Prepares on-wire format from raw buffer
///
diff --git a/tests/tools/perfdhcp/perfdhcp.cc b/tests/tools/perfdhcp/perfdhcp.cc
index 414db24..b6f1899 100644
--- a/tests/tools/perfdhcp/perfdhcp.cc
+++ b/tests/tools/perfdhcp/perfdhcp.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 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
diff --git a/tests/tools/perfdhcp/pkt_transform.cc b/tests/tools/perfdhcp/pkt_transform.cc
index 679ff99..5ed39bf 100644
--- a/tests/tools/perfdhcp/pkt_transform.cc
+++ b/tests/tools/perfdhcp/pkt_transform.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -44,7 +44,7 @@ PktTransform::pack(const Option::Universe universe,
uint8_t transid_len = (universe == Option::V6) ? 3 : 4;
- if ((transid_offset + transid_len + 1 > in_buffer.size()) ||
+ if ((transid_offset + transid_len >= in_buffer.size()) ||
(transid_offset == 0)) {
cout << "Failed to build packet: provided transaction id offset: "
<< transid_offset << " is out of bounds (expected 1.."
@@ -52,22 +52,14 @@ PktTransform::pack(const Option::Universe universe,
return (false);
}
- // Seek to the transaction id position in output buffer.
- out_buffer.clear();
- out_buffer.skip(transid_offset);
-
try {
+ size_t offset_ptr = transid_offset;
if (universe == Option::V4) {
- out_buffer.writeUint8(transid >> 24 & 0xFF);
+ out_buffer.writeUint8At(transid >> 24 & 0xFF, offset_ptr++);
}
- out_buffer.writeUint8(transid >> 16 & 0xFF);
- out_buffer.writeUint8(transid >> 8 & 0xFF);
- out_buffer.writeUint8(transid & 0xFF);
-
- // Buffer pointer is at the end of transaction id.
- // We have to seek to the end of buffer so as data don't
- // get truncated.
- out_buffer.skip(in_buffer.size() - out_buffer.getLength());
+ out_buffer.writeUint8At(transid >> 16 & 0xFF, offset_ptr++);
+ out_buffer.writeUint8At(transid >> 8 & 0xFF, offset_ptr++);
+ out_buffer.writeUint8At(transid & 0xFF, offset_ptr++);
// We already have packet template stored in output buffer
// but still some options have to be updated if client
@@ -98,16 +90,15 @@ PktTransform::unpack(const Option::Universe universe,
return (false);
}
- if (universe == Option::V6) {
- transid = ((in_buffer[transid_offset] << 16) +
- (in_buffer[transid_offset + 1] << 8) +
- (in_buffer[transid_offset + 2]))
- & 0xFFFFFF;
- } else {
- transid = ((in_buffer[transid_offset] << 24) +
- (in_buffer[transid_offset + 1] << 16) +
- (in_buffer[transid_offset + 2] << 8) +
- (in_buffer[transid_offset + 3]));
+ // Read transaction id from the buffer.
+ // For DHCPv6 we transaction id is 3 bytes long so the high byte
+ // of transid will be zero.
+ OptionBufferConstIter it = in_buffer.begin() + transid_offset;
+ transid = 0;
+ for (int i = 0; i < transid_len; ++i, ++it) {
+ // Read next byte and shift it left to its position in
+ // transid (shift by the number of bytes read so far.
+ transid += *it << (transid_len - i - 1) * 8;
}
try {
@@ -133,6 +124,9 @@ PktTransform::packOptions(const OptionBuffer& in_buffer,
// Get options with their position (offset).
boost::shared_ptr<LocalizedOption> option =
boost::dynamic_pointer_cast<LocalizedOption>(it->second);
+ if (option == NULL) {
+ isc_throw(isc::BadValue, "option is null");
+ }
uint32_t offset = option->getOffset();
if ((offset == 0) ||
(offset + option->len() > in_buffer.size())) {
@@ -141,14 +135,20 @@ PktTransform::packOptions(const OptionBuffer& in_buffer,
<< " is out of bounds (expected 1.."
<< in_buffer.size() - option->len() << ")");
}
- out_buffer.clear();
- out_buffer.skip(offset);
- // Replace existing option with new value.
- option->pack(out_buffer);
+ // Create temporary buffer to store option contents.
+ util::OutputBuffer buf(option->len());
+ // Pack option contents into temporary buffer.
+ option->pack(buf);
+ // OutputBuffer class has nice functions that write
+ // data at the specified position so we can use it to
+ // inject contents of temporary buffer to output buffer.
+ const uint8_t *buf_data =
+ static_cast<const uint8_t*>(buf.getData());
+ for (int i = 0; i < buf.getLength(); ++i) {
+ out_buffer.writeUint8At(buf_data[i], offset + i);
+ }
}
- // Seek to the end of the buffer to make sure its size is correct.
- out_buffer.skip(in_buffer.size() - out_buffer.getLength());
}
catch (const Exception&) {
isc_throw(isc::BadValue, "failed to pack options into buffer.");
@@ -163,6 +163,9 @@ PktTransform::unpackOptions(const OptionBuffer& in_buffer,
boost::shared_ptr<LocalizedOption> option =
boost::dynamic_pointer_cast<LocalizedOption>(it->second);
+ if (option == NULL) {
+ isc_throw(isc::BadValue, "option is null");
+ }
size_t opt_pos = option->getOffset();
if (opt_pos == 0) {
isc_throw(isc::BadValue, "failed to unpack packet from raw buffer "
diff --git a/tests/tools/perfdhcp/pkt_transform.h b/tests/tools/perfdhcp/pkt_transform.h
index cdd0a5f..7fb19f4 100644
--- a/tests/tools/perfdhcp/pkt_transform.h
+++ b/tests/tools/perfdhcp/pkt_transform.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -57,7 +57,7 @@ public:
/// \param in_buffer Input buffer holding intial packet
/// data, this can be directly read from template file
/// \param options Options collection with offsets
- /// \param transid_Offset offset of transaction id in a packet,
+ /// \param transid_offset offset of transaction id in a packet,
/// transaction ID will be written to output buffer at this
/// offset
/// \param transid Transaction ID value
diff --git a/tests/tools/perfdhcp/tests/command_options_unittest.cc b/tests/tools/perfdhcp/tests/command_options_unittest.cc
index c92edd0..8e1053d 100644
--- a/tests/tools/perfdhcp/tests/command_options_unittest.cc
+++ b/tests/tools/perfdhcp/tests/command_options_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
diff --git a/tests/tools/perfdhcp/tests/localized_option_unittest.cc b/tests/tools/perfdhcp/tests/localized_option_unittest.cc
index 8990569..e51560e 100644
--- a/tests/tools/perfdhcp/tests/localized_option_unittest.cc
+++ b/tests/tools/perfdhcp/tests/localized_option_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
diff --git a/tests/tools/perfdhcp/tests/perf_pkt4_unittest.cc b/tests/tools/perfdhcp/tests/perf_pkt4_unittest.cc
index e4063d7..3863faa 100644
--- a/tests/tools/perfdhcp/tests/perf_pkt4_unittest.cc
+++ b/tests/tools/perfdhcp/tests/perf_pkt4_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -75,10 +75,10 @@ public:
};
uint8_t v4Opts[] = {
- 12, 3, 0, 1, 2, // Host name option.
- 13, 3, 10, 11, 12, // Boot file size option
- 14, 3, 20, 21, 22, // Merit dump file
- 53, 1, 1, // DHCP message type.
+ DHO_HOST_NAME, 3, 0, 1, 2, // Host name option.
+ DHO_BOOT_SIZE, 3, 10, 11, 12, // Boot file size option
+ DHO_MERIT_DUMP, 3, 20, 21, 22, // Merit dump file
+ DHO_DHCP_MESSAGE_TYPE, 1, 1, // DHCP message type.
128, 3, 30, 31, 32,
254, 3, 40, 41, 42,
};
@@ -114,25 +114,30 @@ public:
TEST_F(PerfPkt4Test, Constructor) {
// Initialize some dummy payload.
uint8_t data[250];
- for (int i = 0; i < 250; i++) {
+ for (int i = 0; i < 250; ++i) {
data[i] = i;
}
// Test constructor to be used for incoming messages.
// Use default (1) offset value and don't specify transaction id.
- boost::scoped_ptr<PerfPkt4> pkt1(new PerfPkt4(data, sizeof(data), 1));
- EXPECT_EQ(1, pkt1->getTransIdOffset());
+ const size_t offset_transid[] = { 1, 10 };
+ boost::scoped_ptr<PerfPkt4> pkt1(new PerfPkt4(data,
+ sizeof(data),
+ offset_transid[0]));
+ EXPECT_EQ(1, pkt1->getTransidOffset());
// Test constructor to be used for outgoing messages.
// Use non-zero offset and specify transaction id.
+ const uint32_t transid = 0x010203;
boost::scoped_ptr<PerfPkt4> pkt2(new PerfPkt4(data, sizeof(data),
- 10, 0x010203));
- EXPECT_EQ(0x010203, pkt2->getTransid());
- EXPECT_EQ(10, pkt2->getTransIdOffset());
+ offset_transid[1],
+ transid));
+ EXPECT_EQ(transid, pkt2->getTransid());
+ EXPECT_EQ(offset_transid[1], pkt2->getTransidOffset());
// Test default constructor. Transaction id offset is expected to be 1.
boost::scoped_ptr<PerfPkt4> pkt3(new PerfPkt4(data, sizeof(data)));
- EXPECT_EQ(1, pkt3->getTransIdOffset());
+ EXPECT_EQ(1, pkt3->getTransidOffset());
}
TEST_F(PerfPkt4Test, RawPack) {
@@ -141,21 +146,24 @@ TEST_F(PerfPkt4Test, RawPack) {
boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size()));
// Initialize options data.
- uint8_t buf_hostname[] = { 12, 3, 4, 5, 6 };
- uint8_t buf_boot_filesize[] = { 13, 3, 1, 2, 3 };
- OptionBuffer vec_hostname(buf_hostname + 2, buf_hostname + 5);
+ uint8_t buf_hostname[] = { DHO_HOST_NAME, 3, 4, 5, 6 };
+ uint8_t buf_boot_filesize[] = { DHO_BOOT_SIZE, 3, 1, 2, 3 };
+ OptionBuffer vec_hostname(buf_hostname + 2,
+ buf_hostname + sizeof(buf_hostname));
OptionBuffer vec_boot_filesize(buf_boot_filesize + 2,
- buf_boot_filesize + 5);
+ buf_boot_filesize + sizeof(buf_hostname));
// Create options objects.
+ const size_t offset_hostname = 240;
LocalizedOptionPtr pkt_hostname(new LocalizedOption(Option::V4,
DHO_HOST_NAME,
vec_hostname,
- 240));
+ offset_hostname));
+ const size_t offset_boot_filesize = 245;
LocalizedOptionPtr pkt_boot_filesize(new LocalizedOption(Option::V4,
DHO_BOOT_SIZE,
vec_boot_filesize,
- 245));
+ offset_boot_filesize));
// Try to add options to packet.
ASSERT_NO_THROW(pkt->addOption(pkt_boot_filesize));
@@ -173,8 +181,12 @@ TEST_F(PerfPkt4Test, RawPack) {
static_cast<const uint8_t*>(pkt_output.getData());
// Check if options we read from buffer is valid.
- EXPECT_EQ(0, memcmp(buf_hostname, out_buf_data + 240, 5));
- EXPECT_EQ(0, memcmp(buf_boot_filesize, out_buf_data + 245, 5));
+ EXPECT_EQ(0, memcmp(buf_hostname,
+ out_buf_data + offset_hostname,
+ sizeof(buf_hostname)));
+ EXPECT_EQ(0, memcmp(buf_boot_filesize,
+ out_buf_data + offset_boot_filesize,
+ sizeof(buf_boot_filesize)));
}
TEST_F(PerfPkt4Test, RawUnpack) {
@@ -183,15 +195,17 @@ TEST_F(PerfPkt4Test, RawUnpack) {
boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size()));
// Create options (existing in the packet) and specify their offsets.
+ const size_t offset_merit = 250;
LocalizedOptionPtr opt_merit(new LocalizedOption(Option::V4,
DHO_MERIT_DUMP,
OptionBuffer(),
- 250));
+ offset_merit));
+ const size_t offset_msg_type = 255;
LocalizedOptionPtr opt_msg_type(new LocalizedOption(Option::V4,
DHO_DHCP_MESSAGE_TYPE,
OptionBuffer(),
- 255));
+ offset_msg_type));
// Addition should be successful
ASSERT_NO_THROW(pkt->addOption(opt_merit));
ASSERT_NO_THROW(pkt->addOption(opt_msg_type));
@@ -236,10 +250,11 @@ TEST_F(PerfPkt4Test, InvalidOptions) {
// Create option with invalid offset.
// This option is at offset 250 (not 251).
+ const size_t offset_merit = 251;
LocalizedOptionPtr opt_merit(new LocalizedOption(Option::V4,
DHO_MERIT_DUMP,
OptionBuffer(),
- 251));
+ offset_merit));
ASSERT_NO_THROW(pkt1->addOption(opt_merit));
cout << "Testing unpack of invalid options. "
@@ -255,10 +270,11 @@ TEST_F(PerfPkt4Test, InvalidOptions) {
// Create DHO_DHCP_MESSAGE_TYPE option that has the wrong offset.
// With this offset, option goes beyond packet size (268).
+ const size_t offset_msg_type = 266;
LocalizedOptionPtr opt_msg_type(new LocalizedOption(Option::V4,
DHO_DHCP_MESSAGE_TYPE,
OptionBuffer(1, 2),
- 266));
+ offset_msg_type));
// Adding option is expected to be successful because no
// offset validation takes place at this point.
ASSERT_NO_THROW(pkt2->addOption(opt_msg_type));
@@ -276,10 +292,11 @@ TEST_F(PerfPkt4Test, TruncatedPacket) {
// Option DHO_BOOT_SIZE is now truncated because whole packet
// is truncated. This option ends at 249 while last index of
// truncated packet is now 248.
+ const size_t offset_boot_filesize = 245;
LocalizedOptionPtr opt_boot_filesize(new LocalizedOption(Option::V4,
DHO_BOOT_SIZE,
OptionBuffer(3, 1),
- 245));
+ offset_boot_filesize));
ASSERT_NO_THROW(pkt->addOption(opt_boot_filesize));
cout << "Testing pack and unpack of options in truncated "
@@ -294,9 +311,13 @@ TEST_F(PerfPkt4Test, TruncatedPacket) {
TEST_F(PerfPkt4Test, PackTransactionId) {
// Create dummy packet that consists of zeros.
std::vector<uint8_t> buf(268, 0);
+
+ const size_t offset_transid[] = { 10, 265 };
+ const uint32_t transid = 0x0102;
// Initialize transaction id 0x00000102 at offset 10.
boost::scoped_ptr<PerfPkt4> pkt1(new PerfPkt4(&buf[0], buf.size(),
- 10, 0x0102));
+ offset_transid[0],
+ transid));
// Pack will inject transaction id at offset 10 into the
// packet buffer.
@@ -313,7 +334,7 @@ TEST_F(PerfPkt4Test, PackTransactionId) {
// Expect that reference transaction id matches what we have
// read from buffer.
- EXPECT_EQ(0, memcmp(ref_data, out_buf_data + 10, 4));
+ EXPECT_EQ(0, memcmp(ref_data, out_buf_data + offset_transid[0], 4));
cout << "Testing pack with invalid transaction id offset. "
<< "This may produce spurious errors" << endl;
@@ -322,7 +343,8 @@ TEST_F(PerfPkt4Test, PackTransactionId) {
// Packet length is 268, transaction id is 4 bytes long so last byte of
// transaction id is out of bounds.
boost::scoped_ptr<PerfPkt4> pkt2(new PerfPkt4(&buf[0], buf.size(),
- 265, 0x0102));
+ offset_transid[1],
+ transid));
EXPECT_FALSE(pkt2->rawPack());
}
@@ -337,9 +359,10 @@ TEST_F(PerfPkt4Test, UnpackTransactionId) {
}
// Create packet from initialized buffer.
+ const size_t offset_transid[] = { 100, 270 };
boost::scoped_ptr<PerfPkt4> pkt1(new PerfPkt4(&in_data[0],
in_data.size(),
- 100));
+ offset_transid[0]));
ASSERT_TRUE(pkt1->rawUnpack());
// Get unpacked transaction id and compare with reference.
@@ -348,7 +371,7 @@ TEST_F(PerfPkt4Test, UnpackTransactionId) {
// Create packet with transaction id at invalid offset.
boost::scoped_ptr<PerfPkt4> pkt2(new PerfPkt4(&in_data[0],
in_data.size(),
- 270));
+ offset_transid[1]));
cout << "Testing unpack of transaction id at invalid offset. "
<< "This may produce spurious errors." << endl;
diff --git a/tests/tools/perfdhcp/tests/perf_pkt6_unittest.cc b/tests/tools/perfdhcp/tests/perf_pkt6_unittest.cc
index 6e4ec57..de134cc 100644
--- a/tests/tools/perfdhcp/tests/perf_pkt6_unittest.cc
+++ b/tests/tools/perfdhcp/tests/perf_pkt6_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 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
@@ -111,18 +111,20 @@ TEST_F(PerfPkt6Test, Constructor) {
// Test constructor to be used for incoming messages.
// Use default (1) offset value and don't specify transaction id.
boost::scoped_ptr<PerfPkt6> pkt1(new PerfPkt6(data, sizeof(data)));
- EXPECT_EQ(6, pkt1->getData().size());
+ EXPECT_EQ(sizeof(data), pkt1->getData().size());
EXPECT_EQ(0, memcmp(&pkt1->getData()[0], data, sizeof(data)));
- EXPECT_EQ(1, pkt1->getTransIdOffset());
+ EXPECT_EQ(1, pkt1->getTransidOffset());
// Test constructor to be used for outgoing messages.
// Use non-zero offset and specify transaction id.
+ const size_t offset_transid = 10;
+ const uint32_t transid = 0x010203;
boost::scoped_ptr<PerfPkt6> pkt2(new PerfPkt6(data, sizeof(data),
- 10, 0x010203));
- EXPECT_EQ(6, pkt2->getData().size());
+ offset_transid, transid));
+ EXPECT_EQ(sizeof(data), pkt2->getData().size());
EXPECT_EQ(0, memcmp(&pkt2->getData()[0], data, sizeof(data)));
EXPECT_EQ(0x010203, pkt2->getTransid());
- EXPECT_EQ(10, pkt2->getTransIdOffset());
+ EXPECT_EQ(10, pkt2->getTransidOffset());
}
TEST_F(PerfPkt6Test, RawPackUnpack) {
@@ -131,19 +133,22 @@ TEST_F(PerfPkt6Test, RawPackUnpack) {
// Create some input buffers to initialize options.
uint8_t buf_elapsed_time[] = { 1, 1 };
- uint8_t buf_duid[14] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+ uint8_t buf_duid[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
// Create options.
- OptionBuffer vec_elapsed_time(buf_elapsed_time, buf_elapsed_time + 2);
- OptionBuffer vec_duid(buf_duid, buf_duid + 14);
+ const size_t offset_elapsed_time = 86;
+ OptionBuffer vec_elapsed_time(buf_elapsed_time,
+ buf_elapsed_time + sizeof(buf_elapsed_time));
LocalizedOptionPtr pkt1_elapsed_time(new LocalizedOption(Option::V6,
D6O_ELAPSED_TIME,
vec_elapsed_time,
- 86));
+ offset_elapsed_time));
+ const size_t offset_duid = 4;
+ OptionBuffer vec_duid(buf_duid, buf_duid + sizeof(buf_duid));
LocalizedOptionPtr pkt1_duid(new LocalizedOption(Option::V6,
D6O_CLIENTID,
vec_duid,
- 4));
+ offset_duid));
// Add option to packet and create on-wire format from added options.
// Contents of options will override contents of packet buffer.
@@ -169,11 +174,11 @@ TEST_F(PerfPkt6Test, RawPackUnpack) {
LocalizedOptionPtr pkt2_elapsed_time(new LocalizedOption(Option::V6,
D6O_ELAPSED_TIME,
vec_elapsed_time,
- 86));
+ offset_elapsed_time));
LocalizedOptionPtr pkt2_duid(new LocalizedOption(Option::V6,
D6O_CLIENTID,
vec_duid,
- 4));
+ offset_duid));
// Add options to packet to pass their offsets.
pkt2->addOption(pkt2_elapsed_time);
pkt2->addOption(pkt2_duid);
@@ -207,10 +212,11 @@ TEST_F(PerfPkt6Test, InvalidOptions) {
OptionBuffer vec_server_id;
vec_server_id.resize(10);
// Testing invalid offset of the option (greater than packet size)
+ const size_t offset_serverid[] = { 150, 85 };
LocalizedOptionPtr pkt1_serverid(new LocalizedOption(Option::V6,
D6O_SERVERID,
vec_server_id,
- 150));
+ offset_serverid[0]));
pkt1->addOption(pkt1_serverid);
// Pack has to fail due to invalid offset.
EXPECT_FALSE(pkt1->rawPack());
@@ -222,7 +228,7 @@ TEST_F(PerfPkt6Test, InvalidOptions) {
LocalizedOptionPtr pkt2_serverid(new LocalizedOption(Option::V6,
D6O_SERVERID,
vec_server_id,
- 85));
+ offset_serverid[1]));
pkt2->addOption(pkt2_serverid);
// Pack must fail due to invalid offset.
EXPECT_FALSE(pkt2->rawPack());
@@ -237,10 +243,11 @@ TEST_F(PerfPkt6Test, TruncatedPacket) {
boost::scoped_ptr<PerfPkt6> pkt1(captureTruncated());
OptionBuffer vec_duid;
vec_duid.resize(30);
+ const size_t offset_duid = 4;
LocalizedOptionPtr pkt1_duid(new LocalizedOption(Option::V6,
D6O_CLIENTID,
vec_duid,
- 4));
+ offset_duid));
pkt1->addOption(pkt1_duid);
// Pack/unpack must fail because length of the option read from buffer
// will extend over the actual packet length.
@@ -249,13 +256,17 @@ TEST_F(PerfPkt6Test, TruncatedPacket) {
}
TEST_F(PerfPkt6Test, PackTransactionId) {
- uint8_t data[100] = { 0 };
+ uint8_t data[100];
+ memset(&data, 0, sizeof(data));
+
+ const size_t offset_transid[] = { 50, 100 };
+ const uint32_t transid = 0x010203;
// Create dummy packet that is simply filled with zeros.
boost::scoped_ptr<PerfPkt6> pkt1(new PerfPkt6(data,
sizeof(data),
- 50,
- 0x010203));
+ offset_transid[0],
+ transid));
// Reference data are non zero so we can detect them in dummy packet.
uint8_t ref_data[3] = { 1, 2, 3 };
@@ -271,13 +282,14 @@ TEST_F(PerfPkt6Test, PackTransactionId) {
(out_buf.getData());
// Validate transaction id.
- EXPECT_EQ(0, memcmp(out_buf_data + 50, ref_data, 3));
+ EXPECT_EQ(0, memcmp(out_buf_data + offset_transid[0], ref_data, 3));
+
// Out of bounds transaction id offset.
boost::scoped_ptr<PerfPkt6> pkt2(new PerfPkt6(data,
sizeof(data),
- 100,
- 0x010202));
+ offset_transid[1],
+ transid));
cout << "Testing out of bounds offset. "
"This may produce spurious errors ..." << endl;
EXPECT_FALSE(pkt2->rawPack());
@@ -292,9 +304,10 @@ TEST_F(PerfPkt6Test, UnpackTransactionId) {
data[i] = i - 49;
}
// Create packet and point out that transaction id is at offset 50.
+ const size_t offset_transid[] = { 50, 300 };
boost::scoped_ptr<PerfPkt6> pkt1(new PerfPkt6(data,
sizeof(data),
- 50));
+ offset_transid[0]));
// Get transaction id out of buffer and store in class member.
ASSERT_TRUE(pkt1->rawUnpack());
@@ -304,7 +317,7 @@ TEST_F(PerfPkt6Test, UnpackTransactionId) {
// Out of bounds transaction id offset.
boost::scoped_ptr<PerfPkt6> pkt2(new PerfPkt6(data,
sizeof(data),
- 300));
+ offset_transid[1]));
cout << "Testing out of bounds offset. "
"This may produce spurious errors ..." << endl;
EXPECT_FALSE(pkt2->rawUnpack());
More information about the bind10-changes
mailing list