Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/invoking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ the executable.
iperf3 versions. Use this option to preserve the less secure,
but more compatible, behavior.

--control-tos n
Set the IP type of service bits of the control connection. The
usual prefixes for octal and hex can be used, i.e. 52, 064 and
0x34 all specify the same value.

--control-dscp dscp
Set the IP DSCP bits of the control connection. Both numeric and
symbolic values are accepted. Numeric values can be specified in
decimal, octal and hex (see --control-tos above).

-m, --mptcp
Use the MPTCP variant for the current protocol. This only ap-
plies to TCP and enables MPTCP usage.
Expand Down
1 change: 1 addition & 0 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ struct iperf_settings
int mss; /* for TCP MSS */
int ttl; /* IP TTL option */
int tos; /* type of service bit */
int ctrl_tos; /* type of service for control socket */
int flowlabel; /* IPv6 flow label */
iperf_size_t bytes; /* number of bytes to send */
iperf_size_t blocks; /* number of blocks (packets) to send */
Expand Down
46 changes: 46 additions & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{"version6", no_argument, NULL, '6'},
{"tos", required_argument, NULL, 'S'},
{"dscp", required_argument, NULL, OPT_DSCP},
{"control-tos", required_argument, NULL, OPT_CONTROL_TOS},
{"control-dscp", required_argument, NULL, OPT_CONTROL_DSCP},
{"extra-data", required_argument, NULL, OPT_EXTRA_DATA},
#if defined(HAVE_FLOWLABEL)
{"flowlabel", required_argument, NULL, 'L'},
Expand Down Expand Up @@ -1505,6 +1507,22 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
}
client_flag = 1;
break;
case OPT_CONTROL_TOS:
test->settings->ctrl_tos = strtol(optarg, &endptr, 0);
if (endptr == optarg ||
test->settings->ctrl_tos < 0 ||
test->settings->ctrl_tos > 255) {
i_errno = IEBADTOS;
return -1;
}
break;
case OPT_CONTROL_DSCP:
test->settings->ctrl_tos = parse_qos(optarg);
if(test->settings->ctrl_tos < 0) {
i_errno = IEBADTOS;
return -1;
}
break;
case OPT_EXTRA_DATA:
test->extra_data = strdup(optarg);
client_flag = 1;
Expand Down Expand Up @@ -5487,6 +5505,34 @@ iflush(struct iperf_test *test)
return rc2;
}

int
iperf_set_tos(int s, int tos)
{
if (tos) {
if (getsockdomain(s) == AF_INET6) {
#ifdef IPV6_TCLASS
if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) < 0) {
i_errno = IESETCOS;
return -1;
}
if (setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
/* ignore any failure of v4 TOS in IPv6 case */
}
#else
i_errno = IESETCOS;
return -1;
#endif
} else {
if (setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
i_errno = IESETTOS;
return -1;
}
}
}

return 0;
}

#if defined (HAVE_TCP_KEEPALIVE)
// Set Control Connection TCP Keepalive (especially useful for long UDP test sessions)
int
Expand Down
8 changes: 8 additions & 0 deletions src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ typedef atomic_uint_fast64_t atomic_iperf_size_t;
#define OPT_SKIP_RX_COPY 32
#define OPT_JSON_STREAM_FULL_OUTPUT 33
#define OPT_SERVER_MAX_DURATION 34
#define OPT_CONTROL_TOS 35
#define OPT_CONTROL_DSCP 36

/* states */
#define TEST_START 1
Expand Down Expand Up @@ -319,6 +321,12 @@ void iperf_free_stream(struct iperf_stream * sp);
*/
int iperf_common_sockopts(struct iperf_test *, int s);

/**
* iperf_set_tos -- set socket TOS
*
*/
int iperf_set_tos(int s, int tos);

#if defined (HAVE_TCP_KEEPALIVE)
/**
* iperf_set_control_keepalive -- set control connection TCP keepalive
Expand Down
5 changes: 5 additions & 0 deletions src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ iperf_connect(struct iperf_test *test)
return -1;
}

// Set IP TOS
if (iperf_set_tos(test->ctrl_sck, test->settings->ctrl_tos) < 0) {
return -1;
}

// set TCP_NODELAY for lower latency on control messages
int flag = 1;
if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int))) {
Expand Down
7 changes: 7 additions & 0 deletions src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
" and client during the authentication process\n"
" --use-pkcs1-padding use pkcs1 padding at your own risk\n"
#endif //HAVE_SSL
" --control-tos N set the IP type of service of the control connection, 0-255.\n"
" The usual prefixes for octal and hex can be used,\n"
" i.e. 52, 064 and 0x34 all specify the same value.\n"

" --control-dscp val set the IP dscp value of the control connection, either 0-63 or symbolic.\n"
" Numeric values can be specified in decimal,\n"
" octal and hex (see --control-tos above).\n"
"Client specific:\n"
" -c, --client <host>[%%<dev>] run in client mode, connecting to <host>\n"
" (option <dev> equivalent to `--bind-dev <dev>`)\n"
Expand Down
11 changes: 11 additions & 0 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ iperf_server_listen(struct iperf_test *test)
}
}

// Set IP TOS
if (iperf_set_tos(test->listener, test->settings->ctrl_tos) < 0) {
close(test->listener);
return -1;
}

if (!test->json_output) {
if (test->server_last_run_rc != 2)
test->server_test_number +=1;
Expand Down Expand Up @@ -174,6 +180,11 @@ iperf_accept(struct iperf_test *test)
goto error_handling;
}

// Set IP TOS
if (iperf_set_tos(test->ctrl_sck, test->settings->ctrl_tos) < 0) {
goto error_handling;
}

#if defined(HAVE_TCP_USER_TIMEOUT)
int opt;
if ((opt = test->settings->snd_timeout)) {
Expand Down