Debian Codegraph @

src/net/dnsconfig.go

raw
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package net
6
7 import (
8 "os"
9 "sync/atomic"
10 "time"
11 _ "unsafe"
12 )
13
14 // defaultNS is the default name servers to use in the absence of DNS configuration.
15 //
16 // defaultNS should be an internal detail,
17 // but widely used packages access it using linkname.
18 // Notable members of the hall of shame include:
19 // - github.com/pojntfx/hydrapp/hydrapp
20 // - github.com/mtibben/androiddnsfix
21 //
22 // Do not remove or change the type signature.
23 // See go.dev/issue/67401.
24 //
25 //go:linkname defaultNS
26 var defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
27
28 var getHostname = os.Hostname // variable for testing
29
30 type dnsConfig struct {
31 servers []string // server addresses (in host:port form) to use
32 search []string // rooted suffixes to append to local name
33 ndots int // number of dots in name to trigger absolute lookup
34 timeout time.Duration // wait before giving up on a query, including retries
35 attempts int // lost packets before giving up on server
36 rotate bool // round robin among servers
37 unknownOpt bool // anything unknown was encountered
38 lookup []string // OpenBSD top-level database "lookup" order
39 err error // any error that occurs during open of resolv.conf
40 mtime time.Time // time of resolv.conf modification
41 soffset uint32 // used by serverOffset
42 singleRequest bool // use sequential A and AAAA queries instead of parallel queries
43 useTCP bool // force usage of TCP for DNS resolutions
44 trustAD bool // add AD flag to queries
45 noReload bool // do not check for config file updates
46 }
47
48 // serverOffset returns an offset that can be used to determine
49 // indices of servers in c.servers when making queries.
50 // When the rotate option is enabled, this offset increases.
51 // Otherwise it is always 0.
52 func (c *dnsConfig) serverOffset() uint32 {
53 if c.rotate {
54 return atomic.AddUint32(&c.soffset, 1) - 1 // return 0 to start
55 }
56 return 0
57 }