Skip to content

Commit

Permalink
device: allow compiling with Go 1.15
Browse files Browse the repository at this point in the history
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 <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Jan 20, 2021
1 parent 86a58b5 commit 06f1482
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions conn/conn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down
13 changes: 13 additions & 0 deletions conn/net_err_closed.go
Original file line number Diff line number Diff line change
@@ -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 net.errClosed
var NetErrClosed error
2 changes: 1 addition & 1 deletion device/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 06f1482

Please sign in to comment.