summaryrefslogtreecommitdiffstats
path: root/conn
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-02-09 19:46:57 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-09 19:46:57 +0100
commit5cdb862f15fc4d0772ace2ca3fd0271233012185 (patch)
treede6bb87444618d32d9bbd14ab0c8989c7ab6e4c2 /conn
parentdevice: handshake routine writes into encryption queue (diff)
downloadwireguard-go-5cdb862f15fc4d0772ace2ca3fd0271233012185.tar.xz
wireguard-go-5cdb862f15fc4d0772ace2ca3fd0271233012185.zip
conn: use errors.Is for unwrapping
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conn')
-rw-r--r--conn/conn_default.go20
1 files changed, 4 insertions, 16 deletions
diff --git a/conn/conn_default.go b/conn/conn_default.go
index 22248af..2360068 100644
--- a/conn/conn_default.go
+++ b/conn/conn_default.go
@@ -8,8 +8,8 @@
package conn
import (
+ "errors"
"net"
- "os"
"syscall"
)
@@ -84,18 +84,6 @@ func listenNet(network string, port int) (*net.UDPConn, int, error) {
return conn, uaddr.Port, nil
}
-func extractErrno(err error) error {
- opErr, ok := err.(*net.OpError)
- if !ok {
- return nil
- }
- syscallErr, ok := opErr.Err.(*os.SyscallError)
- if !ok {
- return nil
- }
- return syscallErr.Err
-}
-
func createBind(uport uint16) (Bind, uint16, error) {
var err error
var bind nativeBind
@@ -105,16 +93,16 @@ again:
port := int(uport)
bind.ipv4, port, err = listenNet("udp4", port)
- if err != nil && extractErrno(err) != syscall.EAFNOSUPPORT {
+ if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
return nil, 0, err
}
bind.ipv6, port, err = listenNet("udp6", port)
- if uport == 0 && err != nil && extractErrno(err) == syscall.EADDRINUSE && tries < 100 {
+ if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
tries++
goto again
}
- if err != nil && extractErrno(err) != syscall.EAFNOSUPPORT {
+ if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
bind.ipv4.Close()
bind.ipv4 = nil
return nil, 0, err