From 1996bef9e6cad6ee954facc186ea70e411eb108c Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Thu, 7 Oct 2021 22:57:55 +0800 Subject: [PATCH] Chore: doh request should with id 0 (#1660) --- dns/doh.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dns/doh.go b/dns/doh.go index 3437501..53b0fb3 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -28,13 +28,19 @@ func (dc *dohClient) Exchange(m *D.Msg) (msg *D.Msg, err error) { } func (dc *dohClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) { - req, err := dc.newRequest(m) + // https://datatracker.ietf.org/doc/html/rfc8484#section-4.1 + // In order to maximize cache friendliness, SHOULD use a DNS ID of 0 in every DNS request. + newM := *m + newM.Id = 0 + req, err := dc.newRequest(&newM) if err != nil { return nil, err } req = req.WithContext(ctx) - return dc.doRequest(req) + msg, err = dc.doRequest(req) + msg.Id = m.Id + return } // newRequest returns a new DoH request given a dns.Msg.