Browse Source

Fix #2536

pull/2543/head
Max Lv 5 years ago
parent
commit
1ba753adaa
4 changed files with 32 additions and 36 deletions
  1. 12
      config.json
  2. 6
      src/netutils.c
  3. 28
      src/server.c
  4. 22
      src/udprelay.c

12
config.json

@ -1,12 +0,0 @@
{
"server":"la.maxlv.net",
"server_port":1080,
"local_address":"0.0.0.0",
"local_port":1080,
"password":"CCCCCCCC",
"method":"aes-256-gcm",
"timeout":60,
"mode":"tcp_and_udp",
"plugin":"obfs-local",
"plugin_opts":"obfs=http;obfs-host=www.CCCCCCC.com"
}

6
src/netutils.c

@ -99,18 +99,18 @@ parse_local_addr(struct sockaddr_storage *storage_v4,
inet_pton(AF_INET, host, &addr->sin_addr);
addr->sin_family = AF_INET;
LOGI("binding to outbound IPv4 addr: %s", host);
return 0;
return AF_INET;
} else if (ip.version == 6) {
memset(storage_v6, 0, sizeof(struct sockaddr_storage));
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)storage_v6;
inet_pton(AF_INET6, host, &addr->sin6_addr);
addr->sin6_family = AF_INET6;
LOGI("binding to outbound IPv6 addr: %s", host);
return 0;
return AF_INET6;
}
}
}
return -1;
return 0;
}
int

28
src/server.c

@ -478,10 +478,12 @@ connect_to_remote(EV_P_ struct addrinfo *res,
if (is_bind_local_addr) {
struct sockaddr_storage *local_addr =
res->ai_family == AF_INET ? &local_addr_v4 : &local_addr_v6;
if (bind_to_addr(local_addr, sockfd) == -1) {
ERROR("bind_to_addr");
close(sockfd);
return NULL;
if (res->ai_family == local_addr->ss_family) {
if (bind_to_addr(local_addr, sockfd) == -1) {
ERROR("bind_to_addr");
FATAL("cannot bind socket");
return NULL;
}
}
}
@ -1568,6 +1570,8 @@ main(int argc, char **argv)
int server_num = 0;
ss_addr_t server_addr[MAX_REMOTE_NUM];
memset(server_addr, 0, sizeof(ss_addr_t) * MAX_REMOTE_NUM);
memset(&local_addr_v4, 0, sizeof(struct sockaddr_storage));
memset(&local_addr_v6, 0, sizeof(struct sockaddr_storage));
static struct option long_options[] = {
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
@ -1635,8 +1639,7 @@ main(int argc, char **argv)
}
break;
case 'b':
if (parse_local_addr(&local_addr_v4, &local_addr_v6, optarg) == 0)
is_bind_local_addr = 1;
is_bind_local_addr += parse_local_addr(&local_addr_v4, &local_addr_v6, optarg);
break;
case 'p':
server_port = optarg;
@ -1760,12 +1763,13 @@ main(int argc, char **argv)
fast_open = conf->fast_open;
}
if (is_bind_local_addr == 0) {
if (parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr) == 0)
is_bind_local_addr = 1;
if (parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr_v4) == 0)
is_bind_local_addr = 1;
if (parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr_v6) == 0)
is_bind_local_addr = 1;
is_bind_local_addr += parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr);
}
if (is_bind_local_addr == 0) {
is_bind_local_addr += parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr_v4);
}
if (is_bind_local_addr == 0) {
is_bind_local_addr += parse_local_addr(&local_addr_v4, &local_addr_v6, conf->local_addr_v6);
}
#ifdef HAVE_SETRLIMIT
if (nofile == 0) {

22
src/udprelay.c

@ -377,15 +377,17 @@ create_remote_socket(int ipv6)
}
#ifdef MODULE_REMOTE
if (is_bind_local_addr) {
if (bind_to_addr(&local_addr_v6, remote_sock) == -1) {
ERROR("bind_to_addr");
FATAL("[udp] cannot bind remote");
return -1;
if (local_addr_v6.ss_family == AF_INET6) {
if (bind_to_addr(&local_addr_v6, remote_sock) == -1) {
ERROR("bind_to_addr");
FATAL("[udp] cannot bind socket");
return -1;
}
}
} else {
#endif
if (bind(remote_sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
FATAL("[udp] cannot bind remote");
FATAL("[udp] cannot bind socket");
return -1;
}
#ifdef MODULE_REMOTE
@ -405,10 +407,12 @@ create_remote_socket(int ipv6)
}
#ifdef MODULE_REMOTE
if (is_bind_local_addr) {
if (bind_to_addr(&local_addr_v4, remote_sock) == -1) {
ERROR("bind_to_addr");
FATAL("[udp] cannot bind remote");
return -1;
if (local_addr_v4.ss_family == AF_INET) {
if (bind_to_addr(&local_addr_v4, remote_sock) == -1) {
ERROR("bind_to_addr");
FATAL("[udp] cannot bind socket");
return -1;
}
}
} else {
#endif

Loading…
Cancel
Save