From 483f02c92a5cabe0e7086a1cf1985096023826ea Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Mon, 28 Dec 2020 19:26:37 +0300 Subject: [PATCH] Pull request: doc the Question[0] inspection Merge in DNS/adguard-home from 2465-question-0 to master Closes #2465. Squashed commit of the following: commit 0dbcaf7eea4f582cedc31f37d1b20162fe1c38df Merge: 0d7c22cd0 8a1d86aa7 Author: Eugene Burkov Date: Mon Dec 28 19:09:25 2020 +0300 Merge branch 'master' into 2465-question-0 commit 0d7c22cd0eb930bd301a4bb7b8f23e9fd78a2ccd Author: Eugene Burkov Date: Wed Dec 23 14:17:13 2020 +0300 dnsforward: doc the Question[0] inspection --- internal/dnsforward/dns.go | 6 ++++++ internal/dnsforward/msg.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/dnsforward/dns.go b/internal/dnsforward/dns.go index c6c5a6b6..4a47cdc1 100644 --- a/internal/dnsforward/dns.go +++ b/internal/dnsforward/dns.go @@ -41,6 +41,12 @@ func (s *Server) handleDNSRequest(_ *proxy.Proxy, d *proxy.DNSContext) error { ctx.startTime = time.Now() type modProcessFunc func(ctx *dnsContext) int + + // Since (*dnsforward.Server).handleDNSRequest(...) is used as + // proxy.(Config).RequestHandler, there is no need for additional index + // out of range checking in any of the following functions, because the + // (*proxy.Proxy).handleDNSRequest method performs it before calling the + // appropriate handler. mods := []modProcessFunc{ processInitial, processInternalHosts, diff --git a/internal/dnsforward/msg.go b/internal/dnsforward/msg.go index 28a8ac3a..71497a6c 100644 --- a/internal/dnsforward/msg.go +++ b/internal/dnsforward/msg.go @@ -11,7 +11,8 @@ import ( "github.com/miekg/dns" ) -// Create a DNS response by DNS request and set necessary flags +// makeResponse creates a DNS response by req and sets necessary flags. It also +// guarantees that req.Question will be not empty. func (s *Server) makeResponse(req *dns.Msg) (resp *dns.Msg) { resp = &dns.Msg{ MsgHdr: dns.MsgHdr{