1
1

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.
Этот коммит содержится в:
Bruce A. Mah 2015-11-18 09:40:24 -08:00
родитель 44485b5b88
Коммит 956d115851
4 изменённых файлов: 21 добавлений и 9 удалений

Просмотреть файл

@ -662,6 +662,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
int flag; int flag;
int blksize; int blksize;
int server_flag, client_flag, rate_flag, duration_flag; int server_flag, client_flag, rate_flag, duration_flag;
char *endptr;
#if defined(HAVE_CPU_AFFINITY) #if defined(HAVE_CPU_AFFINITY)
char* comma; char* comma;
#endif /* HAVE_CPU_AFFINITY */ #endif /* HAVE_CPU_AFFINITY */
@ -825,13 +826,20 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
test->settings->domain = AF_INET6; test->settings->domain = AF_INET6;
break; break;
case 'S': 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; client_flag = 1;
break; break;
case 'L': case 'L':
#if defined(HAVE_FLOWLABEL) #if defined(HAVE_FLOWLABEL)
test->settings->flowlabel = strtol(optarg, NULL, 0); test->settings->flowlabel = strtol(optarg, &endptr, 0);
if (test->settings->flowlabel < 1 || test->settings->flowlabel > 0xfffff) { if (endptr == optarg ||
test->settings->flowlabel < 1 || test->settings->flowlabel > 0xfffff) {
i_errno = IESETFLOW; i_errno = IESETFLOW;
return -1; return -1;
} }
@ -876,8 +884,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
break; break;
case 'A': case 'A':
#if defined(HAVE_CPU_AFFINITY) #if defined(HAVE_CPU_AFFINITY)
test->affinity = atoi(optarg); test->affinity = strtol(optarg, &endptr, 0);
if (test->affinity < 0 || test->affinity > 1024) { if (endptr == optarg ||
test->affinity < 0 || test->affinity > 1024) {
i_errno = IEAFFINITY; i_errno = IEAFFINITY;
return -1; return -1;
} }

Просмотреть файл

@ -289,6 +289,7 @@ enum {
IENOSCTP = 18, // No SCTP support available IENOSCTP = 18, // No SCTP support available
IEBIND = 19, // Local port specified with no local bind option IEBIND = 19, // Local port specified with no local bind option
IEUDPBLOCKSIZE = 20, // Block size too large. Maximum value = %dMAX_UDP_BLOCKSIZE IEUDPBLOCKSIZE = 20, // Block size too large. Maximum value = %dMAX_UDP_BLOCKSIZE
IEBADTOS = 21, // Bad TOS value
/* Test errors */ /* Test errors */
IENEWTEST = 100, // Unable to create a new test (check perror) IENEWTEST = 100, // Unable to create a new test (check perror)
IEINITTEST = 101, // Test initialization failed (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 * California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of * to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved. * Energy). All rights reserved.
@ -127,6 +127,9 @@ iperf_strerror(int i_errno)
case IEUDPBLOCKSIZE: case IEUDPBLOCKSIZE:
snprintf(errstr, len, "block size too large (maximum = %d bytes)", MAX_UDP_BLOCKSIZE); snprintf(errstr, len, "block size too large (maximum = %d bytes)", MAX_UDP_BLOCKSIZE);
break; break;
case IEBADTOS:
snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)");
break;
case IEMSS: case IEMSS:
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS); snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS);
break; 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 * California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of * to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved. * Energy). All rights reserved.
@ -153,10 +153,9 @@ run(struct iperf_test *test)
for (;;) { for (;;) {
if (iperf_run_server(test) < 0) { if (iperf_run_server(test) < 0) {
iperf_err(test, "error - %s", iperf_strerror(i_errno)); iperf_err(test, "error - %s", iperf_strerror(i_errno));
fprintf(stderr, "\n");
++consecutive_errors; ++consecutive_errors;
if (consecutive_errors >= 5) { if (consecutive_errors >= 5) {
fprintf(stderr, "too many errors, exiting\n"); iperf_errexit(test, "too many errors, exiting");
break; break;
} }
} else } else