]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: move stats fields back down and add test diagnostics
authorDavid Crawshaw <crawshaw@tailscale.com>
Tue, 7 Apr 2020 04:52:17 +0000 (14:52 +1000)
committerDavid Crawshaw <crawshaw@tailscale.com>
Tue, 7 Apr 2020 05:55:53 +0000 (15:55 +1000)
This reverts the movement of fields from d49f4e9.
That commit was cherry-picked from another branch where a field
had changed and misaligned the atomic fields. After cherry-picking,
moving the fields was no longer necessary but got dragged along.

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
device/peer.go
device/peer_test.go

index a96f2612a1a5544b19224a24626f06089ad8c6f4..cb348d516223586460cd4ddb84e98f414d774906 100644 (file)
@@ -21,6 +21,14 @@ const (
 )
 
 type Peer struct {
+       // Mostly protects endpoint, but is generally taken whenever we modify peer
+       sync.RWMutex
+       keypairs                    Keypairs
+       handshake                   Handshake
+       device                      *Device
+       endpoint                    conn.Endpoint
+       persistentKeepaliveInterval uint16
+
        // These fields are accessed with atomic operations, which must be
        // 64-bit aligned even on 32-bit platforms. Go guarantees that an
        // allocated struct will be 64-bit aligned. So we place
@@ -35,14 +43,6 @@ type Peer struct {
        // bits. Don't place other atomic fields after this one.
        isRunning AtomicBool
 
-       // Mostly protects endpoint, but is generally taken whenever we modify peer
-       sync.RWMutex
-       keypairs                    Keypairs
-       handshake                   Handshake
-       device                      *Device
-       endpoint                    conn.Endpoint
-       persistentKeepaliveInterval uint16
-
        timers struct {
                retransmitHandshake     *Timer
                sendKeepalive           *Timer
index de87ab6386257fd2347edfd4495c77f2eaf02c21..b389f1e9f28c00c07637200d8627b8de6aae02be 100644 (file)
@@ -6,6 +6,7 @@
 package device
 
 import (
+       "reflect"
        "testing"
        "unsafe"
 )
@@ -24,6 +25,19 @@ func checkAlignment(t *testing.T, name string, offset uintptr) {
 // hard segfault at runtime.
 func TestPeerAlignment(t *testing.T) {
        var p Peer
+
+       typ := reflect.TypeOf(p)
+       t.Logf("Peer type size: %d, with fields:", typ.Size())
+       for i := 0; i < typ.NumField(); i++ {
+               field := typ.Field(i)
+               t.Logf("\t%30s\toffset=%3v\t(type size=%3d, align=%d)",
+                       field.Name,
+                       field.Offset,
+                       field.Type.Size(),
+                       field.Type.Align(),
+               )
+       }
+
        checkAlignment(t, "Peer.stats", unsafe.Offsetof(p.stats))
        checkAlignment(t, "Peer.isRunning", unsafe.Offsetof(p.isRunning))
 }