aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-01-08 14:25:37 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-08 14:30:04 +0100
commitea6c1cd7e6525f76041d341074a0e10b800d4e13 (patch)
tree20d488a58b5d9960a509edce216540707d286704
parentconn: linux: do not allow ReceiveIPvX to race with Close (diff)
downloadwireguard-go-ea6c1cd7e6525f76041d341074a0e10b800d4e13.tar.xz
wireguard-go-ea6c1cd7e6525f76041d341074a0e10b800d4e13.zip
device: receive: do not exit immediately on transient UDP receive errors
Some users report seeing lines like: > Routine: receive incoming IPv4 - stopped Popping up unexpectedly. Let's sleep and try again before failing, and also log the error, and perhaps we'll eventually understand this situation better in future versions. Because we have to distinguish between the socket being closed explicitly and whatever error this is, we bump the module to require Go 1.16. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--conn/conn_linux.go8
-rw-r--r--device/receive.go22
-rw-r--r--go.mod8
-rw-r--r--go.sum17
4 files changed, 32 insertions, 23 deletions
diff --git a/conn/conn_linux.go b/conn/conn_linux.go
index ef5c0ba..642ad7d 100644
--- a/conn/conn_linux.go
+++ b/conn/conn_linux.go
@@ -204,7 +204,7 @@ func (bind *nativeBind) ReceiveIPv6(buff []byte) (int, Endpoint, error) {
var end NativeEndpoint
if bind.sock6 == -1 {
- return 0, nil, syscall.EAFNOSUPPORT
+ return 0, nil, net.ErrClosed
}
n, err := receive6(
bind.sock6,
@@ -220,7 +220,7 @@ func (bind *nativeBind) ReceiveIPv4(buff []byte) (int, Endpoint, error) {
var end NativeEndpoint
if bind.sock4 == -1 {
- return 0, nil, syscall.EAFNOSUPPORT
+ return 0, nil, net.ErrClosed
}
n, err := receive4(
bind.sock4,
@@ -237,12 +237,12 @@ func (bind *nativeBind) Send(buff []byte, end Endpoint) error {
nend := end.(*NativeEndpoint)
if !nend.isV6 {
if bind.sock4 == -1 {
- return syscall.EAFNOSUPPORT
+ return net.ErrClosed
}
return send4(bind.sock4, nend, buff)
} else {
if bind.sock6 == -1 {
- return syscall.EAFNOSUPPORT
+ return net.ErrClosed
}
return send6(bind.sock6, nend, buff)
}
diff --git a/device/receive.go b/device/receive.go
index 0bd22bf..fa31a1a 100644
--- a/device/receive.go
+++ b/device/receive.go
@@ -8,6 +8,7 @@ package device
import (
"bytes"
"encoding/binary"
+ "errors"
"net"
"strconv"
"sync"
@@ -17,6 +18,7 @@ import (
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
+
"golang.zx2c4.com/wireguard/conn"
)
@@ -117,15 +119,13 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) {
buffer := device.GetMessageBuffer()
var (
- err error
- size int
- endpoint conn.Endpoint
+ err error
+ size int
+ endpoint conn.Endpoint
+ deathSpiral int
)
for {
-
- // read next datagram
-
switch IP {
case ipv4.Version:
size, endpoint, err = bind.ReceiveIPv4(buffer[:])
@@ -137,8 +137,18 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) {
if err != nil {
device.PutMessageBuffer(buffer)
+ if errors.Is(err, net.ErrClosed) {
+ return
+ }
+ device.log.Error.Printf("Failed to receive packet: %v", err)
+ if deathSpiral < 10 {
+ deathSpiral++
+ time.Sleep(time.Second / 3)
+ continue
+ }
return
}
+ deathSpiral = 0
if size < MinMessageSize {
continue
diff --git a/go.mod b/go.mod
index 1dbdb67..11b6c7f 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,9 @@
module golang.zx2c4.com/wireguard
-go 1.14
+go 1.16
require (
- golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392
- golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
- golang.org/x/sys v0.0.0-20201126233918-771906719818
+ golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
+ golang.org/x/net v0.0.0-20201224014010-6772e930b67b
+ golang.org/x/sys v0.0.0-20210105210732-16f7687f5001
)
diff --git a/go.sum b/go.sum
index 96e4ae0..a58d796 100644
--- a/go.sum
+++ b/go.sum
@@ -1,17 +1,16 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 h1:xYJJ3S178yv++9zXV/hnr29plCAGO9vAFG9dorqaFQc=
-golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
+golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
+golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
-golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
+golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20201126233918-771906719818 h1:f1CIuDlJhwANEC2MM87MBEVMr3jl5bifgsfj90XAF9c=
-golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210105210732-16f7687f5001 h1:/dSxr6gT0FNI1MO5WLJo8mTmItROeOKTkDn+7OwWBos=
+golang.org/x/sys v0.0.0-20210105210732-16f7687f5001/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=