summaryrefslogtreecommitdiff
path: root/src/net/dnsconfig_unix.go
diff options
context:
space:
mode:
authorDan Peterson <dpiddy@gmail.com>2016-09-15 17:24:42 -0300
committerMatthew Dempsky <mdempsky@google.com>2016-09-17 00:34:19 +0000
commita1bf203b57ab854f2c1b7668ae96bc34e60e02fc (patch)
tree662a0e5b8a3be9c43a31b07fd03c75620621cc5f /src/net/dnsconfig_unix.go
parentf7e49f6644bde3f17b4a795218a35876347455a1 (diff)
downloadgo-git-a1bf203b57ab854f2c1b7668ae96bc34e60e02fc.tar.gz
net: respect resolv.conf rotate option
Instead of ranging over servers in the config, grab an offset from the config that is used to determine indices. When the rotate option is enabled, the offset increases which rotates queries through servers. Otherwise, it is always 0 which uses servers in config order. Fixes #17126 Change-Id: If233f6de7bfa42f88570055b9ab631be08a76b3e Reviewed-on: https://go-review.googlesource.com/29233 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/net/dnsconfig_unix.go')
-rw-r--r--src/net/dnsconfig_unix.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/net/dnsconfig_unix.go b/src/net/dnsconfig_unix.go
index 683ae71812..9c8108d11c 100644
--- a/src/net/dnsconfig_unix.go
+++ b/src/net/dnsconfig_unix.go
@@ -10,6 +10,7 @@ package net
import (
"os"
+ "sync/atomic"
"time"
)
@@ -29,6 +30,7 @@ type dnsConfig struct {
lookup []string // OpenBSD top-level database "lookup" order
err error // any error that occurs during open of resolv.conf
mtime time.Time // time of resolv.conf modification
+ soffset uint32 // used by serverOffset
}
// See resolv.conf(5) on a Linux machine.
@@ -136,6 +138,17 @@ func dnsReadConfig(filename string) *dnsConfig {
return conf
}
+// serverOffset returns an offset that can be used to determine
+// indices of servers in c.servers when making queries.
+// When the rotate option is enabled, this offset increases.
+// Otherwise it is always 0.
+func (c *dnsConfig) serverOffset() uint32 {
+ if c.rotate {
+ return atomic.AddUint32(&c.soffset, 1) - 1 // return 0 to start
+ }
+ return 0
+}
+
func dnsDefaultSearch() []string {
hn, err := getHostname()
if err != nil {