]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: receive: do not exit immediately on transient UDP receive errors
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 8 Jan 2021 13:25:37 +0000 (14:25 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 8 Jan 2021 13:30:04 +0000 (14:30 +0100)
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>
conn/conn_linux.go
device/receive.go
go.mod
go.sum

index ef5c0bab38fa64fd1da3f5b2b76f98efb47ff74d..642ad7df9baa7f8b43a4c4441d774385e41fc627 100644 (file)
@@ -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)
        }
index 0bd22bff581f23b02a368a7e32f35707119d2e97..fa31a1aa927f623abc496b4ad903d972ff0e413b 100644 (file)
@@ -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 1dbdb677d410fa0defd1b511cbbf1d4ef30b8cd3..11b6c7f23db19d150a79dc49819ae17e60cc71d5 100644 (file)
--- 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 96e4ae0fdb14b74762e624532f08d4c24a1c788c..a58d796640af29276a1345d53c764019c433edc1 100644 (file)
--- 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=