mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-31 22:45:40 +00:00
Compare commits
79 Commits
jamesits/p
...
v2.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b63e86bab3 | ||
|
|
7c96cd4436 | ||
|
|
f5f1a8f3f4 | ||
|
|
4f46b89feb | ||
|
|
2c7e70466e | ||
|
|
88f9ef84d1 | ||
|
|
63bceea638 | ||
|
|
16120fdc11 | ||
|
|
b2fcfb706c | ||
|
|
64e9375e3b | ||
|
|
34feec9f5d | ||
|
|
6d30a12d5f | ||
|
|
0c878a6ad7 | ||
|
|
a8aed7e09a | ||
|
|
31ea7c520d | ||
|
|
6e99d8153a | ||
|
|
2d4495a0dd | ||
|
|
b30056a590 | ||
|
|
b92da52539 | ||
|
|
f43d2c69e0 | ||
|
|
5f1f418664 | ||
|
|
9a316a56a8 | ||
|
|
81b977ca11 | ||
|
|
b7d252de7b | ||
|
|
e12b87b48d | ||
|
|
09bdfe2b14 | ||
|
|
a84b65dd56 | ||
|
|
540f6e3043 | ||
|
|
7db67db247 | ||
|
|
026d89ac8d | ||
|
|
8228ea6299 | ||
|
|
59f79fb666 | ||
|
|
502caabd15 | ||
|
|
f151c90e9d | ||
|
|
d8e3969640 | ||
|
|
475ef65f57 | ||
|
|
72165bffff | ||
|
|
82317bd63e | ||
|
|
acf3e3c328 | ||
|
|
b708ff47b9 | ||
|
|
4f4966878f | ||
|
|
a09dfbbbc1 | ||
|
|
cc60be718c | ||
|
|
2067eb688f | ||
|
|
ba9b14045e | ||
|
|
ebcc85c01a | ||
|
|
48618aa6e2 | ||
|
|
b78329afbc | ||
|
|
b1c41e5818 | ||
|
|
637d50ad91 | ||
|
|
ce13a961db | ||
|
|
b74220718f | ||
|
|
db522591a1 | ||
|
|
1eda33aec3 | ||
|
|
268e203540 | ||
|
|
21264c78cf | ||
|
|
ae74f1efe5 | ||
|
|
d02c31d3ee | ||
|
|
edc86f32e5 | ||
|
|
1c321be49c | ||
|
|
852d0f6767 | ||
|
|
a2d65bc89a | ||
|
|
6d8efe0939 | ||
|
|
7e35e18164 | ||
|
|
f40a7160b8 | ||
|
|
c8c22873bb | ||
|
|
cb64f6694b | ||
|
|
5c27ae02c0 | ||
|
|
f5ba377d2a | ||
|
|
1ec9548ff1 | ||
|
|
81f1cfba5d | ||
|
|
ebba9c8ef5 | ||
|
|
6a2f2cea22 | ||
|
|
63f07d20af | ||
|
|
f0dec57e1a | ||
|
|
f6b52a653a | ||
|
|
9a07f5b856 | ||
|
|
8787921faf | ||
|
|
1642730af0 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,7 +3,9 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
build/
|
darwin-wrapper/doh-logger
|
||||||
|
doh-client/doh-client
|
||||||
|
doh-server/doh-server
|
||||||
|
|
||||||
# Test binary, build with `go test -c`
|
# Test binary, build with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
@@ -15,3 +17,4 @@ build/
|
|||||||
.glide/
|
.glide/
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
vendor/
|
||||||
|
|||||||
46
Changelog.md
46
Changelog.md
@@ -4,6 +4,52 @@ This Changelog records major changes between versions.
|
|||||||
|
|
||||||
Not all changes are recorded. Please check git log for details.
|
Not all changes are recorded. Please check git log for details.
|
||||||
|
|
||||||
|
## Version 2.2.3
|
||||||
|
|
||||||
|
- Use the library ipTree to determine whether an IP is global routable, improving the performance
|
||||||
|
- Google's 8.8.8.8 resolver is now marked as "Good ECS" in the example configuration file
|
||||||
|
|
||||||
|
## Version 2.2.2
|
||||||
|
|
||||||
|
- Allow client to opt-out EDNS0 Client Support
|
||||||
|
- [JSON-DoH] Honor DNSSEC OK flag for incoming DNS requests
|
||||||
|
- [JSON-DoH] Add support for non-standard response formats
|
||||||
|
- `X-Real-IP` is now used in logging if set by frontend load balancer
|
||||||
|
- Fix documentation
|
||||||
|
|
||||||
|
## Version 2.2.1
|
||||||
|
|
||||||
|
- Fix messy log
|
||||||
|
|
||||||
|
## Version 2.2.0
|
||||||
|
|
||||||
|
- Breaking change: The configuration format of doh-server is changed
|
||||||
|
- Add support for type prefix for upstream addresses of doh-server
|
||||||
|
- Add support for DNS-over-TLS upstream addresses of doh-server
|
||||||
|
- Remove `tcp_only` configuration option in doh-server
|
||||||
|
- Add `no_user_agent` configuration option in doh-server
|
||||||
|
- Add an RPM package script with SELinux policy
|
||||||
|
- Fix Opcode never assigned in `jsonDNS.PrepareReply`
|
||||||
|
- Improve error logging / checking
|
||||||
|
- Updated Readme
|
||||||
|
|
||||||
|
## Version 2.1.2
|
||||||
|
|
||||||
|
- Update address for google's resolver
|
||||||
|
- Fix a typo
|
||||||
|
|
||||||
|
## Version 2.1.1
|
||||||
|
|
||||||
|
- Add a set of Dockerfile contributed by the community
|
||||||
|
- Include DNS.SB's resolver in example configuration
|
||||||
|
|
||||||
|
## Version 2.1.0
|
||||||
|
|
||||||
|
- Add `local_addr` configuration for doh-server (#39)
|
||||||
|
- Fix a problem when compiling on macOS 10.14.4 or newer
|
||||||
|
- Add Quad9 DoH server to the example `doh-client.conf`
|
||||||
|
- Use TCP when appropriate for the given query type/response (AXFR/IXFR)
|
||||||
|
|
||||||
## Version 2.0.1
|
## Version 2.0.1
|
||||||
|
|
||||||
- Fix a crash with the random load balancing algorithm.
|
- Fix a crash with the random load balancing algorithm.
|
||||||
|
|||||||
23
Dockerfile.client
Normal file
23
Dockerfile.client
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM golang:alpine AS build-env
|
||||||
|
|
||||||
|
RUN apk add --no-cache git make
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
ADD . /src
|
||||||
|
RUN make doh-client/doh-client
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
COPY --from=build-env /src/doh-client/doh-client /doh-client
|
||||||
|
|
||||||
|
ADD doh-client/doh-client.conf /doh-client.conf
|
||||||
|
|
||||||
|
RUN sed -i '$!N;s/"127.0.0.1:53",.*"127.0.0.1:5380",/":53",/;P;D' /doh-client.conf
|
||||||
|
RUN sed -i '$!N;s/"\[::1\]:53",.*"\[::1\]:5380",/":5380",/;P;D' /doh-client.conf
|
||||||
|
|
||||||
|
EXPOSE 53/udp
|
||||||
|
EXPOSE 53/tcp
|
||||||
|
EXPOSE 5380
|
||||||
|
|
||||||
|
ENTRYPOINT ["/doh-client"]
|
||||||
|
CMD ["-conf", "/doh-client.conf"]
|
||||||
20
Dockerfile.server
Normal file
20
Dockerfile.server
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM golang:alpine AS build-env
|
||||||
|
|
||||||
|
RUN apk add --no-cache git make
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
ADD . /src
|
||||||
|
RUN make doh-server/doh-server
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
COPY --from=build-env /src/doh-server/doh-server /doh-server
|
||||||
|
|
||||||
|
ADD doh-server/doh-server.conf /doh-server.conf
|
||||||
|
|
||||||
|
RUN sed -i '$!N;s/"127.0.0.1:8053",\s*"\[::1\]:8053",/":8053",/;P;D' /doh-server.conf
|
||||||
|
|
||||||
|
EXPOSE 8053
|
||||||
|
|
||||||
|
ENTRYPOINT ["/doh-server"]
|
||||||
|
CMD ["-conf", "/doh-server.conf"]
|
||||||
1
Makefile
1
Makefile
@@ -59,6 +59,7 @@ uninstall:
|
|||||||
|
|
||||||
deps:
|
deps:
|
||||||
@# I am not sure if it is the correct way to keep the common library updated
|
@# I am not sure if it is the correct way to keep the common library updated
|
||||||
|
$(GOGET_UPDATE) github.com/m13253/dns-over-https/doh-client/config
|
||||||
$(GOGET_UPDATE) github.com/m13253/dns-over-https/json-dns
|
$(GOGET_UPDATE) github.com/m13253/dns-over-https/json-dns
|
||||||
$(GOGET) ./doh-client ./doh-server
|
$(GOGET) ./doh-client ./doh-server
|
||||||
|
|
||||||
|
|||||||
277
Readme.md
277
Readme.md
@@ -4,57 +4,68 @@ DNS-over-HTTPS
|
|||||||
Client and server software to query DNS over HTTPS, using [Google DNS-over-HTTPS protocol](https://developers.google.com/speed/public-dns/docs/dns-over-https)
|
Client and server software to query DNS over HTTPS, using [Google DNS-over-HTTPS protocol](https://developers.google.com/speed/public-dns/docs/dns-over-https)
|
||||||
and [IETF DNS-over-HTTPS (RFC 8484)](https://www.rfc-editor.org/rfc/rfc8484.txt).
|
and [IETF DNS-over-HTTPS (RFC 8484)](https://www.rfc-editor.org/rfc/rfc8484.txt).
|
||||||
|
|
||||||
## Guide
|
## Guides
|
||||||
|
|
||||||
[Tutorial to setup your own DNS-over-HTTPS (DoH) server](https://www.aaflalo.me/2018/10/tutorial-setup-dns-over-https-server/). (Thanks to Antoine Aflalo)
|
- [Tutorial: Setup your own DNS-over-HTTPS (DoH) server](https://www.aaflalo.me/2018/10/tutorial-setup-dns-over-https-server/). (Thanks to Antoine Aflalo)
|
||||||
|
- [Tutorial: Setup your own Docker based DNS-over-HTTPS (DoH) server](https://github.com/satishweb/docker-doh/blob/master/README.md). (Thanks to Satish Gaikwad)
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
### From Source
|
||||||
|
- Install [Go](https://golang.org), at least version 1.10.
|
||||||
|
> Note for Debian/Ubuntu users: You need to set `$GOROOT` if you could not get your new version of Go selected by the Makefile.)
|
||||||
|
|
||||||
Install [Go](https://golang.org), at least version 1.10.
|
- First create an empty directory, used for `$GOPATH`:
|
||||||
|
```bash
|
||||||
(Note for Debian/Ubuntu users: You need to set `$GOROOT` if you could not get your new version of Go selected by the Makefile.)
|
mkdir ~/gopath
|
||||||
|
export GOPATH=~/gopath
|
||||||
First create an empty directory, used for `$GOPATH`:
|
```
|
||||||
|
- To build the program, type:
|
||||||
mkdir ~/gopath
|
```bash
|
||||||
export GOPATH=~/gopath
|
make
|
||||||
|
```
|
||||||
To build the program, type:
|
- To install DNS-over-HTTPS as Systemd services, type:
|
||||||
|
```bash
|
||||||
make
|
sudo make install
|
||||||
|
```
|
||||||
To install DNS-over-HTTPS as Systemd services, type:
|
- By default, [Google DNS over HTTPS](https://dns.google.com) is used. It should
|
||||||
|
|
||||||
sudo make install
|
|
||||||
|
|
||||||
By default, [Google DNS over HTTPS](https://dns.google.com) is used. It should
|
|
||||||
work for most users (except for People's Republic of China). If you need to
|
work for most users (except for People's Republic of China). If you need to
|
||||||
modify the default settings, type:
|
modify the default settings, type:
|
||||||
|
```bash
|
||||||
|
sudoedit /etc/dns-over-https/doh-client.conf
|
||||||
|
```
|
||||||
|
- To automatically start DNS-over-HTTPS client as a system service, type:
|
||||||
|
```bash
|
||||||
|
sudo systemctl start doh-client.service
|
||||||
|
sudo systemctl enable doh-client.service
|
||||||
|
```
|
||||||
|
- Then, modify your DNS settings (usually with NetworkManager) to 127.0.0.1.
|
||||||
|
|
||||||
sudoedit /etc/dns-over-https/doh-client.conf
|
- To test your configuration, type:
|
||||||
|
```bash
|
||||||
|
dig www.google.com
|
||||||
|
Output:
|
||||||
|
;; SERVER: 127.0.0.1#53(127.0.0.1)
|
||||||
|
```
|
||||||
|
#### Uninstall
|
||||||
|
|
||||||
To automatically start DNS-over-HTTPS client as a system service, type:
|
- To uninstall, type:
|
||||||
|
```bash
|
||||||
|
sudo make uninstall
|
||||||
|
```
|
||||||
|
> Note: The configuration files are kept at `/etc/dns-over-https`. Remove them manually if you want.
|
||||||
|
|
||||||
sudo systemctl start doh-client.service
|
### Using docker image
|
||||||
sudo systemctl enable doh-client.service
|
```bash
|
||||||
|
docker run -itd --name doh-server \
|
||||||
Then, modify your DNS settings (usually with NetworkManager) to 127.0.0.1.
|
-p 8053:8053 \
|
||||||
|
-e UPSTREAM_DNS_SERVER="udp:8.8.8.8:53" \
|
||||||
To test your configuration, type:
|
-e DOH_HTTP_PREFIX="/dns-query"
|
||||||
|
-e DOH_SERVER_LISTEN=":8053"
|
||||||
dig www.google.com
|
-e DOH_SERVER_TIMEOUT="10"
|
||||||
|
-e DOH_SERVER_TRIES="3"
|
||||||
If it is OK, you will wee:
|
-e DOH_SERVER_VERBOSE="false"
|
||||||
|
satishweb/doh-server
|
||||||
;; SERVER: 127.0.0.1#53(127.0.0.1)
|
```
|
||||||
|
|
||||||
### Uninstalling
|
|
||||||
|
|
||||||
To uninstall, type:
|
|
||||||
|
|
||||||
sudo make uninstall
|
|
||||||
|
|
||||||
The configuration files are kept at `/etc/dns-over-https`. Remove them manually if you want.
|
|
||||||
|
|
||||||
## Server Configuration
|
## Server Configuration
|
||||||
|
|
||||||
@@ -79,12 +90,192 @@ you can host DNS-over-HTTPS along with other HTTPS services.
|
|||||||
HTTP/2 with at least TLS v1.3 is recommended. OCSP stapling must be enabled,
|
HTTP/2 with at least TLS v1.3 is recommended. OCSP stapling must be enabled,
|
||||||
otherwise DNS recursion may happen.
|
otherwise DNS recursion may happen.
|
||||||
|
|
||||||
|
### Configuration file
|
||||||
|
|
||||||
|
The main configuration file is `doh-client.conf`.
|
||||||
|
|
||||||
|
**Server selectors.** If several upstream servers are set, one is selected according to `upstream_selector` for each request. With `upstream_selector = "random"`, a random upstream server will be chosen for each request.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# available selector: random (default) or weighted_round_robin or lvs_weighted_round_robin
|
||||||
|
upstream_selector = "random"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example configuration: Apache
|
||||||
|
```bash
|
||||||
|
SSLProtocol TLSv1.2
|
||||||
|
SSLHonorCipherOrder On
|
||||||
|
SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+3DES:!aNULL:!MD5:!DSS:!eNULL:!EXP:!LOW:!MD5
|
||||||
|
SSLUseStapling on
|
||||||
|
SSLStaplingCache shmcb:/var/lib/apache2/stapling_cache(512000)
|
||||||
|
|
||||||
|
<VirtualHost *:443>
|
||||||
|
ServerName MY_SERVER_NAME
|
||||||
|
Protocols h2 http/1.1
|
||||||
|
ProxyPass /dns-query http://[::1]:8053/dns-query
|
||||||
|
ProxyPassReverse /dns-query http://[::1]:8053/dns-query
|
||||||
|
</VirtualHost>
|
||||||
|
```
|
||||||
|
(Credit: [Joan Moreau](https://github.com/m13253/dns-over-https/issues/51#issuecomment-526820884))
|
||||||
|
|
||||||
|
### Example configuration: Nginx
|
||||||
|
```bash
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2 default_server;
|
||||||
|
listen [::]:443 ssl http2 default_server;
|
||||||
|
server_name MY_SERVER_NAME;
|
||||||
|
|
||||||
|
server_tokens off;
|
||||||
|
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3; # TLS 1.3 requires nginx >= 1.13.0
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_dhparam /etc/nginx/dhparam.pem; # openssl dhparam -dsaparam -out /etc/nginx/dhparam.pem 4096
|
||||||
|
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
|
||||||
|
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
|
||||||
|
ssl_session_timeout 10m;
|
||||||
|
ssl_session_cache shared:SSL:10m;
|
||||||
|
ssl_session_tickets off; # Requires nginx >= 1.5.9
|
||||||
|
ssl_stapling on; # Requires nginx >= 1.3.7
|
||||||
|
ssl_stapling_verify on; # Requires nginx => 1.3.7
|
||||||
|
ssl_early_data off; # 0-RTT, enable if desired - Requires nginx >= 1.15.4
|
||||||
|
resolver 1.1.1.1 valid=300s; # Replace with your local resolver
|
||||||
|
resolver_timeout 5s;
|
||||||
|
# HTTP Security Headers
|
||||||
|
add_header X-Frame-Options DENY;
|
||||||
|
add_header X-Content-Type-Options nosniff;
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header Strict-Transport-Security "max-age=63072000";
|
||||||
|
ssl_certificate /path/to/your/server/certificates/fullchain.pem;
|
||||||
|
ssl_certificate_key /path/to/your/server/certificates/privkey.pem;
|
||||||
|
location /dns-query {
|
||||||
|
proxy_pass http://localhost:8053/dns-query;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
(Credit: [Cipherli.st](https://cipherli.st/))
|
||||||
|
|
||||||
|
### Example configuration: Caddy (v2)
|
||||||
|
```bash
|
||||||
|
my.server.name {
|
||||||
|
reverse_proxy * localhost:8053
|
||||||
|
tls your@email.address
|
||||||
|
try_files {path} {path}/index.php /index.php?{query}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
### Example configuration: Docker Compose + Traefik + Unbound (Raspberry Pi/Linux/Mac) [linux/amd64,linux/arm64,linux/arm/v7]
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '2.2'
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
services:
|
||||||
|
proxy:
|
||||||
|
# The official v2 Traefik docker image
|
||||||
|
image: traefik:v2.2
|
||||||
|
hostname: proxy
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
environment:
|
||||||
|
TRAEFIK_ACCESSLOG: "true"
|
||||||
|
TRAEFIK_API: "true"
|
||||||
|
TRAEFIK_PROVIDERS_DOCKER: "true"
|
||||||
|
TRAEFIK_API_INSECURE: "true"
|
||||||
|
TRAEFIK_PROVIDERS_DOCKER_NETWORK: "${STACK}_default"
|
||||||
|
# DNS provider specific environment variables for DNS Challenge using route53 (AWS)
|
||||||
|
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
|
||||||
|
AWS_REGION: ${AWS_REGION}
|
||||||
|
AWS_HOSTED_ZONE_ID: ${AWS_HOSTED_ZONE_ID}
|
||||||
|
ports:
|
||||||
|
# The HTTP port
|
||||||
|
- "80:80"
|
||||||
|
# The HTTPS port
|
||||||
|
- "443:443"
|
||||||
|
# The Web UI (enabled by --api.insecure=true)
|
||||||
|
- "8080:8080"
|
||||||
|
command:
|
||||||
|
#- "--log.level=DEBUG"
|
||||||
|
- "--providers.docker.exposedbydefault=false"
|
||||||
|
- "--entrypoints.web.address=:80"
|
||||||
|
- "--entrypoints.websecure.address=:443"
|
||||||
|
- "--certificatesresolvers.letsencrypt.acme.dnschallenge=true"
|
||||||
|
# Providers list:
|
||||||
|
# https://docs.traefik.io/https/acme/#providers
|
||||||
|
# https://go-acme.github.io/lego/dns/
|
||||||
|
- "--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=route53"
|
||||||
|
# Enable below line to use staging letsencrypt server.
|
||||||
|
#- "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
|
||||||
|
- "--certificatesresolvers.letsencrypt.acme.email=${EMAIL}"
|
||||||
|
- "--certificatesresolvers.letsencrypt.acme.storage=/certs/acme.json"
|
||||||
|
volumes:
|
||||||
|
# So that Traefik can listen to the Docker events
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./data/proxy/certs:/certs
|
||||||
|
doh-server:
|
||||||
|
image: satishweb/doh-server:latest
|
||||||
|
hostname: doh-server
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
environment:
|
||||||
|
# Enable below line to see more logs
|
||||||
|
# DEBUG: "1"
|
||||||
|
UPSTREAM_DNS_SERVER: "udp:unbound:53"
|
||||||
|
DOH_HTTP_PREFIX: "${DOH_HTTP_PREFIX}"
|
||||||
|
DOH_SERVER_LISTEN: ":${DOH_SERVER_LISTEN}"
|
||||||
|
DOH_SERVER_TIMEOUT: "10"
|
||||||
|
DOH_SERVER_TRIES: "3"
|
||||||
|
DOH_SERVER_VERBOSE: "false"
|
||||||
|
#volumes:
|
||||||
|
# - ./doh-server.conf:/server/doh-server.conf
|
||||||
|
# - ./app-config:/app-config
|
||||||
|
depends_on:
|
||||||
|
- unbound
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.doh-server.rule=Host(`${SUBDOMAIN}.${DOMAIN}`) && Path(`${DOH_HTTP_PREFIX}`)"
|
||||||
|
- "traefik.http.services.doh-server.loadbalancer.server.port=${DOH_SERVER_LISTEN}"
|
||||||
|
- "traefik.http.middlewares.mw-doh-compression.compress=true"
|
||||||
|
- "traefik.http.routers.doh-server.tls=true"
|
||||||
|
- "traefik.http.middlewares.mw-doh-tls.headers.sslredirect=true"
|
||||||
|
- "traefik.http.middlewares.mw-doh-tls.headers.sslforcehost=true"
|
||||||
|
- "traefik.http.routers.doh-server.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.routers.doh-server.tls.domains[0].main=${DOMAIN}"
|
||||||
|
- "traefik.http.routers.doh-server.tls.domains[0].sans=${SUBDOMAIN}.${DOMAIN}"
|
||||||
|
# Protection from requests flood
|
||||||
|
- "traefik.http.middlewares.mw-doh-ratelimit.ratelimit.average=100"
|
||||||
|
- "traefik.http.middlewares.mw-doh-ratelimit.ratelimit.burst=50"
|
||||||
|
- "traefik.http.middlewares.mw-doh-ratelimit.ratelimit.period=10s"
|
||||||
|
unbound:
|
||||||
|
image: satishweb/unbound:latest
|
||||||
|
hostname: unbound
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
ports:
|
||||||
|
# Disable these ports if DOH server is the only client
|
||||||
|
- 53:53/tcp
|
||||||
|
- 53:53/udp
|
||||||
|
volumes:
|
||||||
|
- ./unbound.sample.conf:/templates/unbound.sample.conf
|
||||||
|
- ./data/unbound/custom:/etc/unbound/custom
|
||||||
|
# Keep your custom.hosts file inside custom folder
|
||||||
|
#environment:
|
||||||
|
# DEBUG: "1"
|
||||||
|
````
|
||||||
|
|
||||||
|
> Complete Guide available at: https://github.com/satishweb/docker-doh
|
||||||
|
|
||||||
|
> No IPV6 Support: Docker Swarm does not support IPV6 as of yet. Issue is logged [here](https://github.com/moby/moby/issues/24379)
|
||||||
|
|
||||||
|
> IPV6 Support for Docker Compose based configuration TBA
|
||||||
|
|
||||||
## DNSSEC
|
## DNSSEC
|
||||||
|
|
||||||
DNS-over-HTTPS is compatible with DNSSEC, and requests DNSSEC signatures by
|
DNS-over-HTTPS is compatible with DNSSEC, and requests DNSSEC signatures by
|
||||||
default. However signature validation is not built-in. It is highly recommended
|
default. However signature validation is not built-in. It is highly recommended
|
||||||
that you install `unbound` or `bind` and pass results for them to validate DNS
|
that you install `unbound` or `bind` and pass results for them to validate DNS
|
||||||
records.
|
records. An instance of [Pi Hole](https://pi-hole.net) could also be used to validate DNS signatures as well as provide other capabilities.
|
||||||
|
|
||||||
## EDNS0-Client-Subnet (GeoDNS)
|
## EDNS0-Client-Subnet (GeoDNS)
|
||||||
|
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# This is a script used for automated packaging.
|
|
||||||
# Debian maintainers please don't use this.
|
|
||||||
#
|
|
||||||
# Environment assumption:
|
|
||||||
# * Ubuntu 16.04
|
|
||||||
# * run with normal user
|
|
||||||
# * sudo with no password
|
|
||||||
# * go and fpm is pre-installed
|
|
||||||
# * rpmbuild is required if you need rpm packages
|
|
||||||
#
|
|
||||||
# Compatible with Azure DevOps hosted Ubuntu 16.04 agent
|
|
||||||
|
|
||||||
export DEBIAN_FRONTEND="noninteractive"
|
|
||||||
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/..
|
|
||||||
export BUILD_BINARIESDIRECTORY="${BUILD_BINARIESDIRECTORY:-${DIR}/build/bin}"
|
|
||||||
export BUILD_ARTIFACTSTAGINGDIRECTORY="${BUILD_ARTIFACTSTAGINGDIRECTORY:-${DIR}/build/packages}"
|
|
||||||
export TMP_DIRECTORY="/tmp/dohbuild"
|
|
||||||
export GOPATH="${GOPATH:-/tmp/go}"
|
|
||||||
export GOBIN="${GOBIN:-/tmp/go/bin}"
|
|
||||||
|
|
||||||
function prepare_env() {
|
|
||||||
echo "Checking dependencies"
|
|
||||||
|
|
||||||
if ! [ -x "$(command -v go)" ]; then
|
|
||||||
echo "Please install golang"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x "$(command -v apt-get)" ]; then
|
|
||||||
sudo apt-get -y update
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ -x "$(command -v rpmbuild)" ]; then
|
|
||||||
# TODO: correctly install rpmbuild
|
|
||||||
! sudo apt-get -y install rpmbuild
|
|
||||||
fi
|
|
||||||
|
|
||||||
# if ! [ -x "$(command -v upx)" ]; then
|
|
||||||
# sudo apt-get -y install upx
|
|
||||||
# fi
|
|
||||||
|
|
||||||
echo "Creating directories"
|
|
||||||
|
|
||||||
mkdir -p "${BUILD_BINARIESDIRECTORY}/nm-dispatcher"
|
|
||||||
mkdir -p "${BUILD_BINARIESDIRECTORY}/launchd"
|
|
||||||
mkdir -p "${BUILD_BINARIESDIRECTORY}/systemd"
|
|
||||||
mkdir -p "${BUILD_BINARIESDIRECTORY}/config"
|
|
||||||
mkdir -p "${BUILD_ARTIFACTSTAGINGDIRECTORY}"
|
|
||||||
mkdir -p "${TMP_DIRECTORY}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function build_common() {
|
|
||||||
cp NetworkManager/dispatcher.d/* "${BUILD_BINARIESDIRECTORY}"/nm-dispatcher
|
|
||||||
cp launchd/*.plist "${BUILD_BINARIESDIRECTORY}"/launchd
|
|
||||||
cp systemd/*.service "${BUILD_BINARIESDIRECTORY}"/systemd
|
|
||||||
cp doh-server/doh-server.conf "${BUILD_BINARIESDIRECTORY}"/config
|
|
||||||
cp doh-client/doh-client.conf "${BUILD_BINARIESDIRECTORY}"/config
|
|
||||||
}
|
|
||||||
|
|
||||||
# used to get version
|
|
||||||
function build_native() {
|
|
||||||
echo "Building a native binary..."
|
|
||||||
|
|
||||||
go build -ldflags="-s -w" -o ${BUILD_BINARIESDIRECTORY}/"${EXE}"-native
|
|
||||||
}
|
|
||||||
|
|
||||||
function build() {
|
|
||||||
echo "Building ${EXE} for OS=$1 ARCH=$2"
|
|
||||||
env GOOS="$1" GOARCH="$2" go build -ldflags="-s -w" -o ${BUILD_BINARIESDIRECTORY}/"${EXE}"-"$3"
|
|
||||||
|
|
||||||
# echo "Compressing executable"
|
|
||||||
# ! upx --ultra-brute ${BUILD_BINARIESDIRECTORY}/${EXE}-"$3" || true
|
|
||||||
}
|
|
||||||
|
|
||||||
function package() {
|
|
||||||
VERSION=$("${BUILD_BINARIESDIRECTORY}/${EXE}-native" --version | head -n 1 | cut -d" " -f2)
|
|
||||||
REVISION=$(git log --pretty=format:'%h' -n 1)
|
|
||||||
|
|
||||||
echo "Packaging ${EXE} ${VERSION} for OS=$1 ARCH=$2 TYPE=$3 DST=$4"
|
|
||||||
|
|
||||||
! rm -rf "${TMP_DIRECTORY}"/*
|
|
||||||
|
|
||||||
mkdir -p "${TMP_DIRECTORY}"/usr/bin
|
|
||||||
cp "${BUILD_BINARIESDIRECTORY}"/"${EXE}"-"$3" "${TMP_DIRECTORY}"/usr/bin/"${EXE}"
|
|
||||||
|
|
||||||
mkdir -p "${TMP_DIRECTORY}"/usr/lib/systemd/system
|
|
||||||
cp "${BUILD_BINARIESDIRECTORY}"/systemd/"${EXE}".service "${TMP_DIRECTORY}"/usr/lib/systemd/system
|
|
||||||
|
|
||||||
mkdir -p "${TMP_DIRECTORY}"/etc/dns-over-https
|
|
||||||
cp "${BUILD_BINARIESDIRECTORY}"/config/"${EXE}".conf "${TMP_DIRECTORY}"/etc/dns-over-https
|
|
||||||
|
|
||||||
mkdir -p "${TMP_DIRECTORY}"/etc/NetworkManager/dispatcher.d
|
|
||||||
cp "${BUILD_BINARIESDIRECTORY}"/nm-dispatcher/"${EXE}" "${TMP_DIRECTORY}"/etc/NetworkManager/dispatcher.d
|
|
||||||
|
|
||||||
# call fpm
|
|
||||||
fpm --input-type dir \
|
|
||||||
--output-type $4 \
|
|
||||||
--chdir "${TMP_DIRECTORY}" \
|
|
||||||
--package "${BUILD_ARTIFACTSTAGINGDIRECTORY}" \
|
|
||||||
--name "${EXE}" \
|
|
||||||
--description "${DESCR}" \
|
|
||||||
--version "${VERSION}" \
|
|
||||||
--iteration "${REVISION}" \
|
|
||||||
--url "https://github.com/m13253/dns-over-https" \
|
|
||||||
--vendor "Star Brilliant <coder@poorlab.com>" \
|
|
||||||
--license "MIT License" \
|
|
||||||
--category "net" \
|
|
||||||
--maintainer "James Swineson <autopkg@public.swineson.me>" \
|
|
||||||
--architecture "$2" \
|
|
||||||
--force \
|
|
||||||
.
|
|
||||||
}
|
|
||||||
|
|
||||||
cd "${DIR}"/..
|
|
||||||
prepare_env
|
|
||||||
make deps
|
|
||||||
build_common
|
|
||||||
|
|
||||||
pushd doh-server
|
|
||||||
export EXE="doh-server"
|
|
||||||
export DESCR="DNS-over-HTTPS Server"
|
|
||||||
|
|
||||||
build_native
|
|
||||||
|
|
||||||
build linux amd64 linux-amd64
|
|
||||||
package linux amd64 linux-amd64 deb
|
|
||||||
! package linux amd64 linux-amd64 rpm
|
|
||||||
package linux amd64 linux-amd64 pacman
|
|
||||||
|
|
||||||
build linux arm linux-armhf
|
|
||||||
package linux arm linux-armhf deb
|
|
||||||
! package linux arm linux-armhf rpm
|
|
||||||
package linux arm linux-armhf pacman
|
|
||||||
|
|
||||||
build linux arm64 linux-arm64
|
|
||||||
package linux arm64 linux-arm64 deb
|
|
||||||
! package linux arm64 linux-arm64 rpm
|
|
||||||
package linux arm64 linux-arm64 pacman
|
|
||||||
|
|
||||||
# build darwin amd64 darwin-amd64
|
|
||||||
# build windows 386 windows-x86.exe
|
|
||||||
# build windows amd64 windows-amd64.exe
|
|
||||||
popd
|
|
||||||
|
|
||||||
pushd doh-client
|
|
||||||
export EXE="doh-client"
|
|
||||||
export DESCR="DNS-over-HTTPS Client"
|
|
||||||
|
|
||||||
build_native
|
|
||||||
|
|
||||||
build linux amd64 linux-amd64
|
|
||||||
package linux amd64 linux-amd64 deb
|
|
||||||
! package linux amd64 linux-amd64 rpm
|
|
||||||
package linux amd64 linux-amd64 pacman
|
|
||||||
|
|
||||||
build linux arm linux-armhf
|
|
||||||
package linux arm linux-armhf deb
|
|
||||||
! package linux arm linux-armhf rpm
|
|
||||||
package linux arm linux-armhf pacman
|
|
||||||
|
|
||||||
build linux arm64 linux-arm64
|
|
||||||
package linux arm64 linux-arm64 deb
|
|
||||||
! package linux arm64 linux-arm64 rpm
|
|
||||||
package linux arm64 linux-arm64 pacman
|
|
||||||
|
|
||||||
# build darwin amd64 darwin-amd64
|
|
||||||
# build windows 386 windows-x86.exe
|
|
||||||
# build windows amd64 windows-amd64.exe
|
|
||||||
popd
|
|
||||||
|
|
||||||
36
contrib/rpm/dns-over-https-2.1.2-systemd.patch
Normal file
36
contrib/rpm/dns-over-https-2.1.2-systemd.patch
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
diff -Naur dns-over-https-2.1.2.org/systemd/doh-client.service dns-over-https-2.1.2/systemd/doh-client.service
|
||||||
|
--- dns-over-https-2.1.2.org/systemd/doh-client.service 2019-09-10 12:08:35.177574074 +0200
|
||||||
|
+++ dns-over-https-2.1.2/systemd/doh-client.service 2019-09-10 12:10:05.473700374 +0200
|
||||||
|
@@ -7,12 +7,12 @@
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||||
|
-ExecStart=/usr/local/bin/doh-client -conf /etc/dns-over-https/doh-client.conf
|
||||||
|
+ExecStart=/usr/bin/doh-client -conf /etc/dns-over-https/doh-client.conf
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
Type=simple
|
||||||
|
-User=nobody
|
||||||
|
+User=doh-client
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
diff -Naur dns-over-https-2.1.2.org/systemd/doh-server.service dns-over-https-2.1.2/systemd/doh-server.service
|
||||||
|
--- dns-over-https-2.1.2.org/systemd/doh-server.service 2019-09-10 12:08:35.177574074 +0200
|
||||||
|
+++ dns-over-https-2.1.2/systemd/doh-server.service 2019-09-10 12:10:20.980273992 +0200
|
||||||
|
@@ -5,12 +5,12 @@
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||||
|
-ExecStart=/usr/local/bin/doh-server -conf /etc/dns-over-https/doh-server.conf
|
||||||
|
+ExecStart=/usr/bin/doh-server -conf /etc/dns-over-https/doh-server.conf
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
Type=simple
|
||||||
|
-User=nobody
|
||||||
|
+User=doh-server
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
240
contrib/rpm/doh.spec
Normal file
240
contrib/rpm/doh.spec
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
%global _hardened_build 1
|
||||||
|
# Debug package is empty anyway
|
||||||
|
%define debug_package %{nil}
|
||||||
|
|
||||||
|
%global _release 1
|
||||||
|
%global provider github
|
||||||
|
%global provider_tld com
|
||||||
|
%global project m13253
|
||||||
|
%global repo dns-over-https
|
||||||
|
%global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo}
|
||||||
|
%global import_path %{provider_prefix}
|
||||||
|
|
||||||
|
#define commit 984df34ca7b45897ecb5871791e398cc160a4b93
|
||||||
|
|
||||||
|
%if 0%{?commit:1}
|
||||||
|
%define shortcommit %(c=%{commit}; echo ${c:0:7})
|
||||||
|
%define _date %(date +'%%Y%%m%%dT%%H%%M%%S')
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%define rand_id %(head -c20 /dev/urandom|od -An -tx1|tr -d '[[:space:]]')
|
||||||
|
|
||||||
|
%if ! 0%{?gobuild:1}
|
||||||
|
%define gobuild(o:) go build -ldflags "${LDFLAGS:-} -B 0x%{rand_id}" -a -v -x %{?**};
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if ! 0%{?gotest:1}
|
||||||
|
%define gotest() go test -ldflags "${LDFLAGS:-}" %{?**}
|
||||||
|
%endif
|
||||||
|
|
||||||
|
Name: %{repo}
|
||||||
|
Version: 2.1.2
|
||||||
|
%if 0%{?commit:1}
|
||||||
|
Release: %{_release}.git%{shortcommit}.%{_date}%{?dist}
|
||||||
|
Source0: https://%{import_path}/archive/%{commit}.tar.gz
|
||||||
|
%else
|
||||||
|
Release: %{_release}%{?dist}
|
||||||
|
Source0: https://%{import_path}/archive/v%{version}.tar.gz
|
||||||
|
%endif
|
||||||
|
Patch0: %{name}-%{version}-systemd.patch
|
||||||
|
|
||||||
|
Summary: High performance DNS over HTTPS client & server
|
||||||
|
License: MIT
|
||||||
|
URL: https://github.com/m13253/dns-over-https
|
||||||
|
|
||||||
|
|
||||||
|
# e.g. el6 has ppc64 arch without gcc-go, so EA tag is required
|
||||||
|
# If go_compiler is not set to 1, there is no virtual provide. Use golang instead.
|
||||||
|
#BuildRequires: %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang} >= 1.10
|
||||||
|
BuildRequires: golang >= 1.10
|
||||||
|
BuildRequires: systemd
|
||||||
|
BuildRequires: upx
|
||||||
|
|
||||||
|
%description
|
||||||
|
%{summary}
|
||||||
|
|
||||||
|
%package common
|
||||||
|
BuildArch: noarch
|
||||||
|
Summary: %{summary} - common files
|
||||||
|
|
||||||
|
%description common
|
||||||
|
%{summary}
|
||||||
|
|
||||||
|
%package server
|
||||||
|
ExclusiveArch: %{?go_arches:%{go_arches}}%{!?go_arches:%{ix86} x86_64 %{arm}}
|
||||||
|
Summary: %{summary} - Server
|
||||||
|
Requires(pre): shadow-utils
|
||||||
|
Requires(post): systemd
|
||||||
|
Requires(preun): systemd
|
||||||
|
Requires(postun): systemd
|
||||||
|
|
||||||
|
%description server
|
||||||
|
%{summary}
|
||||||
|
|
||||||
|
%package client
|
||||||
|
ExclusiveArch: %{?go_arches:%{go_arches}}%{!?go_arches:%{ix86} x86_64 %{arm}}
|
||||||
|
Summary: %{summary} - Client
|
||||||
|
Requires(pre): shadow-utils
|
||||||
|
Requires(post): systemd
|
||||||
|
Requires(preun): systemd
|
||||||
|
Requires(postun): systemd
|
||||||
|
|
||||||
|
%description client
|
||||||
|
%{summary}
|
||||||
|
|
||||||
|
%package selinux
|
||||||
|
BuildArch: noarch
|
||||||
|
|
||||||
|
Source3: doh_server.fc
|
||||||
|
Source4: doh_server.if
|
||||||
|
Source5: doh_server.te
|
||||||
|
Source6: doh_client.fc
|
||||||
|
Source7: doh_client.if
|
||||||
|
Source8: doh_client.te
|
||||||
|
|
||||||
|
BuildRequires: selinux-policy
|
||||||
|
BuildRequires: selinux-policy-devel
|
||||||
|
Requires: %{name}
|
||||||
|
|
||||||
|
Requires(post): policycoreutils
|
||||||
|
Requires(post): policycoreutils-python
|
||||||
|
Requires(postun): policycoreutils
|
||||||
|
|
||||||
|
Summary: SELinux policy for %{name}
|
||||||
|
|
||||||
|
%description selinux
|
||||||
|
%summary
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%if 0%{?commit:1}
|
||||||
|
%autosetup -n %{name}-%{commit} -p1
|
||||||
|
%else
|
||||||
|
%autosetup -n %{name}-%{version} -p1
|
||||||
|
%endif
|
||||||
|
|
||||||
|
mkdir -p selinux
|
||||||
|
cp %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} %{SOURCE7} %{SOURCE8} selinux
|
||||||
|
|
||||||
|
%build
|
||||||
|
cd selinux
|
||||||
|
make -f /usr/share/selinux/devel/Makefile doh_server.pp doh_client.pp || exit
|
||||||
|
cd -
|
||||||
|
|
||||||
|
%set_build_flags
|
||||||
|
%make_build \
|
||||||
|
PREFIX=%{_prefix} \
|
||||||
|
GOBUILD="go build -ldflags \"-s -w -B 0x%{rand_id}\" -a -v -x"
|
||||||
|
|
||||||
|
%install
|
||||||
|
%make_install \
|
||||||
|
PREFIX=%{_prefix}
|
||||||
|
install -Dpm 0600 selinux/doh_server.pp %{buildroot}%{_datadir}/selinux/packages/doh_server.pp
|
||||||
|
install -Dpm 0644 selinux/doh_server.if %{buildroot}%{_datadir}/selinux/devel/include/contrib/doh_server.if
|
||||||
|
install -Dpm 0600 selinux/doh_client.pp %{buildroot}%{_datadir}/selinux/packages/doh_client.pp
|
||||||
|
install -Dpm 0644 selinux/doh_client.if %{buildroot}%{_datadir}/selinux/devel/include/contrib/doh_client.if
|
||||||
|
|
||||||
|
mkdir -p %{buildroot}%{_docdir}/%{name}
|
||||||
|
mv %{buildroot}%{_sysconfdir}/%{name}/*.example %{buildroot}%{_docdir}/%{name}
|
||||||
|
|
||||||
|
mkdir -p %{buildroot}%{_libdir}
|
||||||
|
mv %{buildroot}%{_sysconfdir}/NetworkManager %{buildroot}%{_libdir}/
|
||||||
|
|
||||||
|
for i in $(find %{_buildroot}%{_bindir} -type f)
|
||||||
|
do
|
||||||
|
upx $i
|
||||||
|
done
|
||||||
|
|
||||||
|
%files common
|
||||||
|
%license LICENSE
|
||||||
|
%doc Changelog.md Readme.md
|
||||||
|
|
||||||
|
%files server
|
||||||
|
%{_libdir}/NetworkManager/dispatcher.d/doh-server
|
||||||
|
%{_docdir}/%{name}/doh-server.conf.example
|
||||||
|
%config(noreplace) %{_sysconfdir}/%{name}/doh-server.conf
|
||||||
|
%{_bindir}/doh-server
|
||||||
|
%{_unitdir}/doh-server.service
|
||||||
|
|
||||||
|
%files client
|
||||||
|
%{_libdir}/NetworkManager/dispatcher.d/doh-client
|
||||||
|
%{_docdir}/%{name}/doh-client.conf.example
|
||||||
|
%config(noreplace) %{_sysconfdir}/%{name}/doh-client.conf
|
||||||
|
%{_bindir}/doh-client
|
||||||
|
%{_unitdir}/doh-client.service
|
||||||
|
|
||||||
|
%pre server
|
||||||
|
test -d %{_sharedstatedir}/home || mkdir -p %{_sharedstatedir}/home
|
||||||
|
getent group doh-server > /dev/null || groupadd -r doh-server
|
||||||
|
getent passwd doh-server > /dev/null || \
|
||||||
|
useradd -r -d %{_sharedstatedir}/home/doh-server -g doh-server \
|
||||||
|
-s /sbin/nologin -c "%{name} - server" doh-server
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
%pre client
|
||||||
|
test -d %{_sharedstatedir}/home || mkdir -p %{_sharedstatedir}/home
|
||||||
|
getent group doh-client > /dev/null || groupadd -r doh-client
|
||||||
|
getent passwd doh-client > /dev/null || \
|
||||||
|
useradd -r -d %{_sharedstatedir}/home/doh-client -g doh-client \
|
||||||
|
-s /sbin/nologin -c "%{name} - client" doh-client
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
%post server
|
||||||
|
%systemd_post doh-server.service
|
||||||
|
|
||||||
|
%preun server
|
||||||
|
%systemd_preun doh-server.service
|
||||||
|
|
||||||
|
%postun server
|
||||||
|
%systemd_postun_with_restart doh-server.service
|
||||||
|
|
||||||
|
%post client
|
||||||
|
%systemd_post doh-client.service
|
||||||
|
|
||||||
|
%preun client
|
||||||
|
%systemd_preun doh-client.service
|
||||||
|
|
||||||
|
%postun client
|
||||||
|
%systemd_postun_with_restart doh-client.service
|
||||||
|
|
||||||
|
%files selinux
|
||||||
|
%{_datadir}/selinux/packages/doh_server.pp
|
||||||
|
%{_datadir}/selinux/devel/include/contrib/doh_server.if
|
||||||
|
%{_datadir}/selinux/packages/doh_client.pp
|
||||||
|
%{_datadir}/selinux/devel/include/contrib/doh_client.if
|
||||||
|
|
||||||
|
%post selinux
|
||||||
|
semodule -n -i %{_datadir}/selinux/packages/doh_server.pp
|
||||||
|
semodule -n -i %{_datadir}/selinux/packages/doh_client.pp
|
||||||
|
if /usr/sbin/selinuxenabled ; then
|
||||||
|
/usr/sbin/load_policy
|
||||||
|
/usr/sbin/fixfiles -R %{name}-server restore
|
||||||
|
/usr/sbin/fixfiles -R %{name}-client restore
|
||||||
|
fi;
|
||||||
|
semanage -i - << __eof
|
||||||
|
port -a -t doh_server_port_t -p tcp "8053"
|
||||||
|
port -a -t doh_client_port_t -p udp "5380"
|
||||||
|
__eof
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
%postun selinux
|
||||||
|
if [ $1 -eq 0 ]; then
|
||||||
|
semanage -i - << __eof
|
||||||
|
port -d -t doh_server_port_t -p tcp "8053"
|
||||||
|
port -d -t doh_client_port_t -p udp "5380"
|
||||||
|
__eof
|
||||||
|
|
||||||
|
semodule -n -r doh_server
|
||||||
|
semodule -n -r doh_client
|
||||||
|
if /usr/sbin/selinuxenabled ; then
|
||||||
|
/usr/sbin/load_policy
|
||||||
|
/usr/sbin/fixfiles -R %{name}-server restore
|
||||||
|
/usr/sbin/fixfiles -R %{name}-client restore
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Tue Sep 10 2019 fuero <fuerob@gmail.com> 2.1.2-1
|
||||||
|
- initial package
|
||||||
|
|
||||||
2
contrib/rpm/doh_client.fc
Normal file
2
contrib/rpm/doh_client.fc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/usr/bin/doh-client -- gen_context(system_u:object_r:doh_client_exec_t,s0)
|
||||||
|
/usr/lib/systemd/system/doh-client.service -- gen_context(system_u:object_r:doh_client_unit_file_t,s0)
|
||||||
103
contrib/rpm/doh_client.if
Normal file
103
contrib/rpm/doh_client.if
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
|
||||||
|
## <summary>policy for doh_client</summary>
|
||||||
|
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_client_exec_t in the doh_client domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed to transition.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_client_domtrans',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_client_t, doh_client_exec_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
corecmd_search_bin($1)
|
||||||
|
domtrans_pattern($1, doh_client_exec_t, doh_client_t)
|
||||||
|
')
|
||||||
|
|
||||||
|
######################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_client in the caller domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_client_exec',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_client_exec_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
corecmd_search_bin($1)
|
||||||
|
can_exec($1, doh_client_exec_t)
|
||||||
|
')
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_client server in the doh_client domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed to transition.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_client_systemctl',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_client_t;
|
||||||
|
type doh_client_unit_file_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
systemd_exec_systemctl($1)
|
||||||
|
systemd_read_fifo_file_passwd_run($1)
|
||||||
|
allow $1 doh_client_unit_file_t:file read_file_perms;
|
||||||
|
allow $1 doh_client_unit_file_t:service manage_service_perms;
|
||||||
|
|
||||||
|
ps_process_pattern($1, doh_client_t)
|
||||||
|
')
|
||||||
|
|
||||||
|
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## All of the rules required to administrate
|
||||||
|
## an doh_client environment
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
## <param name="role">
|
||||||
|
## <summary>
|
||||||
|
## Role allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
## <rolecap/>
|
||||||
|
#
|
||||||
|
interface(`doh_client_admin',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_client_t;
|
||||||
|
type doh_client_unit_file_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
allow $1 doh_client_t:process { signal_perms };
|
||||||
|
ps_process_pattern($1, doh_client_t)
|
||||||
|
|
||||||
|
tunable_policy(`deny_ptrace',`',`
|
||||||
|
allow $1 doh_client_t:process ptrace;
|
||||||
|
')
|
||||||
|
|
||||||
|
doh_client_systemctl($1)
|
||||||
|
admin_pattern($1, doh_client_unit_file_t)
|
||||||
|
allow $1 doh_client_unit_file_t:service all_service_perms;
|
||||||
|
optional_policy(`
|
||||||
|
systemd_passwd_agent_exec($1)
|
||||||
|
systemd_read_fifo_file_passwd_run($1)
|
||||||
|
')
|
||||||
|
')
|
||||||
49
contrib/rpm/doh_client.te
Normal file
49
contrib/rpm/doh_client.te
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
policy_module(doh_client, 1.0.0)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
#
|
||||||
|
# Declarations
|
||||||
|
#
|
||||||
|
|
||||||
|
type doh_client_t;
|
||||||
|
type doh_client_exec_t;
|
||||||
|
init_daemon_domain(doh_client_t, doh_client_exec_t)
|
||||||
|
|
||||||
|
type doh_client_port_t;
|
||||||
|
|
||||||
|
corenet_port(doh_client_port_t)
|
||||||
|
|
||||||
|
type doh_client_unit_file_t;
|
||||||
|
systemd_unit_file(doh_client_unit_file_t)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
#
|
||||||
|
# doh_client local policy
|
||||||
|
#
|
||||||
|
allow doh_client_t self:fifo_file rw_fifo_file_perms;
|
||||||
|
allow doh_client_t self:unix_stream_socket create_stream_socket_perms;
|
||||||
|
|
||||||
|
allow doh_client_t self:capability net_bind_service;
|
||||||
|
allow doh_client_t self:process execmem;
|
||||||
|
allow doh_client_t self:tcp_socket { accept bind connect create getattr getopt listen read setopt write };
|
||||||
|
allow doh_client_t self:udp_socket { bind connect create getattr read setopt write };
|
||||||
|
|
||||||
|
allow doh_client_t doh_client_exec_t:file execmod;
|
||||||
|
allow doh_client_t doh_client_port_t:tcp_socket name_bind;
|
||||||
|
|
||||||
|
corenet_tcp_bind_dns_port(doh_client_t)
|
||||||
|
corenet_tcp_bind_generic_node(doh_client_t)
|
||||||
|
corenet_tcp_connect_http_port(doh_client_t)
|
||||||
|
corenet_udp_bind_dns_port(doh_client_t)
|
||||||
|
corenet_udp_bind_generic_node(doh_client_t)
|
||||||
|
corenet_udp_bind_generic_port(doh_client_t)
|
||||||
|
kernel_read_net_sysctls(doh_client_t)
|
||||||
|
kernel_search_network_sysctl(doh_client_t)
|
||||||
|
miscfiles_read_certs(doh_client_t)
|
||||||
|
sysnet_read_config(doh_client_t)
|
||||||
|
|
||||||
|
domain_use_interactive_fds(doh_client_t)
|
||||||
|
|
||||||
|
files_read_etc_files(doh_client_t)
|
||||||
|
|
||||||
|
miscfiles_read_localization(doh_client_t)
|
||||||
2
contrib/rpm/doh_server.fc
Normal file
2
contrib/rpm/doh_server.fc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/usr/bin/doh-server -- gen_context(system_u:object_r:doh_server_exec_t,s0)
|
||||||
|
/usr/lib/systemd/system/doh-server.service -- gen_context(system_u:object_r:doh_server_unit_file_t,s0)
|
||||||
122
contrib/rpm/doh_server.if
Normal file
122
contrib/rpm/doh_server.if
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
|
||||||
|
## <summary>policy for doh_server</summary>
|
||||||
|
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_server_exec_t in the doh_server domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed to transition.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_server_domtrans',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_server_t, doh_server_exec_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
corecmd_search_bin($1)
|
||||||
|
domtrans_pattern($1, doh_server_exec_t, doh_server_t)
|
||||||
|
')
|
||||||
|
|
||||||
|
######################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_server in the caller domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_server_exec',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_server_exec_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
corecmd_search_bin($1)
|
||||||
|
can_exec($1, doh_server_exec_t)
|
||||||
|
')
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## Execute doh_server server in the doh_server domain.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed to transition.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_server_systemctl',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_server_t;
|
||||||
|
type doh_server_unit_file_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
systemd_exec_systemctl($1)
|
||||||
|
systemd_read_fifo_file_passwd_run($1)
|
||||||
|
allow $1 doh_server_unit_file_t:file read_file_perms;
|
||||||
|
allow $1 doh_server_unit_file_t:service manage_service_perms;
|
||||||
|
|
||||||
|
ps_process_pattern($1, doh_server_t)
|
||||||
|
')
|
||||||
|
|
||||||
|
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## All of the rules required to administrate
|
||||||
|
## an doh_server environment
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
## <param name="role">
|
||||||
|
## <summary>
|
||||||
|
## Role allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
## <rolecap/>
|
||||||
|
#
|
||||||
|
interface(`doh_server_admin',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_server_t;
|
||||||
|
type doh_server_unit_file_t;
|
||||||
|
')
|
||||||
|
|
||||||
|
allow $1 doh_server_t:process { signal_perms };
|
||||||
|
ps_process_pattern($1, doh_server_t)
|
||||||
|
|
||||||
|
tunable_policy(`deny_ptrace',`',`
|
||||||
|
allow $1 doh_server_t:process ptrace;
|
||||||
|
')
|
||||||
|
|
||||||
|
doh_server_systemctl($1)
|
||||||
|
admin_pattern($1, doh_server_unit_file_t)
|
||||||
|
allow $1 doh_server_unit_file_t:service all_service_perms;
|
||||||
|
optional_policy(`
|
||||||
|
systemd_passwd_agent_exec($1)
|
||||||
|
systemd_read_fifo_file_passwd_run($1)
|
||||||
|
')
|
||||||
|
')
|
||||||
|
|
||||||
|
########################################
|
||||||
|
## <summary>
|
||||||
|
## Make a TCP connection to the vault_ocsp_responder port.
|
||||||
|
## </summary>
|
||||||
|
## <param name="domain">
|
||||||
|
## <summary>
|
||||||
|
## Domain allowed access.
|
||||||
|
## </summary>
|
||||||
|
## </param>
|
||||||
|
#
|
||||||
|
interface(`doh_server_connect',`
|
||||||
|
gen_require(`
|
||||||
|
type doh_server_port_t;
|
||||||
|
type $1;
|
||||||
|
')
|
||||||
|
|
||||||
|
allow $1 doh_server_port_t:tcp_socket name_connect;
|
||||||
|
')
|
||||||
42
contrib/rpm/doh_server.te
Normal file
42
contrib/rpm/doh_server.te
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
policy_module(doh_server, 1.0.0)
|
||||||
|
|
||||||
|
require {
|
||||||
|
class process execmem;
|
||||||
|
class tcp_socket { accept bind create read write getattr listen setopt connect getopt };
|
||||||
|
class udp_socket { connect create getattr setopt read write };
|
||||||
|
class file execmod;
|
||||||
|
}
|
||||||
|
|
||||||
|
type doh_server_t;
|
||||||
|
type doh_server_exec_t;
|
||||||
|
|
||||||
|
init_daemon_domain(doh_server_t, doh_server_exec_t)
|
||||||
|
|
||||||
|
type doh_server_port_t;
|
||||||
|
|
||||||
|
corenet_port(doh_server_port_t)
|
||||||
|
|
||||||
|
type doh_server_unit_file_t;
|
||||||
|
systemd_unit_file(doh_server_unit_file_t)
|
||||||
|
|
||||||
|
allow doh_server_t self:fifo_file rw_fifo_file_perms;
|
||||||
|
allow doh_server_t self:unix_stream_socket create_stream_socket_perms;
|
||||||
|
allow doh_server_t self:process execmem;
|
||||||
|
allow doh_server_t self:tcp_socket { accept read write bind create getattr listen setopt connect getopt};
|
||||||
|
allow doh_server_t self:udp_socket { connect create getattr setopt read write };
|
||||||
|
|
||||||
|
allow doh_server_t doh_server_exec_t:file execmod;
|
||||||
|
allow doh_server_t doh_server_port_t:tcp_socket name_bind;
|
||||||
|
|
||||||
|
domain_use_interactive_fds(doh_server_t)
|
||||||
|
|
||||||
|
files_read_etc_files(doh_server_t)
|
||||||
|
|
||||||
|
corenet_tcp_bind_generic_node(doh_server_t)
|
||||||
|
corenet_tcp_connect_dns_port(doh_server_t)
|
||||||
|
doh_server_connect(httpd_t)
|
||||||
|
|
||||||
|
kernel_read_net_sysctls(doh_server_t)
|
||||||
|
kernel_search_network_sysctl(doh_server_t)
|
||||||
|
|
||||||
|
miscfiles_read_localization(doh_server_t)
|
||||||
@@ -6,7 +6,7 @@ PREFIX = /usr/local
|
|||||||
all: doh-logger
|
all: doh-logger
|
||||||
|
|
||||||
doh-logger: doh-logger.swift
|
doh-logger: doh-logger.swift
|
||||||
$(SWIFTC) -o $@ -O -static-stdlib $<
|
$(SWIFTC) -o $@ -O $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f doh-logger
|
rm -f doh-logger
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import (
|
|||||||
|
|
||||||
"github.com/m13253/dns-over-https/doh-client/config"
|
"github.com/m13253/dns-over-https/doh-client/config"
|
||||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||||
"github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/idna"
|
"golang.org/x/net/idna"
|
||||||
@@ -305,7 +305,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
|
|
||||||
if len(r.Question) != 1 {
|
if len(r.Question) != 1 {
|
||||||
log.Println("Number of questions is not 1")
|
log.Println("Number of questions is not 1")
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeFormatError
|
reply.Rcode = dns.RcodeFormatError
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
@@ -356,7 +356,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply = jsonDNS.PrepareReply(r)
|
reply = jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
@@ -471,7 +471,7 @@ func (c *Client) findClientIP(w dns.ResponseWriter, r *dns.Msg) (ednsClientAddre
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||||
if ipv4 := ip.To4(); ipv4 != nil {
|
if ipv4 := ip.To4(); ipv4 != nil {
|
||||||
ednsClientAddress = ipv4.Mask(ipv4Mask24)
|
ednsClientAddress = ipv4.Mask(ipv4Mask24)
|
||||||
ednsClientNetmask = 24
|
ednsClientNetmask = 24
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type others struct {
|
|||||||
NoCookies bool `toml:"no_cookies"`
|
NoCookies bool `toml:"no_cookies"`
|
||||||
NoECS bool `toml:"no_ecs"`
|
NoECS bool `toml:"no_ecs"`
|
||||||
NoIPv6 bool `toml:"no_ipv6"`
|
NoIPv6 bool `toml:"no_ipv6"`
|
||||||
|
NoUserAgent bool `toml:"no_user_agent"`
|
||||||
Verbose bool `toml:"verbose"`
|
Verbose bool `toml:"verbose"`
|
||||||
DebugHTTPHeaders []string `toml:"debug_http_headers"`
|
DebugHTTPHeaders []string `toml:"debug_http_headers"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ listen = [
|
|||||||
"127.0.0.1:5380",
|
"127.0.0.1:5380",
|
||||||
"[::1]:53",
|
"[::1]:53",
|
||||||
"[::1]:5380",
|
"[::1]:5380",
|
||||||
|
|
||||||
|
## To listen on both 0.0.0.0:53 and [::]:53, use the following line
|
||||||
|
# ":53",
|
||||||
]
|
]
|
||||||
|
|
||||||
# HTTP path for upstream resolver
|
# HTTP path for upstream resolver
|
||||||
@@ -15,34 +18,34 @@ upstream_selector = "random"
|
|||||||
|
|
||||||
# weight should in (0, 100], if upstream_selector is random, weight will be ignored
|
# weight should in (0, 100], if upstream_selector is random, weight will be ignored
|
||||||
|
|
||||||
## Google's productive resolver, good ECS, bad DNSSEC
|
## Google's resolver, good ECS, good DNSSEC
|
||||||
#[[upstream.upstream_google]]
|
#[[upstream.upstream_ietf]]
|
||||||
# url = "https://dns.google.com/resolve"
|
# url = "https://dns.google/dns-query"
|
||||||
# weight = 50
|
# weight = 50
|
||||||
|
|
||||||
## CloudFlare's resolver, bad ECS, good DNSSEC
|
## CloudFlare's resolver, bad ECS, good DNSSEC
|
||||||
#[[upstream.upstream_google]]
|
## ECS is disabled for privacy by design: https://developers.cloudflare.com/1.1.1.1/nitty-gritty-details/#edns-client-subnet
|
||||||
# url = "https://cloudflare-dns.com/dns-query"
|
|
||||||
# weight = 50
|
|
||||||
|
|
||||||
## CloudFlare's resolver, bad ECS, good DNSSEC
|
|
||||||
#[[upstream.upstream_google]]
|
|
||||||
# url = "https://1.1.1.1/dns-query"
|
|
||||||
# weight = 50
|
|
||||||
|
|
||||||
# CloudFlare's resolver, bad ECS, good DNSSEC
|
|
||||||
[[upstream.upstream_ietf]]
|
[[upstream.upstream_ietf]]
|
||||||
url = "https://cloudflare-dns.com/dns-query"
|
url = "https://cloudflare-dns.com/dns-query"
|
||||||
weight = 50
|
weight = 50
|
||||||
|
|
||||||
## CloudFlare's resolver, bad ECS, good DNSSEC
|
## CloudFlare's resolver, bad ECS, good DNSSEC
|
||||||
|
## ECS is disabled for privacy by design: https://developers.cloudflare.com/1.1.1.1/nitty-gritty-details/#edns-client-subnet
|
||||||
|
## Note that some ISPs have problems connecting to 1.1.1.1, try 1.0.0.1 if problems happen.
|
||||||
#[[upstream.upstream_ietf]]
|
#[[upstream.upstream_ietf]]
|
||||||
# url = "https://1.1.1.1/dns-query"
|
# url = "https://1.1.1.1/dns-query"
|
||||||
# weight = 50
|
# weight = 50
|
||||||
|
|
||||||
## Google's experimental resolver, good ECS, good DNSSEC
|
## DNS.SB's resolver, good ECS, good DNSSEC
|
||||||
|
## The provider claims no logging: https://dns.sb/doh/
|
||||||
#[[upstream.upstream_ietf]]
|
#[[upstream.upstream_ietf]]
|
||||||
# url = "https://dns.google.com/experimental"
|
# url = "https://doh.dns.sb/dns-query"
|
||||||
|
# weight = 50
|
||||||
|
|
||||||
|
## Quad9's resolver, bad ECS, good DNSSEC
|
||||||
|
## ECS is disabled for privacy by design: https://www.quad9.net/faq/#What_is_EDNS_Client-Subnet
|
||||||
|
#[[upstream.upstream_ietf]]
|
||||||
|
# url = "https://9.9.9.9/dns-query"
|
||||||
# weight = 50
|
# weight = 50
|
||||||
|
|
||||||
## CloudFlare's resolver for Tor, available only with Tor
|
## CloudFlare's resolver for Tor, available only with Tor
|
||||||
@@ -61,7 +64,7 @@ upstream_selector = "random"
|
|||||||
# bootstrap server, please make this list empty.
|
# bootstrap server, please make this list empty.
|
||||||
bootstrap = [
|
bootstrap = [
|
||||||
|
|
||||||
# Google's resolver, bad ECS, good DNSSEC
|
# Google's resolver, good ECS, good DNSSEC
|
||||||
"8.8.8.8:53",
|
"8.8.8.8:53",
|
||||||
"8.8.4.4:53",
|
"8.8.4.4:53",
|
||||||
|
|
||||||
@@ -116,5 +119,16 @@ no_ecs = false
|
|||||||
# Note that DNS listening and bootstrapping is not controlled by this option.
|
# Note that DNS listening and bootstrapping is not controlled by this option.
|
||||||
no_ipv6 = false
|
no_ipv6 = false
|
||||||
|
|
||||||
|
# Disable submitting User-Agent
|
||||||
|
#
|
||||||
|
# It is generally not recommended to disable submitting User-Agent because it
|
||||||
|
# is still possible to probe client version according to behavior differences,
|
||||||
|
# such as TLS handshaking, handling of malformed packets, and specific bugs.
|
||||||
|
# Additionally, User-Agent is an important way for the server to distinguish
|
||||||
|
# buggy, old, or insecure clients, and to workaround specific bugs.
|
||||||
|
# (e.g. doh-server can detect and workaround certain issues of DNSCrypt-Proxy
|
||||||
|
# and older Firefox.)
|
||||||
|
no_user_agent = false
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
verbose = false
|
verbose = false
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
questionName := question.Name
|
questionName := question.Name
|
||||||
questionClass := question.Qclass
|
questionClass := question.Qclass
|
||||||
if questionClass != dns.ClassINET {
|
if questionClass != dns.ClassINET {
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeRefused
|
reply.Rcode = dns.RcodeRefused
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -67,6 +67,9 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
udpSize := uint16(512)
|
udpSize := uint16(512)
|
||||||
if opt := r.IsEdns0(); opt != nil {
|
if opt := r.IsEdns0(); opt != nil {
|
||||||
udpSize = opt.UDPSize()
|
udpSize = opt.UDPSize()
|
||||||
|
if opt.Do() {
|
||||||
|
requestURL += "&do=1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ednsClientAddress, ednsClientNetmask := c.findClientIP(w, r)
|
ednsClientAddress, ednsClientNetmask := c.findClientIP(w, r)
|
||||||
@@ -77,7 +80,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -86,7 +89,11 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Accept", "application/json, application/dns-message, application/dns-udpwireformat")
|
req.Header.Set("Accept", "application/json, application/dns-message, application/dns-udpwireformat")
|
||||||
req.Header.Set("User-Agent", USER_AGENT)
|
if !c.conf.Other.NoUserAgent {
|
||||||
|
req.Header.Set("User-Agent", USER_AGENT)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("User-Agent", "")
|
||||||
|
}
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
|
|
||||||
c.httpClientMux.RLock()
|
c.httpClientMux.RLock()
|
||||||
@@ -104,7 +111,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -114,7 +121,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
|
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
response: resp,
|
response: resp,
|
||||||
reply: jsonDNS.PrepareReply(r),
|
reply: jsondns.PrepareReply(r),
|
||||||
udpSize: udpSize,
|
udpSize: udpSize,
|
||||||
ednsClientAddress: ednsClientAddress,
|
ednsClientAddress: ednsClientAddress,
|
||||||
ednsClientNetmask: ednsClientNetmask,
|
ednsClientNetmask: ednsClientNetmask,
|
||||||
@@ -141,7 +148,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var respJSON jsonDNS.Response
|
var respJSON jsondns.Response
|
||||||
err = json.Unmarshal(body, &respJSON)
|
err = json.Unmarshal(body, &respJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -153,8 +160,9 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
if respJSON.Status != dns.RcodeSuccess && respJSON.Comment != "" {
|
if respJSON.Status != dns.RcodeSuccess && respJSON.Comment != "" {
|
||||||
log.Printf("DNS error: %s\n", respJSON.Comment)
|
log.Printf("DNS error: %s\n", respJSON.Comment)
|
||||||
}
|
}
|
||||||
|
fixEmptyNames(&respJSON)
|
||||||
|
|
||||||
fullReply := jsonDNS.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
fullReply := jsondns.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
||||||
buf, err := fullReply.Pack()
|
buf, err := fullReply.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -173,3 +181,19 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
}
|
}
|
||||||
w.Write(buf)
|
w.Write(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix DNS response empty []RR.Name
|
||||||
|
// Additional section won't be rectified
|
||||||
|
// see: https://stackoverflow.com/questions/52136176/what-is-additional-section-in-dns-and-how-it-works
|
||||||
|
func fixEmptyNames(respJSON *jsondns.Response) {
|
||||||
|
for i := range respJSON.Answer {
|
||||||
|
if respJSON.Answer[i].Name == "" {
|
||||||
|
respJSON.Answer[i].Name = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range respJSON.Authority {
|
||||||
|
if respJSON.Authority[i].Name == "" {
|
||||||
|
respJSON.Authority[i].Name = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||||
"github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
requestBinary, err := r.Pack()
|
requestBinary, err := r.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeFormatError
|
reply.Rcode = dns.RcodeFormatError
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -107,7 +107,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
|
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -118,7 +118,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -128,7 +128,11 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
req.Header.Set("Content-Type", "application/dns-message")
|
req.Header.Set("Content-Type", "application/dns-message")
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/dns-message, application/dns-udpwireformat, application/json")
|
req.Header.Set("Accept", "application/dns-message, application/dns-udpwireformat, application/json")
|
||||||
req.Header.Set("User-Agent", USER_AGENT)
|
if !c.conf.Other.NoUserAgent {
|
||||||
|
req.Header.Set("User-Agent", USER_AGENT)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("User-Agent", "")
|
||||||
|
}
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
c.httpClientMux.RLock()
|
c.httpClientMux.RLock()
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
@@ -145,7 +149,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -155,7 +159,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
|
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
response: resp,
|
response: resp,
|
||||||
reply: jsonDNS.PrepareReply(r),
|
reply: jsondns.PrepareReply(r),
|
||||||
udpSize: udpSize,
|
udpSize: udpSize,
|
||||||
ednsClientAddress: ednsClientAddress,
|
ednsClientAddress: ednsClientAddress,
|
||||||
ednsClientNetmask: ednsClientNetmask,
|
ednsClientNetmask: ednsClientNetmask,
|
||||||
@@ -176,7 +180,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
|
|
||||||
body, err := ioutil.ReadAll(req.response.Body)
|
body, err := ioutil.ReadAll(req.response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("read error from upstream %s: %v\n", req.currentUpstream, err)
|
||||||
req.reply.Rcode = dns.RcodeServerFailure
|
req.reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(req.reply)
|
w.WriteMsg(req.reply)
|
||||||
return
|
return
|
||||||
@@ -187,7 +191,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
if nowDate, err := time.Parse(http.TimeFormat, headerNow); err == nil {
|
if nowDate, err := time.Parse(http.TimeFormat, headerNow); err == nil {
|
||||||
now = nowDate
|
now = nowDate
|
||||||
} else {
|
} else {
|
||||||
log.Println(err)
|
log.Printf("Date header parse error from upstream %s: %v\n", req.currentUpstream, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
headerLastModified := req.response.Header.Get("Last-Modified")
|
headerLastModified := req.response.Header.Get("Last-Modified")
|
||||||
@@ -196,7 +200,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
if lastModifiedDate, err := time.Parse(http.TimeFormat, headerLastModified); err == nil {
|
if lastModifiedDate, err := time.Parse(http.TimeFormat, headerLastModified); err == nil {
|
||||||
lastModified = lastModifiedDate
|
lastModified = lastModifiedDate
|
||||||
} else {
|
} else {
|
||||||
log.Println(err)
|
log.Printf("Last-Modified header parse error from upstream %s: %v\n", req.currentUpstream, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeDelta := now.Sub(lastModified)
|
timeDelta := now.Sub(lastModified)
|
||||||
@@ -207,7 +211,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
fullReply := new(dns.Msg)
|
fullReply := new(dns.Msg)
|
||||||
err = fullReply.Unpack(body)
|
err = fullReply.Unpack(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("unpacking error from upstream %s: %v\n", req.currentUpstream, err)
|
||||||
req.reply.Rcode = dns.RcodeServerFailure
|
req.reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(req.reply)
|
w.WriteMsg(req.reply)
|
||||||
return
|
return
|
||||||
@@ -229,7 +233,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
|
|
||||||
buf, err := fullReply.Pack()
|
buf, err := fullReply.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("packing error with upstream %s: %v\n", req.currentUpstream, err)
|
||||||
req.reply.Rcode = dns.RcodeServerFailure
|
req.reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(req.reply)
|
w.WriteMsg(req.reply)
|
||||||
return
|
return
|
||||||
@@ -238,12 +242,15 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
fullReply.Truncated = true
|
fullReply.Truncated = true
|
||||||
buf, err = fullReply.Pack()
|
buf, err = fullReply.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("re-packing error with upstream %s: %v\n", req.currentUpstream, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
buf = buf[:req.udpSize]
|
buf = buf[:req.udpSize]
|
||||||
}
|
}
|
||||||
w.Write(buf)
|
_, err = w.Write(buf)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to write to client: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixRecordTTL(rr dns.RR, delta time.Duration) dns.RR {
|
func fixRecordTTL(rr dns.RR, delta time.Duration) dns.RR {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Printf("doh-server %s\nHomepage: https://github.com/m13253/dns-over-https\n", VERSION)
|
fmt.Printf("doh-client %s\nHomepage: https://github.com/m13253/dns-over-https\n", VERSION)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.0.1"
|
VERSION = "2.2.3"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
@@ -38,7 +39,6 @@ type config struct {
|
|||||||
Upstream []string `toml:"upstream"`
|
Upstream []string `toml:"upstream"`
|
||||||
Timeout uint `toml:"timeout"`
|
Timeout uint `toml:"timeout"`
|
||||||
Tries uint `toml:"tries"`
|
Tries uint `toml:"tries"`
|
||||||
TCPOnly bool `toml:"tcp_only"`
|
|
||||||
Verbose bool `toml:"verbose"`
|
Verbose bool `toml:"verbose"`
|
||||||
DebugHTTPHeaders []string `toml:"debug_http_headers"`
|
DebugHTTPHeaders []string `toml:"debug_http_headers"`
|
||||||
LogGuessedIP bool `toml:"log_guessed_client_ip"`
|
LogGuessedIP bool `toml:"log_guessed_client_ip"`
|
||||||
@@ -62,7 +62,7 @@ func loadConfig(path string) (*config, error) {
|
|||||||
conf.Path = "/dns-query"
|
conf.Path = "/dns-query"
|
||||||
}
|
}
|
||||||
if len(conf.Upstream) == 0 {
|
if len(conf.Upstream) == 0 {
|
||||||
conf.Upstream = []string{"8.8.8.8:53", "8.8.4.4:53"}
|
conf.Upstream = []string{"udp:8.8.8.8:53", "udp:8.8.4.4:53"}
|
||||||
}
|
}
|
||||||
if conf.Timeout == 0 {
|
if conf.Timeout == 0 {
|
||||||
conf.Timeout = 10
|
conf.Timeout = 10
|
||||||
@@ -75,9 +75,35 @@ func loadConfig(path string) (*config, error) {
|
|||||||
return nil, &configError{"You must specify both -cert and -key to enable TLS"}
|
return nil, &configError{"You must specify both -cert and -key to enable TLS"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate all upstreams
|
||||||
|
for _, us := range conf.Upstream {
|
||||||
|
address, t := addressAndType(us)
|
||||||
|
if address == "" {
|
||||||
|
return nil, &configError{"One of the upstreams has not a (udp|tcp|tcp-tls) prefix e.g. udp:1.1.1.1:53"}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t {
|
||||||
|
case "tcp", "udp", "tcp-tls":
|
||||||
|
// OK
|
||||||
|
default:
|
||||||
|
return nil, &configError{"Invalid upstream prefix specified, choose one of: udp tcp tcp-tls"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rxUpstreamWithTypePrefix = regexp.MustCompile("^[a-z-]+(:)")
|
||||||
|
|
||||||
|
func addressAndType(us string) (string, string) {
|
||||||
|
p := rxUpstreamWithTypePrefix.FindStringSubmatchIndex(us)
|
||||||
|
if len(p) != 4 {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return us[p[2]+1:], us[:p[2]]
|
||||||
|
}
|
||||||
|
|
||||||
type configError struct {
|
type configError struct {
|
||||||
err string
|
err string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
listen = [
|
listen = [
|
||||||
"127.0.0.1:8053",
|
"127.0.0.1:8053",
|
||||||
"[::1]:8053",
|
"[::1]:8053",
|
||||||
|
|
||||||
|
## To listen on both 0.0.0.0:8053 and [::]:8053, use the following line
|
||||||
|
# ":8053",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Local address and port for upstream DNS
|
# Local address and port for upstream DNS
|
||||||
@@ -24,11 +27,16 @@ path = "/dns-query"
|
|||||||
|
|
||||||
# Upstream DNS resolver
|
# Upstream DNS resolver
|
||||||
# If multiple servers are specified, a random one will be chosen each time.
|
# If multiple servers are specified, a random one will be chosen each time.
|
||||||
|
# You can use "udp", "tcp" or "tcp-tls" for the type prefix.
|
||||||
|
# For "udp", UDP will first be used, and switch to TCP when the server asks to
|
||||||
|
# or the response is too large.
|
||||||
|
# For "tcp", only TCP will be used.
|
||||||
|
# For "tcp-tls", DNS-over-TLS (RFC 7858) will be used to secure the upstream connection.
|
||||||
upstream = [
|
upstream = [
|
||||||
"1.1.1.1:53",
|
"udp:1.1.1.1:53",
|
||||||
"1.0.0.1:53",
|
"udp:1.0.0.1:53",
|
||||||
"8.8.8.8:53",
|
"udp:8.8.8.8:53",
|
||||||
"8.8.4.4:53",
|
"udp:8.8.4.4:53",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Upstream timeout
|
# Upstream timeout
|
||||||
@@ -37,9 +45,6 @@ timeout = 10
|
|||||||
# Number of tries if upstream DNS fails
|
# Number of tries if upstream DNS fails
|
||||||
tries = 3
|
tries = 3
|
||||||
|
|
||||||
# Only use TCP for DNS query
|
|
||||||
tcp_only = false
|
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
verbose = false
|
verbose = false
|
||||||
|
|
||||||
|
|||||||
@@ -170,11 +170,11 @@ func (s *Server) parseRequestGoogle(ctx context.Context, w http.ResponseWriter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||||
respJSON := jsonDNS.Marshal(req.response)
|
respJSON := jsondns.Marshal(req.response)
|
||||||
respStr, err := json.Marshal(respJSON)
|
respStr, err := json.Marshal(respJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
jsondns.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,12 +156,12 @@ func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||||
respJSON := jsonDNS.Marshal(req.response)
|
respJSON := jsondns.Marshal(req.response)
|
||||||
req.response.Id = req.transactionID
|
req.response.Id = req.transactionID
|
||||||
respBytes, err := req.response.Pack()
|
respBytes, err := req.response.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("DNS packet construct failure with upstream %s: %v\n", req.currentUpstream, err)
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
jsondns.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +183,13 @@ func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if respJSON.Status == dns.RcodeServerFailure {
|
if respJSON.Status == dns.RcodeServerFailure {
|
||||||
|
log.Printf("received server failure from upstream %s: %v\n", req.currentUpstream, req.response)
|
||||||
w.WriteHeader(503)
|
w.WriteHeader(503)
|
||||||
}
|
}
|
||||||
w.Write(respBytes)
|
_, err = w.Write(respBytes)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to write to client: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe
|
// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe
|
||||||
|
|||||||
@@ -35,15 +35,16 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
conf *config
|
conf *config
|
||||||
udpClient *dns.Client
|
udpClient *dns.Client
|
||||||
tcpClient *dns.Client
|
tcpClient *dns.Client
|
||||||
servemux *http.ServeMux
|
tcpClientTLS *dns.Client
|
||||||
|
servemux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
type DNSRequest struct {
|
type DNSRequest struct {
|
||||||
@@ -69,6 +70,10 @@ func NewServer(conf *config) (*Server, error) {
|
|||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
},
|
},
|
||||||
|
tcpClientTLS: &dns.Client{
|
||||||
|
Net: "tcp-tls",
|
||||||
|
Timeout: timeout,
|
||||||
|
},
|
||||||
servemux: http.NewServeMux(),
|
servemux: http.NewServeMux(),
|
||||||
}
|
}
|
||||||
if conf.LocalAddr != "" {
|
if conf.LocalAddr != "" {
|
||||||
@@ -88,6 +93,10 @@ func NewServer(conf *config) (*Server, error) {
|
|||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
LocalAddr: tcpLocalAddr,
|
LocalAddr: tcpLocalAddr,
|
||||||
}
|
}
|
||||||
|
s.tcpClientTLS.Dialer = &net.Dialer{
|
||||||
|
Timeout: timeout,
|
||||||
|
LocalAddr: tcpLocalAddr,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s.servemux.HandleFunc(conf.Path, s.handlerFunc)
|
s.servemux.HandleFunc(conf.Path, s.handlerFunc)
|
||||||
return s, nil
|
return s, nil
|
||||||
@@ -127,6 +136,18 @@ func (s *Server) Start() error {
|
|||||||
func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
|
if realIP := r.Header.Get("X-Real-IP"); realIP != "" {
|
||||||
|
if strings.ContainsRune(realIP, ':') {
|
||||||
|
r.RemoteAddr = "[" + realIP + "]:0"
|
||||||
|
} else {
|
||||||
|
r.RemoteAddr = realIP + ":0"
|
||||||
|
}
|
||||||
|
_, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
|
if err != nil {
|
||||||
|
r.RemoteAddr = realIP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST")
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
@@ -195,14 +216,14 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else if contentType == "application/dns-udpwireformat" {
|
} else if contentType == "application/dns-udpwireformat" {
|
||||||
req = s.parseRequestIETF(ctx, w, r)
|
req = s.parseRequestIETF(ctx, w, r)
|
||||||
} else {
|
} else {
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
jsondns.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.errcode == 444 {
|
if req.errcode == 444 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.errcode != 0 {
|
if req.errcode != 0 {
|
||||||
jsonDNS.FormatError(w, req.errtext, req.errcode)
|
jsondns.FormatError(w, req.errtext, req.errcode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +232,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
var err error
|
var err error
|
||||||
req, err = s.doDNSQuery(ctx, req)
|
req, err = s.doDNSQuery(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
jsondns.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,12 +246,17 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) findClientIP(r *http.Request) net.IP {
|
func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||||
|
noEcs := r.URL.Query().Get("no_ecs")
|
||||||
|
if strings.ToLower(noEcs) == "true" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
XForwardedFor := r.Header.Get("X-Forwarded-For")
|
XForwardedFor := r.Header.Get("X-Forwarded-For")
|
||||||
if XForwardedFor != "" {
|
if XForwardedFor != "" {
|
||||||
for _, addr := range strings.Split(XForwardedFor, ",") {
|
for _, addr := range strings.Split(XForwardedFor, ",") {
|
||||||
addr = strings.TrimSpace(addr)
|
addr = strings.TrimSpace(addr)
|
||||||
ip := net.ParseIP(addr)
|
ip := net.ParseIP(addr)
|
||||||
if jsonDNS.IsGlobalIP(ip) {
|
if jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,7 +265,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
|||||||
if XRealIP != "" {
|
if XRealIP != "" {
|
||||||
addr := strings.TrimSpace(XRealIP)
|
addr := strings.TrimSpace(XRealIP)
|
||||||
ip := net.ParseIP(addr)
|
ip := net.ParseIP(addr)
|
||||||
if jsonDNS.IsGlobalIP(ip) {
|
if jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,7 +273,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -263,20 +289,50 @@ func (s *Server) patchRootRD(req *DNSRequest) *DNSRequest {
|
|||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the position index for the question of qtype from a DNS msg, otherwise return -1
|
||||||
|
func (s *Server) indexQuestionType(msg *dns.Msg, qtype uint16) int {
|
||||||
|
for i, question := range msg.Question {
|
||||||
|
if question.Qtype == qtype {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequest, err error) {
|
func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequest, err error) {
|
||||||
// TODO(m13253): Make ctx work. Waiting for a patch for ExchangeContext from miekg/dns.
|
|
||||||
numServers := len(s.conf.Upstream)
|
numServers := len(s.conf.Upstream)
|
||||||
for i := uint(0); i < s.conf.Tries; i++ {
|
for i := uint(0); i < s.conf.Tries; i++ {
|
||||||
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
||||||
if !s.conf.TCPOnly {
|
|
||||||
req.response, _, err = s.udpClient.Exchange(req.request, req.currentUpstream)
|
upstream, t := addressAndType(req.currentUpstream)
|
||||||
if err == nil && req.response != nil && req.response.Truncated {
|
|
||||||
log.Println(err)
|
switch t {
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
default:
|
||||||
|
log.Printf("invalid DNS type %q in upstream %q", t, upstream)
|
||||||
|
return nil, &configError{"invalid DNS type"}
|
||||||
|
// Use DNS-over-TLS (DoT) if configured to do so
|
||||||
|
case "tcp-tls":
|
||||||
|
req.response, _, err = s.tcpClientTLS.ExchangeContext(ctx, req.request, upstream)
|
||||||
|
case "tcp", "udp":
|
||||||
|
// Use TCP if always configured to or if the Query type dictates it (AXFR)
|
||||||
|
if t == "tcp" || (s.indexQuestionType(req.request, dns.TypeAXFR) > -1) {
|
||||||
|
req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
|
} else {
|
||||||
|
req.response, _, err = s.udpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
|
if err == nil && req.response != nil && req.response.Truncated {
|
||||||
|
log.Println(err)
|
||||||
|
req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry with TCP if this was an IXFR request and we only received an SOA
|
||||||
|
if (s.indexQuestionType(req.request, dns.TypeIXFR) > -1) &&
|
||||||
|
(len(req.response.Answer) == 1) &&
|
||||||
|
(req.response.Answer[0].Header().Rrtype == dns.TypeSOA) {
|
||||||
|
req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.0.1"
|
VERSION = "2.2.3"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
11
go.mod
11
go.mod
@@ -5,9 +5,10 @@ go 1.12
|
|||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/gorilla/handlers v1.4.0
|
github.com/gorilla/handlers v1.4.0
|
||||||
github.com/miekg/dns v1.1.6
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9
|
||||||
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a // indirect
|
github.com/miekg/dns v1.1.31
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313 // indirect
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 // indirect
|
||||||
|
golang.org/x/text v0.3.2 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
49
go.sum
49
go.sum
@@ -2,24 +2,39 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
|
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
|
||||||
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
||||||
github.com/miekg/dns v1.1.4 h1:rCMZsU2ScVSYcAsOXgmC6+AKOK+6pmQTOcw03nfwYV0=
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9 h1:w66aaP3c6SIQ0pi3QH1Tb4AMO3aWoEPxd1CNvLphbkA=
|
||||||
github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9/go.mod h1:BaIJzjD2ZnHmx2acPF6XfGLPzNCMiBbMRqJr+8/8uRI=
|
||||||
github.com/miekg/dns v1.1.6 h1:jVwb4GDwD65q/gtItR/lIZHjNH93QfeGxZUkzJcW9mc=
|
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
|
||||||
github.com/miekg/dns v1.1.6/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exqr0evNhKRNe5K/gi+zKh4U=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||||
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 h1:fY7Dsw114eJN4boqzVSbpVHO6rTdhq6/GnXeu+PKnzU=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
|
||||||
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190308023053-584f3b12f43e h1:K7CV15oJ823+HLXQ+M7MSMrUg8LjfqY7O3naO+8Pp/I=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190308023053-584f3b12f43e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE=
|
||||||
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -38,11 +38,11 @@ type dnsError struct {
|
|||||||
|
|
||||||
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
errJson := dnsError{
|
errJSON := dnsError{
|
||||||
Status: dns.RcodeServerFailure,
|
Status: dns.RcodeServerFailure,
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
}
|
}
|
||||||
errStr, err := json.Marshal(errJson)
|
errStr, err := json.Marshal(errJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,109 +21,111 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/infobloxopen/go-trees/iptree"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RFC6890
|
var defaultFilter *iptree.Tree
|
||||||
var localIPv4Nets = []net.IPNet{
|
|
||||||
// This host on this network
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{0, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{10, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Shared Address Space
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{100, 64, 0, 0},
|
|
||||||
net.IPMask{255, 192, 0, 0},
|
|
||||||
},
|
|
||||||
// Loopback
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{127, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Link Local
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{169, 254, 0, 0},
|
|
||||||
net.IPMask{255, 255, 0, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{172, 16, 0, 0},
|
|
||||||
net.IPMask{255, 240, 0, 0},
|
|
||||||
},
|
|
||||||
// DS-Lite
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 0, 0, 0},
|
|
||||||
net.IPMask{255, 255, 255, 248},
|
|
||||||
},
|
|
||||||
// 6to4 Relay Anycast
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 88, 99, 0},
|
|
||||||
net.IPMask{255, 255, 255, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 168, 0, 0},
|
|
||||||
net.IPMask{255, 255, 0, 0},
|
|
||||||
},
|
|
||||||
// Reserved for Future Use & Limited Broadcast
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{240, 0, 0, 0},
|
|
||||||
net.IPMask{240, 0, 0, 0},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// RFC6890
|
func init() {
|
||||||
var localIPv6Nets = []net.IPNet{
|
defaultFilter = iptree.NewTree()
|
||||||
|
|
||||||
|
// RFC6890
|
||||||
|
// This host on this network
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{0, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{10, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Shared Address Space
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{100, 64, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 192, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Loopback
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{127, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Link Local
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{169, 254, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{172, 16, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 240, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// DS-Lite
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 255, 248},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// 6to4 Relay Anycast
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 88, 99, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 255, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 168, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Reserved for Future Use & Limited Broadcast
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{240, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{240, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// RFC6890
|
||||||
// Unspecified & Loopback Address
|
// Unspecified & Loopback Address
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Discard-Only Prefix
|
// Discard-Only Prefix
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Unique-Local
|
// Unique-Local
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Linked-Scoped Unicast
|
// Linked-Scoped Unicast
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsGlobalIP(ip net.IP) bool {
|
func IsGlobalIP(ip net.IP) bool {
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ipv4 := ip.To4(); len(ipv4) == net.IPv4len {
|
_, contained := defaultFilter.GetByIP(ip)
|
||||||
for _, ipnet := range localIPv4Nets {
|
return !contained
|
||||||
if ipnet.Contains(ip) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if len(ip) == net.IPv6len {
|
|
||||||
for _, ipnet := range localIPv6Nets {
|
|
||||||
if ipnet.Contains(ip) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
json-dns/globalip_test.go
Normal file
34
json-dns/globalip_test.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package jsondns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleIsGlobalIP() {
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("127.0.0.1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{192, 168, 1, 1}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("8.8.8.8")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{8, 8, 4, 4}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("2001:4860:4860::8888")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x44}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::ffff:127.0.0.1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 192, 168, 1, 1}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::ffff:808:808")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 8, 8, 4, 4}))
|
||||||
|
// Output:
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|||||||
@@ -21,12 +21,32 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type QuestionList []Question
|
||||||
|
|
||||||
|
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
||||||
|
// Fix variant question response in Response.Question
|
||||||
|
//
|
||||||
|
// Solution taken from:
|
||||||
|
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
||||||
|
// https://archive.is/NU4zR
|
||||||
|
if len(b) > 0 && b[0] == '[' {
|
||||||
|
return json.Unmarshal(b, (*[]Question)(ql))
|
||||||
|
}
|
||||||
|
var q Question
|
||||||
|
if err := json.Unmarshal(b, &q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*ql = []Question{q}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
// Standard DNS response code (32 bit integer)
|
// Standard DNS response code (32 bit integer)
|
||||||
Status uint32 `json:"Status"`
|
Status uint32 `json:"Status"`
|
||||||
@@ -40,13 +60,13 @@ type Response struct {
|
|||||||
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
||||||
AD bool `json:"AD"`
|
AD bool `json:"AD"`
|
||||||
// Whether the client asked to disable DNSSEC
|
// Whether the client asked to disable DNSSEC
|
||||||
CD bool `json:"CD"`
|
CD bool `json:"CD"`
|
||||||
Question []Question `json:"Question"`
|
Question QuestionList `json:"Question"`
|
||||||
Answer []RR `json:"Answer,omitempty"`
|
Answer []RR `json:"Answer,omitempty"`
|
||||||
Authority []RR `json:"Authority,omitempty"`
|
Authority []RR `json:"Authority,omitempty"`
|
||||||
Additional []RR `json:"Additional,omitempty"`
|
Additional []RR `json:"Additional,omitempty"`
|
||||||
Comment string `json:"Comment,omitempty"`
|
Comment string `json:"Comment,omitempty"`
|
||||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||||
// Least time-to-live
|
// Least time-to-live
|
||||||
HaveTTL bool `json:"-"`
|
HaveTTL bool `json:"-"`
|
||||||
LeastTTL uint32 `json:"-"`
|
LeastTTL uint32 `json:"-"`
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -38,7 +38,7 @@ func PrepareReply(req *dns.Msg) *dns.Msg {
|
|||||||
reply := new(dns.Msg)
|
reply := new(dns.Msg)
|
||||||
reply.Id = req.Id
|
reply.Id = req.Id
|
||||||
reply.Response = true
|
reply.Response = true
|
||||||
reply.Opcode = reply.Opcode
|
reply.Opcode = req.Opcode
|
||||||
reply.RecursionDesired = req.RecursionDesired
|
reply.RecursionDesired = req.RecursionDesired
|
||||||
reply.RecursionAvailable = req.RecursionDesired
|
reply.RecursionAvailable = req.RecursionDesired
|
||||||
reply.CheckingDisabled = req.CheckingDisabled
|
reply.CheckingDisabled = req.CheckingDisabled
|
||||||
|
|||||||
Reference in New Issue
Block a user