From 244af0e631fedc0356eefd7f1bb7541ee773a44e Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Fri, 24 Nov 2017 22:04:36 +0800 Subject: [PATCH] Add option -no-ecs --- doh-client/client.go | 7 ++++++- doh-client/main.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doh-client/client.go b/doh-client/client.go index 09e3c3e..f9873c3 100644 --- a/doh-client/client.go +++ b/doh-client/client.go @@ -39,16 +39,18 @@ type Client struct { upstream string bootstrap string timeout uint + noECS bool udpServer *dns.Server tcpServer *dns.Server httpClient *http.Client } -func NewClient(addr, upstream, bootstrap string, timeout uint) (c *Client, err error) { +func NewClient(addr, upstream, bootstrap string, timeout uint, noECS bool) (c *Client, err error) { c = &Client { addr: addr, upstream: upstream, timeout: timeout, + noECS: noECS, } c.udpServer = &dns.Server { Addr: addr, @@ -224,6 +226,9 @@ var ( func (c *Client) findClientIP(w dns.ResponseWriter, r *dns.Msg) (ednsClientAddress net.IP, ednsClientNetmask uint8) { ednsClientNetmask = 255 + if c.noECS { + return net.IPv4(0, 0, 0, 0), 0 + } if opt := r.IsEdns0(); opt != nil { for _, option := range opt.Option { if option.Option() == dns.EDNS0SUBNET { diff --git a/doh-client/main.go b/doh-client/main.go index 1242572..ef3c157 100644 --- a/doh-client/main.go +++ b/doh-client/main.go @@ -28,9 +28,10 @@ func main() { upstream := flag.String("upstream", "https://dns.google.com/resolve", "HTTP path for upstream resolver") bootstrap := flag.String("bootstrap", "", "The bootstrap DNS server to resolve the address of the upstream resolver") timeout := flag.Uint("timeout", 10, "Timeout for upstream request") + noECS := flag.Bool("no-ecs", false, "Disable EDNS0-Client-Subnet, do not send client's IP address") flag.Parse() - client, err := NewClient(*addr, *upstream, *bootstrap, *timeout) + client, err := NewClient(*addr, *upstream, *bootstrap, *timeout, *noECS) if err != nil { log.Fatalln(err) } _ = client.Start() }