From 92f0baa789ee7881efd642dbf0f77f4fe0fc9859 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 14 Jan 2017 10:40:14 +0800 Subject: [PATCH] Update SIP003 interfaces --- doc/ss-local.asciidoc | 6 +++++- doc/ss-manager.asciidoc | 6 +++++- doc/ss-redir.asciidoc | 6 +++++- doc/ss-server.asciidoc | 6 +++++- doc/ss-tunnel.asciidoc | 6 +++++- src/jconf.c | 4 ++++ src/jconf.h | 1 + src/local.c | 9 ++++++++- src/manager.c | 16 ++++++++++++++-- src/manager.h | 2 +- src/plugin.c | 4 ++++ src/plugin.h | 1 + src/redir.c | 9 ++++++++- src/server.c | 9 ++++++++- src/tunnel.c | 9 ++++++++- src/utils.c | 6 +++++- 16 files changed, 87 insertions(+), 13 deletions(-) diff --git a/doc/ss-local.asciidoc b/doc/ss-local.asciidoc index 1f532c92..a1f2b0f2 100644 --- a/doc/ss-local.asciidoc +++ b/doc/ss-local.asciidoc @@ -14,6 +14,7 @@ SYNOPSIS [-t ] [-c ] [-i ] [-a ] [-b ] [--fast-open] [--acl ] [--mtu ] + [--plugin ] [--plugin_opts :: +--plugin :: Enable SIP003 plugin. (Experimental) +--plugin_opts :: +Set SIP003 plugin options. (Experimental) + -v:: Enable verbose mode. diff --git a/doc/ss-manager.asciidoc b/doc/ss-manager.asciidoc index 5730d572..ba5e17fc 100644 --- a/doc/ss-manager.asciidoc +++ b/doc/ss-manager.asciidoc @@ -15,6 +15,7 @@ SYNOPSIS [-b ] [-a ] [--manager-address ] [--executable ] + [--plugin ] [--plugin_opts :: +--plugin :: Enable SIP003 plugin. (Experimental) +--plugin_opts :: +Set SIP003 plugin options. (Experimental) + -v:: Enable verbose mode. diff --git a/doc/ss-redir.asciidoc b/doc/ss-redir.asciidoc index 7a8a10d9..84b9c8bd 100644 --- a/doc/ss-redir.asciidoc +++ b/doc/ss-redir.asciidoc @@ -13,6 +13,7 @@ SYNOPSIS [-k ] [-m ] [-f ] [-t ] [-c ] [-b ] [-a ] [-n ] [--mtu ] + [--plugin ] [--plugin_opts :: +--plugin :: Enable SIP003 plugin. (Experimental) +--plugin_opts :: +Set SIP003 plugin options. (Experimental) + -v:: Enable verbose mode. diff --git a/doc/ss-server.asciidoc b/doc/ss-server.asciidoc index ef070c9a..19547d9f 100644 --- a/doc/ss-server.asciidoc +++ b/doc/ss-server.asciidoc @@ -16,6 +16,7 @@ SYNOPSIS [-b ] [--mtu ] [--manager-address ] + [--plugin ] [--plugin_opts :: +--plugin :: Enable SIP003 plugin. (Experimental) +--plugin_opts :: +Set SIP003 plugin options. (Experimental) + -v:: Enable verbose mode. diff --git a/doc/ss-tunnel.asciidoc b/doc/ss-tunnel.asciidoc index 4bafd45b..ffd6ed88 100644 --- a/doc/ss-tunnel.asciidoc +++ b/doc/ss-tunnel.asciidoc @@ -14,6 +14,7 @@ SYNOPSIS [-t ] [-c ] [-i ] [-b ] [-a ] [-n ] [-L addr:port] [--mtu ] + [--plugin ] [--plugin_opts :: +--plugin :: Enable SIP003 plugin. (Experimental) +--plugin_opts :: +Set SIP003 plugin options. (Experimental) + -v:: Enable verbose mode. diff --git a/src/jconf.c b/src/jconf.c index 1a0c2a55..e6323e6c 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -114,6 +114,8 @@ read_jconf(const char *file) char *buf; json_value *obj; + LOGI("test"); + FILE *f = fopen(file, "rb"); if (f == NULL) { FATAL("Invalid config path."); @@ -201,6 +203,8 @@ read_jconf(const char *file) conf.user = to_string(value); } else if (strcmp(name, "plugin") == 0) { conf.plugin = to_string(value); + } else if (strcmp(name, "plugin_opts") == 0) { + conf.plugin_opts = to_string(value); } else if (strcmp(name, "fast_open") == 0) { check_json_value_type(value, json_boolean, "invalid config file: option 'fast_open' must be a boolean"); diff --git a/src/jconf.h b/src/jconf.h index 143ec75e..98a4357b 100644 --- a/src/jconf.h +++ b/src/jconf.h @@ -57,6 +57,7 @@ typedef struct { char *timeout; char *user; char *plugin; + char *plugin_opts; int auth; int fast_open; int nofile; diff --git a/src/local.c b/src/local.c index e1581313..ed018c30 100644 --- a/src/local.c +++ b/src/local.c @@ -1193,6 +1193,7 @@ main(int argc, char **argv) char *iface = NULL; char *plugin = NULL; + char *plugin_opts = NULL; char *plugin_host = NULL; char *plugin_port = NULL; char tmp_port[8]; @@ -1210,6 +1211,7 @@ main(int argc, char **argv) { "mtu", required_argument, 0, 0 }, { "mptcp", no_argument, 0, 0 }, { "plugin", required_argument, 0, 0 }, + { "plugin-opts", required_argument, 0, 0 }, { "help", no_argument, 0, 0 }, { 0, 0, 0, 0 } }; @@ -1241,6 +1243,8 @@ main(int argc, char **argv) } else if (option_index == 4) { plugin = optarg; } else if (option_index == 5) { + plugin_opts = optarg; + } else if (option_index == 6) { usage(); exit(EXIT_SUCCESS); } @@ -1362,6 +1366,9 @@ main(int argc, char **argv) if (plugin == NULL) { plugin = conf->plugin; } + if (plugin_opts == NULL) { + plugin_opts = conf->plugin_opts; + } if (auth == 0) { auth = conf->auth; } @@ -1463,7 +1470,7 @@ main(int argc, char **argv) snprintf(remote_str + len, buf_size - len, "|%s", remote_addr[i].host); len = strlen(remote_str); } - int err = start_plugin(plugin, remote_str, + int err = start_plugin(plugin, plugin_opts, remote_str, remote_port, plugin_host, plugin_port); if (err) { FATAL("failed to start the plugin"); diff --git a/src/manager.c b/src/manager.c index e32f43c1..6093b566 100644 --- a/src/manager.c +++ b/src/manager.c @@ -179,7 +179,11 @@ construct_command_line(struct manager_ctx *manager, struct server *server) } if (manager->plugin) { int len = strlen(cmd); - snprintf(cmd + len, BUF_SIZE - len, " --plugin %s", manager->plugin); + snprintf(cmd + len, BUF_SIZE - len, " --plugin \"%s\"", manager->plugin); + } + if (manager->plugin_opts) { + int len = strlen(cmd); + snprintf(cmd + len, BUF_SIZE - len, " --plugin_opts \"%s\"", manager->plugin_opts); } for (i = 0; i < manager->nameserver_num; i++) { int len = strlen(cmd); @@ -880,6 +884,7 @@ main(int argc, char **argv) char *iface = NULL; char *manager_address = NULL; char *plugin = NULL; + char *plugin_opts = NULL; int auth = 0; int fast_open = 0; @@ -907,6 +912,7 @@ main(int argc, char **argv) { "executable", required_argument, 0, 0 }, { "mtu", required_argument, 0, 0 }, { "plugin", required_argument, 0, 0 }, + { "plugin_opts", required_argument, 0, 0 }, { "help", no_argument, 0, 0 }, { 0, 0, 0, 0 } }; @@ -932,6 +938,8 @@ main(int argc, char **argv) } else if (option_index == 5) { plugin = optarg; } else if (option_index == 6) { + plugin_opts = optarg; + } else if (option_index == 7) { usage(); exit(EXIT_SUCCESS); } @@ -1039,9 +1047,12 @@ main(int argc, char **argv) if (mtu == 0) { mtu = conf->mtu; } - if (plugin == 0) { + if (plugin == NULL) { plugin = conf->plugin; } + if (plugin_opts == NULL) { + plugin_opts = conf->plugin_opts; + } if (ipv6first == 0) { ipv6first = conf->ipv6_first; } @@ -1122,6 +1133,7 @@ main(int argc, char **argv) manager.nameserver_num = nameserver_num; manager.mtu = mtu; manager.plugin = plugin; + manager.plugin_opts = plugin_opts; manager.ipv6first = ipv6first; #ifdef HAVE_SETRLIMIT manager.nofile = nofile; diff --git a/src/manager.h b/src/manager.h index b7d2e2cc..e212f025 100644 --- a/src/manager.h +++ b/src/manager.h @@ -45,7 +45,7 @@ struct manager_ctx { char *acl; char *user; char *plugin; - char *plugin_args; + char *plugin_opts; char *manager_address; char **hosts; int host_num; diff --git a/src/plugin.c b/src/plugin.c index 536cb705..e929e605 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -82,6 +82,7 @@ struct cork_stream_consumer plugin_log = { int start_plugin(const char *plugin, + const char *plugin_opts, const char *remote_host, const char *remote_port, const char *local_host, @@ -127,6 +128,9 @@ start_plugin(const char *plugin, cork_env_add(env, "SS_LOCAL_HOST", local_host); cork_env_add(env, "SS_LOCAL_PORT", local_port); + if (plugin_opts != NULL) + cork_env_add(env, "SS_PLUGIN_OPTIONS", plugin_opts); + exec = cork_exec_new_with_params("sh", "-c", cmd, NULL); cork_exec_set_env(exec, env); diff --git a/src/plugin.h b/src/plugin.h index f74c7861..71035a4d 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -28,6 +28,7 @@ #define PLUGIN_RUNNING 0 int start_plugin(const char *plugin, + const char *plugin_opts, const char *remote_host, const char *remote_port, const char *local_host, diff --git a/src/redir.c b/src/redir.c index 5c3f7d30..0543e49d 100644 --- a/src/redir.c +++ b/src/redir.c @@ -794,6 +794,7 @@ main(int argc, char **argv) char *conf_path = NULL; char *plugin = NULL; + char *plugin_opts = NULL; char *plugin_host = NULL; char *plugin_port = NULL; char tmp_port[8]; @@ -807,6 +808,7 @@ main(int argc, char **argv) { "mtu", required_argument, 0, 0 }, { "mptcp", no_argument, 0, 0 }, { "plugin", required_argument, 0, 0 }, + { "plugin_opts", required_argument, 0, 0 }, { "help", no_argument, 0, 0 }, { 0, 0, 0, 0 } }; @@ -828,6 +830,8 @@ main(int argc, char **argv) } else if (option_index == 2) { plugin = optarg; } else if (option_index == 3) { + plugin_opts = optarg; + } else if (option_index == 4) { usage(); exit(EXIT_SUCCESS); } @@ -939,6 +943,9 @@ main(int argc, char **argv) if (plugin == NULL) { plugin = conf->plugin; } + if (plugin_opts == NULL) { + plugin_opts = conf->plugin_opts; + } if (auth == 0) { auth = conf->auth; } @@ -1021,7 +1028,7 @@ main(int argc, char **argv) snprintf(remote_str + len, buf_size - len, "|%s", remote_addr[i].host); len = strlen(remote_str); } - int err = start_plugin(plugin, remote_str, + int err = start_plugin(plugin, plugin_opts, remote_str, remote_port, plugin_host, plugin_port); if (err) { FATAL("failed to start the plugin"); diff --git a/src/server.c b/src/server.c index cfbb71b4..944fec21 100644 --- a/src/server.c +++ b/src/server.c @@ -1585,6 +1585,7 @@ main(int argc, char **argv) char *conf_path = NULL; char *iface = NULL; + char *plugin_opts = NULL; char *plugin_port = NULL; char tmp_port[8]; @@ -1602,6 +1603,7 @@ main(int argc, char **argv) { "mtu", required_argument, 0, 0 }, { "help", no_argument, 0, 0 }, { "plugin", required_argument, 0, 0 }, + { "plugin_opts", required_argument, 0, 0 }, #ifdef __linux__ { "mptcp", no_argument, 0, 0 }, #endif @@ -1632,6 +1634,8 @@ main(int argc, char **argv) } else if (option_index == 5) { plugin = optarg; } else if (option_index == 6) { + plugin_opts = optarg; + } else if (option_index == 7) { mptcp = 1; LOGI("enable multipath TCP"); } @@ -1741,6 +1745,9 @@ main(int argc, char **argv) if (plugin == NULL) { plugin = conf->plugin; } + if (plugin_opts == NULL) { + plugin_opts = conf->plugin_opts; + } if (auth == 0) { auth = conf->auth; } @@ -1898,7 +1905,7 @@ main(int argc, char **argv) server_host[0] = "127.0.0.1"; server_num = 1; - int err = start_plugin(plugin, server_str, + int err = start_plugin(plugin, plugin_opts, server_str, plugin_port, server_host[0], server_port); if (err) { FATAL("failed to start the plugin"); diff --git a/src/tunnel.c b/src/tunnel.c index 0e87c807..670b7d33 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -759,6 +759,7 @@ main(int argc, char **argv) char *iface = NULL; char *plugin = NULL; + char *plugin_opts = NULL; char *plugin_host = NULL; char *plugin_port = NULL; char tmp_port[8]; @@ -775,6 +776,7 @@ main(int argc, char **argv) { "mtu", required_argument, 0, 0 }, { "mptcp", no_argument, 0, 0 }, { "plugin", required_argument, 0, 0 }, + { "plugin_opts", required_argument, 0, 0 }, { "help", no_argument, 0, 0 }, { 0, 0, 0, 0 } }; @@ -801,6 +803,8 @@ main(int argc, char **argv) } else if (option_index == 2) { plugin = optarg; } else if (option_index == 3) { + plugin_opts = optarg; + } else if (option_index == 4) { usage(); exit(EXIT_SUCCESS); } @@ -926,6 +930,9 @@ main(int argc, char **argv) if (plugin == NULL) { plugin = conf->plugin; } + if (plugin_opts == NULL) { + plugin_opts = conf->plugin_opts; + } if (auth == 0) { auth = conf->auth; } @@ -1021,7 +1028,7 @@ main(int argc, char **argv) snprintf(remote_str + len, buf_size - len, "|%s", remote_addr[i].host); len = strlen(remote_str); } - int err = start_plugin(plugin, remote_str, + int err = start_plugin(plugin, plugin_opts, remote_str, remote_port, plugin_host, plugin_port); if (err) { FATAL("failed to start the plugin"); diff --git a/src/utils.c b/src/utils.c index 6183cb54..9b3c9a48 100644 --- a/src/utils.c +++ b/src/utils.c @@ -357,8 +357,12 @@ usage() printf( " [--mptcp] Enable Multipath TCP on MPTCP Kernel.\n"); #endif +#ifndef __MINGW32__ + printf( + " [--plugin ] Enable SIP003 plugin. (Experimental)\n"); printf( - " [--plugin ] Enable SIP003 plugin. (Experimental)\n"); + " [--plugin_opts ] Set SIP003 plugin options. (Experimental)\n"); +#endif printf("\n"); printf( " [-v] Verbose mode.\n");