Browse Source

Fix #615

pull/616/head
Max Lv 9 years ago
parent
commit
72ee77ea35
8 changed files with 38 additions and 22 deletions
  1. 3
      man/ss-server.1
  2. 6
      src/local.c
  3. 2
      src/redir.c
  4. 7
      src/resolv.c
  5. 2
      src/resolv.h
  6. 36
      src/server.c
  7. 2
      src/tunnel.c
  8. 2
      src/utils.c

3
man/ss-server.1

@ -105,6 +105,9 @@ Enable UDP relay and disable TCP relay.
.B \-A .B \-A
Enable onetime authentication. Enable onetime authentication.
.TP .TP
.B \-6
Resovle hostname to IPv6 address first.
.TP
.B \-w .B \-w
Enable white list mode (when ACL enabled). Enable white list mode (when ACL enabled).
.TP .TP

6
src/local.c

@ -1007,7 +1007,7 @@ int main(int argc, char **argv)
if (option_index == 0) { if (option_index == 0) {
fast_open = 1; fast_open = 1;
} else if (option_index == 1) { } else if (option_index == 1) {
LOGI("initialize acl...");
LOGI("initializing acl...");
acl = !init_acl(optarg, BLACK_LIST); acl = !init_acl(optarg, BLACK_LIST);
} else if (option_index == 2) { } else if (option_index == 2) {
usage(); usage();
@ -1188,7 +1188,7 @@ int main(int argc, char **argv)
ev_signal_start(EV_DEFAULT, &sigterm_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher);
// Setup keys // Setup keys
LOGI("initialize ciphers... %s", method);
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method); int m = enc_init(password, method);
// Setup proxy context // Setup proxy context
@ -1326,7 +1326,7 @@ int start_ss_local_server(profile_t profile)
ev_signal_start(EV_DEFAULT, &sigterm_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher);
// Setup keys // Setup keys
LOGI("initialize ciphers... %s", method);
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method); int m = enc_init(password, method);
struct sockaddr_storage *storage = ss_malloc(sizeof(struct sockaddr_storage)); struct sockaddr_storage *storage = ss_malloc(sizeof(struct sockaddr_storage));

2
src/redir.c

@ -834,7 +834,7 @@ int main(int argc, char **argv)
signal(SIGABRT, SIG_IGN); signal(SIGABRT, SIG_IGN);
// Setup keys // Setup keys
LOGI("initialize ciphers... %s", method);
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method); int m = enc_init(password, method);
// Setup proxy context // Setup proxy context

7
src/resolv.c

