Browse Source

Make CNAME records optionally use the current zone name

In pgeodns they didn't because the whole data structure
was shared between different origin names if they used
the same .json.
Ask Bjørn Hansen 12 years ago
parent
commit
e1107d6f43
7 changed files with 47 additions and 2 deletions
  1. 8 0
      CHANGES.md
  2. 5 0
      README.md
  3. 5 1
      config.go
  4. 15 0
      config_test.go
  5. 6 0
      dns/test.example.com.json
  6. 1 1
      geodns.go
  7. 7 0
      serve_test.go

+ 8 - 0
CHANGES.md

@@ -0,0 +1,8 @@
+# GeoDNS Changelog
+
+## 2.2.0
+
+- The CNAME configuration changed so the name of the current zone is appended
+to the target name if the target is not a fqdn (ends with a "."). This is a rare
+change not compatible with existing data. To upgrade make all cname's fqdn's until
+all servers are running v2.2.0 or newer.

+ 5 - 0
README.md

@@ -102,6 +102,11 @@ Same format as A records (except the record type is "aaaa").
 
 
 ### CNAME
 ### CNAME
 
 
+The target will have the current zone name appended if it's not a FQDN (since v2.2.0).
+
+  { "cname": "target.example.com." }
+  { "cname": "www" }
+
 ### NS
 ### NS
 
 
 ### MX
 ### MX

+ 5 - 1
config.go

@@ -279,7 +279,11 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 
 
 				case dns.TypeCNAME:
 				case dns.TypeCNAME:
 					rec := records[rType][i]
 					rec := records[rType][i]
-					record.RR = &dns.RR_CNAME{Hdr: h, Target: dns.Fqdn(rec.(string))}
+					target := rec.(string)
+					if !dns.IsFqdn(target) {
+						target = target + "." + Zone.Origin
+					}
+					record.RR = &dns.RR_CNAME{Hdr: h, Target: dns.Fqdn(target)}
 
 
 				case dns.TypeMF:
 				case dns.TypeMF:
 					rec := records[rType][i]
 					rec := records[rType][i]

+ 15 - 0
config_test.go

@@ -1,6 +1,7 @@
 package main
 package main
 
 
 import (
 import (
+	"github.com/miekg/dns"
 	. "launchpad.net/gocheck"
 	. "launchpad.net/gocheck"
 	"testing"
 	"testing"
 )
 )
@@ -29,4 +30,18 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
 	c.Check(tz.Options.MaxHosts, Equals, 2)
 	c.Check(tz.Options.MaxHosts, Equals, 2)
 	c.Check(tz.Options.Contact, Equals, "support.bitnames.com")
 	c.Check(tz.Options.Contact, Equals, "support.bitnames.com")
 	c.Check(tz.Labels["weight"].MaxHosts, Equals, 1)
 	c.Check(tz.Labels["weight"].MaxHosts, Equals, 1)
+
+	/* test different cname targets */
+	c.Check(tz.Labels["www"].
+		firstRR(dns.TypeCNAME).(*dns.RR_CNAME).
+		Target, Equals, "geo.bitnames.com.")
+
+	c.Check(tz.Labels["www-cname"].
+		firstRR(dns.TypeCNAME).(*dns.RR_CNAME).
+		Target, Equals, "bar.test.example.com.")
+
+	c.Check(tz.Labels["www-alias"].
+		firstRR(dns.TypeCNAME).(*dns.RR_CNAME).
+		Target, Equals, "bar-alias.test.example.com.")
+
 }
 }

+ 6 - 0
dns/test.example.com.json

@@ -38,6 +38,12 @@
     "www": {
     "www": {
       "cname": "geo.bitnames.com."
       "cname": "geo.bitnames.com."
     },
     },
+    "www-cname": {
+      "cname": "bar"
+    },
+    "www-alias": {
+      "cname": "bar-alias"
+    },
     "cname-long-ttl": {
     "cname-long-ttl": {
       "cname": "geo.bitnames.com.",
       "cname": "geo.bitnames.com.",
       "ttl": 86400
       "ttl": 86400

+ 1 - 1
geodns.go

@@ -11,7 +11,7 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-var VERSION string = "2.1.2"
+var VERSION string = "2.2.0"
 var gitVersion string
 var gitVersion string
 var serverId string
 var serverId string
 
 

+ 7 - 0
serve_test.go

@@ -36,6 +36,13 @@ func (s *ConfigSuite) TestServing(c *C) {
 	r = exchange(c, "test.example.com.", dns.TypeAAAA)
 	r = exchange(c, "test.example.com.", dns.TypeAAAA)
 	soa2 := r.Ns[0].(*dns.RR_SOA)
 	soa2 := r.Ns[0].(*dns.RR_SOA)
 	c.Check(soa, DeepEquals, soa2)
 	c.Check(soa, DeepEquals, soa2)
+
+	r = exchange(c, "www.test.example.com.", dns.TypeA)
+	c.Check(r.Answer[0].(*dns.RR_CNAME).Target, Equals, "geo.bitnames.com.")
+
+	// TODO: make the alias and cname respond with the data for the target, too?
+	r = exchange(c, "www-alias.test.example.com.", dns.TypeA)
+	c.Check(r.Answer[0].(*dns.RR_CNAME).Target, Equals, "bar-alias.test.example.com.")
 }
 }
 
 
 func exchange(c *C, name string, dnstype uint16) *dns.Msg {
 func exchange(c *C, name string, dnstype uint16) *dns.Msg {