Skip to content

Commit 146b70c

Browse files
wgotklauser
authored andcommitted
all: add support for zos/s390x
This adds net support for zos/s390x. These changes should not affect other platforms. Fixes golang/go#42130 Change-Id: Ia7faa29de76b7c5713120657b296106c2e27bfd2 Reviewed-on: https://go-review.googlesource.com/c/net/+/264028 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Trust: Tobias Klauser <tobias.klauser@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
1 parent be3efd7 commit 146b70c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+660
-59
lines changed

http2/server_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1189,10 +1189,9 @@ func TestServer_MaxQueuedControlFrames(t *testing.T) {
11891189
}
11901190

11911191
func TestServer_RejectsLargeFrames(t *testing.T) {
1192-
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
1192+
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" || runtime.GOOS == "zos" {
11931193
t.Skip("see golang.org/issue/13434, golang.org/issue/37321")
11941194
}
1195-
11961195
st := newServerTester(t, nil)
11971196
defer st.Close()
11981197
st.greet()

internal/socket/cmsghdr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos
66

77
package socket
88

internal/socket/cmsghdr_stub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!zos
66

77
package socket
88

internal/socket/cmsghdr_zos_s390x.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package socket
6+
7+
import "syscall"
8+
9+
func (h *cmsghdr) set(l, lvl, typ int) {
10+
h.Len = int32(l)
11+
h.Level = int32(lvl)
12+
h.Type = int32(typ)
13+
}
14+
15+
func controlHeaderLen() int {
16+
return syscall.CmsgLen(0)
17+
}
18+
19+
func controlMessageLen(dataLen int) int {
20+
return syscall.CmsgLen(dataLen)
21+
}
22+
23+
func controlMessageSpace(dataLen int) int {
24+
return syscall.CmsgSpace(dataLen)
25+
}

internal/socket/error_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos
66

77
package socket
88

internal/socket/iovec_64bit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// +build arm64 amd64 ppc64 ppc64le mips64 mips64le riscv64 s390x
6-
// +build aix darwin dragonfly freebsd linux netbsd openbsd
6+
// +build aix darwin dragonfly freebsd linux netbsd openbsd zos
77

88
package socket
99

internal/socket/iovec_stub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!zos
66

77
package socket
88

internal/socket/msghdr_stub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!zos
66

77
package socket
88

internal/socket/msghdr_zos_s390x.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build s390x
6+
// +build zos
7+
8+
package socket
9+
10+
import "unsafe"
11+
12+
func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
13+
for i := range vs {
14+
vs[i].set(bs[i])
15+
}
16+
if len(vs) > 0 {
17+
h.Iov = &vs[0]
18+
h.Iovlen = int32(len(vs))
19+
}
20+
if len(oob) > 0 {
21+
h.Control = (*byte)(unsafe.Pointer(&oob[0]))
22+
h.Controllen = uint32(len(oob))
23+
}
24+
if sa != nil {
25+
h.Name = (*byte)(unsafe.Pointer(&sa[0]))
26+
h.Namelen = uint32(len(sa))
27+
}
28+
}
29+
30+
func (h *msghdr) controllen() int {
31+
return int(h.Controllen)
32+
}
33+
34+
func (h *msghdr) flags() int {
35+
return int(h.Flags)
36+
}

internal/socket/rawconn_msg.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows zos
66

77
package socket
88

99
import (
1010
"os"
11+
"runtime"
1112
"syscall"
1213
)
1314

