Browse Source

Only return one CNAME when there are several weighted options

Ask Bjørn Hansen 10 years ago
parent
commit
05231ac3ce
2 changed files with 6 additions and 0 deletions
  1. 4 0
      picker.go
  2. 2 0
      serve_test.go

+ 4 - 0
picker.go

@@ -31,6 +31,10 @@ func (label *Label) Picker(qtype uint16, max int) Records {
 			return labelRR
 			return labelRR
 		}
 		}
 
 
+		if qtype == dns.TypeCNAME || qtype == dns.TypeMF {
+			max = 1
+		}
+
 		rrCount := len(labelRR)
 		rrCount := len(labelRR)
 		if max > rrCount {
 		if max > rrCount {
 			max = rrCount
 			max = rrCount

+ 2 - 0
serve_test.go

@@ -152,6 +152,8 @@ func (s *ServeSuite) TestCname(c *C) {
 
 
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
 		r := exchange(c, "www.se.test.example.com.", dns.TypeA)
 		r := exchange(c, "www.se.test.example.com.", dns.TypeA)
+		// only return one CNAME even if there are multiple options
+		c.Check(r.Answer, HasLen, 1)
 		target := r.Answer[0].(*dns.CNAME).Target
 		target := r.Answer[0].(*dns.CNAME).Target
 		results[target]++
 		results[target]++
 	}
 	}