Browse Source

Merge pull request #2118 from chenhw2/master

Multipe nameservers support
pull/2120/head
Max Lv 6 years ago
committed by GitHub
parent
commit
38f72a1006
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 21 deletions
  1. 2
      doc/shadowsocks-libev.asciidoc
  2. 2
      doc/ss-manager.asciidoc
  3. 2
      doc/ss-server.asciidoc
  4. 6
      docker/alpine/Dockerfile
  5. 4
      docker/alpine/README.md
  6. 16
      src/manager.c
  7. 3
      src/manager.h

2
doc/shadowsocks-libev.asciidoc

@ -121,7 +121,7 @@ Specify destination server address and port for local port forwarding.
Only available in tunnel mode. Only available in tunnel mode.
-d <addr>:: -d <addr>::
Setup name servers for internal DNS resolver (libudns).
Setup name servers for internal DNS resolver (libc-ares).
The default server is fetched from /etc/resolv.conf. The default server is fetched from /etc/resolv.conf.
+ +
Only available in server and manager mode. Only available in server and manager mode.

2
doc/ss-manager.asciidoc

@ -90,7 +90,7 @@ Enable UDP relay and disable TCP relay.
Enable onetime authentication. Enable onetime authentication.
-d <addr>:: -d <addr>::
Setup name servers for internal DNS resolver (libudns).
Setup name servers for internal DNS resolver (libc-ares).
The default server is fetched from `/etc/resolv.conf`. The default server is fetched from `/etc/resolv.conf`.
--fast-open:: --fast-open::

2
doc/ss-server.asciidoc

@ -100,7 +100,7 @@ Enable UDP relay and disable TCP relay.
Resovle hostname to IPv6 address first. Resovle hostname to IPv6 address first.
-d <addr>:: -d <addr>::
Setup name servers for internal DNS resolver (libudns).
Setup name servers for internal DNS resolver (libc-ares).
The default server is fetched from '/etc/resolv.conf'. The default server is fetched from '/etc/resolv.conf'.
--fast-open:: --fast-open::

6
docker/alpine/Dockerfile

@ -10,8 +10,7 @@ ENV SERVER_PORT 8388
ENV PASSWORD= ENV PASSWORD=
ENV METHOD aes-256-cfb ENV METHOD aes-256-cfb
ENV TIMEOUT 300 ENV TIMEOUT 300
ENV DNS_ADDR 8.8.8.8
ENV DNS_ADDR_2 8.8.4.4
ENV DNS_ADDRS 8.8.8.8,8.8.4.4
ENV ARGS= ENV ARGS=
COPY . /tmp/repo COPY . /tmp/repo
@ -51,7 +50,6 @@ CMD exec ss-server \
-m $METHOD \ -m $METHOD \
-t $TIMEOUT \ -t $TIMEOUT \
--fast-open \ --fast-open \
-d $DNS_ADDR \
-d $DNS_ADDR_2 \
-d $DNS_ADDRS \
-u \ -u \
$ARGS $ARGS

4
docker/alpine/README.md

@ -33,7 +33,7 @@ $ docker run -p 8388:8388 -p 8388:8388/udp -d --restart always shadowsocks/shado
``` ```
This starts a container of the latest release with all the default settings, which is equivalent to This starts a container of the latest release with all the default settings, which is equivalent to
```bash ```bash
$ ss-server -s 0.0.0.0 -p 8388 -k "$(hostname)" -m aes-256-cfb -t 300 --fast-open -d 8.8.8.8 -d 8.8.4.4 -u
$ ss-server -s 0.0.0.0 -p 8388 -k "$(hostname)" -m aes-256-cfb -t 300 --fast-open -d "8.8.8.8,8.8.4.4" -u
``` ```
> **Note**: It's the hostname in the container that is used as the password, not that of the host. > **Note**: It's the hostname in the container that is used as the password, not that of the host.
@ -61,7 +61,7 @@ Besides `PASSWORD`, the image also defines the following environment variables t
* `SERVER_ADDR`: the IP/domain to bind to, defaults to `0.0.0.0` * `SERVER_ADDR`: the IP/domain to bind to, defaults to `0.0.0.0`
* `METHOD`: encryption method to use, defaults to `aes-256-cfb` * `METHOD`: encryption method to use, defaults to `aes-256-cfb`
* `TIMEOUT`: defaults to `300` * `TIMEOUT`: defaults to `300`
* `DNS_ADDR`, `DNS_ADDR_2`: DNS servers to redirect NS lookup requests to, defaults to `8.8.8.8` and `8.8.4.4`
* `DNS_ADDRS`: DNS servers to redirect NS lookup requests to, defaults to `8.8.8.8,8.8.4.4`
Additional arguments supported by `ss-server` can be passed with the environment variable `ARGS`, for instance to start in verbose mode: Additional arguments supported by `ss-server` can be passed with the environment variable `ARGS`, for instance to start in verbose mode:
```bash ```bash

