Skip to content

Commit

Permalink
all: fix tests on dragonfly after ABI changes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tklauser committed Oct 21, 2019
1 parent da9a3fd commit 24d2ffb
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 7 deletions.
27 changes: 26 additions & 1 deletion internal/socket/sys_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,29 @@

package socket

func probeProtocolStack() int { return 4 }
import (
"sync"
"syscall"
"unsafe"
)

// See version list in https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/param.h
var (
osreldateOnce sync.Once
osreldate uint32
)

// First __DragonFly_version after September 2019 ABI changes
// http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html
const _dragonflyABIChangeVersion = 500705

func probeProtocolStack() int {
osreldateOnce.Do(func() { osreldate, _ = syscall.SysctlUint32("kern.osreldate") })
var p uintptr
if int(unsafe.Sizeof(p)) == 8 && osreldate >= _dragonflyABIChangeVersion {
return int(unsafe.Sizeof(p))
}
// 64-bit Dragonfly before the September 2019 ABI changes still requires
// 32-bit aligned access to network subsystem.
return 4
}
8 changes: 8 additions & 0 deletions ipv6/multicastlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
switch runtime.GOOS {
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
case "dragonfly":
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
}
if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
Expand Down Expand Up @@ -63,6 +65,8 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
switch runtime.GOOS {
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
case "dragonfly":
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
}
if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
Expand Down Expand Up @@ -118,6 +122,8 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
switch runtime.GOOS {
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
case "dragonfly":
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
}
if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
Expand Down Expand Up @@ -174,6 +180,8 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
switch runtime.GOOS {
case "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
case "dragonfly":
t.Skipf("skipping on %s until CL 202317 is vendored into std; see golang.org/issue/34368", runtime.GOOS)
}
if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
Expand Down
25 changes: 24 additions & 1 deletion route/defs_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ package route
#include <net/route.h>
#include <netinet/in.h>
struct ifa_msghdr_dfly4 {
u_short ifam_msglen;
u_char ifam_version;
u_char ifam_type;
int ifam_addrs;
int ifam_flags;
u_short ifam_index;
int ifam_metric;
};
struct ifa_msghdr_dfly58 {
u_short ifam_msglen;
u_char ifam_version;
u_char ifam_type;
u_short ifam_index;
int ifam_flags;
int ifam_addrs;
int ifam_addrflags;
int ifam_metric;
};
*/
import "C"

Expand Down Expand Up @@ -98,10 +119,12 @@ const (

const (
sizeofIfMsghdrDragonFlyBSD4 = C.sizeof_struct_if_msghdr
sizeofIfaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifa_msghdr
sizeofIfaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifa_msghdr_dfly4
sizeofIfmaMsghdrDragonFlyBSD4 = C.sizeof_struct_ifma_msghdr
sizeofIfAnnouncemsghdrDragonFlyBSD4 = C.sizeof_struct_if_announcemsghdr

sizeofIfaMsghdrDragonFlyBSD58 = C.sizeof_struct_ifa_msghdr_dfly58

sizeofRtMsghdrDragonFlyBSD4 = C.sizeof_struct_rt_msghdr
sizeofRtMetricsDragonFlyBSD4 = C.sizeof_struct_rt_metrics

Expand Down
2 changes: 1 addition & 1 deletion route/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
if len(b) < l {
return nil, errMessageTooShort
}
if b[2] != sysRTM_VERSION {
if b[2] != rtmVersion {
b = b[l:]
continue
}
Expand Down
2 changes: 1 addition & 1 deletion route/route_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (m *RouteMessage) marshal() ([]byte, error) {
b := make([]byte, l)
nativeEndian.PutUint16(b[:2], uint16(l))
if m.Version == 0 {
b[2] = sysRTM_VERSION
b[2] = rtmVersion
} else {
b[2] = byte(m.Version)
}
Expand Down
3 changes: 3 additions & 0 deletions route/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "unsafe"
var (
nativeEndian binaryByteOrder
kernelAlign int
rtmVersion byte
wireFormats map[int]*wireFormat
)

Expand All @@ -22,6 +23,8 @@ func init() {
} else {
nativeEndian = bigEndian
}
// might get overridden in probeRoutingStack
rtmVersion = sysRTM_VERSION
kernelAlign, wireFormats = probeRoutingStack()
}

Expand Down
14 changes: 13 additions & 1 deletion route/sys_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package route

import "unsafe"
import (
"syscall"
"unsafe"
)

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

Expand Down Expand Up @@ -56,6 +59,15 @@ func probeRoutingStack() (int, map[int]*wireFormat) {
ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
ifanm.parse = ifanm.parseInterfaceAnnounceMessage

rel, _ := syscall.SysctlUint32("kern.osreldate")
if rel >= 500705 {
// https://github.com/DragonFlyBSD/DragonFlyBSD/commit/43a373152df2d405c9940983e584e6a25e76632d
// but only the size of struct ifa_msghdr actually changed
rtmVersion = 7
ifam.bodyOff = sizeofIfaMsghdrDragonFlyBSD58
}

return int(unsafe.Sizeof(p)), map[int]*wireFormat{
sysRTM_ADD: rtm,
sysRTM_DELETE: rtm,
Expand Down
4 changes: 2 additions & 2 deletions route/zsys_dragonfly.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24d2ffb

Please sign in to comment.