Compare commits
1 Commits
b599dab525
...
2993911883
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2993911883 |
@@ -480,7 +480,6 @@ type queryState struct {
|
|||||||
gotNXDomain bool
|
gotNXDomain bool
|
||||||
gotSERVFAIL bool
|
gotSERVFAIL bool
|
||||||
gotTimeout bool
|
gotTimeout bool
|
||||||
gotError bool
|
|
||||||
hasRecords bool
|
hasRecords bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,11 +517,8 @@ func (r *Resolver) querySingleType(
|
|||||||
) {
|
) {
|
||||||
msg, err := r.queryDNS(ctx, nsIP, hostname, qtype)
|
msg, err := r.queryDNS(ctx, nsIP, hostname, qtype)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var netErr net.Error
|
if isTimeout(err) {
|
||||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
|
||||||
state.gotTimeout = true
|
state.gotTimeout = true
|
||||||
} else {
|
|
||||||
state.gotError = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -562,6 +558,16 @@ func collectAnswerRecords(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isTimeout checks whether an error is a network timeout.
|
||||||
|
func isTimeout(err error) bool {
|
||||||
|
var netErr net.Error
|
||||||
|
if errors.As(err, &netErr) {
|
||||||
|
return netErr.Timeout()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func classifyResponse(resp *NameserverResponse, state queryState) {
|
func classifyResponse(resp *NameserverResponse, state queryState) {
|
||||||
switch {
|
switch {
|
||||||
case state.gotNXDomain && !state.hasRecords:
|
case state.gotNXDomain && !state.hasRecords:
|
||||||
@@ -569,22 +575,14 @@ func classifyResponse(resp *NameserverResponse, state queryState) {
|
|||||||
case state.gotTimeout && !state.hasRecords:
|
case state.gotTimeout && !state.hasRecords:
|
||||||
resp.Status = StatusTimeout
|
resp.Status = StatusTimeout
|
||||||
resp.Error = "all queries timed out"
|
resp.Error = "all queries timed out"
|
||||||
case (state.gotError || state.gotSERVFAIL) && !state.hasRecords:
|
case state.gotSERVFAIL && !state.hasRecords:
|
||||||
resp.Status = StatusError
|
resp.Status = StatusError
|
||||||
resp.Error = errorMessageForState(state)
|
resp.Error = "server returned SERVFAIL"
|
||||||
case !state.hasRecords && !state.gotNXDomain:
|
case !state.hasRecords && !state.gotNXDomain:
|
||||||
resp.Status = StatusNoData
|
resp.Status = StatusNoData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorMessageForState(state queryState) string {
|
|
||||||
if state.gotSERVFAIL {
|
|
||||||
return "server returned SERVFAIL"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "query failed due to non-timeout error"
|
|
||||||
}
|
|
||||||
|
|
||||||
// extractRecordValue formats a DNS RR value as a string.
|
// extractRecordValue formats a DNS RR value as a string.
|
||||||
func extractRecordValue(rr dns.RR) string {
|
func extractRecordValue(rr dns.RR) string {
|
||||||
switch r := rr.(type) {
|
switch r := rr.(type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user