BIND 10 trac1522, updated. 1f9be59567c5c6154c7f840e67c1353163e9e097 [1522] added note about an assumption on the token length in some tests.

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jan 4 09:21:18 UTC 2012


The branch, trac1522 has been updated
       via  1f9be59567c5c6154c7f840e67c1353163e9e097 (commit)
       via  65000f777ce98ccdcb51c2c6d685bf6045d7c511 (commit)
      from  0a9bcf007a5e71875e15a0c878c440bd51ca5e40 (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 1f9be59567c5c6154c7f840e67c1353163e9e097
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Wed Jan 4 00:47:47 2012 -0800

    [1522] added note about an assumption on the token length in some tests.

commit 65000f777ce98ccdcb51c2c6d685bf6045d7c511
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Wed Jan 4 00:32:40 2012 -0800

    [1522] used protocolString in createRequestSocketMessage.  also added
    checks for some bogus parameters for requestSocket().

-----------------------------------------------------------------------

Summary of changes:
 src/lib/server_common/socket_request.cc            |   41 ++++++++++----------
 src/lib/server_common/socket_request.h             |    6 ++-
 .../server_common/tests/socket_requestor_test.cc   |   27 ++++++++++++-
 3 files changed, 50 insertions(+), 24 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/server_common/socket_request.cc b/src/lib/server_common/socket_request.cc
index 399a6e4..4af354c 100644
--- a/src/lib/server_common/socket_request.cc
+++ b/src/lib/server_common/socket_request.cc
@@ -63,6 +63,20 @@ const std::string& RELEASE_SOCKET_COMMAND() {
     return (str);
 }
 
+// A helper converter from numeric protocol ID to the corresponding string.
+// used both for generating a message for the boss process and for logging.
+inline const char*
+protocolString(SocketRequestor::Protocol protocol) {
+    switch (protocol) {
+    case SocketRequestor::TCP:
+        return ("TCP");
+    case SocketRequestor::UDP:
+        return ("UDP");
+    default:
+        return ("unknown protocol");
+    }
+}
+
 // Creates the cc session message to request a socket.
 // The actual command format is hardcoded, and should match
 // the format as read in bind10_src.py.in
@@ -75,14 +89,11 @@ createRequestSocketMessage(SocketRequestor::Protocol protocol,
     const isc::data::ElementPtr request = isc::data::Element::createMap();
     request->set("address", isc::data::Element::create(address));
     request->set("port", isc::data::Element::create(port));
-    switch (protocol) {
-    case SocketRequestor::UDP:
-        request->set("protocol", isc::data::Element::create("UDP"));
-        break;
-    case SocketRequestor::TCP:
-        request->set("protocol", isc::data::Element::create("TCP"));
-        break;
+    if (protocol != SocketRequestor::TCP && protocol != SocketRequestor::UDP) {
+        isc_throw(InvalidParameter, "invalid protocol: " << protocol);
     }
+    request->set("protocol",
+                 isc::data::Element::create(protocolString(protocol)));
     switch (share_mode) {
     case SocketRequestor::DONT_SHARE:
         request->set("share_mode", isc::data::Element::create("NO"));
@@ -93,6 +104,8 @@ createRequestSocketMessage(SocketRequestor::Protocol protocol,
     case SocketRequestor::SHARE_ANY:
         request->set("share_mode", isc::data::Element::create("ANY"));
         break;
+    default:
+        isc_throw(InvalidParameter, "invalid share mode: " << share_mode);
     }
     request->set("share_name", isc::data::Element::create(share_name));
 
@@ -231,20 +244,6 @@ getSocketFd(const std::string& token, int sock_pass_fd) {
     return (passed_sock_fd);
 }
 
-namespace {
-inline const char*
-protocolString(SocketRequestor::Protocol protocol) {
-    switch (protocol) {
-    case SocketRequestor::TCP:
-        return ("TCP");
-    case SocketRequestor::UDP:
-        return ("UDP");
-    default:
-        return ("unknown protocol");
-    }
-}
-}
-
 // This implementation class for SocketRequestor uses
 // a ModuleCCSession for communication with the boss process,
 // and fd_share to read out the socket(s).
diff --git a/src/lib/server_common/socket_request.h b/src/lib/server_common/socket_request.h
index f4dcfea..35c3fa4 100644
--- a/src/lib/server_common/socket_request.h
+++ b/src/lib/server_common/socket_request.h
@@ -109,15 +109,19 @@ public:
     /// Asks the socket creator to give us a socket. The socket will be bound
     /// to the given address and port.
     ///
-    /// \param protocol specifies the protocol of the socket.
+    /// \param protocol specifies the protocol of the socket.  This must be
+    /// either UDP or TCP.
     /// \param address to which the socket should be bound.
     /// \param port the port to which the socket should be bound (native endian,
     ///     not network byte order).
     /// \param share_mode how the socket can be shared with other requests.
+    /// This must be one of the defined values of ShareMode.
     /// \param share_name the name of sharing group, relevant for SHARE_SAME
     ///     (specified by us or someone else).
     /// \return the socket, as a file descriptor and token representing it on
     ///     the socket creator side.
+    ///
+    /// \throw InvalidParameter protocol or share_mode is invalid
     /// \throw CCSessionError when we have a problem talking over the CC
     ///     session.
     /// \throw SocketError in case the other side doesn't want to give us
diff --git a/src/lib/server_common/tests/socket_requestor_test.cc b/src/lib/server_common/tests/socket_requestor_test.cc
index a32a53d..3b5f93f 100644
--- a/src/lib/server_common/tests/socket_requestor_test.cc
+++ b/src/lib/server_common/tests/socket_requestor_test.cc
@@ -195,6 +195,24 @@ TEST_F(SocketRequestorTest, testSocketRequestMessages) {
     ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
 }
 
+TEST_F(SocketRequestorTest, invalidParameterForSocketRequest) {
+    // Bad protocol
+    EXPECT_THROW(socketRequestor().
+                 requestSocket(static_cast<SocketRequestor::Protocol>(2),
+                               "192.0.2.1", 12345,
+                               SocketRequestor::DONT_SHARE,
+                               "test"),
+                 InvalidParameter);
+
+    // Bad share mode
+    EXPECT_THROW(socketRequestor().
+                 requestSocket(SocketRequestor::UDP,
+                               "192.0.2.1", 12345,
+                               static_cast<SocketRequestor::ShareMode>(3),
+                               "test"),
+                 InvalidParameter);
+}
+
 TEST_F(SocketRequestorTest, testBadRequestAnswers) {
     // Test various scenarios where the requestor gets back bad answers
 
@@ -402,8 +420,13 @@ private:
         }
     }
 
-    // Accept one connection, then send all values from the vector using
-    // send_fd() (prepended by a status code 'ok').
+    // Accept one connection, then for each value of the vector,
+    // read the socket token from the connection and match the string
+    // part of the vector element, and send the integer part of the element
+    // using send_fd() (prepended by a status code 'ok').  For simplicity
+    // we assume the tokens are 4 bytes long; if the test case uses a
+    // different size of token the test will fail.
+    //
     // There are a few specific exceptions;
     // when the value is -1, it will send back an error value (signaling
     // CREATOR_SOCKET_UNAVAILABLE)




More information about the bind10-changes mailing list