Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conn/bind_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (s *StdNetBind) receiveIP(
if runtime.GOOS == "linux" || runtime.GOOS == "android" {
if rxOffload {
readAt := len(*msgs) - (IdealBatchSize / udpSegmentMaxDatagrams)
numMsgs, err = br.ReadBatch((*msgs)[readAt:], 0)
_, err = br.ReadBatch((*msgs)[readAt:], 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here ReadBatch with zero flags (blocking mode) always reads up until msgs length so return value could be ignored.

if err != nil {
return 0, err
}
Expand Down
14 changes: 7 additions & 7 deletions conn/bind_std_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_coalesceMessages(t *testing.T) {
{
name: "one message no coalesce",
buffs: [][]byte{
make([]byte, 1, 1),
make([]byte, 1),
},
wantLens: []int{1},
wantGSO: []int{0},
Expand All @@ -51,7 +51,7 @@ func Test_coalesceMessages(t *testing.T) {
name: "two messages equal len coalesce",
buffs: [][]byte{
make([]byte, 1, 2),
make([]byte, 1, 1),
make([]byte, 1),
},
wantLens: []int{2},
wantGSO: []int{1},
Expand All @@ -60,7 +60,7 @@ func Test_coalesceMessages(t *testing.T) {
name: "two messages unequal len coalesce",
buffs: [][]byte{
make([]byte, 2, 3),
make([]byte, 1, 1),
make([]byte, 1),
},
wantLens: []int{3},
wantGSO: []int{2},
Expand All @@ -69,8 +69,8 @@ func Test_coalesceMessages(t *testing.T) {
name: "three messages second unequal len coalesce",
buffs: [][]byte{
make([]byte, 2, 3),
make([]byte, 1, 1),
make([]byte, 2, 2),
make([]byte, 1),
make([]byte, 2),
},
wantLens: []int{3, 2},
wantGSO: []int{2, 0},
Expand All @@ -79,8 +79,8 @@ func Test_coalesceMessages(t *testing.T) {
name: "three messages limited cap coalesce",
buffs: [][]byte{
make([]byte, 2, 4),
make([]byte, 2, 2),
make([]byte, 2, 2),
make([]byte, 2),
make([]byte, 2),
},
wantLens: []int{4, 2},
wantGSO: []int{2, 0},
Expand Down
7 changes: 4 additions & 3 deletions device/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ package device

import (
"bytes"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"math/rand"
mrand "math/rand/v2"
"net/netip"
"os"
"runtime"
Expand Down Expand Up @@ -224,11 +225,11 @@ func TestUpDown(t *testing.T) {
if err := d.Up(); err != nil {
t.Errorf("failed up bring up device: %v", err)
}
time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
time.Sleep(mrand.N(time.Nanosecond * (0x10000 - 1)))
if err := d.Down(); err != nil {
t.Errorf("failed to bring down device: %v", err)
}
time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
time.Sleep(mrand.N(time.Nanosecond * (0x10000 - 1)))
}
}(pair[i].dev)
}
Expand Down
2 changes: 1 addition & 1 deletion device/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package device

import (
"math/rand"
"crypto/rand"
"net/netip"
)

Expand Down
7 changes: 3 additions & 4 deletions device/noise-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ func (sk *NoisePrivateKey) publicKey() (pk NoisePublicKey) {
var errInvalidPublicKey = errors.New("invalid public key")

func (sk *NoisePrivateKey) sharedSecret(pk NoisePublicKey) (ss [NoisePublicKeySize]byte, err error) {
apk := (*[NoisePublicKeySize]byte)(&pk)
ask := (*[NoisePrivateKeySize]byte)(sk)
curve25519.ScalarMult(&ss, ask, apk)
if isZero(ss[:]) {
p, err := curve25519.X25519(sk[:], pk[:])
if err != nil {
return ss, errInvalidPublicKey
}
copy(ss[:], p)
return ss, nil
}
23 changes: 11 additions & 12 deletions device/noise-protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/poly1305"

"golang.zx2c4.com/wireguard/tai64n"
)
Expand Down Expand Up @@ -61,13 +60,13 @@ const (
)

const (
MessageInitiationSize = 148 // size of handshake initiation message
MessageResponseSize = 92 // size of response message
MessageCookieReplySize = 64 // size of cookie reply message
MessageTransportHeaderSize = 16 // size of data preceding content in transport message
MessageTransportSize = MessageTransportHeaderSize + poly1305.TagSize // size of empty transport
MessageKeepaliveSize = MessageTransportSize // size of keepalive
MessageHandshakeSize = MessageInitiationSize // size of largest handshake related message
MessageInitiationSize = 148 // size of handshake initiation message
MessageResponseSize = 92 // size of response message
MessageCookieReplySize = 64 // size of cookie reply message
MessageTransportHeaderSize = 16 // size of data preceding content in transport message
MessageTransportSize = MessageTransportHeaderSize + chacha20poly1305.Overhead // size of empty transport
MessageKeepaliveSize = MessageTransportSize // size of keepalive
MessageHandshakeSize = MessageInitiationSize // size of largest handshake related message
)

const (
Expand All @@ -86,8 +85,8 @@ type MessageInitiation struct {
Type uint32
Sender uint32
Ephemeral NoisePublicKey
Static [NoisePublicKeySize + poly1305.TagSize]byte
Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte
Static [NoisePublicKeySize + chacha20poly1305.Overhead]byte
Timestamp [tai64n.TimestampSize + chacha20poly1305.Overhead]byte
MAC1 [blake2s.Size128]byte
MAC2 [blake2s.Size128]byte
}
Expand All @@ -97,7 +96,7 @@ type MessageResponse struct {
Sender uint32
Receiver uint32
Ephemeral NoisePublicKey
Empty [poly1305.TagSize]byte
Empty [chacha20poly1305.Overhead]byte
MAC1 [blake2s.Size128]byte
MAC2 [blake2s.Size128]byte
}
Expand All @@ -113,7 +112,7 @@ type MessageCookieReply struct {
Type uint32
Receiver uint32
Nonce [chacha20poly1305.NonceSizeX]byte
Cookie [blake2s.Size128 + poly1305.TagSize]byte
Cookie [blake2s.Size128 + chacha20poly1305.Overhead]byte
}

var errMessageLengthMismatch = errors.New("message length mismatch")
Expand Down
2 changes: 1 addition & 1 deletion device/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive
return
}
device.log.Verbosef("Failed to receive %s packet: %v", recvName, err)
if neterr, ok := err.(net.Error); ok && !neterr.Temporary() {
if neterr, ok := err.(net.Error); ok && !neterr.Timeout() {
return
}
if deathSpiral < 10 {
Expand Down
2 changes: 1 addition & 1 deletion tun/tun_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if name != "utun" {
_, err := fmt.Sscanf(name, "utun%d", &ifIndex)
if err != nil || ifIndex < 0 {
return nil, fmt.Errorf("Interface name must be utun[0-9]*")
return nil, fmt.Errorf("interface name must be utun[0-9]*")
}
}

Expand Down