Skip to content

Commit

Permalink
Make CNAME records optionally use the current zone name
Browse files Browse the repository at this point in the history
In pgeodns they didn't because the whole data structure
was shared between different origin names if they used
the same .json.
  • Loading branch information
abh committed Dec 16, 2012
1 parent 41174aa commit e1107d6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Same format as A records (except the record type is "aaaa").

### 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

### MX
Expand Down
6 changes: 5 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {

case dns.TypeCNAME:
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:
rec := records[rType][i]
Expand Down
15 changes: 15 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/miekg/dns"
. "launchpad.net/gocheck"
"testing"
)
Expand Down Expand Up @@ -29,4 +30,18 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
c.Check(tz.Options.MaxHosts, Equals, 2)
c.Check(tz.Options.Contact, Equals, "support.bitnames.com")
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 changes: 6 additions & 0 deletions dns/test.example.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
"www": {
"cname": "geo.bitnames.com."
},
"www-cname": {
"cname": "bar"
},
"www-alias": {
"cname": "bar-alias"
},
"cname-long-ttl": {
"cname": "geo.bitnames.com.",
"ttl": 86400
Expand Down
2 changes: 1 addition & 1 deletion geodns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

var VERSION string = "2.1.2"
var VERSION string = "2.2.0"
var gitVersion string
var serverId string

Expand Down
7 changes: 7 additions & 0 deletions serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ func (s *ConfigSuite) TestServing(c *C) {
r = exchange(c, "test.example.com.", dns.TypeAAAA)
soa2 := r.Ns[0].(*dns.RR_SOA)
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 {
Expand Down

0 comments on commit e1107d6

Please sign in to comment.