Skip to content

Commit 59665e5

Browse files
database64128gopherbot
authored andcommitted
unix: add Connectx for darwin
connectx(2) can be used to initiate a connection with TCP Fast Open. Change-Id: I113ee4dede7df1c01e16a0c07fec2b384b266cb0 GitHub-Last-Rev: 31665b9 GitHub-Pull-Request: #215 Reviewed-on: https://go-review.googlesource.com/c/sys/+/606155 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
1 parent a0c72ef commit 59665e5

13 files changed

+136
-0
lines changed

unix/darwin_amd64_test.go

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

unix/darwin_arm64_test.go

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

unix/mkerrors.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ ccflags="$@"
552552
$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
553553
$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
554554
$2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ ||
555+
$2 ~ /^(CONNECT|SAE)_/ ||
555556
$2 ~ /^FIORDCHK$/ ||
556557
$2 ~ /^SIOC/ ||
557558
$2 ~ /^TIOC/ ||

unix/syscall_darwin.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,43 @@ func PthreadFchdir(fd int) (err error) {
566566
return pthread_fchdir_np(fd)
567567
}
568568

569+
// Connectx calls connectx(2) to initiate a connection on a socket.
570+
//
571+
// srcIf, srcAddr, and dstAddr are filled into a [SaEndpoints] struct and passed as the endpoints argument.
572+
//
573+
// - srcIf is the optional source interface index. 0 means unspecified.
574+
// - srcAddr is the optional source address. nil means unspecified.
575+
// - dstAddr is the destination address.
576+
//
577+
// On success, Connectx returns the number of bytes enqueued for transmission.
578+
func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocID, flags uint32, iov []Iovec, connid *SaeConnID) (n uintptr, err error) {
579+
endpoints := SaEndpoints{
580+
Srcif: srcIf,
581+
}
582+
583+
if srcAddr != nil {
584+
addrp, addrlen, err := srcAddr.sockaddr()
585+
if err != nil {
586+
return 0, err
587+
}
588+
endpoints.Srcaddr = (*RawSockaddr)(addrp)
589+
endpoints.Srcaddrlen = uint32(addrlen)
590+
}
591+
592+
if dstAddr != nil {
593+
addrp, addrlen, err := dstAddr.sockaddr()
594+
if err != nil {
595+
return 0, err
596+
}
597+
endpoints.Dstaddr = (*RawSockaddr)(addrp)
598+
endpoints.Dstaddrlen = uint32(addrlen)
599+
}
600+
601+
err = connectx(fd, &endpoints, associd, flags, iov, &n, connid)
602+
return
603+
}
604+
605+
//sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error)
569606
//sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error)
570607

571608
//sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error)

unix/types_darwin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ type XVSockPgen C.struct_xvsockpgen
177177

178178
type _Socklen C.socklen_t
179179

180+
type SaeAssocID C.sae_associd_t
181+
182+
type SaeConnID C.sae_connid_t
183+
184+
type SaEndpoints C.struct_sa_endpoints
185+
180186
type Xucred C.struct_xucred
181187

182188
type Linger C.struct_linger

unix/zerrors_darwin_amd64.go

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

unix/zerrors_darwin_arm64.go

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

unix/zsyscall_darwin_amd64.go

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

unix/zsyscall_darwin_amd64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
248248
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
249249
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)
250250

251+
TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
252+
JMP libc_connectx(SB)
253+
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
254+
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)
255+
251256
TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
252257
JMP libc_sendfile(SB)
253258
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8

unix/zsyscall_darwin_arm64.go

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

unix/zsyscall_darwin_arm64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
248248
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
249249
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)
250250

251+
TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
252+
JMP libc_connectx(SB)
253+
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
254+
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)
255+
251256
TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
252257
JMP libc_sendfile(SB)
253258
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8

unix/ztypes_darwin_amd64.go

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

unix/ztypes_darwin_arm64.go

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

0 commit comments

Comments
 (0)