From 294d3bedf959c9c496aaa877919a762acf07c684 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 20 Jan 2021 20:04:31 +0100 Subject: [PATCH] device: allow compiling with Go 1.15 Until we depend on Go 1.16 (which isn't released yet), alias our own variable to the private member of the net package. This will allow an easy find replace to make this go away when we eventually switch to 1.16. Signed-off-by: Jason A. Donenfeld --- conn/conn_linux.go | 8 ++++---- conn/net_err_closed.go | 13 +++++++++++++ device/receive.go | 2 +- go.mod | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 conn/net_err_closed.go diff --git a/conn/conn_linux.go b/conn/conn_linux.go index 642ad7d..c32ee0d 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, net.ErrClosed + return 0, nil, NetErrClosed } 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, net.ErrClosed + return 0, nil, NetErrClosed } 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 net.ErrClosed + return NetErrClosed } return send4(bind.sock4, nend, buff) } else { if bind.sock6 == -1 { - return net.ErrClosed + return NetErrClosed } return send6(bind.sock6, nend, buff) } diff --git a/conn/net_err_closed.go b/conn/net_err_closed.go new file mode 100644 index 0000000..e4dcfae --- /dev/null +++ b/conn/net_err_closed.go @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2021 WireGuard LLC. All Rights Reserved. + */ + +package conn + +import _ "unsafe" + +//TODO: replace this with net.ErrClosed for Go 1.16 + +//go:linkname NetErrClosed internal/poll.ErrNetClosing +var NetErrClosed error diff --git a/device/receive.go b/device/receive.go index 701e308..605303e 100644 --- a/device/receive.go +++ b/device/receive.go @@ -112,7 +112,7 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) { if err != nil { device.PutMessageBuffer(buffer) - if errors.Is(err, net.ErrClosed) { + if errors.Is(err, conn.NetErrClosed) { return } device.log.Error.Printf("Failed to receive packet: %v", err) diff --git a/go.mod b/go.mod index 7b2c60f..10c0163 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module golang.zx2c4.com/wireguard -go 1.16 +go 1.15 require ( golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad