Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r1047 committed - Split out handling of MSG_LOGIN and MSG_EXTENDED_LOGIN...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r1047 committed - Split out handling of MSG_LOGIN and MSG_EXTENDED_LOGIN...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r1047 committed - Split out handling of MSG_LOGIN and MSG_EXTENDED_LOGIN...
  • Date: Thu, 03 Apr 2014 19:32:13 +0000

Revision: 1047
Author:

Date: Thu Apr 3 19:31:48 2014 UTC
Log: Split out handling of MSG_LOGIN and MSG_EXTENDED_LOGIN
to make them easier to understand. Also, define constants
that limit the size of the version number transmitted
by clients.


http://code.google.com/p/ndt/source/detail?r=1047

Modified:
/branches/Issue143/src/protocol.h
/branches/Issue143/src/testoptions.c
/branches/Issue143/src/testoptions.h

=======================================
--- /branches/Issue143/src/protocol.h Wed Apr 2 23:01:31 2014 UTC
+++ /branches/Issue143/src/protocol.h Thu Apr 3 19:31:48 2014 UTC
@@ -25,6 +25,8 @@
#define MSG_WAITING 10
#define MSG_EXTENDED_LOGIN 11

+#define CS_VERSION_LENGTH_MAX 32
+
#define SRV_QUEUE_TEST_STARTS_NOW 0
#define SRV_QUEUE_TEST_STARTS_NOW_STR "0"

=======================================
--- /branches/Issue143/src/testoptions.c Wed Apr 2 23:01:31 2014 UTC
+++ /branches/Issue143/src/testoptions.c Thu Apr 3 19:31:48 2014 UTC
@@ -206,14 +206,15 @@

int initialize_tests(int ctlsockfd, TestOptions* options, char * buff,
size_t buff_strlen) {
- unsigned char msgValue[33] = {'\0', };
+ unsigned char msgValue[CS_VERSION_LENGTH_MAX + 1] = {'\0', };
unsigned char useropt = 0;
int msgType;
- int msgLen = 33;
+ int msgLen = CS_VERSION_LENGTH_MAX + 1;
int first = 1;
char *invalid_test_suite = "Invalid test suite request.";
char *client_timeout = "Client timeout.";
char *invalid_test = "Invalid test request.";
+ char *invalid_login_msg = "Invalid login message.";

// char remhostarr[256], protologlocalarr[256];
// char *remhost_ptr = get_remotehost();
@@ -221,7 +222,7 @@
assert(ctlsockfd != -1);
assert(options);

- memset(options->client_version, 0, 33);
+ memset(options->client_version, 0, sizeof(options->client_version));

// read the test suite request
if (recv_msg(ctlsockfd, &msgType, msgValue, &msgLen)) {
@@ -239,26 +240,36 @@
* payload byte indicating tests to be run and potentially
* a US-ASCII string indicating the version number.
* Three cases:
- * 1: MSG_LOGIN
- * 2: MSG_EXTENDED_LOGIN:
+ * 1: MSG_LOGIN: Check that msgLen is 1
+ * 2: MSG_EXTENDED_LOGIN: Check that msgLen is >= 1 and
+ * <= the maximum length of the client/server version
+ * string (plus 1 to account for the initial useropt
+ * and then copy the client version into client_version.
* 3: Neither
+ *
+ * In case (1) or (2) we copy the 0th byte from the msgValue
+ * into useropt so we'll do that in the fallthrough.
*/
- if (msgType == MSG_LOGIN || msgType == MSG_EXTENDED_LOGIN) {
- if (msgLen < 1) {
+ if (msgType == MSG_LOGIN) { /* Case 1 */
+ if (msgLen != 1) {
send_msg(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test));
return (-2);
}
- useropt = msgValue[0];
- if (msgLen > 1) {
- log_println(0, "msgLen: %d-\n", msgLen);
- log_println(0, "msgValue: %s-\n", msgValue + 1);
- memcpy(options->client_version, msgValue + 1, msgLen-1);
+ } else if (msgType == MSG_EXTENDED_LOGIN) { /* Case 2 */
+ if (msgLen >= 1 && msgLen <= (CS_VERSION_LENGTH_MAX + 1)) {
+ memcpy(options->client_version, msgValue + 1, msgLen - 1);
log_println(0, "Client version: %s-\n", options->client_version);
+ } else {
+ send_msg(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test));
+ return (-2);
}
- } else {
- send_msg(ctlsockfd, MSG_ERROR, invalid_test, strlen(invalid_test));
+ } else { /* Case 3 */
+ send_msg(ctlsockfd, MSG_ERROR,
+ invalid_login_msg,
+ strlen(invalid_login_msg));
return (-2);
}
+ useropt = msgValue[0];

// client connect received correctly. Logging activity
// log that client connected, and create log file
=======================================
--- /branches/Issue143/src/testoptions.h Wed Apr 2 23:01:31 2014 UTC
+++ /branches/Issue143/src/testoptions.h Thu Apr 3 19:31:48 2014 UTC
@@ -10,6 +10,7 @@
#define SRC_TESTOPTIONS_H_

#include "web100srv.h"
+#include "protocol.h"

#define LISTENER_SOCKET_CREATE_FAILED -1
#define SOCKET_CONNECT_TIMEOUT -100
@@ -21,7 +22,7 @@
int multiple; // multiples tests enabled
int mainport; // main port used for test

- char client_version[33]; // client version number.
+ char client_version[CS_VERSION_LENGTH_MAX + 1]; // client version number.

int midopt; // middlebox test to be perfomed?
int midsockfd; // socket file desc for middlebox test


  • [ndt-dev] [ndt] r1047 committed - Split out handling of MSG_LOGIN and MSG_EXTENDED_LOGIN..., ndt, 04/03/2014

Archive powered by MHonArc 2.6.16.

Top of Page