Source file src/net/dnsconfig.go

     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  )
    12  
    13  var (
    14  	defaultNS   = []string{"127.0.0.1:53", "[::1]:53"}
    15  	getHostname = os.Hostname // variable for testing
    16  )
    17  
    18  type dnsConfig struct {
    19  	servers       []string      // server addresses (in host:port form) to use
    20  	search        []string      // rooted suffixes to append to local name
    21  	ndots         int           // number of dots in name to trigger absolute lookup
    22  	timeout       time.Duration // wait before giving up on a query, including retries
    23  	attempts      int           // lost packets before giving up on server
    24  	rotate        bool          // round robin among servers
    25  	unknownOpt    bool          // anything unknown was encountered
    26  	lookup        []string      // OpenBSD top-level database "lookup" order
    27  	err           error         // any error that occurs during open of resolv.conf
    28  	mtime         time.Time     // time of resolv.conf modification
    29  	soffset       uint32        // used by serverOffset
    30  	singleRequest bool          // use sequential A and AAAA queries instead of parallel queries
    31  	useTCP        bool          // force usage of TCP for DNS resolutions
    32  }
    33  
    34  // serverOffset returns an offset that can be used to determine
    35  // indices of servers in c.servers when making queries.
    36  // When the rotate option is enabled, this offset increases.
    37  // Otherwise it is always 0.
    38  func (c *dnsConfig) serverOffset() uint32 {
    39  	if c.rotate {
    40  		return atomic.AddUint32(&c.soffset, 1) - 1 // return 0 to start
    41  	}
    42  	return 0
    43  }
    44  

View as plain text