Browse Source

Update SIP003 interfaces

pull/1085/head
Max Lv 8 years ago
parent
commit
92f0baa789
16 changed files with 87 additions and 13 deletions
  1. 6
      doc/ss-local.asciidoc
  2. 6
      doc/ss-manager.asciidoc
  3. 6
      doc/ss-redir.asciidoc
  4. 6
      doc/ss-server.asciidoc
  5. 6
      doc/ss-tunnel.asciidoc
  6. 4
      src/jconf.c
  7. 1
      src/jconf.h
  8. 9
      src/local.c
  9. 16
      src/manager.c
  10. 2
      src/manager.h
  11. 4
      src/plugin.c
  12. 1
      src/plugin.h
  13. 9
      src/redir.c
  14. 9
      src/server.c
  15. 9
      src/tunnel.c
  16. 6
      src/utils.c

6
doc/ss-local.asciidoc

@ -14,6 +14,7 @@ SYNOPSIS
[-t <timeout>] [-c <config_file>] [-i <interface>]
[-a <user_name>] [-b <local_address] [-n <nofile>]
[--fast-open] [--acl <acl_config>] [--mtu <MTU>]
[--plugin <plugin_name>] [--plugin_opts <plugin_options]
DESCRIPTION
-----------
@ -115,9 +116,12 @@ Enable Multipath TCP.
+
Only available with MPTCP enabled Linux kernel.
--plugin <plugin_args>::
--plugin <plugin_name>::
Enable SIP003 plugin. (Experimental)
--plugin_opts <plugin_options>::
Set SIP003 plugin options. (Experimental)
-v::
Enable verbose mode.

6
doc/ss-manager.asciidoc

@ -15,6 +15,7 @@ SYNOPSIS
[-b <local_addr>] [-a <user_name>]
[--manager-address <path_to_unix_domain>]
[--executable <path_to_server_executable>]
[--plugin <plugin_name>] [--plugin_opts <plugin_options]
DESCRIPTION
-----------
@ -105,9 +106,12 @@ Specify the executable path of ss-server.
+
Only available in manager mode.
--plugin <plugin_args>::
--plugin <plugin_name>::
Enable SIP003 plugin. (Experimental)
--plugin_opts <plugin_options>::
Set SIP003 plugin options. (Experimental)
-v::
Enable verbose mode.

6
doc/ss-redir.asciidoc

@ -13,6 +13,7 @@ SYNOPSIS
[-k <password>] [-m <encrypt_method>] [-f <pid_file>]
[-t <timeout>] [-c <config_file>] [-b <local_address>]
[-a <user_name>] [-n <nofile>] [--mtu <MTU>]
[--plugin <plugin_name>] [--plugin_opts <plugin_options]
DESCRIPTION
-----------
@ -101,9 +102,12 @@ Enable Multipath TCP.
+
Only available with MPTCP enabled Linux kernel.
--plugin <plugin_args>::
--plugin <plugin_name>::
Enable SIP003 plugin. (Experimental)
--plugin_opts <plugin_options>::
Set SIP003 plugin options. (Experimental)
-v::
Enable verbose mode.

6
doc/ss-server.asciidoc

@ -16,6 +16,7 @@ SYNOPSIS
[-b <local_address] [--fast-open] [--mptcp]
[--acl <acl_config>] [--mtu <MTU>]
[--manager-address <path_to_unix_domain>]
[--plugin <plugin_name>] [--plugin_opts <plugin_options]
DESCRIPTION
-----------
@ -127,9 +128,12 @@ Enable Multipath TCP.
+
Only available with MPTCP enabled Linux kernel.
--plugin <plugin_args>::
--plugin <plugin_name>::
Enable SIP003 plugin. (Experimental)
--plugin_opts <plugin_options>::
Set SIP003 plugin options. (Experimental)
-v::
Enable verbose mode.

6
doc/ss-tunnel.asciidoc

@ -14,6 +14,7 @@ SYNOPSIS
[-t <timeout>] [-c <config_file>] [-i <interface>]
[-b <local_addr>] [-a <user_name>] [-n <nofile>]
[-L addr:port] [--mtu <MTU>]
[--plugin <plugin_name>] [--plugin_opts <plugin_options]
DESCRIPTION
-----------
@ -112,9 +113,12 @@ Enable Multipath TCP.
+
Only available with MPTCP enabled Linux kernel.
--plugin <plugin_args>::
--plugin <plugin_name>::
Enable SIP003 plugin. (Experimental)
--plugin_opts <plugin_options>::
Set SIP003 plugin options. (Experimental)
-v::
Enable verbose mode.

4
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");

1
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;

9
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");

16
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;

2
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;

4
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);

1
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,

9
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");

9
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");

9
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");

6
src/utils.c

@ -357,8 +357,12 @@ usage()
printf(
" [--mptcp] Enable Multipath TCP on MPTCP Kernel.\n");
#endif
#ifndef __MINGW32__
printf(
" [--plugin <name>] Enable SIP003 plugin. (Experimental)\n");
printf(
" [--plugin <plugin_args>] Enable SIP003 plugin. (Experimental)\n");
" [--plugin_opts <options>] Set SIP003 plugin options. (Experimental)\n");
#endif
printf("\n");
printf(
" [-v] Verbose mode.\n");

Loading…
Cancel
Save