Skip to content

Commit e4503c8

Browse files
authored
Add Time Flag For The Iperf Server Process (#1684)
* reject measurements from client's whose duration exceeds that of the server * sum of test duration and omit must not exceed server's max duration * client's test duration cannot be 0 when server sets max duration * formatting * add flag description to man page * add server flag to case * changes made for review comments * handle errno * man page capitalization * adjust error code for server time max violation * move validation to within get_parameters * move validation to the end of the function
1 parent 543c8a7 commit e4503c8

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

src/iperf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ struct iperf_test
312312
int server_port;
313313
int omit; /* duration of omit period (-O flag) */
314314
int duration; /* total duration of test (-t flag) */
315+
int max_server_duration; /* maximum possible duration of test as enforced by the server (--max-server-duration flag) */
315316
char *diskfile_name; /* -F option */
316317
int affinity, server_affinity; /* -A option */
317318
#if defined(HAVE_CPUSET_SETAFFINITY)

src/iperf3.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ Restart the server after \fIn\fR seconds in case it gets stuck.
250250
In one-off mode, this is the number of seconds the server will wait
251251
before exiting.
252252
.TP
253+
.BR --server-max-duration " "
254+
The maximum time, in seconds, that an iperf client can run against the server.
255+
When the sum of the client's time and omit values exceeds the max duration set by the server
256+
or the client's time value is 0, the measurement is rejected.
257+
.TP
253258
.BR --server-bitrate-limit " \fIn\fR[KMGT][/\fCn\fR]"
254259
Set a limit on the server side, which will cause a test to abort if
255260
the client specifies a test of more than \fIn\fR bits per second, or

src/iperf_api.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
11141114
{"udp", no_argument, NULL, 'u'},
11151115
{"bitrate", required_argument, NULL, 'b'},
11161116
{"bandwidth", required_argument, NULL, 'b'},
1117-
{"server-bitrate-limit", required_argument, NULL, OPT_SERVER_BITRATE_LIMIT},
1117+
{"server-bitrate-limit", required_argument, NULL, OPT_SERVER_BITRATE_LIMIT},
1118+
{"server-max-duration", required_argument, NULL, OPT_SERVER_MAX_DURATION},
11181119
{"time", required_argument, NULL, 't'},
11191120
{"bytes", required_argument, NULL, 'n'},
11201121
{"blockcount", required_argument, NULL, 'k'},
@@ -1555,6 +1556,14 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
15551556
}
15561557
server_flag = 1;
15571558
break;
1559+
case OPT_SERVER_MAX_DURATION:
1560+
test->max_server_duration = atoi(optarg);
1561+
if (test->max_server_duration < 0 || test->max_server_duration > MAX_TIME) {
1562+
i_errno = IEDURATION;
1563+
return -1;
1564+
}
1565+
server_flag = 1;
1566+
break;
15581567
case OPT_RCV_TIMEOUT:
15591568
rcv_timeout_in = atoi(optarg);
15601569
if (rcv_timeout_in < MIN_NO_MSG_RCVD_TIMEOUT || rcv_timeout_in > MAX_TIME * SEC_TO_mS) {
@@ -2576,6 +2585,13 @@ get_parameters(struct iperf_test *test)
25762585
if (test->settings->rate)
25772586
cJSON_AddNumberToObject(test->json_start, "target_bitrate", test->settings->rate);
25782587
cJSON_Delete(j);
2588+
2589+
/* Ensure that the client does not request to run longer than the server's configured max */
2590+
if ((test->max_server_duration > 0) && (((test->duration + test->omit) > test->max_server_duration) || (test->duration == 0))) {
2591+
i_errno = IEMAXSERVERTESTDURATIONEXCEEDED;
2592+
r = -1;
2593+
}
2594+
25792595
}
25802596
return r;
25812597
}

src/iperf_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef atomic_uint_fast64_t atomic_iperf_size_t;
105105
#define OPT_CNTL_KA 31
106106
#define OPT_SKIP_RX_COPY 32
107107
#define OPT_JSON_STREAM_FULL_OUTPUT 33
108+
#define OPT_SERVER_MAX_DURATION 34
108109

109110
/* states */
110111
#define TEST_START 1
@@ -440,6 +441,7 @@ enum {
440441
IEUDPFILETRANSFER = 34, // Cannot transfer file using UDP
441442
IESERVERAUTHUSERS = 35, // Cannot access authorized users file
442443
IECNTLKA = 36, // Control connection Keepalive period should be larger than the full retry period (interval * count)
444+
IEMAXSERVERTESTDURATIONEXCEEDED = 37, // Client's duration exceeds server's maximum duration
443445
/* Test errors */
444446
IENEWTEST = 100, // Unable to create a new test (check perror)
445447
IEINITTEST = 101, // Test initialization failed (check perror)

src/iperf_error.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ iperf_strerror(int int_errno)
551551
snprintf(errstr, len, "unable to set/get socket keepalive TCP number of retries (TCP_KEEPCNT) option");
552552
perr = 1;
553553
break;
554+
case IEMAXSERVERTESTDURATIONEXCEEDED:
555+
snprintf(errstr, len, "client's requested duration exceeds the server's maximum permitted limit");
556+
break;
554557
default:
555558
snprintf(errstr, len, "int_errno=%d", int_errno);
556559
perr = 1;

src/iperf_locale.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
149149
" total data rate. Default is 5 seconds)\n"
150150
" --idle-timeout # restart idle server after # seconds in case it\n"
151151
" got stuck (default - no timeout)\n"
152+
" --server-max-duration # max time, in seconds, that an iperf test can run against the server\n"
152153
#if defined(HAVE_SSL)
153154
" --rsa-private-key-path path to the RSA private key used to decrypt\n"
154155
" authentication credentials\n"

0 commit comments

Comments
 (0)