Browse Source

Revert "[2157] pass IP versions and transport protocols with enum"

This reverts commit c2165222deb85cb2ff99a7146b28c659624edc24.

Conflicts:
	src/bin/auth/statistics.cc.pre
	src/bin/auth/statistics.h
	src/bin/auth/tests/statistics_unittest.cc.pre
Yoshitaka Aharen 12 years ago
parent
commit
d792272541

+ 2 - 6
src/bin/auth/auth_srv.cc

@@ -503,13 +503,9 @@ AuthSrv::processMessage(const IOMessage& io_message, Message& message,
     MessageAttributes stats_attrs;
 
     stats_attrs.setRequestIPVersion(
-        io_message.getRemoteEndpoint().getFamily() == AF_INET ?
-            MessageAttributes::IP_VERSION_IPV4 :
-            MessageAttributes::IP_VERSION_IPV6);
+        io_message.getRemoteEndpoint().getFamily());
     stats_attrs.setRequestTransportProtocol(
-        io_message.getRemoteEndpoint().getProtocol() == IPPROTO_UDP ?
-            MessageAttributes::TRANSPORT_UDP :
-            MessageAttributes::TRANSPORT_TCP);
+        io_message.getRemoteEndpoint().getProtocol());
 
     // First, check the header part.  If we fail even for the base header,
     // just drop the message.

+ 16 - 10
src/bin/auth/statistics.cc.pre

@@ -26,6 +26,12 @@
 
 #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;
