Explorar el Código

Add _country.pgeodns debug query

Ask Bjørn Hansen hace 13 años
padre
commit
288e9ce2d1
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      serve.go

+ 17 - 0
serve.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"encoding/json"
+	"geodns/countries"
 	"github.com/miekg/dns"
 	"log"
 	"os"
@@ -62,6 +63,22 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *Zone) {
 			return
 		}
 
+		if label == "_country" && (qtype == dns.TypeANY || qtype == dns.TypeTXT) {
+			h := dns.RR_Header{Ttl: 1, Class: dns.ClassINET, Rrtype: dns.TypeTXT}
+			h.Name = "_country." + z.Origin + "."
+
+			m.Answer = []dns.RR{&dns.RR_TXT{Hdr: h,
+				Txt: []string{
+					string(country),
+					string(countries.CountryContinent[country]),
+				},
+			}}
+
+			m.Authoritative = true
+			w.Write(m)
+			return
+		}
+
 		// return NXDOMAIN
 		m.SetRcode(req, dns.RcodeNameError)
 		m.Authoritative = true