From f4397adcbfedc6987e7ca12b4470485f22c17f71 Mon Sep 17 00:00:00 2001 From: Yannik Sembritzki Date: Thu, 10 Feb 2022 01:39:19 +0300 Subject: [PATCH] Merge joohoi/acme-dns#271 to our fork MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: İlteriş Yağıztegin Eroğlu Signed-off-by: İlteriş Yağıztegin Eroğlu --- dns.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dns.go b/dns.go index a01fb9c5..2f29395b 100644 --- a/dns.go +++ b/dns.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/miekg/dns" log "github.com/sirupsen/logrus" + "net" "strings" "time" ) @@ -89,6 +90,7 @@ func (d *DNSServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { m := new(dns.Msg) m.SetReply(r) + remoteAddr := w.RemoteAddr() // handle edns0 opt := r.IsEdns0() if opt != nil { @@ -100,21 +102,21 @@ func (d *DNSServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { // We can safely do this as we know that we're not setting other OPT RRs within acme-dns. m.SetEdns0(512, false) if r.Opcode == dns.OpcodeQuery { - d.readQuery(m) + d.readQuery(m, remoteAddr) } } } else { if r.Opcode == dns.OpcodeQuery { - d.readQuery(m) + d.readQuery(m, remoteAddr) } } _ = w.WriteMsg(m) } -func (d *DNSServer) readQuery(m *dns.Msg) { +func (d *DNSServer) readQuery(m *dns.Msg, remoteAddr net.Addr) { var authoritative = false for _, que := range m.Question { - if rr, rc, auth, err := d.answer(que); err == nil { + if rr, rc, auth, err := d.answer(que, remoteAddr); err == nil { if auth { authoritative = auth } @@ -190,7 +192,7 @@ func (d *DNSServer) isOwnChallenge(name string) bool { return false } -func (d *DNSServer) answer(q dns.Question) ([]dns.RR, int, bool, error) { +func (d *DNSServer) answer(q dns.Question, remoteAddr net.Addr) ([]dns.RR, int, bool, error) { var rcode int var err error var txtRRs []dns.RR @@ -213,7 +215,7 @@ func (d *DNSServer) answer(q dns.Question) ([]dns.RR, int, bool, error) { // Make sure that we return NOERROR if there were dynamic records for the domain rcode = dns.RcodeSuccess } - log.WithFields(log.Fields{"qtype": dns.TypeToString[q.Qtype], "domain": q.Name, "rcode": dns.RcodeToString[rcode]}).Debug("Answering question for domain") + log.WithFields(log.Fields{"qtype": dns.TypeToString[q.Qtype], "remoteaddr": remoteAddr, "domain": q.Name, "rcode": dns.RcodeToString[rcode]}).Debug("Answering question for domain") return r, rcode, authoritative, nil }