Skip to content

Commit

Permalink
Support ANY queries
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Aug 28, 2012
1 parent cbbf744 commit 586b42b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
25 changes: 21 additions & 4 deletions picker.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
package main

import (
"github.com/miekg/dns"
"math/rand"
)

func (label *Label) Picker(dnsType uint16, max int) Records {
func (label *Label) Picker(qtype uint16, max int) Records {

if label_rr := label.Records[dnsType]; label_rr != nil {
if qtype == dns.TypeANY {
result := make([]Record, 0)
for rtype, _ := range label.Records {

rtype_records := label.Picker(rtype, max)

tmp_result := make(Records, len(result)+len(rtype_records))

copy(tmp_result, result)
copy(tmp_result[len(result):], rtype_records)
result = tmp_result
}

return result
}

if label_rr := label.Records[qtype]; label_rr != nil {

// not "balanced", just return all
if label.Weight[dnsType] == 0 {
if label.Weight[qtype] == 0 {
return label_rr
}

Expand All @@ -21,7 +38,7 @@ func (label *Label) Picker(dnsType uint16, max int) Records {
servers := make([]Record, len(label_rr))
copy(servers, label_rr)
result := make([]Record, max)
sum := label.Weight[dnsType]
sum := label.Weight[qtype]

for si := 0; si < max; si++ {
n := rand.Intn(sum + 1)
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (z *Zone) SoaRR() dns.RR {

func (z *Zone) findLabels(s, cc string, qtype uint16) *Label {

if qtype == dns.TypeANY {
// short-circuit mostly to avoid subtle bugs later
return z.Labels[s]
}

selectors := []string{}

if len(cc) > 0 {
Expand Down

0 comments on commit 586b42b

Please sign in to comment.