Browse Source

Merge pull request #94 from faide/master

Add support for PTR records
Ask Bjørn Hansen 9 years ago
parent
commit
5f305ff1c3
5 changed files with 44 additions and 2 deletions
  1. 2 0
      .gitignore
  2. 8 0
      README.md
  3. 20 0
      dns/1.168.192.in-addr.arpa.json
  4. 9 1
      serve_test.go
  5. 5 1
      zones.go

+ 2 - 0
.gitignore

@@ -3,3 +3,5 @@
 /geodns
 /REVISION
 /run
+.idea
+/dns/geodns.conf

+ 8 - 0
README.md

@@ -49,6 +49,14 @@ To test the responses run
 
 `dig -t a test.example.com @127.1 -p 5053`
 
+or
+
+`dig -t ptr 2.1.168.192.IN-ADDR.ARPA. @127.1 -p 5053`
+
+or more simply put
+
+`dig -x 192.168.1.2 @127.1 -p 5053`
+
 The binary can be moved to /usr/local/bin, /opt/geodns/ or wherever you find appropriate.
 
 ### Command options

+ 20 - 0
dns/1.168.192.in-addr.arpa.json

@@ -0,0 +1,20 @@
+{ "serial": 3,
+  "ttl":    600,
+  "max_hosts": 2,
+  "origin": "1.168.192.IN-ADDR.ARPA.",
+  "logging": {
+    "stathat": true,
+    "stathat_api": "abc-test"
+  },
+  "targeting": "country continent @ regiongroup region ip asn",
+  "contact": "support.bitnames.com",
+  "data" : {
+    "":  {
+      "ns": { "ns1.example.net.": null, "ns2.example.net.": null }
+    },
+    "2": {
+        "ptr": [ [ "bar.example.com." ] ],
+        "ttl": "601"
+    }
+  }
+}

+ 9 - 1
serve_test.go

@@ -31,7 +31,7 @@ func (s *ServeSuite) SetUpSuite(c *C) {
 	setupRootZone()
 	zonesReadDir("dns", Zones)
 
-	// listenAndServe returns after listning on udp + tcp, so just
+	// listenAndServe returns after listening on udp + tcp, so just
 	// wait for it before continuing
 	listenAndServe(PORT)
 
@@ -130,6 +130,14 @@ func (s *ServeSuite) TestServing(c *C) {
 	r = exchange(c, "one.test.example.com.", dns.TypeA)
 	ip = r.Answer[0].(*dns.A).A
 	c.Check(ip.String(), Equals, "192.168.1.6")
+
+	// PTR
+	r = exchange(c, "2.1.168.192.IN-ADDR.ARPA.", dns.TypePTR)
+	c.Check(r.Answer, HasLen, 1)
+	// NOERROR for PTR request
+	c.Check(r.Rcode, Equals, dns.RcodeSuccess)
+	name := r.Answer[0].(*dns.PTR).Ptr
+	c.Check(name, Equals, "bar.example.com.")
 }
 
 func (s *ServeSuite) TestServingMixedCase(c *C) {

+ 5 - 1
zones.go

@@ -275,6 +275,7 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 		"txt":   dns.TypeTXT,
 		"spf":   dns.TypeSPF,
 		"srv":   dns.TypeSRV,
+		"ptr":   dns.TypePTR,
 	}
 
 	for dk, dv_inter := range data {
@@ -353,13 +354,16 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 				}
 
 				switch dnsType {
-				case dns.TypeA, dns.TypeAAAA:
+				case dns.TypeA, dns.TypeAAAA, dns.TypePTR:
 
 					str, weight := getStringWeight(records[rType][i].([]interface{}))
 					ip := str
 					record.Weight = weight
 
 					switch dnsType {
+					case dns.TypePTR:
+						record.RR = &dns.PTR{Hdr: h, Ptr: ip}
+						break
 					case dns.TypeA:
 						if x := net.ParseIP(ip); x != nil {
 							record.RR = &dns.A{Hdr: h, A: x}