From 44027da3264ab34b9b167485b0177fc7c19891a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E9=87=8E=E3=83=8F=E3=82=B8=E3=83=A1?= Date: Mon, 30 Oct 2017 10:35:14 +0800 Subject: [PATCH] enable TCP_NODELAY from config file (#1757) * Fix #1739 Refine #1739 * enable TCP_NODELAY from config file --- .gitignore | 3 +++ README.md | 12 +++++++++++- completions/bash/ss-local | 2 +- completions/bash/ss-server | 2 +- completions/zsh/_ss-local | 1 + completions/zsh/_ss-redir | 1 + completions/zsh/_ss-server | 1 + doc/shadowsocks-libev.asciidoc | 1 + src/jconf.c | 5 +++++ src/jconf.h | 1 + src/local.c | 7 +++++++ src/redir.c | 7 +++++++ src/server.c | 7 +++++++ src/tunnel.c | 3 +++ 14 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7df17bd1..8e260abd 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ doc/*.html *.tar.gz *.tgz # + +# Visual Studio Code +.vscode/* diff --git a/README.md b/README.md index f61c0b63..f899f17c 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ Supported distributions: If you are using CentOS 7, you need to install these prequirement to build from source code: -```bash +```bash yum install epel-release -y yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y ``` @@ -381,9 +381,13 @@ you may refer to the man pages of the applications, respectively. for local port forwarding, only available in tunnel mode + [-6] Resovle hostname to IPv6 address first. + [-d ] setup name servers for internal DNS resolver, only available in server mode + [--reuse-port] Enable port reuse. + [--fast-open] enable TCP fast open, only available in local and server mode, with Linux kernel > 3.7.0 @@ -394,6 +398,12 @@ you may refer to the man pages of the applications, respectively. [--manager-address ] UNIX domain socket address only available in server and manager mode + [--mtu ] MTU of your network interface. + + [--mptcp] Enable Multipath TCP on MPTCP Kernel. + + [--no-delay] Enable TCP_NODELAY. + [--executable ] path to the executable of ss-server only available in manager mode diff --git a/completions/bash/ss-local b/completions/bash/ss-local index e014af0a..0186ccc4 100644 --- a/completions/bash/ss-local +++ b/completions/bash/ss-local @@ -1,7 +1,7 @@ _ss_local() { local cur prev opts ciphers - opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -v -h --reuse-port --fast-open --acl --mtu --mptcp --key --plugin --plugin-opts --help' + opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -v -h --reuse-port --fast-open --acl --mtu --mptcp --no-delay --key --plugin --plugin-opts --help' ciphers='rc4-md5 aes-128-gcm aes-192-gcm aes-256-gcm aes-128-cfb aes-192-cfb aes-256-cfb aes-128-ctr aes-192-ctr aes-256-ctr camellia-128-cfb camellia-192-cfb camellia-256-cfb bf-cfb chacha20-ietf-poly1305 salsa20 chacha20 chacha20-ietf' cur=${COMP_WORDS[COMP_CWORD]} prev="${COMP_WORDS[COMP_CWORD-1]}" diff --git a/completions/bash/ss-server b/completions/bash/ss-server index 4d428ccd..cec983ce 100644 --- a/completions/bash/ss-server +++ b/completions/bash/ss-server @@ -1,7 +1,7 @@ _ss_server() { local cur prev opts ciphers - opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -6 -d -v -h --reuse-port --fast-open --acl --manager-address --mtu --mptcp --key --plugin --plugin-opts --help' + opts='-s -p -l -k -m -a -f -t -c -n -i -b -u -U -6 -d -v -h --reuse-port --fast-open --acl --manager-address --mtu --mptcp --no-delay --key --plugin --plugin-opts --help' ciphers='rc4-md5 aes-128-gcm aes-192-gcm aes-256-gcm aes-128-cfb aes-192-cfb aes-256-cfb aes-128-ctr aes-192-ctr aes-256-ctr camellia-128-cfb camellia-192-cfb camellia-256-cfb bf-cfb chacha20-ietf-poly1305 salsa20 chacha20 chacha20-ietf' COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} diff --git a/completions/zsh/_ss-local b/completions/zsh/_ss-local index 9b6e4d64..c56ed521 100644 --- a/completions/zsh/_ss-local +++ b/completions/zsh/_ss-local @@ -24,6 +24,7 @@ _arguments "-h::" \ "--acl:acl file:_files" \ "--mtu::" \ "--mptcp::" \ + "--no-delay::" \ "--key:key in base64:" \ "--plugin:plugin name:" \ "--plugin-opts:plugin options:" \ diff --git a/completions/zsh/_ss-redir b/completions/zsh/_ss-redir index 117f8b2a..4f3b065e 100644 --- a/completions/zsh/_ss-redir +++ b/completions/zsh/_ss-redir @@ -23,6 +23,7 @@ _arguments "-h::" \ "--acl:acl file:_files" \ "--mtu::" \ "--mptcp::" \ + "--no-delay::" \ "--key:key in base64:" \ "--plugin:plugin name:" \ "--plugin-opts:plugin options:" \ diff --git a/completions/zsh/_ss-server b/completions/zsh/_ss-server index 030165fd..8d9f4316 100644 --- a/completions/zsh/_ss-server +++ b/completions/zsh/_ss-server @@ -27,6 +27,7 @@ _arguments "-h::" \ "--acl:acl file:_files" \ "--mtu::" \ "--mptcp::" \ + "--no-delay::" \ "--key:key in base64:" \ "--plugin:plugin name:" \ "--plugin-opts:plugin options:" \ diff --git a/doc/shadowsocks-libev.asciidoc b/doc/shadowsocks-libev.asciidoc index 78cd4d70..5a62f669 100644 --- a/doc/shadowsocks-libev.asciidoc +++ b/doc/shadowsocks-libev.asciidoc @@ -179,6 +179,7 @@ The config file equivalent of command line options is listed as example below. | -a nobody | "user": "nobody" | --fast-open | "fast_open": true | --reuse-port | "reuse_port": true +| --no-delay | "no_delay": true | --plugin "obfs-server" | "plugin": "obfs-server" | --plugin-opts "obfs=http" | "plugin_opts": "obfs=http" | -6 | "ipv6_first": true diff --git a/src/jconf.c b/src/jconf.c index 4050fdae..abd69572 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -326,6 +326,11 @@ read_jconf(const char *file) "invalid config file: option 'use_syslog' must be a boolean"); use_syslog = value->u.boolean; #endif + } else if (strcmp(name, "no_delay") == 0) { + check_json_value_type( + value, json_boolean, + "invalid config file: option 'no_delay' must be a boolean"); + conf.no_delay = value->u.boolean; } } } else { diff --git a/src/jconf.h b/src/jconf.h index 0aafebca..17a6706f 100644 --- a/src/jconf.h +++ b/src/jconf.h @@ -86,6 +86,7 @@ typedef struct { int mtu; int mptcp; int ipv6_first; + int no_delay; } jconf_t; jconf_t *read_jconf(const char *file); diff --git a/src/local.c b/src/local.c index 570d8cd8..3a9935b5 100644 --- a/src/local.c +++ b/src/local.c @@ -1493,6 +1493,9 @@ main(int argc, char **argv) if (mptcp == 0) { mptcp = conf->mptcp; } + if (no_delay == 0) { + no_delay = conf->no_delay; + } #ifdef HAVE_SETRLIMIT if (nofile == 0) { nofile = conf->nofile; @@ -1563,6 +1566,10 @@ main(int argc, char **argv) #endif } + if (no_delay) { + LOGI("enable TCP no-delay"); + } + if (ipv6first) { LOGI("resolving hostname to IPv6 address first"); } diff --git a/src/redir.c b/src/redir.c index 3cec8d00..a83e5ab9 100644 --- a/src/redir.c +++ b/src/redir.c @@ -1071,6 +1071,9 @@ main(int argc, char **argv) if (mptcp == 0) { mptcp = conf->mptcp; } + if (no_delay == 0) { + no_delay = conf->no_delay; + } if (reuse_port == 0) { reuse_port = conf->reuse_port; } @@ -1150,6 +1153,10 @@ main(int argc, char **argv) daemonize(pid_path); } + if (no_delay) { + LOGI("enable TCP no-delay"); + } + if (ipv6first) { LOGI("resolving hostname to IPv6 address first"); } diff --git a/src/server.c b/src/server.c index 9f77c03e..3e88de4a 100644 --- a/src/server.c +++ b/src/server.c @@ -1679,6 +1679,9 @@ main(int argc, char **argv) if (mptcp == 0) { mptcp = conf->mptcp; } + if (no_delay == 0) { + no_delay = conf->no_delay; + } if (reuse_port == 0) { reuse_port = conf->reuse_port; } @@ -1771,6 +1774,10 @@ main(int argc, char **argv) LOGI("TCP relay disabled"); } + if (no_delay) { + LOGI("enable TCP no-delay"); + } + // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGABRT, SIG_IGN); diff --git a/src/tunnel.c b/src/tunnel.c index 9e6cd0dd..0cae1e1d 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -974,6 +974,9 @@ main(int argc, char **argv) if (mptcp == 0) { mptcp = conf->mptcp; } + if (no_delay == 0) { + no_delay = conf->no_delay; + } if (reuse_port == 0) { reuse_port = conf->reuse_port; }