From af69798355aa107b5beddcc32f80ba0e33f61a30 Mon Sep 17 00:00:00 2001 From: anonymous-contributor Date: Fri, 1 Jul 2016 12:19:13 +0800 Subject: [PATCH] New jconf parameters (#695) * Add 'tunnel_address' support for json config parser And allow ss-tunnel to use the newly introduced parser. Signed-off-by: Adam Anonymous * Add "mode" support for jconf Now jconf supports "mode" setting, allowed values are "tcp_only", "tcp_and_udp" and "udp_only". Signed-off-by: Adam Anonymous * Use jconf "mode" for server/local/tunnel/manager Signed-off-by: Adam Anonymous * Add per-project vimrc to gitignore As the coding style differs from kernel and other projects, so such project vimrc should be helpful. Signed-off-by: Adam Anonymous --- .gitignore | 3 +++ src/common.h | 4 ---- src/jconf.c | 15 +++++++++++++++ src/jconf.h | 7 +++++++ src/local.c | 6 ++++++ src/manager.c | 3 +++ src/server.c | 3 +++ src/tunnel.c | 6 ++++++ 8 files changed, 43 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 101e8514..b671d1d0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ shadowsocks-libev.pc debian/libshadowsocks-libev1.symbols libsodium/src/libsodium/include/sodium/version.h +# Ignore per-project vim config +.vimrc + # Ignore garbage of OS X *.DS_Store diff --git a/src/common.h b/src/common.h index fa3b98cc..c1155d87 100644 --- a/src/common.h +++ b/src/common.h @@ -49,10 +49,6 @@ #define SOL_TCP IPPROTO_TCP #endif -#define TCP_ONLY 0 -#define TCP_AND_UDP 1 -#define UDP_ONLY 3 - #if defined(MODULE_TUNNEL) || defined(MODULE_REDIR) #define MODULE_LOCAL #endif diff --git a/src/jconf.c b/src/jconf.c index 4ef9b44d..73b83bb0 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -191,6 +191,21 @@ jconf_t *read_jconf(const char *file) conf.nofile = value->u.integer; } else if (strcmp(name, "nameserver") == 0) { conf.nameserver = to_string(value); + } else if (strcmp(name, "tunnel_address") == 0) { + conf.tunnel_address = to_string(value); + } else if (strcmp(name, "mode") == 0) { + char *mode_str = to_string(value); + + if (strcmp(mode_str, "tcp_only") == 0) + conf.mode = TCP_ONLY; + else if (strcmp(mode_str, "tcp_and_udp") == 0) + conf.mode = TCP_AND_UDP; + else if (strcmp(mode_str, "udp_only") == 0) + conf.mode = UDP_ONLY; + else + LOGI("ignore unknown mode: %s, use tcp_only as fallback", + mode_str); + free(mode_str); } } } else { diff --git a/src/jconf.h b/src/jconf.h index 86e1f02f..b7a1111a 100644 --- a/src/jconf.h +++ b/src/jconf.h @@ -29,6 +29,11 @@ #define MAX_CONNECT_TIMEOUT 10 #define MIN_UDP_TIMEOUT 10 +#define TCP_ONLY 0 +#define TCP_AND_UDP 1 +#define UDP_ONLY 3 + + typedef struct { char *host; char *port; @@ -54,6 +59,8 @@ typedef struct { int fast_open; int nofile; char *nameserver; + char *tunnel_address; + int mode; } jconf_t; jconf_t *read_jconf(const char *file); diff --git a/src/local.c b/src/local.c index 947194f2..a81880ab 100644 --- a/src/local.c +++ b/src/local.c @@ -1137,6 +1137,12 @@ int main(int argc, char **argv) if (fast_open == 0) { fast_open = conf->fast_open; } + if (mode == TCP_ONLY) { + if (conf->mode == UDP_ONLY) + LOGI("ignore unsupported mode: udp_only, use tcp_only as fallback"); + else + mode = conf->mode; + } #ifdef HAVE_SETRLIMIT if (nofile == 0) { nofile = conf->nofile; diff --git a/src/manager.c b/src/manager.c index 792e3c2a..b1618552 100644 --- a/src/manager.c +++ b/src/manager.c @@ -703,6 +703,9 @@ int main(int argc, char **argv) if (auth == 0) { auth = conf->auth; } + if (mode == TCP_ONLY) { + mode = conf->mode; + } } if (server_num == 0) { diff --git a/src/server.c b/src/server.c index f9097a28..e1a0eefe 100644 --- a/src/server.c +++ b/src/server.c @@ -1485,6 +1485,9 @@ int main(int argc, char **argv) if (auth == 0) { auth = conf->auth; } + if (mode == TCP_ONLY) { + mode = conf->mode; + } #ifdef TCP_FASTOPEN if (fast_open == 0) { fast_open = conf->fast_open; diff --git a/src/tunnel.c b/src/tunnel.c index 03933e97..4d158a7e 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -843,6 +843,12 @@ int main(int argc, char **argv) if (auth == 0) { auth = conf->auth; } + if (tunnel_addr_str == NULL) { + tunnel_addr_str = conf->tunnel_address; + } + if (mode == TCP_ONLY) { + mode = conf->mode; + } #ifdef HAVE_SETRLIMIT if (nofile == 0) { nofile = conf->nofile;