From 72ee77ea35c83017af4426775f59021692850769 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 28 Apr 2016 10:34:26 +0800 Subject: [PATCH] Fix #615 --- man/ss-server.1 | 3 +++ src/local.c | 6 +++--- src/redir.c | 2 +- src/resolv.c | 7 +++++-- src/resolv.h | 2 +- src/server.c | 36 ++++++++++++++++++++++-------------- src/tunnel.c | 2 +- src/utils.c | 2 ++ 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/man/ss-server.1 b/man/ss-server.1 index 5f4223c0..b49ec1de 100644 --- a/man/ss-server.1 +++ b/man/ss-server.1 @@ -105,6 +105,9 @@ Enable UDP relay and disable TCP relay. .B \-A Enable onetime authentication. .TP +.B \-6 +Resovle hostname to IPv6 address first. +.TP .B \-w Enable white list mode (when ACL enabled). .TP diff --git a/src/local.c b/src/local.c index d420ebbd..4530e303 100644 --- a/src/local.c +++ b/src/local.c @@ -1007,7 +1007,7 @@ int main(int argc, char **argv) if (option_index == 0) { fast_open = 1; } else if (option_index == 1) { - LOGI("initialize acl..."); + LOGI("initializing acl..."); acl = !init_acl(optarg, BLACK_LIST); } else if (option_index == 2) { usage(); @@ -1188,7 +1188,7 @@ int main(int argc, char **argv) ev_signal_start(EV_DEFAULT, &sigterm_watcher); // Setup keys - LOGI("initialize ciphers... %s", method); + LOGI("initializing ciphers... %s", method); int m = enc_init(password, method); // Setup proxy context @@ -1326,7 +1326,7 @@ int start_ss_local_server(profile_t profile) ev_signal_start(EV_DEFAULT, &sigterm_watcher); // Setup keys - LOGI("initialize ciphers... %s", method); + LOGI("initializing ciphers... %s", method); int m = enc_init(password, method); struct sockaddr_storage *storage = ss_malloc(sizeof(struct sockaddr_storage)); diff --git a/src/redir.c b/src/redir.c index bd30b54c..366cca99 100644 --- a/src/redir.c +++ b/src/redir.c @@ -834,7 +834,7 @@ int main(int argc, char **argv) signal(SIGABRT, SIG_IGN); // Setup keys - LOGI("initialize ciphers... %s", method); + LOGI("initializing ciphers... %s", method); int m = enc_init(password, method); // Setup proxy context diff --git a/src/resolv.c b/src/resolv.c index cbab9915..1e30bb47 100644 --- a/src/resolv.c +++ b/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_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; if (nameservers == NULL) { diff --git a/src/resolv.h b/src/resolv.h index f4cf91eb..05529223 100644 --- a/src/resolv.h +++ b/src/resolv.h @@ -40,7 +40,7 @@ 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 *, void *), void (*)( void *), void *, uint16_t); diff --git a/src/server.c b/src/server.c index b7c817db..d09c7d53 100644 --- a/src/server.c +++ b/src/server.c @@ -112,6 +112,7 @@ static int white_list = 0; static int acl = 0; static int mode = TCP_ONLY; static int auth = 0; +static int ipv6first = 0; static int fast_open = 0; #ifdef HAVE_SETRLIMIT @@ -1327,14 +1328,14 @@ int main(int argc, char **argv) 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) { switch (c) { case 0: if (option_index == 0) { fast_open = 1; } else if (option_index == 1) { - LOGI("initialize acl..."); + LOGI("initializing acl..."); acl = 1; acl_path = optarg; } else if (option_index == 2) { @@ -1402,6 +1403,9 @@ int main(int argc, char **argv) case 'w': white_list = 1; break; + case '6': + ipv6first = 1; + break; case '?': // The option character is not recognized. opterr = 1; @@ -1491,6 +1495,10 @@ int main(int argc, char **argv) daemonize(pid_path); } + if (ipv6first) { + LOGI("resolving hostname to IPv6 address first"); + } + if (fast_open == 1) { #ifdef TCP_FASTOPEN LOGI("using tcp fast open"); @@ -1503,6 +1511,14 @@ int main(int argc, char **argv) LOGI("onetime authentication enabled"); } + if (mode != TCP_ONLY) { + LOGI("UDP relay enabled"); + } + + if (mode == UDP_ONLY) { + LOGI("TCP relay disabled"); + } + #ifdef __MINGW32__ winsock_init(); #else @@ -1520,7 +1536,7 @@ int main(int argc, char **argv) ev_signal_start(EV_DEFAULT, &sigterm_watcher); // setup keys - LOGI("initialize ciphers... %s", method); + LOGI("initializing ciphers... %s", method); int m = enc_init(password, method); // inilitialize ev loop @@ -1530,12 +1546,12 @@ int main(int argc, char **argv) if (nameserver_num == 0) { #ifdef __MINGW32__ nameservers[nameserver_num++] = "8.8.8.8"; - resolv_init(loop, nameservers, nameserver_num); + resolv_init(loop, nameservers, nameserver_num, ipv6first); #else - resolv_init(loop, NULL, 0); + resolv_init(loop, NULL, 0, ipv6first); #endif } else { - resolv_init(loop, nameservers, nameserver_num); + resolv_init(loop, nameservers, nameserver_num, ipv6first); } 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); } - if (mode != TCP_ONLY) { - LOGI("UDP relay enabled"); - } - - if (mode == UDP_ONLY) { - LOGI("TCP relay disabled"); - } - // setuid if (user != NULL) { run_as(user); diff --git a/src/tunnel.c b/src/tunnel.c index ed5d6cf9..ded83762 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -891,7 +891,7 @@ int main(int argc, char **argv) #endif // Setup keys - LOGI("initialize ciphers... %s", method); + LOGI("initializing ciphers... %s", method); int m = enc_init(password, method); // Setup proxy context diff --git a/src/utils.c b/src/utils.c index 7d3cd533..af08ea60 100644 --- a/src/utils.c +++ b/src/utils.c @@ -261,6 +261,8 @@ void usage() printf( " [-A] Enable onetime authentication.\n"); #ifdef MODULE_REMOTE + printf( + " [-6] Resovle hostname to IPv6 address first.\n"); printf( " [-w] Enable white list mode (when ACL enabled).\n"); #endif