Skip to content

Commit

Permalink
fix(netxlite): map servfail error (#728)
Browse files Browse the repository at this point in the history
This error occurred for example when querying kazemjalali.com
in websteps measurements run from Iran.

This error is relatively uncommon, but it still makes sense to
create a specific mapping rule for it.

Originally: bassosimone/websteps-illustrated@4269e82

See ooni/probe#2096
  • Loading branch information
bassosimone authored May 13, 2022
1 parent b872dd0 commit 5904e69
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
11 changes: 10 additions & 1 deletion internal/netxlite/classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,17 @@ const (
// unexported errors used by the Go standard library.
var (
ErrOODNSNoSuchHost = fmt.Errorf("ooniresolver: %s", DNSNoSuchHostSuffix)
ErrOODNSRefused = errors.New("ooniresolver: refused")
ErrOODNSMisbehaving = fmt.Errorf("ooniresolver: %s", DNSServerMisbehavingSuffix)
ErrOODNSNoAnswer = fmt.Errorf("ooniresolver: %s", DNSNoAnswerSuffix)
)

// These errors are not part of the Go standard library but we can
// return them in our custom resolvers.
var (
ErrOODNSRefused = errors.New("ooniresolver: refused")
ErrOODNSServfail = errors.New("ooniresolver: servfail")
)

// classifyResolverError maps DNS resolution errors to
// OONI failure strings.
//
Expand All @@ -278,6 +284,9 @@ func classifyResolverError(err error) string {
if errors.Is(err, ErrOODNSRefused) {
return FailureDNSRefusedError // not in MK
}
if errors.Is(err, ErrOODNSServfail) {
return FailureDNSServfailError
}
return classifyGenericError(err)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/netxlite/classify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ func TestClassifyResolverError(t *testing.T) {
}
})

t.Run("for servfail", func(t *testing.T) {
if classifyResolverError(ErrOODNSServfail) != FailureDNSServfailError {
t.Fatal("unexpected result")
}
})

t.Run("for another kind of error", func(t *testing.T) {
if classifyResolverError(io.EOF) != FailureEOFError {
t.Fatal("unexpected result")
Expand Down
2 changes: 2 additions & 0 deletions internal/netxlite/dnsdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (d *DNSDecoderMiekg) parseReply(data []byte) (*dns.Msg, error) {
return nil, ErrOODNSNoSuchHost
case dns.RcodeRefused:
return nil, ErrOODNSRefused
case dns.RcodeServerFailure:
return nil, ErrOODNSServfail
default:
return nil, ErrOODNSMisbehaving
}
Expand Down
12 changes: 12 additions & 0 deletions internal/netxlite/dnsdecoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ func TestDNSDecoder(t *testing.T) {
}
})

t.Run("Servfail", func(t *testing.T) {
d := &DNSDecoderMiekg{}
data, err := d.DecodeLookupHost(
dns.TypeA, dnsGenReplyWithError(t, dns.TypeA, dns.RcodeServerFailure))
if !errors.Is(err, ErrOODNSServfail) {
t.Fatal("not the error we expected", err)
}
if data != nil {
t.Fatal("expected nil data here")
}
})

t.Run("no address", func(t *testing.T) {
d := &DNSDecoderMiekg{}
data, err := d.DecodeLookupHost(dns.TypeA, dnsGenLookupHostReplySuccess(t, dns.TypeA))
Expand Down
1 change: 0 additions & 1 deletion internal/netxlite/dnsencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func TestDNSEncoder(t *testing.T) {

t.Run("encode A", func(t *testing.T) {
e := &DNSEncoderMiekg{}
data, err := e.Encode("x.org", dns.TypeA, false)
Expand Down
4 changes: 3 additions & 1 deletion internal/netxlite/errno.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/netxlite/internal/generrno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ var Specs = []*ErrorSpec{
NewLibraryError("DNS_refused_error"),
NewLibraryError("DNS_server_misbehaving"),
NewLibraryError("DNS_no_answer"),
NewLibraryError("DNS_servfail_error"),
NewLibraryError("EOF_error"),
NewLibraryError("generic_timeout_error"),
NewLibraryError("QUIC_incompatible_version"),
Expand Down

0 comments on commit 5904e69

Please sign in to comment.