@@ -120,16 +126,16 @@ Counters::Counters() :
 void
 Counters::incRequest(const MessageAttributes& msgattrs) {
     // protocols carrying request
-    server_msg_counter_.inc(
-        msgattrs.getRequestIPVersion() ==
-            MessageAttributes::IP_VERSION_IPV4 ?
-            MSG_REQUEST_IPV4 :
-            MSG_REQUEST_IPV6);
-    server_msg_counter_.inc(
-        msgattrs.getRequestTransportProtocol() ==
-            MessageAttributes::TRANSPORT_UDP ?
-            MSG_REQUEST_UDP :
-            MSG_REQUEST_TCP);
+    if (msgattrs.getRequestIPVersion() == AF_INET) {
+        server_msg_counter_.inc(MSG_REQUEST_IPV4);
+    } else if (msgattrs.getRequestIPVersion() == AF_INET6) {
+        server_msg_counter_.inc(MSG_REQUEST_IPV6);
+    }
+    if (msgattrs.getRequestTransportProtocol() == IPPROTO_UDP) {
+        server_msg_counter_.inc(MSG_REQUEST_UDP);
+    } else if (msgattrs.getRequestTransportProtocol() == IPPROTO_TCP) {
+        server_msg_counter_.inc(MSG_REQUEST_TCP);
+    }
 
     // request TSIG
     if (msgattrs.getRequestSigTSIG()) {

+ 18 - 28
src/bin/auth/statistics.h

@@ -54,8 +54,8 @@ public:
     };
 private:
     // request attributes
-    IPVersionType req_ip_version_;                  // IP version
-    TransportProtocolType req_transport_protocol_;  // Transport layer protocol
+    int req_ip_version_;            // IP version
+    int req_transport_protocol_;    // Transport layer protocol
     boost::optional<isc::dns::Opcode> req_opcode_;  // OpCode
     enum BitAttributes {
         REQ_WITH_EDNS_0,            // request with EDNS ver.0
@@ -71,9 +71,7 @@ public:
     /// \brief The constructor.
     ///
     /// \throw None
-    MessageAttributes() :
-        req_ip_version_(IP_VERSION_UNSPEC),
-        req_transport_protocol_(TRANSPORT_UNSPEC)
+    MessageAttributes() : req_ip_version_(0), req_transport_protocol_(0)
     {}
 
     /// \brief Return opcode of the request.
@@ -94,39 +92,32 @@ public:
         req_opcode_ = opcode;
     }
 
-    /// \brief Return IP version carrying the request.
-    /// \return IP version carrying the request
+    /// \brief Get IP version carrying a request.
+    /// \return IP version carrying a request (AF_INET or AF_INET6)
     /// \throw None
-    IPVersionType getRequestIPVersion() const {
+    int getRequestIPVersion() const {
         return (req_ip_version_);
     }
 
-    /// \brief Set IP version carrying the request.
-    /// \param ip_version IP version carrying the request
-    /// \throw isc::InvalidParameter ip_version is invalid
-    void setRequestIPVersion(const IPVersionType ip_version) {
-        if (ip_version == IP_VERSION_UNSPEC) {
-            isc_throw(isc::InvalidParameter, "Invalid IP version");
-        }
+    /// \brief Set IP version carrying a request.
+    /// \param ip_version AF_INET or AF_INET6
+    /// \throw None
+    void setRequestIPVersion(const int ip_version) {
         req_ip_version_ = ip_version;
     }
 
-    /// \brief Return transport protocol carrying the request.
-    /// \return Transport protocol carrying the request
+    /// \brief Get transport protocol carrying a request.
+    /// \return Transport protocol carrying a request
+    ///         (IPPROTO_UDP or IPPROTO_TCP)
     /// \throw None
-    TransportProtocolType getRequestTransportProtocol() const {
+    int getRequestTransportProtocol() const {
         return (req_transport_protocol_);
     }
 
-    /// \brief Set transport protocol carrying the request.
-    /// \param transport_protocol Transport protocol carrying the request
-    /// \throw isc::InvalidParameter transport_protocol is invalid
-    void setRequestTransportProtocol(
-        const TransportProtocolType transport_protocol)
-    {
-        if (transport_protocol == TRANSPORT_UNSPEC) {
-            isc_throw(isc::InvalidParameter, "Invalid transport protocol");
-        }
+    /// \brief Set transport protocol carrying a request.
+    /// \param transport_protocol IPPROTO_UDP or IPPROTO_TCP
+    /// \throw None
+    void setRequestTransportProtocol(const int transport_protocol) {
         req_transport_protocol_ = transport_protocol;
     }
 
@@ -233,7 +224,6 @@ class Counters : boost::noncopyable {
 private:
     // counter for DNS message attributes
     isc::statistics::Counter server_msg_counter_;
-
     void incRequest(const MessageAttributes& msgattrs);
     void incResponse(const MessageAttributes& msgattrs,
                      const isc::dns::Message& response);

+ 13 - 33
src/bin/auth/tests/statistics_unittest.cc.pre

@@ -56,27 +56,13 @@ protected:
 
 void
 buildSkeletonMessage(MessageAttributes& msgattrs) {
-    msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_IPV4);
-    msgattrs.setRequestTransportProtocol(MessageAttributes::TRANSPORT_UDP);
+    msgattrs.setRequestIPVersion(AF_INET);
+    msgattrs.setRequestTransportProtocol(IPPROTO_UDP);
     msgattrs.setRequestOpCode(Opcode::QUERY());
     msgattrs.setRequestEDNS0(true);
     msgattrs.setRequestDO(true);
 }
 
-TEST_F(CountersTest, invalidParameter) {
-    MessageAttributes msgattrs;
-
-    // Passing *_UNSPEC should trigger throwing an exception
-    // isc::InvalidParameter.
-    EXPECT_THROW(
-        msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_UNSPEC),
-        isc::InvalidParameter);
-    EXPECT_THROW(
-        msgattrs.setRequestTransportProtocol(
-            MessageAttributes::TRANSPORT_UNSPEC),
-        isc::InvalidParameter);
-}
-
 TEST_F(CountersTest, invalidOperationForGetRequestOpCode) {
     MessageAttributes msgattrs;
 
@@ -137,17 +123,11 @@ TEST_F(CountersTest, incrementProtocolType) {
     //      ipv6        tcp
     int count_v4 = 0, count_v6 = 0, count_udp = 0, count_tcp = 0;
     for (int i = 0; i < 4; ++i) {
-        const enum MessageAttributes::IPVersionType ipversion =
-            (i & 1) != 0 ?
-            MessageAttributes::IP_VERSION_IPV4 :
-            MessageAttributes::IP_VERSION_IPV6;
-        const enum MessageAttributes::TransportProtocolType proto =
-            (i & 2) != 0 ?
-            MessageAttributes::TRANSPORT_UDP :
-            MessageAttributes::TRANSPORT_TCP;
+        const int af = i & 1 ? AF_INET : AF_INET6;
+        const int proto = i & 2 ? IPPROTO_UDP : IPPROTO_TCP;
 
         buildSkeletonMessage(msgattrs);
-        msgattrs.setRequestIPVersion(ipversion);
+        msgattrs.setRequestIPVersion(af);
         msgattrs.setRequestTransportProtocol(proto);
 
         response.setRcode(Rcode::REFUSED());
@@ -157,12 +137,12 @@ TEST_F(CountersTest, incrementProtocolType) {
 
         counters.inc(msgattrs, response, true);
 
-        if (ipversion == MessageAttributes::IP_VERSION_IPV4) {
+        if (af == AF_INET) {
             ++count_v4;
         } else {
             ++count_v6;
         }
-        if (proto == MessageAttributes::TRANSPORT_UDP) {
+        if (proto == IPPROTO_UDP) {
             ++count_udp;
         } else {
             ++count_tcp;
@@ -548,8 +528,8 @@ TEST_F(CountersTest, incrementQrySuccess) {
     std::map<std::string, int> expect;
 
     // Opcode = QUERY, Rcode = NOERROR, ANCOUNT > 0
-    msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_IPV4);
-    msgattrs.setRequestTransportProtocol(MessageAttributes::TRANSPORT_UDP);
+    msgattrs.setRequestIPVersion(AF_INET);
+    msgattrs.setRequestTransportProtocol(IPPROTO_UDP);
     msgattrs.setRequestOpCode(Opcode::QUERY());
     msgattrs.setRequestEDNS0(true);
     msgattrs.setRequestDO(true);
@@ -598,8 +578,8 @@ TEST_F(CountersTest, incrementQryReferralAndNxrrset) {
     int count_referral = 0, count_nxrrset = 0;
     for (int i = 0; i < 2; ++i) {
         const bool is_aa_set = i & 1;
-        msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_IPV4);
-        msgattrs.setRequestTransportProtocol(MessageAttributes::TRANSPORT_UDP);
+        msgattrs.setRequestIPVersion(AF_INET);
+        msgattrs.setRequestTransportProtocol(IPPROTO_UDP);
         msgattrs.setRequestOpCode(Opcode::QUERY());
         msgattrs.setRequestEDNS0(true);
         msgattrs.setRequestDO(true);
@@ -642,8 +622,8 @@ TEST_F(CountersTest, incrementAuthQryRej) {
     std::map<std::string, int> expect;
 
     // Opcode = QUERY, Rcode = REFUSED, ANCOUNT = 0 (don't care)
-    msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_IPV4);
-    msgattrs.setRequestTransportProtocol(MessageAttributes::TRANSPORT_UDP);
+    msgattrs.setRequestIPVersion(AF_INET);
+    msgattrs.setRequestTransportProtocol(IPPROTO_UDP);
     msgattrs.setRequestOpCode(Opcode::QUERY());
     msgattrs.setRequestEDNS0(true);
     msgattrs.setRequestDO(true);