Act as the authority even though were not

letsencrypt needs to talk to the authoritative name server, but
I have all dns traffic redirected to here so we get the SOA using the
same request (probably only works by accident) and then make a request
to the address listed in the SOA

Fix typos in IPv6 addresses
This commit is contained in:
lordwelch 2021-05-26 23:04:33 -07:00
parent b801bf699f
commit 61b59517fc

View File

@ -92,8 +92,8 @@ func NewServer(addr, domain string) *Server {
// https://developers.google.com/speed/public-dns/docs/using#google_public_dns_ip_addresses
"1.1.1.1:53",
"1.0.0.1:53",
"2606:4700:4700::1111:53",
"2606:4700:4700::1001:53",
"[2606:4700:4700::1111]:53",
"[2606:4700:4700::1001]:53",
"8.8.8.8:53",
"8.8.4.4:53",
"[2001:4860:4860::8888]:53",
@ -536,6 +536,7 @@ func (s *Server) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
s.promInc("DNS", r)
if r.RecursionDesired {
for idx, u := range s.upstreams() {
in, _, err := s.client.Exchange(r, u)
if err != nil {
@ -568,6 +569,31 @@ func (s *Server) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
}
return
}
} else {
for _, u := range s.upstreams() {
nr := r.Copy()
nr.Question[0].Qtype = dns.TypeSOA
nr.RecursionDesired = true
soa, _, err := s.client.Exchange(nr, u)
fmt.Println(err, soa)
fmt.Println()
fmt.Println(soa.Ns)
if len(soa.Ns) > 0 {
soa2 := soa.Ns[0].(*dns.SOA)
in, _, err := s.client.Exchange(r, strings.TrimRight(soa2.Ns, ".")+":53")
fmt.Println(err, in)
if err != nil {
if s.sometimes.Allow() {
log.Printf("resolving %v failed: %v", r.Question, err)
}
continue // fall back to next-slower upstream
}
w.WriteMsg(in)
return
}
}
}
// DNS has no reply for resolving errors
}