Browse Source

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 <anonymous_temp_user@yahoo.co.jp>

* 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 <anonymous_temp_mail@yahoo.co.jp>

* Use jconf "mode" for server/local/tunnel/manager

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>

* 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 <anonymous_temp_mail@yahoo.co.jp>
pull/698/head
anonymous-contributor 8 years ago
committed by Max Lv
parent
commit
af69798355
8 changed files with 43 additions and 4 deletions
  1. 3
      .gitignore
  2. 4
      src/common.h
  3. 15
      src/jconf.c
  4. 7
      src/jconf.h
  5. 6
      src/local.c
  6. 3
      src/manager.c
  7. 3
      src/server.c
  8. 6
      src/tunnel.c

3
.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

4
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

15
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 {

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

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

3
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) {

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

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

Loading…
Cancel
Save