package pancheri import ( "github.com/miekg/dns" "github.com/sirupsen/logrus" ) type Handler struct { C *Config R *Resolver } func (h *Handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { // figure out how we should resolve this // is this in our list of authoritative domains? // TODO // okay, do we have upstream resolution enabled? if h.C.Resolver.Enable { // alright, resolve it with the resolver msg := new(dns.Msg) msg.SetReply(r) msg.Authoritative = true for _, question := range r.Question { answers, err := h.R.Resolve(question.Name, question.Qtype) if err != nil { logrus.Errorf("error resolving: %s", err) return } msg.Answer = append(msg.Answer, answers...) } err := w.WriteMsg(msg) if err != nil { logrus.Errorf("error responding: %s", err) return } } else { // alright, send an nxdomain msg := new(dns.Msg) msg.SetReply(r) msg.Authoritative = true if r.RecursionDesired { msg.RecursionAvailable = true } msg.Rcode = dns.RcodeNameError err := w.WriteMsg(msg) if err != nil { logrus.Errorf("error responding: %s", err) return } } }