From d7bc7508e57d6227646f6aa81e5393a41a904518 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 9 Feb 2021 15:30:32 +0100 Subject: [PATCH] device: fix alignment on 32-bit machines and test for it The test previously checked the offset within a substruct, not the offset within the allocated struct, so this adds the two together. It then fixes an alignment crash on 32-bit machines. Signed-off-by: Jason A. Donenfeld --- device/alignment_test.go | 3 +-- device/device.go | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/device/alignment_test.go b/device/alignment_test.go index 46baeb1..a918112 100644 --- a/device/alignment_test.go +++ b/device/alignment_test.go @@ -61,6 +61,5 @@ func TestDeviceAlignment(t *testing.T) { field.Type.Align(), ) } - - checkAlignment(t, "Device.rate.underLoadUntil", unsafe.Offsetof(d.rate.underLoadUntil)) + checkAlignment(t, "Device.rate.underLoadUntil", unsafe.Offsetof(d.rate)+unsafe.Offsetof(d.rate.underLoadUntil)) } diff --git a/device/device.go b/device/device.go index 895c9db..cb0c3ee 100644 --- a/device/device.go +++ b/device/device.go @@ -21,10 +21,6 @@ import ( ) type Device struct { - log *Logger - - // synchronized resources (locks acquired in order) - state struct { // state holds the device's state. It is accessed atomically. // Use the device.deviceState method to read it. @@ -64,8 +60,6 @@ type Device struct { keyMap map[NoisePublicKey]*Peer } - // unprotected / "self-synchronising resources" - allowedips AllowedIPs indexTable IndexTable cookieChecker CookieChecker @@ -94,6 +88,7 @@ type Device struct { ipcMutex sync.RWMutex closed chan struct{} + log *Logger } // deviceState represents the state of a Device.