unix: add support for TCP_CONNECTION_INFO on macOS

x/sys provides support for accessing TCP_INFO on Linux but does
not provide support for accessing the equivalent (TCP_CONNECTION_INFO)
on macOS. This patch adds that functionality.

Fixes golang/go#53330

Change-Id: Ia1c1bf79a8bbb76f3ccfe58c61e1a82e08735152
Reviewed-on: https://go-review.googlesource.com/c/sys/+/411734
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Will Hawkins 2022-06-10 19:51:48 -04:00 коммит произвёл Gopher Robot
Родитель bf31f56cad
Коммит ff8c426e75
4 изменённых файлов: 133 добавлений и 69 удалений

Просмотреть файл

@ -393,6 +393,13 @@ func GetsockoptXucred(fd, level, opt int) (*Xucred, error) {
return x, err
}
func GetsockoptTCPConnectionInfo(fd, level, opt int) (*TCPConnectionInfo, error) {
var value TCPConnectionInfo
vallen := _Socklen(SizeofTCPConnectionInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
return &value, err
}
func SysctlKinfoProc(name string, args ...int) (*KinfoProc, error) {
mib, err := sysctlmib(name, args...)
if err != nil {

Просмотреть файл

@ -200,30 +200,33 @@ type IPv6MTUInfo C.struct_ip6_mtuinfo
type ICMPv6Filter C.struct_icmp6_filter
type TCPConnectionInfo C.struct_tcp_connection_info
const (
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
SizeofSockaddrCtl = C.sizeof_struct_sockaddr_ctl
SizeofSockaddrVM = C.sizeof_struct_sockaddr_vm
SizeofXvsockpcb = C.sizeof_struct_xvsockpcb
SizeofXSocket = C.sizeof_struct_xsocket
SizeofXSockbuf = C.sizeof_struct_xsockbuf
SizeofXVSockPgen = C.sizeof_struct_xvsockpgen
SizeofXucred = C.sizeof_struct_xucred
SizeofLinger = C.sizeof_struct_linger
SizeofIovec = C.sizeof_struct_iovec
SizeofIPMreq = C.sizeof_struct_ip_mreq
SizeofIPMreqn = C.sizeof_struct_ip_mreqn
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
SizeofMsghdr = C.sizeof_struct_msghdr
SizeofCmsghdr = C.sizeof_struct_cmsghdr
SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
SizeofSockaddrCtl = C.sizeof_struct_sockaddr_ctl
SizeofSockaddrVM = C.sizeof_struct_sockaddr_vm
SizeofXvsockpcb = C.sizeof_struct_xvsockpcb
SizeofXSocket = C.sizeof_struct_xsocket
SizeofXSockbuf = C.sizeof_struct_xsockbuf
SizeofXVSockPgen = C.sizeof_struct_xvsockpgen
SizeofXucred = C.sizeof_struct_xucred
SizeofLinger = C.sizeof_struct_linger
SizeofIovec = C.sizeof_struct_iovec
SizeofIPMreq = C.sizeof_struct_ip_mreq
SizeofIPMreqn = C.sizeof_struct_ip_mreqn
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
SizeofMsghdr = C.sizeof_struct_msghdr
SizeofCmsghdr = C.sizeof_struct_cmsghdr
SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
SizeofTCPConnectionInfo = C.sizeof_struct_tcp_connection_info
)
// Ptrace requests

Просмотреть файл

@ -366,30 +366,57 @@ type ICMPv6Filter struct {
Filt [8]uint32
}
type TCPConnectionInfo struct {
State uint8
Snd_wscale uint8
Rcv_wscale uint8
_ uint8
Options uint32
Flags uint32
Rto uint32
Maxseg uint32
Snd_ssthresh uint32
Snd_cwnd uint32
Snd_wnd uint32
Snd_sbbytes uint32
Rcv_wnd uint32
Rttcur uint32
Srtt uint32
Rttvar uint32
Txpackets uint64
Txbytes uint64
Txretransmitbytes uint64
Rxpackets uint64
Rxbytes uint64
Rxoutoforderbytes uint64
Txretransmitpackets uint64
}
const (
SizeofSockaddrInet4 = 0x10
SizeofSockaddrInet6 = 0x1c
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofSockaddrCtl = 0x20
SizeofSockaddrVM = 0xc
SizeofXvsockpcb = 0xa8
SizeofXSocket = 0x64
SizeofXSockbuf = 0x18
SizeofXVSockPgen = 0x20
SizeofXucred = 0x4c
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
SizeofIPMreqn = 0xc
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet4Pktinfo = 0xc
SizeofInet6Pktinfo = 0x14
SizeofIPv6MTUInfo = 0x20
SizeofICMPv6Filter = 0x20
SizeofSockaddrInet4 = 0x10
SizeofSockaddrInet6 = 0x1c
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofSockaddrCtl = 0x20
SizeofSockaddrVM = 0xc
SizeofXvsockpcb = 0xa8
SizeofXSocket = 0x64
SizeofXSockbuf = 0x18
SizeofXVSockPgen = 0x20
SizeofXucred = 0x4c
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
SizeofIPMreqn = 0xc
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet4Pktinfo = 0xc
SizeofInet6Pktinfo = 0x14
SizeofIPv6MTUInfo = 0x20
SizeofICMPv6Filter = 0x20
SizeofTCPConnectionInfo = 0x70
)
const (

Просмотреть файл

@ -366,30 +366,57 @@ type ICMPv6Filter struct {
Filt [8]uint32
}
type TCPConnectionInfo struct {
State uint8
Snd_wscale uint8
Rcv_wscale uint8
_ uint8
Options uint32
Flags uint32
Rto uint32
Maxseg uint32
Snd_ssthresh uint32
Snd_cwnd uint32
Snd_wnd uint32
Snd_sbbytes uint32
Rcv_wnd uint32
Rttcur uint32
Srtt uint32
Rttvar uint32
Txpackets uint64
Txbytes uint64
Txretransmitbytes uint64
Rxpackets uint64
Rxbytes uint64
Rxoutoforderbytes uint64
Txretransmitpackets uint64
}
const (
SizeofSockaddrInet4 = 0x10
SizeofSockaddrInet6 = 0x1c
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofSockaddrCtl = 0x20
SizeofSockaddrVM = 0xc
SizeofXvsockpcb = 0xa8
SizeofXSocket = 0x64
SizeofXSockbuf = 0x18
SizeofXVSockPgen = 0x20
SizeofXucred = 0x4c
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
SizeofIPMreqn = 0xc
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet4Pktinfo = 0xc
SizeofInet6Pktinfo = 0x14
SizeofIPv6MTUInfo = 0x20
SizeofICMPv6Filter = 0x20
SizeofSockaddrInet4 = 0x10
SizeofSockaddrInet6 = 0x1c
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofSockaddrCtl = 0x20
SizeofSockaddrVM = 0xc
SizeofXvsockpcb = 0xa8
SizeofXSocket = 0x64
SizeofXSockbuf = 0x18
SizeofXVSockPgen = 0x20
SizeofXucred = 0x4c
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
SizeofIPMreqn = 0xc
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet4Pktinfo = 0xc
SizeofInet6Pktinfo = 0x14
SizeofIPv6MTUInfo = 0x20
SizeofICMPv6Filter = 0x20
SizeofTCPConnectionInfo = 0x70
)
const (