@@ -35,6 +35,7 @@ type DomainConfig struct {
35
35
36
36
// "type": "forwarding"
37
37
Nameservers []string `json:"nameservers"` // [ "8.8.8.8", "8.8.4.4" ]
38
+ Randomize * bool `json:"randomize"` // whether to randomize recursive lookups to spread upstream load (defaults to true)
38
39
39
40
// "type": "static"
40
41
Addrs []string `json:"addrs"`
@@ -74,6 +75,13 @@ func main() {
74
75
}
75
76
76
77
for domain := range config {
78
+ if config [domain ].Randomize == nil {
79
+ domainConfig := config [domain ]
80
+ randomize := true
81
+ domainConfig .Randomize = & randomize
82
+ config [domain ] = domainConfig
83
+ }
84
+
77
85
switch config [domain ].Type {
78
86
case "containers" :
79
87
// TODO there must be a better way to pass "domain" along without an anonymous function AND copied variable
@@ -93,8 +101,9 @@ func main() {
93
101
case "forwarding" :
94
102
// TODO there must be a better way to pass "domain" along without an anonymous function AND copied variable
95
103
nameservers := config [domain ].Nameservers
104
+ randomize := * config [domain ].Randomize
96
105
dns .HandleFunc (domain , func (w dns.ResponseWriter , r * dns.Msg ) {
97
- handleForwarding (nameservers , w , r )
106
+ handleForwarding (nameservers , randomize , w , r )
98
107
})
99
108
case "static" :
100
109
cCopy := config [domain ]
@@ -252,7 +261,7 @@ func handleStaticRequest(config DomainConfig, w dns.ResponseWriter, r *dns.Msg)
252
261
},
253
262
Question : []dns.Question {recQ },
254
263
}
255
- recM := handleForwardingRaw (config .Nameservers , recR , w .RemoteAddr ())
264
+ recM := handleForwardingRaw (config .Nameservers , * config . Randomize , recR , w .RemoteAddr ())
256
265
for _ , rr := range recM .Answer {
257
266
dnsAppend (recQ , m , rr )
258
267
}
0 commit comments