Skip to content

Commit 8f4d21c

Browse files
Make --retries global to a name and try with other name servers in a given layer (#451)
* re-work for retries * added network timeout * add comments * consolidated cachedRetryingLookup and retryingLookup into single fn, remove randomRootServer fn * better iterateOnAuth handling * handle status error in iterateOnAuths * remove unused status * update README * update retries in cli * properly handle the NetworkTimeout * PR cleanup * fix defaults for network timeout * fix todo in comment * reset nonqueried map if all nameservers are queried * fix merge issues * comment theorized root cause of issue * resolve compile issues and sanity check the retry logic * more global retry handling * update default timeouts and retries in cli.go --------- Co-authored-by: Zakir Durumeric <[email protected]>
1 parent c9f92e1 commit 8f4d21c

File tree

11 files changed

+247
-182
lines changed

11 files changed

+247
-182
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ routines. This architecture has several caveats:
291291
292292
* `--timeout` The maximum amount of time ZDNS will spend on a single name
293293
* `--iteration-timeout` The maximum amount of time ZDNS will spend on a single iteration step (ex: resolving google.com at the .com layer)
294-
* `--retries` The number of retries ZDNS will make against a single nameserver before giving up for that name
294+
* `--network-timeout` The maximum amount of time ZDNS will wait for a response from a nameserver
295+
* `--retries=N` If a connection to a specific nameserver fails in `--iterative`, ZDNS will retry with another un-queried name server at that layer.
296+
Retries are per-name, so if `--retries=1` then ZDNS will retry a name against a new nameserver once during it's full iteration process. If all nameservers have been queried
297+
then a random nameserver will be chosen.
295298
* `--name-servers` The list of nameservers to use for lookups, mostly useful with `--iterative=false`
296299
297300

src/cli/cli.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ type GeneralOptions struct {
4444
LookupAllNameServers bool `long:"all-nameservers" description:"Perform the lookup via all the nameservers for the domain."`
4545
CacheSize int `long:"cache-size" default:"10000" description:"how many items can be stored in internal recursive cache"`
4646
GoMaxProcs int `long:"go-processes" default:"0" description:"number of OS processes (GOMAXPROCS by default)"`
47-
IterationTimeout int `long:"iteration-timeout" default:"4" description:"timeout for a single iterative step in an iterative query, in seconds. Only applicable with --iterative"`
47+
IterationTimeout int `long:"iteration-timeout" default:"8" description:"timeout for a single iterative step in an iterative query, in seconds. Only applicable with --iterative"`
4848
IterativeResolution bool `long:"iterative" description:"Perform own iteration instead of relying on recursive resolver"`
4949
MaxDepth int `long:"max-depth" default:"10" description:"how deep should we recurse when performing iterative lookups"`
5050
NameServerMode bool `long:"name-server-mode" description:"Treats input as nameservers to query with a static query rather than queries to send to a static name server"`
5151
NameServersString string `long:"name-servers" description:"List of DNS servers to use. Can be passed as comma-delimited string or via @/path/to/file. If no port is specified, defaults to 53."`
5252
UseNanoseconds bool `long:"nanoseconds" description:"Use nanosecond resolution timestamps in output"`
53+
NetworkTimeout int `long:"network-timeout" default:"2" description:"timeout for round trip network operations, in seconds"`
5354
DisableFollowCNAMEs bool `long:"no-follow-cnames" description:"do not follow CNAMEs/DNAMEs in the lookup process"`
54-
Retries int `long:"retries" default:"1" description:"how many times should zdns retry query if timeout or temporary failure"`
55+
Retries int `long:"retries" default:"3" description:"how many times should zdns retry query against a new nameserver if timeout or temporary failure"`
5556
Threads int `short:"t" long:"threads" default:"100" description:"number of lightweight go threads"`
56-
Timeout int `long:"timeout" default:"15" description:"timeout for resolving a individual name, in seconds"`
57+
Timeout int `long:"timeout" default:"20" description:"timeout for resolving a individual name, in seconds"`
5758
Version bool `long:"version" short:"v" description:"Print the version of zdns and exit"`
5859
}
5960

src/cli/worker_manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func populateResolverConfig(gc *CLIConf) *zdns.ResolverConfig {
191191
}
192192

193193
config.Timeout = time.Second * time.Duration(gc.Timeout)
194+
config.NetworkTimeout = time.Second * time.Duration(gc.NetworkTimeout)
194195
config.IterativeTimeout = time.Second * time.Duration(gc.IterationTimeout)
195196
config.LookupAllNameServers = gc.LookupAllNameServers
196197
config.FollowCNAMEs = !gc.DisableFollowCNAMEs // ZFlags only allows default-false bool flags. We'll invert here.

src/modules/bindversion/bindversion_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var queries []QueryRecord
3535
// DoSingleDstServerLookup(r *Resolver, q Question, nameServer string, isIterative bool) (*SingleQueryResult, Trace, Status, error)
3636
type MockLookup struct{}
3737

38-
func (ml MockLookup) DoSingleDstServerLookup(r *zdns.Resolver, question zdns.Question, nameServer *zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39-
queries = append(queries, QueryRecord{q: question, NameServer: nameServer})
38+
func (ml MockLookup) DoDstServersLookup(r *zdns.Resolver, question zdns.Question, nameServers []zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39+
queries = append(queries, QueryRecord{q: question, NameServer: &nameServers[0]})
4040
if res, ok := mockResults[question.Name]; ok {
4141
return res, nil, zdns.StatusNoError, nil
4242
} else {

src/modules/dmarc/dmarc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var queries []QueryRecord
3535

3636
type MockLookup struct{}
3737

38-
func (ml MockLookup) DoSingleDstServerLookup(r *zdns.Resolver, question zdns.Question, nameServer *zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39-
queries = append(queries, QueryRecord{question, nameServer})
38+
func (ml MockLookup) DoDstServersLookup(r *zdns.Resolver, question zdns.Question, nameServers []zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39+
queries = append(queries, QueryRecord{question, &nameServers[0]})
4040
if res, ok := mockResults[question.Name]; ok {
4141
return res, nil, zdns.StatusNoError, nil
4242
} else {

src/modules/spf/spf_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var queries []QueryRecord
3535

3636
type MockLookup struct{}
3737

38-
func (ml MockLookup) DoSingleDstServerLookup(r *zdns.Resolver, question zdns.Question, nameServer *zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39-
queries = append(queries, QueryRecord{question, nameServer})
38+
func (ml MockLookup) DoDstServersLookup(r *zdns.Resolver, question zdns.Question, nameServers []zdns.NameServer, isIterative bool) (*zdns.SingleQueryResult, zdns.Trace, zdns.Status, error) {
39+
queries = append(queries, QueryRecord{question, &nameServers[0]})
4040
if res, ok := mockResults[question.Name]; ok {
4141
return res, nil, zdns.StatusNoError, nil
4242
} else {

0 commit comments

Comments
 (0)