ooni-probe-cli/internal/netxlite/errno_windows.go
Simone Basso 9967803c31
fix(netxlite): map additional GetAddrInfoW errors (#521)
On Windows, GetAddrInfoW is a syscall and the Go resolver does
not attempt to map errors beyond WSA_HOST_NOT_FOUND, which becomes
"no such host", which we map to "dns_nxdomain_error".

See https://github.com/golang/go/blob/go1.17.1/src/net/lookup_windows.go#L16.

To map more GetAddrInfoW errors, thus, we need to enhance our
error classifier to have system specific errors.

Then, we need to filter for the WSA errors that are most likely
to pop up and map them to OONI failures. Those are three:

- WSANO_DATA which we have from our own UDP resolver as well
and which we can map to `dns_no_answer`

- WSANO_RECOVERY which we don't have but existed for MK so
we will use `dns_non_recoverable_failure`, which was an MK error

- WSATRY_AGAIN which likewise we map to the error that MK
used to emit, so `dns_temporary_failure`

This diff should address https://github.com/ooni/probe/issues/1467.
2021-09-29 11:21:28 +02:00

120 lines
3.6 KiB
Go

// Code generated by go generate; DO NOT EDIT.
// Generated: 2021-09-29 10:33:56.628771 +0200 CEST m=+0.563439293
package netxlite
import (
"errors"
"syscall"
"golang.org/x/sys/windows"
)
// This enumeration provides a canonical name for
// every system-call error we support on this systems.
const (
ECONNREFUSED = windows.WSAECONNREFUSED
ECONNRESET = windows.WSAECONNRESET
EHOSTUNREACH = windows.WSAEHOSTUNREACH
ETIMEDOUT = windows.WSAETIMEDOUT
EAFNOSUPPORT = windows.WSAEAFNOSUPPORT
EADDRINUSE = windows.WSAEADDRINUSE
EADDRNOTAVAIL = windows.WSAEADDRNOTAVAIL
EISCONN = windows.WSAEISCONN
EFAULT = windows.WSAEFAULT
EBADF = windows.WSAEBADF
ECONNABORTED = windows.WSAECONNABORTED
EALREADY = windows.WSAEALREADY
EDESTADDRREQ = windows.WSAEDESTADDRREQ
EINTR = windows.WSAEINTR
EINVAL = windows.WSAEINVAL
EMSGSIZE = windows.WSAEMSGSIZE
ENETDOWN = windows.WSAENETDOWN
ENETRESET = windows.WSAENETRESET
ENETUNREACH = windows.WSAENETUNREACH
ENOBUFS = windows.WSAENOBUFS
ENOPROTOOPT = windows.WSAENOPROTOOPT
ENOTSOCK = windows.WSAENOTSOCK
ENOTCONN = windows.WSAENOTCONN
EWOULDBLOCK = windows.WSAEWOULDBLOCK
EACCES = windows.WSAEACCES
EPROTONOSUPPORT = windows.WSAEPROTONOSUPPORT
EPROTOTYPE = windows.WSAEPROTOTYPE
WSANO_DATA = windows.WSANO_DATA
WSANO_RECOVERY = windows.WSANO_RECOVERY
WSATRY_AGAIN = windows.WSATRY_AGAIN
)
// classifySyscallError converts a syscall error to the
// proper OONI error. Returns the OONI error string
// on success, an empty string otherwise.
func classifySyscallError(err error) string {
var errno syscall.Errno
if !errors.As(err, &errno) {
return ""
}
switch errno {
case windows.WSAECONNREFUSED:
return FailureConnectionRefused
case windows.WSAECONNRESET:
return FailureConnectionReset
case windows.WSAEHOSTUNREACH:
return FailureHostUnreachable
case windows.WSAETIMEDOUT:
return FailureTimedOut
case windows.WSAEAFNOSUPPORT:
return FailureAddressFamilyNotSupported
case windows.WSAEADDRINUSE:
return FailureAddressInUse
case windows.WSAEADDRNOTAVAIL:
return FailureAddressNotAvailable
case windows.WSAEISCONN:
return FailureAlreadyConnected
case windows.WSAEFAULT:
return FailureBadAddress
case windows.WSAEBADF:
return FailureBadFileDescriptor
case windows.WSAECONNABORTED:
return FailureConnectionAborted
case windows.WSAEALREADY:
return FailureConnectionAlreadyInProgress
case windows.WSAEDESTADDRREQ:
return FailureDestinationAddressRequired
case windows.WSAEINTR:
return FailureInterrupted
case windows.WSAEINVAL:
return FailureInvalidArgument
case windows.WSAEMSGSIZE:
return FailureMessageSize
case windows.WSAENETDOWN:
return FailureNetworkDown
case windows.WSAENETRESET:
return FailureNetworkReset
case windows.WSAENETUNREACH:
return FailureNetworkUnreachable
case windows.WSAENOBUFS:
return FailureNoBufferSpace
case windows.WSAENOPROTOOPT:
return FailureNoProtocolOption
case windows.WSAENOTSOCK:
return FailureNotASocket
case windows.WSAENOTCONN:
return FailureNotConnected
case windows.WSAEWOULDBLOCK:
return FailureOperationWouldBlock
case windows.WSAEACCES:
return FailurePermissionDenied
case windows.WSAEPROTONOSUPPORT:
return FailureProtocolNotSupported
case windows.WSAEPROTOTYPE:
return FailureWrongProtocolType
case windows.WSANO_DATA:
return FailureDNSNoAnswer
case windows.WSANO_RECOVERY:
return FailureDNSNonRecoverableFailure
case windows.WSATRY_AGAIN:
return FailureDNSTemporaryFailure
}
return ""
}