Improve command error handling.
Exit with non-zero exit code if server mode has too many errors. Properly detect complain about non-numeric arguments to -A, -L, and -S. Implement range checks for argument to -S. Fixes #316.
Этот коммит содержится в:
родитель
44485b5b88
Коммит
956d115851
@ -662,6 +662,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
||||
int flag;
|
||||
int blksize;
|
||||
int server_flag, client_flag, rate_flag, duration_flag;
|
||||
char *endptr;
|
||||
#if defined(HAVE_CPU_AFFINITY)
|
||||
char* comma;
|
||||
#endif /* HAVE_CPU_AFFINITY */
|
||||
@ -825,13 +826,20 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
||||
test->settings->domain = AF_INET6;
|
||||
break;
|
||||
case 'S':
|
||||
test->settings->tos = strtol(optarg, NULL, 0);
|
||||
test->settings->tos = strtol(optarg, &endptr, 0);
|
||||
if (endptr == optarg ||
|
||||
test->settings->tos < 0 ||
|
||||
test->settings->tos > 255) {
|
||||
i_errno = IEBADTOS;
|
||||
return -1;
|
||||
}
|
||||
client_flag = 1;
|
||||
break;
|
||||
case 'L':
|
||||
#if defined(HAVE_FLOWLABEL)
|
||||
test->settings->flowlabel = strtol(optarg, NULL, 0);
|
||||
if (test->settings->flowlabel < 1 || test->settings->flowlabel > 0xfffff) {
|
||||
test->settings->flowlabel = strtol(optarg, &endptr, 0);
|
||||
if (endptr == optarg ||
|
||||
test->settings->flowlabel < 1 || test->settings->flowlabel > 0xfffff) {
|
||||
i_errno = IESETFLOW;
|
||||
return -1;
|
||||
}
|
||||
@ -876,8 +884,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
||||
break;
|
||||
case 'A':
|
||||
#if defined(HAVE_CPU_AFFINITY)
|
||||
test->affinity = atoi(optarg);
|
||||
if (test->affinity < 0 || test->affinity > 1024) {
|
||||
test->affinity = strtol(optarg, &endptr, 0);
|
||||
if (endptr == optarg ||
|
||||
test->affinity < 0 || test->affinity > 1024) {
|
||||
i_errno = IEAFFINITY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -289,6 +289,7 @@ enum {
|
||||
IENOSCTP = 18, // No SCTP support available
|
||||
IEBIND = 19, // Local port specified with no local bind option
|
||||
IEUDPBLOCKSIZE = 20, // Block size too large. Maximum value = %dMAX_UDP_BLOCKSIZE
|
||||
IEBADTOS = 21, // Bad TOS value
|
||||
/* Test errors */
|
||||
IENEWTEST = 100, // Unable to create a new test (check perror)
|
||||
IEINITTEST = 101, // Test initialization failed (check perror)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* iperf, Copyright (c) 2014, The Regents of the University of
|
||||
* iperf, Copyright (c) 2014, 2015, The Regents of the University of
|
||||
* California, through Lawrence Berkeley National Laboratory (subject
|
||||
* to receipt of any required approvals from the U.S. Dept. of
|
||||
* Energy). All rights reserved.
|
||||
@ -127,6 +127,9 @@ iperf_strerror(int i_errno)
|
||||
case IEUDPBLOCKSIZE:
|
||||
snprintf(errstr, len, "block size too large (maximum = %d bytes)", MAX_UDP_BLOCKSIZE);
|
||||
break;
|
||||
case IEBADTOS:
|
||||
snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)");
|
||||
break;
|
||||
case IEMSS:
|
||||
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS);
|
||||
break;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* iperf, Copyright (c) 2014, The Regents of the University of
|
||||
* iperf, Copyright (c) 2014, 2015, The Regents of the University of
|
||||
* California, through Lawrence Berkeley National Laboratory (subject
|
||||
* to receipt of any required approvals from the U.S. Dept. of
|
||||
* Energy). All rights reserved.
|
||||
@ -153,10 +153,9 @@ run(struct iperf_test *test)
|
||||
for (;;) {
|
||||
if (iperf_run_server(test) < 0) {
|
||||
iperf_err(test, "error - %s", iperf_strerror(i_errno));
|
||||
fprintf(stderr, "\n");
|
||||
++consecutive_errors;
|
||||
if (consecutive_errors >= 5) {
|
||||
fprintf(stderr, "too many errors, exiting\n");
|
||||
iperf_errexit(test, "too many errors, exiting");
|
||||
break;
|
||||
}
|
||||
} else
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user