mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-04-07 17:05:38 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2fcfb706c | ||
|
|
64e9375e3b | ||
|
|
34feec9f5d | ||
|
|
6d30a12d5f | ||
|
|
a8aed7e09a | ||
|
|
6e99d8153a | ||
|
|
2d4495a0dd | ||
|
|
b30056a590 | ||
|
|
b92da52539 | ||
|
|
f43d2c69e0 | ||
|
|
5f1f418664 | ||
|
|
9a316a56a8 | ||
|
|
81b977ca11 | ||
|
|
b7d252de7b | ||
|
|
e12b87b48d | ||
|
|
09bdfe2b14 | ||
|
|
a84b65dd56 | ||
|
|
540f6e3043 | ||
|
|
7db67db247 | ||
|
|
026d89ac8d | ||
|
|
8228ea6299 | ||
|
|
59f79fb666 | ||
|
|
502caabd15 | ||
|
|
f151c90e9d | ||
|
|
d8e3969640 | ||
|
|
475ef65f57 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,6 +3,9 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
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
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ 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.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
|
## Version 2.2.1
|
||||||
|
|
||||||
- Fix messy log
|
- Fix messy log
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ 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/"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
|
RUN sed -i '$!N;s/"\[::1\]:53",.*"\[::1\]:5380",/":5380",/;P;D' /doh-client.conf
|
||||||
|
|
||||||
EXPOSE 53
|
EXPOSE 53/udp
|
||||||
|
EXPOSE 53/tcp
|
||||||
EXPOSE 5380
|
EXPOSE 5380
|
||||||
|
|
||||||
ENTRYPOINT ["/doh-client"]
|
ENTRYPOINT ["/doh-client"]
|
||||||
|
|||||||
264
Readme.md
264
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 see:
|
-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,26 +90,37 @@ 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
|
### 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)
|
||||||
|
|
||||||
SSLProtocol TLSv1.2
|
<VirtualHost *:443>
|
||||||
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
|
ServerName MY_SERVER_NAME
|
||||||
Protocols h2 http/1.1
|
Protocols h2 http/1.1
|
||||||
ProxyPass /dns-query http://[::1]:8053/dns-query
|
ProxyPass /dns-query http://[::1]:8053/dns-query
|
||||||
ProxyPassReverse /dns-query http://[::1]:8053/dns-query
|
ProxyPassReverse /dns-query http://[::1]:8053/dns-query
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
|
```
|
||||||
(Credit: [Joan Moreau](https://github.com/m13253/dns-over-https/issues/51#issuecomment-526820884))
|
(Credit: [Joan Moreau](https://github.com/m13253/dns-over-https/issues/51#issuecomment-526820884))
|
||||||
|
|
||||||
### Example configuration: Nginx
|
### Example configuration: Nginx
|
||||||
|
```bash
|
||||||
server {
|
server {
|
||||||
listen 443 ssl http2 default_server;
|
listen 443 ssl http2 default_server;
|
||||||
listen [::]:443 ssl http2 default_server;
|
listen [::]:443 ssl http2 default_server;
|
||||||
server_name MY_SERVER_NAME;
|
server_name MY_SERVER_NAME;
|
||||||
@@ -130,36 +152,130 @@ otherwise DNS recursion may happen.
|
|||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
(Credit: [Cipherli.st](https://cipherli.st/))
|
(Credit: [Cipherli.st](https://cipherli.st/))
|
||||||
|
|
||||||
### Example configuration: Caddy
|
### 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]
|
||||||
|
|
||||||
https://MY_SERVER_NAME {
|
```yaml
|
||||||
log / syslog "{remote} - {user} [{when}] \"{method} {scheme}://{host}{uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {>X-Forwarded-For}"
|
version: '2.2'
|
||||||
errors syslog
|
networks:
|
||||||
gzip
|
default:
|
||||||
proxy /dns-query http://[::1]:18053 {
|
services:
|
||||||
header_upstream Host {host}
|
proxy:
|
||||||
header_upstream X-Real-IP {remote}
|
# The official v2 Traefik docker image
|
||||||
header_upstream X-Forwarded-For {>X-Forwarded-For},{remote}
|
image: traefik:v2.2
|
||||||
header_upstream X-Forwarded-Proto {scheme}
|
hostname: proxy
|
||||||
}
|
networks:
|
||||||
root /var/www
|
- default
|
||||||
tls {
|
environment:
|
||||||
ciphers ECDHE-ECDSA-WITH-CHACHA20-POLY1305 ECDHE-RSA-WITH-CHACHA20-POLY1305 ECDHE-ECDSA-AES256-GCM-SHA384 ECDHE-RSA-AES256-GCM-SHA384 ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-RSA-AES128-GCM-SHA256
|
TRAEFIK_ACCESSLOG: "true"
|
||||||
curves X25519 p384 p521
|
TRAEFIK_API: "true"
|
||||||
must_staple
|
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)
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -157,6 +160,7 @@ 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()
|
||||||
@@ -177,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 = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.2.1"
|
VERSION = "2.2.2"
|
||||||
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)"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -136,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", "*")
|
||||||
@@ -234,6 +246,11 @@ 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, ",") {
|
||||||
@@ -283,7 +300,6 @@ func (s *Server) indexQuestionType(msg *dns.Msg, qtype uint16) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)]
|
||||||
@@ -296,23 +312,23 @@ func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequ
|
|||||||
return nil, &configError{"invalid DNS type"}
|
return nil, &configError{"invalid DNS type"}
|
||||||
// Use DNS-over-TLS (DoT) if configured to do so
|
// Use DNS-over-TLS (DoT) if configured to do so
|
||||||
case "tcp-tls":
|
case "tcp-tls":
|
||||||
req.response, _, err = s.tcpClientTLS.Exchange(req.request, upstream)
|
req.response, _, err = s.tcpClientTLS.ExchangeContext(ctx, req.request, upstream)
|
||||||
case "tcp", "udp":
|
case "tcp", "udp":
|
||||||
// Use TCP if always configured to or if the Query type dictates it (AXFR)
|
// Use TCP if always configured to or if the Query type dictates it (AXFR)
|
||||||
if t == "tcp" || (s.indexQuestionType(req.request, dns.TypeAXFR) > -1) {
|
if t == "tcp" || (s.indexQuestionType(req.request, dns.TypeAXFR) > -1) {
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, upstream)
|
req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
} else {
|
} else {
|
||||||
req.response, _, err = s.udpClient.Exchange(req.request, upstream)
|
req.response, _, err = s.udpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
if err == nil && req.response != nil && req.response.Truncated {
|
if err == nil && req.response != nil && req.response.Truncated {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, upstream)
|
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
|
// Retry with TCP if this was an IXFR request and we only received an SOA
|
||||||
if (s.indexQuestionType(req.request, dns.TypeIXFR) > -1) &&
|
if (s.indexQuestionType(req.request, dns.TypeIXFR) > -1) &&
|
||||||
(len(req.response.Answer) == 1) &&
|
(len(req.response.Answer) == 1) &&
|
||||||
(req.response.Answer[0].Header().Rrtype == dns.TypeSOA) {
|
(req.response.Answer[0].Header().Rrtype == dns.TypeSOA) {
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, upstream)
|
req.response, _, err = s.tcpClient.ExchangeContext(ctx, req.request, upstream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.2.1"
|
VERSION = "2.2.2"
|
||||||
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)"
|
||||||
)
|
)
|
||||||
|
|||||||
9
go.mod
9
go.mod
@@ -5,8 +5,9 @@ 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.22
|
github.com/miekg/dns v1.1.31
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
|
||||||
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 // indirect
|
||||||
|
golang.org/x/text v0.3.2 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
19
go.sum
19
go.sum
@@ -6,18 +6,30 @@ github.com/miekg/dns v1.1.14 h1:wkQWn9wIp4mZbwW8XV6Km6owkvRPbOiV004ZM2CkGvA=
|
|||||||
github.com/miekg/dns v1.1.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.1.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
|
github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
|
||||||
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||||
|
github.com/miekg/dns v1.1.30 h1:Qww6FseFn8PRfw07jueqIXqodm0JKiiKuK0DeXSqfyo=
|
||||||
|
github.com/miekg/dns v1.1.30/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
|
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
|
||||||
|
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
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-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
|
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
|
||||||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
||||||
|
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
||||||
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
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-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-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a h1:Yu34BogBivvmu7SAzHHaB9nZWH5D1C+z3F1jyIaYZSQ=
|
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a h1:Yu34BogBivvmu7SAzHHaB9nZWH5D1C+z3F1jyIaYZSQ=
|
||||||
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/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/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -27,10 +39,17 @@ golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c h1:UIcGWL6/wpCfyGuJnRFJRurA+yj8RrW7Q6x2YMCXt6c=
|
||||||
|
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/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 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
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-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|||||||
@@ -24,9 +24,29 @@
|
|||||||
package jsonDNS
|
package jsonDNS
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type QuestionList []Question
|
||||||
|
|
||||||
|
// 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
|
||||||
|
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
||||||
|
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"`
|
||||||
@@ -41,7 +61,7 @@ type Response struct {
|
|||||||
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"`
|
||||||
|
|||||||
Reference in New Issue
Block a user