Skip to content

Commit 24d2ffb

Browse files
committed
all: fix tests on dragonfly after ABI changes
Detect the ABI version based on kern.osreldate. Only use 32-bit cmsg alignment for versions before the September 2019 ABI changes: http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html Use RTM_VERSION 7 on Dragonfly master (5.8 release). Determine sizeof struct ifa_msghdr at runtime based on the ABI version. Temporarily skip some test relying on the net package which will only be fixed once this CL is re-vendored into std. Updates golang/go#34368 Change-Id: I732fab21d569b303f45dfb6a0bbbb11469511a07 Reviewed-on: https://go-review.googlesource.com/c/net/+/202317 Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent da9a3fd commit 24d2ffb

8 files changed

+78
-7
lines changed

internal/socket/sys_dragonfly.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,29 @@
44

55
package socket
66

7-
func probeProtocolStack() int { return 4 }
7+
import (
8+
"sync"
9+
"syscall"
10+
"unsafe"
11+
)
12+
13+
// See version list in https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/param.h
14+
var (
15+
osreldateOnce sync.Once
16+
osreldate uint32
17+
)
18+
19+
// First __DragonFly_version after September 2019 ABI changes
20+
// http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html
21+
const _dragonflyABIChangeVersion = 500705
22+
23+
func probeProtocolStack() int {
24+
osreldateOnce.Do(func() { osreldate, _ = syscall.SysctlUint32("kern.osreldate") })
25+
var p uintptr
26+
if int(unsafe.Sizeof(p)) == 8 && osreldate >= _dragonflyABIChangeVersion {
27+
return int(unsafe.Sizeof(p))
28+
}
29+
// 64-bit Dragonfly before the September 2019 ABI changes still requires
30+
// 32-bit aligned access to network subsystem.
31+
return 4
32+
}

ipv6/multicastlistener_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
2323
switch runtime.GOOS {
2424
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
2525
t.Skipf("not supported on %s", runtime.GOOS)
26+
case "dragonfly":
27+
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
2628
}
2729
if !nettest.SupportsIPv6() {
2830
t.Skip("ipv6 is not supported")
@@ -63,6 +65,8 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
6365
switch runtime.GOOS {
6466
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
6567
t.Skipf("not supported on %s", runtime.GOOS)
68+
case "dragonfly":
69+
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
6670
}
6771
if !nettest.SupportsIPv6() {
6872
t.Skip("ipv6 is not supported")
@@ -118,6 +122,8 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
118122
switch runtime.GOOS {
119123
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
120124
t.Skipf("not supported on %s", runtime.GOOS)
125+
case "dragonfly":
126+
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
121127
}
122128
if !nettest.SupportsIPv6() {
123129
t.Skip("ipv6 is not supported")
@@ -174,6 +180,8 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
174180
switch runtime.GOOS {
175181
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
176182
t.Skipf("not supported on %s", runtime.GOOS)
183+
case "dragonfly":
184+
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
177185
}
178186
if !nettest.SupportsIPv6() {
179187
t.Skip("ipv6 is not supported")

route/defs_dragonfly.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ package route
1515
#include <net/route.h>
1616
1717
#include <netinet/in.h>
18+
19+
struct ifa_msghdr_dfly4 {
20+
u_short ifam_msglen;
21+
u_char ifam_version;
22+
u_char ifam_type;
23+
int ifam_addrs;
24+
int ifam_flags;
25+
u_short ifam_index;
26+
int ifam_metric;
27+
};
28+
29+
struct ifa_msghdr_dfly58 {
30+
u_short ifam_msglen;
31+
u_char ifam_version;
32+
u_char ifam_type;
33+
u_short ifam_index;
34+
int ifam_flags;
35+
int ifam_addrs;
36+
int ifam_addrflags;
37+
int ifam_metric;
38+
};
1839
*/
1940
import "C"
2041

@@ -98,10 +119,12 @@ const (
98119

99120
const (
100121
sizeofIfMsghdrDragonFlyBSD4 = C.sizeof_struct_if_msghdr
101-
sizeofIfaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifa_msghdr
122+
sizeofIfaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifa_msghdr_dfly4
102123
sizeofIfmaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifma_msghdr
103124
sizeofIfAnnouncemsghdrDragonFlyBSD4 = C.sizeof_struct_if_announcemsghdr
104125

126+
sizeofIfaMsghdrDragonFlyBSD58 = C.sizeof_struct_ifa_msghdr_dfly58
127+
105128
sizeofRtMsghdrDragonFlyBSD4 = C.sizeof_struct_rt_msghdr
106129
sizeofRtMetricsDragonFlyBSD4 = C.sizeof_struct_rt_metrics
107130

route/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
4545
if len(b) < l {
4646
return nil, errMessageTooShort
4747
}
48-
if b[2] != sysRTM_VERSION {
48+
if b[2] != rtmVersion {
4949
b = b[l:]
5050
continue
5151
}

route/route_classic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (m *RouteMessage) marshal() ([]byte, error) {
2525
b := make([]byte, l)
2626
nativeEndian.PutUint16(b[:2], uint16(l))
2727
if m.Version == 0 {
28-
b[2] = sysRTM_VERSION
28+
b[2] = rtmVersion
2929
} else {
3030
b[2] = byte(m.Version)
3131
}

route/sys.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "unsafe"
1111
var (
1212
nativeEndian binaryByteOrder
1313
kernelAlign int
14+
rtmVersion byte
1415
wireFormats map[int]*wireFormat
1516
)
1617

@@ -22,6 +23,8 @@ func init() {
2223
} else {
2324
nativeEndian = bigEndian
2425
}
26+
// might get overridden in probeRoutingStack
27+
rtmVersion = sysRTM_VERSION
2528
kernelAlign, wireFormats = probeRoutingStack()
2629
}
2730

route/sys_dragonfly.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package route
66

7-
import "unsafe"
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
811

912
func (typ RIBType) parseable() bool { return true }
1013

@@ -56,6 +59,15 @@ func probeRoutingStack() (int, map[int]*wireFormat) {
5659
ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
5760
ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
5861
ifanm.parse = ifanm.parseInterfaceAnnounceMessage
62+
63+
rel, _ := syscall.SysctlUint32("kern.osreldate")
64+
if rel >= 500705 {
65+
// https://github.com/DragonFlyBSD/DragonFlyBSD/commit/43a373152df2d405c9940983e584e6a25e76632d
66+
// but only the size of struct ifa_msghdr actually changed
67+
rtmVersion = 7
68+
ifam.bodyOff = sizeofIfaMsghdrDragonFlyBSD58
69+
}
70+
5971
return int(unsafe.Sizeof(p)), map[int]*wireFormat{
6072
sysRTM_ADD: rtm,
6173
sysRTM_DELETE: rtm,

route/zsys_dragonfly.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)