@@ -24,7 +25,7 @@ func (c *Conn) recvMsg(m *Message, flags int) error {
2425
var n int
2526
fn := func(s uintptr) bool {
2627
n, operr = recvmsg(s, &h, flags)
27-
if operr == syscall.EAGAIN {
28+
if operr == syscall.EAGAIN || (runtime.GOOS == "zos" && operr == syscall.EWOULDBLOCK) {
2829
return false
2930
}
3031
return true
@@ -61,7 +62,7 @@ func (c *Conn) sendMsg(m *Message, flags int) error {
6162
var n int
6263
fn := func(s uintptr) bool {
6364
n, operr = sendmsg(s, &h, flags)
64-
if operr == syscall.EAGAIN {
65+
if operr == syscall.EAGAIN || (runtime.GOOS == "zos" && operr == syscall.EWOULDBLOCK) {
6566
return false
6667
}
6768
return true

internal/socket/rawconn_nomsg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows,!zos
66

77
package socket
88

internal/socket/socket_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows zos
66

77
package socket_test
88

internal/socket/sys_const_zos.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build zos
6+
7+
package socket
8+
9+
import "syscall"
10+
11+
const (
12+
sysAF_UNSPEC = syscall.AF_UNSPEC
13+
sysAF_INET = syscall.AF_INET
14+
sysAF_INET6 = syscall.AF_INET6
15+
16+
sysSOCK_RAW = syscall.SOCK_RAW
17+
)

internal/socket/sys_posix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows zos
66

77
package socket
88

internal/socket/sys_stub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows,!zos
66

77
package socket
88

internal/socket/sys_zos_s390x.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package socket
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
func syscall_syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
13+
func syscall_syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
14+
15+
func probeProtocolStack() int {
16+
return 4 // sizeof(int) on GOOS=zos GOARCH=s390x
17+
}
18+
19+
func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
20+
l := uint32(len(b))
21+
_, _, errno := syscall_syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
22+
return int(l), errnoErr(errno)
23+
}
24+
25+
func setsockopt(s uintptr, level, name int, b []byte) error {
26+
_, _, errno := syscall_syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
27+
return errnoErr(errno)
28+
}
29+
30+
func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
31+
n, _, errno := syscall_syscall(syscall.SYS___RECVMSG_A, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
32+
return int(n), errnoErr(errno)
33+
}
34+
35+
func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
36+
n, _, errno := syscall_syscall(syscall.SYS___SENDMSG_A, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
37+
return int(n), errnoErr(errno)
38+
}

internal/socket/sys_zos_s390x.s

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include "textflag.h"
6+
7+
TEXT ·syscall_syscall(SB),NOSPLIT,$0
8+
JMP syscall·_syscall(SB)
9+
10+
TEXT ·syscall_syscall6(SB),NOSPLIT,$0
11+
JMP syscall·_syscall6(SB)

internal/socket/zsys_zos_s390x.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package socket
6+
7+
type iovec struct {
8+
Base *byte
9+
Len uint64
10+
}
11+
12+
type msghdr struct {
13+
Name *byte
14+
Iov *iovec
15+
Control *byte
16+
Flags int32
17+
Namelen uint32
18+
Iovlen int32
19+
Controllen uint32
20+
}
21+
22+
type cmsghdr struct {
23+
Len int32
24+
Level int32
25+
Type int32
26+
}
27+
28+
const (
29+
sizeofCmsghdr = 12
30+
sizeofSockaddrInet = 16
31+
sizeofSockaddrInet6 = 28
32+
)

ipv4/control_stub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows,!zos
66

77
package ipv4
88

ipv4/control_zos.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package ipv4
6+
7+
import (
8+
"net"
9+
"unsafe"
10+
11+
"golang.org/x/net/internal/iana"
12+
"golang.org/x/net/internal/socket"
13+
)
14+
15+
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
16+
m := socket.ControlMessage(b)
17+
m.MarshalHeader(iana.ProtocolIP, sysIP_PKTINFO, sizeofInetPktinfo)
18+
if cm != nil {
19+
pi := (*inetPktinfo)(unsafe.Pointer(&m.Data(sizeofInetPktinfo)[0]))
20+
if ip := cm.Src.To4(); ip != nil {
21+
copy(pi.Addr[:], ip)
22+
}
23+
if cm.IfIndex > 0 {
24+
pi.setIfindex(cm.IfIndex)
25+
}
26+
}
27+
return m.Next(sizeofInetPktinfo)
28+
}
29+
30+
func parsePacketInfo(cm *ControlMessage, b []byte) {
31+
pi := (*inetPktinfo)(unsafe.Pointer(&b[0]))
32+
cm.IfIndex = int(pi.Ifindex)
33+
if len(cm.Dst) < net.IPv4len {
34+
cm.Dst = make(net.IP, net.IPv4len)
35+
}
36+
copy(cm.Dst, pi.Addr[:])
37+
}
38+
39+
func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
40+
opt.Lock()
41+
defer opt.Unlock()
42+
if so, ok := sockOpts[ssoReceiveTTL]; ok && cf&FlagTTL != 0 {
43+
if err := so.SetInt(c, boolint(on)); err != nil {
44+
return err
45+
}
46+
if on {
47+
opt.set(FlagTTL)
48+
} else {
49+
opt.clear(FlagTTL)
50+
}
51+
}
52+
if so, ok := sockOpts[ssoPacketInfo]; ok {
53+
if cf&(FlagSrc|FlagDst|FlagInterface) != 0 {
54+
if err := so.SetInt(c, boolint(on)); err != nil {
55+
return err
56+
}
57+
if on {
58+
opt.set(cf & (FlagSrc | FlagDst | FlagInterface))
59+
} else {
60+
opt.clear(cf & (FlagSrc | FlagDst | FlagInterface))
61+
}
62+
}
63+
} else {
64+
if so, ok := sockOpts[ssoReceiveDst]; ok && cf&FlagDst != 0 {
65+
if err := so.SetInt(c, boolint(on)); err != nil {
66+
return err
67+
}
68+
if on {
69+
opt.set(FlagDst)
70+
} else {
71+
opt.clear(FlagDst)
72+
}
73+
}
74+
if so, ok := sockOpts[ssoReceiveInterface]; ok && cf&FlagInterface != 0 {
75+
if err := so.SetInt(c, boolint(on)); err != nil {
76+
return err
77+
}
78+
if on {
79+
opt.set(FlagInterface)
80+
} else {
81+
opt.clear(FlagInterface)
82+
}
83+
}
84+
}
85+
return nil
86+
}

0 commit comments

Comments
 (0)