From 1c64829dfa5601824eeb2726086bf3d3379a84f8 Mon Sep 17 00:00:00 2001 From: Vladimir Olteanu Date: Fri, 15 Sep 2017 04:17:00 +0300 Subject: [PATCH] Add command-line argument for keeping TCP_NODELAY (#1685) --- src/common.h | 1 + src/local.c | 8 +++++++- src/redir.c | 8 +++++++- src/server.c | 8 +++++++- src/tunnel.c | 8 +++++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/common.h b/src/common.h index 3738da3b..6b9d91be 100644 --- a/src/common.h +++ b/src/common.h @@ -63,6 +63,7 @@ enum { GETOPT_VAL_HELP = 257, GETOPT_VAL_REUSE_PORT, GETOPT_VAL_FAST_OPEN, + GETOPT_VAL_NODELAY, GETOPT_VAL_ACL, GETOPT_VAL_MTU, GETOPT_VAL_MPTCP, diff --git a/src/local.c b/src/local.c index 538d9b70..5141eb64 100644 --- a/src/local.c +++ b/src/local.c @@ -101,6 +101,7 @@ static int acl = 0; static int mode = TCP_ONLY; static int ipv6first = 0; static int fast_open = 0; +static int no_delay = 0; static int udp_fd = 0; static struct ev_signal sigint_watcher; @@ -948,7 +949,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - if (!remote->recv_ctx->connected) { + if (!remote->recv_ctx->connected && !no_delay) { int opt = 0; setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); @@ -1298,6 +1299,7 @@ main(int argc, char **argv) static struct option long_options[] = { { "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT }, { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, + { "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY }, { "acl", required_argument, NULL, GETOPT_VAL_ACL }, { "mtu", required_argument, NULL, GETOPT_VAL_MTU }, { "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP }, @@ -1336,6 +1338,10 @@ main(int argc, char **argv) mptcp = 1; LOGI("enable multipath TCP"); break; + case GETOPT_VAL_NODELAY: + no_delay = 1; + LOGI("enable TCP no-delay"); + break; case GETOPT_VAL_PLUGIN: plugin = optarg; break; diff --git a/src/redir.c b/src/redir.c index c09f7711..17ec5cce 100644 --- a/src/redir.c +++ b/src/redir.c @@ -98,6 +98,7 @@ static int mode = TCP_ONLY; static int nofile = 0; #endif static int fast_open = 0; +static int no_delay = 0; static struct ev_signal sigint_watcher; static struct ev_signal sigterm_watcher; @@ -437,7 +438,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - if (!remote->recv_ctx->connected) { + if (!remote->recv_ctx->connected && !no_delay) { int opt = 0; setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); @@ -905,6 +906,7 @@ main(int argc, char **argv) { "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN }, { "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS }, { "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT }, + { "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY }, { "password", required_argument, NULL, GETOPT_VAL_PASSWORD }, { "key", required_argument, NULL, GETOPT_VAL_KEY }, { "help", no_argument, NULL, GETOPT_VAL_HELP }, @@ -929,6 +931,10 @@ main(int argc, char **argv) mptcp = 1; LOGI("enable multipath TCP"); break; + case GETOPT_VAL_NODELAY: + no_delay = 1; + LOGI("enable TCP no-delay"); + break; case GETOPT_VAL_PLUGIN: plugin = optarg; break; diff --git a/src/server.c b/src/server.c index ffe312e5..d2793c67 100644 --- a/src/server.c +++ b/src/server.c @@ -119,6 +119,7 @@ static int acl = 0; static int mode = TCP_ONLY; static int ipv6first = 0; static int fast_open = 0; +static int no_delay = 0; #ifdef HAVE_SETRLIMIT static int nofile = 0; @@ -1142,7 +1143,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - if (!remote->recv_ctx->connected) { + if (!remote->recv_ctx->connected && !no_delay) { int opt = 0; setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); @@ -1501,6 +1502,7 @@ main(int argc, char **argv) static struct option long_options[] = { { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, { "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT }, + { "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY }, { "acl", required_argument, NULL, GETOPT_VAL_ACL }, { "manager-address", required_argument, NULL, GETOPT_VAL_MANAGER_ADDRESS }, @@ -1526,6 +1528,10 @@ main(int argc, char **argv) case GETOPT_VAL_FAST_OPEN: fast_open = 1; break; + case GETOPT_VAL_NODELAY: + no_delay = 1; + LOGI("enable TCP no-delay"); + break; case GETOPT_VAL_ACL: LOGI("initializing acl..."); acl = !init_acl(optarg); diff --git a/src/tunnel.c b/src/tunnel.c index 11600b69..f5947414 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -94,6 +94,7 @@ static int mode = TCP_ONLY; #ifdef HAVE_SETRLIMIT static int nofile = 0; #endif +static int no_delay = 0; static struct ev_signal sigint_watcher; static struct ev_signal sigterm_watcher; @@ -377,7 +378,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - if (!remote->recv_ctx->connected) { + if (!remote->recv_ctx->connected && !no_delay) { int opt = 0; setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); @@ -788,6 +789,7 @@ main(int argc, char **argv) static struct option long_options[] = { { "mtu", required_argument, NULL, GETOPT_VAL_MTU }, + { "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY }, { "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP }, { "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN }, { "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS }, @@ -818,6 +820,10 @@ main(int argc, char **argv) mptcp = 1; LOGI("enable multipath TCP"); break; + case GETOPT_VAL_NODELAY: + no_delay = 1; + LOGI("enable TCP no-delay"); + break; case GETOPT_VAL_PLUGIN: plugin = optarg; break;