@ -82,9 +82,12 @@ static struct sockaddr *choose_ipv4_first(struct ResolvQuery *);
static struct sockaddr *choose_ipv6_first(struct ResolvQuery *); static struct sockaddr *choose_ipv6_first(struct ResolvQuery *);
static struct sockaddr *choose_any(struct ResolvQuery *); static struct sockaddr *choose_any(struct ResolvQuery *);
int resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num)
int resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num, int ipv6first)
{ {
resolv_mode = MODE_IPV4_FIRST;
if (ipv6first)
resolv_mode = MODE_IPV6_FIRST;
else
resolv_mode = MODE_IPV4_FIRST;
struct dns_ctx *ctx = &dns_defctx; struct dns_ctx *ctx = &dns_defctx;
if (nameservers == NULL) { if (nameservers == NULL) {

2
src/resolv.h

@ -40,7 +40,7 @@
struct ResolvQuery; struct ResolvQuery;
int resolv_init(struct ev_loop *, char **, int);
int resolv_init(struct ev_loop *, char **, int, int);
struct ResolvQuery *resolv_query(const char *, void (*)(struct sockaddr *, struct ResolvQuery *resolv_query(const char *, void (*)(struct sockaddr *,
void *), void (*)( void *), void (*)(
void *), void *, uint16_t); void *), void *, uint16_t);

36
src/server.c

@ -112,6 +112,7 @@ static int white_list = 0;
static int acl = 0; static int acl = 0;
static int mode = TCP_ONLY; static int mode = TCP_ONLY;
static int auth = 0; static int auth = 0;
static int ipv6first = 0;
static int fast_open = 0; static int fast_open = 0;
#ifdef HAVE_SETRLIMIT #ifdef HAVE_SETRLIMIT
@ -1327,14 +1328,14 @@ int main(int argc, char **argv)
USE_TTY(); USE_TTY();
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:n:huUvAw",
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:n:huUvAw6",
long_options, &option_index)) != -1) { long_options, &option_index)) != -1) {
switch (c) { switch (c) {
case 0: case 0:
if (option_index == 0) { if (option_index == 0) {
fast_open = 1; fast_open = 1;
} else if (option_index == 1) { } else if (option_index == 1) {
LOGI("initialize acl...");
LOGI("initializing acl...");
acl = 1; acl = 1;
acl_path = optarg; acl_path = optarg;
} else if (option_index == 2) { } else if (option_index == 2) {
@ -1402,6 +1403,9 @@ int main(int argc, char **argv)
case 'w': case 'w':
white_list = 1; white_list = 1;
break; break;
case '6':
ipv6first = 1;
break;
case '?': case '?':
// The option character is not recognized. // The option character is not recognized.
opterr = 1; opterr = 1;
@ -1491,6 +1495,10 @@ int main(int argc, char **argv)
daemonize(pid_path); daemonize(pid_path);
} }
if (ipv6first) {
LOGI("resolving hostname to IPv6 address first");
}
if (fast_open == 1) { if (fast_open == 1) {
#ifdef TCP_FASTOPEN #ifdef TCP_FASTOPEN
LOGI("using tcp fast open"); LOGI("using tcp fast open");
@ -1503,6 +1511,14 @@ int main(int argc, char **argv)
LOGI("onetime authentication enabled"); LOGI("onetime authentication enabled");
} }
if (mode != TCP_ONLY) {
LOGI("UDP relay enabled");
}
if (mode == UDP_ONLY) {
LOGI("TCP relay disabled");
}
#ifdef __MINGW32__ #ifdef __MINGW32__
winsock_init(); winsock_init();
#else #else
@ -1520,7 +1536,7 @@ int main(int argc, char **argv)
ev_signal_start(EV_DEFAULT, &sigterm_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher);
// setup keys // setup keys
LOGI("initialize ciphers... %s", method);
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method); int m = enc_init(password, method);
// inilitialize ev loop // inilitialize ev loop
@ -1530,12 +1546,12 @@ int main(int argc, char **argv)
if (nameserver_num == 0) { if (nameserver_num == 0) {
#ifdef __MINGW32__ #ifdef __MINGW32__
nameservers[nameserver_num++] = "8.8.8.8"; nameservers[nameserver_num++] = "8.8.8.8";
resolv_init(loop, nameservers, nameserver_num);
resolv_init(loop, nameservers, nameserver_num, ipv6first);
#else #else
resolv_init(loop, NULL, 0);
resolv_init(loop, NULL, 0, ipv6first);
#endif #endif
} else { } else {
resolv_init(loop, nameservers, nameserver_num);
resolv_init(loop, nameservers, nameserver_num, ipv6first);
} }
for (int i = 0; i < nameserver_num; i++) for (int i = 0; i < nameserver_num; i++)
@ -1588,14 +1604,6 @@ int main(int argc, char **argv)
ev_timer_start(EV_DEFAULT, &stat_update_watcher); ev_timer_start(EV_DEFAULT, &stat_update_watcher);
} }
if (mode != TCP_ONLY) {
LOGI("UDP relay enabled");
}
if (mode == UDP_ONLY) {
LOGI("TCP relay disabled");
}
// setuid // setuid
if (user != NULL) { if (user != NULL) {
run_as(user); run_as(user);

2
src/tunnel.c

@ -891,7 +891,7 @@ int main(int argc, char **argv)
#endif #endif
// Setup keys // Setup keys
LOGI("initialize ciphers... %s", method);
LOGI("initializing ciphers... %s", method);
int m = enc_init(password, method); int m = enc_init(password, method);
// Setup proxy context // Setup proxy context

2
src/utils.c

@ -261,6 +261,8 @@ void usage()
printf( printf(
" [-A] Enable onetime authentication.\n"); " [-A] Enable onetime authentication.\n");
#ifdef MODULE_REMOTE #ifdef MODULE_REMOTE
printf(
" [-6] Resovle hostname to IPv6 address first.\n");
printf( printf(
" [-w] Enable white list mode (when ACL enabled).\n"); " [-w] Enable white list mode (when ACL enabled).\n");
#endif #endif

Loading…
Cancel
Save