16
src/manager.c

@ -208,9 +208,9 @@ construct_command_line(struct manager_ctx *manager, struct server *server)
int len = strlen(cmd); int len = strlen(cmd);
snprintf(cmd + len, BUF_SIZE - len, " --plugin-opts \"%s\"", manager->plugin_opts); snprintf(cmd + len, BUF_SIZE - len, " --plugin-opts \"%s\"", manager->plugin_opts);
} }
for (i = 0; i < manager->nameserver_num; i++) {
if (manager->nameservers) {
int len = strlen(cmd); int len = strlen(cmd);
snprintf(cmd + len, BUF_SIZE - len, " -d %s", manager->nameservers[i]);
snprintf(cmd + len, BUF_SIZE - len, " -d \"%s\"", manager->nameservers);
} }
for (i = 0; i < manager->host_num; i++) { for (i = 0; i < manager->host_num; i++) {
int len = strlen(cmd); int len = strlen(cmd);
@ -871,8 +871,7 @@ main(int argc, char **argv)
int server_num = 0; int server_num = 0;
char *server_host[MAX_REMOTE_NUM]; char *server_host[MAX_REMOTE_NUM];
char *nameservers[MAX_DNS_NUM + 1];
int nameserver_num = 0;
char *nameservers = NULL;
jconf_t *conf = NULL; jconf_t *conf = NULL;
@ -953,9 +952,7 @@ main(int argc, char **argv)
iface = optarg; iface = optarg;
break; break;
case 'd': case 'd':
if (nameserver_num < MAX_DNS_NUM) {
nameservers[nameserver_num++] = optarg;
}
nameservers = optarg;
break; break;
case 'a': case 'a':
user = optarg; user = optarg;
@ -1024,8 +1021,8 @@ main(int argc, char **argv)
if (reuse_port == 0) { if (reuse_port == 0) {
reuse_port = conf->reuse_port; reuse_port = conf->reuse_port;
} }
if (conf->nameserver != NULL) {
nameservers[nameserver_num++] = conf->nameserver;
if (nameservers == NULL) {
nameservers = conf->nameserver;
} }
if (mode == TCP_ONLY) { if (mode == TCP_ONLY) {
mode = conf->mode; mode = conf->mode;
@ -1118,7 +1115,6 @@ main(int argc, char **argv)
manager.hosts = server_host; manager.hosts = server_host;
manager.host_num = server_num; manager.host_num = server_num;
manager.nameservers = nameservers; manager.nameservers = nameservers;
manager.nameserver_num = nameserver_num;
manager.mtu = mtu; manager.mtu = mtu;
manager.plugin = plugin; manager.plugin = plugin;
manager.plugin_opts = plugin_opts; manager.plugin_opts = plugin_opts;

3
src/manager.h

@ -56,8 +56,7 @@ struct manager_ctx {
char *manager_address; char *manager_address;
char **hosts; char **hosts;
int host_num; int host_num;
char **nameservers;
int nameserver_num;
char *nameservers;
int mtu; int mtu;
int ipv6first; int ipv6first;
#ifdef HAVE_SETRLIMIT #ifdef HAVE_SETRLIMIT

Loading…
Cancel
Save