BIND 10 trac2157_2, updated. 7d28f0a9b596bd3a4580372c93408904d8f2d8a5 [2157] update docs for getRequestIPVersion()
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jan 30 09:45:04 UTC 2013
The branch, trac2157_2 has been updated
via 7d28f0a9b596bd3a4580372c93408904d8f2d8a5 (commit)
via fb2a1a9621d321c1db03bd3c4184d14e77f9d276 (commit)
via 2755265bad7544bdaacfeed81e71ae590f043866 (commit)
via 722fbab9dc7891a6d4270d9e8fac453791fb0c51 (commit)
via 1954d8d1d6b4b57c3f66443585cbe6aff51b4342 (commit)
via 810a54ae8ffc10a282796b9ba64594c629010580 (commit)
via 20255f329b3db92930f8914c3a10f06de26d8fa5 (commit)
via bfad7cb107492b6459df53f79875c3225096e67e (commit)
via f3710cc1ce7bdd800176c5b70f22710bda652ddc (commit)
via 59d2798eeb72f4b81dd0c7ee380794da67b96424 (commit)
from a1705370803388f15833e588db710fe520fda751 (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 7d28f0a9b596bd3a4580372c93408904d8f2d8a5
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 18:41:34 2013 +0900
[2157] update docs for getRequestIPVersion()
commit fb2a1a9621d321c1db03bd3c4184d14e77f9d276
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 18:16:55 2013 +0900
[2157] add parameter checks for setRequest(IPVersion|TransportProtocol)
commit 2755265bad7544bdaacfeed81e71ae590f043866
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 17:31:57 2013 +0900
[2157] removed a wrong note
commit 722fbab9dc7891a6d4270d9e8fac453791fb0c51
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 16:39:05 2013 +0900
[2157] use common idiom to check an element exists
commit 1954d8d1d6b4b57c3f66443585cbe6aff51b4342
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 16:33:38 2013 +0900
[2157] removed unused member variable
commit 810a54ae8ffc10a282796b9ba64594c629010580
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 16:17:43 2013 +0900
[2157] fixed misuse of constant; simply use a constant numeric
commit 20255f329b3db92930f8914c3a10f06de26d8fa5
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 16:13:50 2013 +0900
[2157] update notes
commit bfad7cb107492b6459df53f79875c3225096e67e
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 16:05:42 2013 +0900
[2157] throw InvalidParameter instead of assert, updated doxygen
commit f3710cc1ce7bdd800176c5b70f22710bda652ddc
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 15:52:24 2013 +0900
[2157] doxygen style fixes: adjust empty lines for readability
commit 59d2798eeb72f4b81dd0c7ee380794da67b96424
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Jan 30 15:13:52 2013 +0900
[2157] simplify return type of getRequestOpCode()
-----------------------------------------------------------------------
Summary of changes:
src/bin/auth/statistics.cc.pre | 10 +---
src/bin/auth/statistics.h | 77 +++++++++++++++++--------
src/bin/auth/tests/statistics_unittest.cc.pre | 53 +++++++++++++++--
src/lib/statistics/counter.h | 6 +-
src/lib/statistics/counter_dict.h | 9 +--
5 files changed, 106 insertions(+), 49 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/auth/statistics.cc.pre b/src/bin/auth/statistics.cc.pre
index 24a28d2..199068e 100644
--- a/src/bin/auth/statistics.cc.pre
+++ b/src/bin/auth/statistics.cc.pre
@@ -26,12 +26,6 @@
#include <boost/optional.hpp>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-
using namespace isc::dns;
using namespace isc::auth;
using namespace isc::statistics;
@@ -159,7 +153,7 @@ Counters::incRequest(const MessageAttributes& msgattrs) {
}
// OPCODE
- const boost::optional<const isc::dns::Opcode&> opcode =
+ const boost::optional<isc::dns::Opcode>& opcode =
msgattrs.getRequestOpCode();
// Increment opcode counter only if the opcode exists.
if (opcode) {
@@ -203,7 +197,7 @@ Counters::incResponse(const MessageAttributes& msgattrs,
server_msg_counter_.inc(MSG_REQUEST_BADEDNSVER);
}
- const boost::optional<const isc::dns::Opcode&> opcode =
+ const boost::optional<isc::dns::Opcode>& opcode =
msgattrs.getRequestOpCode();
if (opcode && opcode.get() == Opcode::QUERY()) {
// compound attributes
diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h
index 7e7a53a..18d2f83 100644
--- a/src/bin/auth/statistics.h
+++ b/src/bin/auth/statistics.h
@@ -29,6 +29,12 @@
#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
namespace isc {
namespace auth {
namespace statistics {
@@ -54,7 +60,7 @@ public:
};
private:
// request attributes
- int req_ip_version_; // IP version
+ int req_address_family_; // IP version
int req_transport_protocol_; // Transport layer protocol
boost::optional<isc::dns::Opcode> req_opcode_; // OpCode
enum BitAttributes {
@@ -71,21 +77,20 @@ public:
/// \brief The constructor.
///
/// \throw None
- MessageAttributes() : req_ip_version_(0), req_transport_protocol_(0)
+ MessageAttributes() : req_address_family_(0), req_transport_protocol_(0)
{}
/// \brief Return opcode of the request.
- /// \return opcode of the request wrapped with boost::optional
- /// \throw isc::InvalidOperation Opcode is not set
- const boost::optional<const isc::dns::Opcode&> getRequestOpCode() const {
- if (req_opcode_) {
- return (req_opcode_.get());
- } else {
- return boost::none;
- }
+ ///
+ /// \return opcode of the request wrapped with boost::optional; it's
+ /// converted to false if Opcode hasn't been set.
+ /// \throw None
+ const boost::optional<isc::dns::Opcode>& getRequestOpCode() const {
+ return (req_opcode_);
}
/// \brief Set opcode of the request.
+ ///
/// \param opcode Opcode of the request
/// \throw None
void setRequestOpCode(const isc::dns::Opcode& opcode) {
@@ -93,20 +98,26 @@ public:
}
/// \brief Get IP version carrying a request.
- /// \return IP version carrying a request (AF_INET or AF_INET6)
+ ///
+ /// \return IP address family carrying a request (AF_INET or AF_INET6)
/// \throw None
int getRequestIPVersion() const {
- return (req_ip_version_);
+ return (req_address_family_);
}
- /// \brief Set IP version carrying a request.
- /// \param ip_version AF_INET or AF_INET6
+ /// \brief Set IP address family carrying a request.
+ ///
+ /// \param address_family AF_INET or AF_INET6
/// \throw None
- void setRequestIPVersion(const int ip_version) {
- req_ip_version_ = ip_version;
+ void setRequestIPVersion(const int address_family) {
+ if (address_family != AF_INET && address_family != AF_INET6) {
+ isc_throw(isc::InvalidParameter, "Unknown address family");
+ }
+ req_address_family_ = address_family;
}
/// \brief Get transport protocol carrying a request.
+ ///
/// \return Transport protocol carrying a request
/// (IPPROTO_UDP or IPPROTO_TCP)
/// \throw None
@@ -115,13 +126,20 @@ public:
}
/// \brief Set transport protocol carrying a request.
+ ///
/// \param transport_protocol IPPROTO_UDP or IPPROTO_TCP
/// \throw None
void setRequestTransportProtocol(const int transport_protocol) {
+ if (transport_protocol != IPPROTO_UDP &&
+ transport_protocol != IPPROTO_TCP)
+ {
+ isc_throw(isc::InvalidParameter, "Unknown transport protocol");
+ }
req_transport_protocol_ = transport_protocol;
}
/// \brief Return whether EDNS version of the request is 0 or not.
+ ///
/// \return true if EDNS version of the request is 0
/// \throw None
bool getRequestEDNS0() const {
@@ -129,6 +147,7 @@ public:
}
/// \brief Set whether EDNS version of the request is 0 or not.
+ ///
/// \param with_edns_0 true if EDNS version of the request is 0
/// \throw None
void setRequestEDNS0(const bool with_edns_0) {
@@ -136,6 +155,7 @@ public:
}
/// \brief Return DNSSEC OK (DO) bit of the request.
+ ///
/// \return true if DNSSEC OK (DO) bit of the request is set
/// \throw None
bool getRequestDO() const {
@@ -143,6 +163,7 @@ public:
}
/// \brief Set DNSSEC OK (DO) bit of the request.
+ ///
/// \param with_dnssec_ok true if DNSSEC OK (DO) bit of the request is set
/// \throw None
void setRequestDO(const bool with_dnssec_ok) {
@@ -150,6 +171,7 @@ public:
}
/// \brief Return whether the request is TSIG signed or not.
+ ///
/// \return true if the request is TSIG signed
/// \throw None
bool getRequestSigTSIG() const {
@@ -157,6 +179,7 @@ public:
}
/// \brief Return whether the signature of the request is bad or not.
+ ///
/// \return true if the signature of the request is bad
/// \throw None
bool getRequestSigBadSig() const {
@@ -164,16 +187,23 @@ public:
}
/// \brief Set TSIG attributes of the request.
+ ///
/// \param signed_tsig true if the request is signed with TSIG
- /// \param badsig true if the signature of the request is bad
- /// \throw None
+ /// \param badsig true if the signature of the request is bad; it must not
+ // be true unless signed_tsig is true
+ /// \throw isc::InvalidParameter if badsig is true though the request is
+ /// not signed
void setRequestTSIG(const bool signed_tsig, const bool badsig) {
- assert(!(!signed_tsig && badsig));
+ if (!signed_tsig && badsig) {
+ isc_throw(isc::InvalidParameter, "Message is not signed but badsig"
+ " is true");
+ }
bit_attributes_[REQ_TSIG_SIGNED] = signed_tsig;
bit_attributes_[REQ_BADSIG] = badsig;
}
/// \brief Return TC (truncated) bit of the response.
+ ///
/// \return true if the response is truncated
/// \throw None
bool getResponseTruncated() const {
@@ -181,6 +211,7 @@ public:
}
/// \brief Set TC (truncated) bit of the response.
+ ///
/// \param is_truncated true if the response is truncated
/// \throw None
void setResponseTruncated(const bool is_truncated) {
@@ -188,6 +219,7 @@ public:
}
/// \brief Return whether the response is TSIG signed or not.
+ ///
/// \return true if the response is signed with TSIG
/// \throw None
bool getResponseTSIG() const {
@@ -195,6 +227,7 @@ public:
}
/// \brief Set whether the response is TSIG signed or not.
+ ///
/// \param signed_tsig true if the response is signed with TSIG
/// \throw None
void setResponseTSIG(const bool signed_tsig) {
@@ -240,14 +273,12 @@ public:
/// item_name is a string seperated by '.'.
/// item_value is an integer.
/// \endverbatim
- ///
typedef isc::data::ConstElementPtr ConstItemTreePtr;
/// \brief The constructor.
///
/// This constructor is mostly exception free. But it may still throw
/// a standard exception if memory allocation fails inside the method.
- ///
Counters();
/// \brief Increment counters according to the parameters.
@@ -255,9 +286,7 @@ public:
/// \param msgattrs DNS message attributes.
/// \param response DNS response message.
/// \param done DNS response was sent to the client.
- ///
/// \throw None
- ///
void inc(const MessageAttributes& msgattrs,
const isc::dns::Message& response, const bool done);
@@ -267,9 +296,7 @@ public:
/// standard exception if memory allocation fails inside the method.
///
/// \return statistics data
- ///
/// \throw std::bad_alloc Internal resource allocation fails
- ///
ConstItemTreePtr get() const;
};
diff --git a/src/bin/auth/tests/statistics_unittest.cc.pre b/src/bin/auth/tests/statistics_unittest.cc.pre
index e6b3aa0..5ba6dd3 100644
--- a/src/bin/auth/tests/statistics_unittest.cc.pre
+++ b/src/bin/auth/tests/statistics_unittest.cc.pre
@@ -63,6 +63,31 @@ buildSkeletonMessage(MessageAttributes& msgattrs) {
msgattrs.setRequestDO(true);
}
+TEST_F(CountersTest, invalidParameterForSetRequestIPVersion) {
+ MessageAttributes msgattrs;
+
+ // It should not throw if the parameter is AF_INET or AF_INET6.
+ EXPECT_NO_THROW(msgattrs.setRequestIPVersion(AF_INET));
+ EXPECT_NO_THROW(msgattrs.setRequestIPVersion(AF_INET6));
+
+ // It should throw isc::InvalidParameter if the parameter is not AF_INET
+ // nor AF_INET6.
+ EXPECT_THROW(msgattrs.setRequestIPVersion(AF_UNIX), isc::InvalidParameter);
+}
+
+TEST_F(CountersTest, invalidParameterForSetRequestTransportProtocol) {
+ MessageAttributes msgattrs;
+
+ // It should not throw if the parameter is IPPROTO_UDP or IPPROTO_TCP.
+ EXPECT_NO_THROW(msgattrs.setRequestTransportProtocol(IPPROTO_UDP));
+ EXPECT_NO_THROW(msgattrs.setRequestTransportProtocol(IPPROTO_TCP));
+
+ // It should throw isc::InvalidParameter if the parameter is not
+ // IPPROTO_UDP nor IPPROTO_TCP.
+ EXPECT_THROW(msgattrs.setRequestTransportProtocol(IPPROTO_IP),
+ isc::InvalidParameter);
+}
+
TEST_F(CountersTest, invalidOperationForGetRequestOpCode) {
MessageAttributes msgattrs;
@@ -75,6 +100,24 @@ TEST_F(CountersTest, invalidOperationForGetRequestOpCode) {
EXPECT_EQ(Opcode::QUERY(), msgattrs.getRequestOpCode().get());
}
+TEST_F(CountersTest, invalidParameterForSetRequestTSIG) {
+ MessageAttributes msgattrs;
+
+ // These patterns should not throw:
+ // request signature badsig
+ // --------------------------
+ // (none) false
+ // TSIG false
+ // TSIG true
+ EXPECT_NO_THROW(msgattrs.setRequestTSIG(false, false));
+ EXPECT_NO_THROW(msgattrs.setRequestTSIG(true, false));
+ EXPECT_NO_THROW(msgattrs.setRequestTSIG(true, true));
+
+ // It should throw isc::InvalidParameter if a message is not signed but
+ // badsig is true
+ EXPECT_THROW(msgattrs.setRequestTSIG(false, true), isc::InvalidParameter);
+}
+
TEST_F(CountersTest, incrementResponse) {
Message response(Message::RENDER);
MessageAttributes msgattrs;
@@ -115,12 +158,12 @@ TEST_F(CountersTest, incrementProtocolType) {
std::map<std::string, int> expect;
// Test these patterns:
- // ipversion protocol
+ // af proto
// -----------------
- // ipv4 udp
- // ipv6 udp
- // ipv4 tcp
- // ipv6 tcp
+ // ipv6 tcp
+ // ipv4 tcp
+ // ipv6 udp
+ // ipv4 udp
int count_v4 = 0, count_v6 = 0, count_udp = 0, count_tcp = 0;
for (int i = 0; i < 4; ++i) {
const int af = i & 1 ? AF_INET : AF_INET6;
diff --git a/src/lib/statistics/counter.h b/src/lib/statistics/counter.h
index 27bfac4..0313cff 100644
--- a/src/lib/statistics/counter.h
+++ b/src/lib/statistics/counter.h
@@ -32,20 +32,18 @@ public:
private:
std::vector<Counter::Value> counters_;
- static const unsigned int InitialValue = 0;
public:
/// The constructor.
///
/// This constructor prepares a set of counters which has \a items
- /// elements. The counters will be initialized with \a InitialValue;
- /// which is defined as 0.
+ /// elements. The counters will be initialized with 0.
///
/// \param items A number of counter items to hold (greater than 0)
///
/// \throw isc::InvalidParameter \a items is 0
explicit Counter(const size_t items) :
- counters_(items, InitialValue)
+ counters_(items, 0)
{
if (items == 0) {
isc_throw(isc::InvalidParameter, "Items must not be 0");
diff --git a/src/lib/statistics/counter_dict.h b/src/lib/statistics/counter_dict.h
index 98b0b81..1f2c037 100644
--- a/src/lib/statistics/counter_dict.h
+++ b/src/lib/statistics/counter_dict.h
@@ -40,7 +40,6 @@ private:
typedef boost::shared_ptr<isc::statistics::Counter> CounterPtr;
typedef std::map<std::string, CounterPtr> DictionaryMap;
DictionaryMap dictionary_;
- std::vector<std::string> elements_;
const size_t items_;
// Default constructor is forbidden; number of counter items must be
// specified at the construction of this class.
@@ -51,7 +50,7 @@ public:
/// This constructor prepares a dictionary of set of counters.
/// Initially the dictionary is empty.
/// Each counter has \a items elements. The counters will be initialized
- /// with \a InitialValue; which is defined as 0.
+ /// with 0.
///
/// \param items A number of counter items to hold (greater than 0)
///
@@ -73,7 +72,7 @@ public:
/// already exists
void addElement(const std::string& name) {
// throw if the element already exists
- if (dictionary_.count(name) != 0) {
+ if (dictionary_.find(name) != dictionary_.end()) {
isc_throw(isc::InvalidParameter,
"Element " << name << " already exists");
}
@@ -139,10 +138,6 @@ public:
{
public:
/// \brief The constructor.
- ///
- /// This constructor is mostly exception free. But it may still
- /// throw a standard exception if memory allocation fails
- /// inside the method.
ConstIterator() {}
/// \brief Constructor from implementation detail
More information about the bind10-changes
mailing list