return "", nil, &DNSError{Err: "no DNS servers", Name: name}
}
- timeout := time.Duration(cfg.timeout) * time.Second
- deadline := time.Now().Add(timeout)
+ deadline := time.Now().Add(cfg.timeout)
if old, ok := ctx.Deadline(); !ok || deadline.Before(old) {
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, deadline)
)
type dnsConfig struct {
- servers []string // servers to use
- search []string // suffixes to append to local name
- ndots int // number of dots in name to trigger absolute lookup
- timeout int // seconds before giving up on packet
- attempts int // lost packets before giving up on server
- rotate bool // round robin among servers
- unknownOpt bool // anything unknown was encountered
- 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
+ servers []string // servers to use
+ search []string // suffixes to append to local name
+ ndots int // number of dots in name to trigger absolute lookup
+ timeout time.Duration // wait before giving up on a query, including retries
+ attempts int // lost packets before giving up on server
+ rotate bool // round robin among servers
+ unknownOpt bool // anything unknown was encountered
+ 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
}
// See resolv.conf(5) on a Linux machine.
func dnsReadConfig(filename string) *dnsConfig {
conf := &dnsConfig{
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
}
file, err := open(filename)
if n < 1 {
n = 1
}
- conf.timeout = n
+ conf.timeout = time.Duration(n) * time.Second
case hasPrefix(s, "attempts:"):
n, _, _ := dtoi(s, 9)
if n < 1 {
servers: []string{"8.8.8.8", "2001:4860:4860::8888", "fe80::1%lo0"},
search: []string{"localdomain"},
ndots: 5,
- timeout: 10,
+ timeout: 10 * time.Second,
attempts: 3,
rotate: true,
unknownOpt: true, // the "options attempts 3" line
servers: []string{"8.8.8.8"},
search: []string{"localdomain"},
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
},
},
servers: []string{"8.8.8.8"},
search: []string{"test", "invalid"},
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
},
},
want: &dnsConfig{
servers: defaultNS,
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
search: []string{"domain.local"},
},
name: "testdata/openbsd-resolv.conf",
want: &dnsConfig{
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
lookup: []string{"file", "bind"},
servers: []string{"169.254.169.254", "10.240.0.1"},
want := &dnsConfig{
servers: defaultNS,
ndots: 1,
- timeout: 5,
+ timeout: 5 * time.Second,
attempts: 2,
search: []string{"domain.local"},
}