Skip to content

Commit

Permalink
unix: add Connectx for darwin
Browse files Browse the repository at this point in the history
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 <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
database64128 authored and gopherbot committed Aug 20, 2024
1 parent a0c72ef commit 59665e5
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions unix/darwin_amd64_test.go

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

1 change: 1 addition & 0 deletions unix/darwin_arm64_test.go

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

1 change: 1 addition & 0 deletions unix/mkerrors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ ccflags="$@"
$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
$2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ ||
$2 ~ /^(CONNECT|SAE)_/ ||
$2 ~ /^FIORDCHK$/ ||
$2 ~ /^SIOC/ ||
$2 ~ /^TIOC/ ||
Expand Down
37 changes: 37 additions & 0 deletions unix/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,43 @@ func PthreadFchdir(fd int) (err error) {
return pthread_fchdir_np(fd)
}

// Connectx calls connectx(2) to initiate a connection on a socket.
//
// srcIf, srcAddr, and dstAddr are filled into a [SaEndpoints] struct and passed as the endpoints argument.
//
// - srcIf is the optional source interface index. 0 means unspecified.
// - srcAddr is the optional source address. nil means unspecified.
// - dstAddr is the destination address.
//
// On success, Connectx returns the number of bytes enqueued for transmission.
func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocID, flags uint32, iov []Iovec, connid *SaeConnID) (n uintptr, err error) {
endpoints := SaEndpoints{
Srcif: srcIf,
}

if srcAddr != nil {
addrp, addrlen, err := srcAddr.sockaddr()
if err != nil {
return 0, err
}
endpoints.Srcaddr = (*RawSockaddr)(addrp)
endpoints.Srcaddrlen = uint32(addrlen)
}

if dstAddr != nil {
addrp, addrlen, err := dstAddr.sockaddr()
if err != nil {
return 0, err
}
endpoints.Dstaddr = (*RawSockaddr)(addrp)
endpoints.Dstaddrlen = uint32(addrlen)
}

err = connectx(fd, &endpoints, associd, flags, iov, &n, connid)
return
}

//sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error)
//sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error)

//sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error)
Expand Down
6 changes: 6 additions & 0 deletions unix/types_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ type XVSockPgen C.struct_xvsockpgen

type _Socklen C.socklen_t

type SaeAssocID C.sae_associd_t

type SaeConnID C.sae_connid_t

type SaEndpoints C.struct_sa_endpoints

type Xucred C.struct_xucred

type Linger C.struct_linger
Expand Down
7 changes: 7 additions & 0 deletions unix/zerrors_darwin_amd64.go

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

7 changes: 7 additions & 0 deletions unix/zerrors_darwin_arm64.go

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

20 changes: 20 additions & 0 deletions unix/zsyscall_darwin_amd64.go

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

5 changes: 5 additions & 0 deletions unix/zsyscall_darwin_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)

TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
JMP libc_connectx(SB)
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)

TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
JMP libc_sendfile(SB)
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8
Expand Down
20 changes: 20 additions & 0 deletions unix/zsyscall_darwin_arm64.go

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

5 changes: 5 additions & 0 deletions unix/zsyscall_darwin_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)

TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
JMP libc_connectx(SB)
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)

TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
JMP libc_sendfile(SB)
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8
Expand Down
13 changes: 13 additions & 0 deletions unix/ztypes_darwin_amd64.go

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

13 changes: 13 additions & 0 deletions unix/ztypes_darwin_arm64.go

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

0 comments on commit 59665e5

Please sign in to comment.