Skip to content

Commit

Permalink
linux: add tcp_cc_info and its related types
Browse files Browse the repository at this point in the history
Add the ability to retrieve congestion control information from a socket via TCP_CC_INFO.

Fixes golang/go#68232

Change-Id: I2ea15928ec0e3192b670759bab4b659e62be553b
GitHub-Last-Rev: b8b8c44
GitHub-Pull-Request: #200
Reviewed-on: https://go-review.googlesource.com/c/sys/+/595676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
  • Loading branch information
costela authored and gopherbot committed Sep 17, 2024
1 parent d58f986 commit 48aad76
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
8 changes: 8 additions & 0 deletions unix/linux/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct termios2 {
#include <linux/if_pppox.h>
#include <linux/if_tun.h>
#include <linux/if_xdp.h>
#include <linux/inet_diag.h>
#include <linux/ipc.h>
#include <linux/kcm.h>
#include <linux/keyctl.h>
Expand Down Expand Up @@ -757,6 +758,12 @@ type Ucred C.struct_ucred

type TCPInfo C.struct_tcp_info

type TCPVegasInfo C.struct_tcpvegas_info

type TCPDCTCPInfo C.struct_tcp_dctcp_info

type TCPBBRInfo C.struct_tcp_bbr_info

type CanFilter C.struct_can_filter

type ifreq C.struct_ifreq
Expand Down Expand Up @@ -798,6 +805,7 @@ const (
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
SizeofUcred = C.sizeof_struct_ucred
SizeofTCPInfo = C.sizeof_struct_tcp_info
SizeofTCPCCInfo = C.sizeof_union_tcp_cc_info
SizeofCanFilter = C.sizeof_struct_can_filter
SizeofTCPRepairOpt = C.sizeof_struct_tcp_repair_opt
)
Expand Down
42 changes: 42 additions & 0 deletions unix/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,48 @@ func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) {
return &value, err
}

// GetsockoptTCPCCVegasInfo returns algorithm specific congestion control information for a socket using the "vegas"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCVegasInfo(fd, level, opt int) (*TCPVegasInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPVegasInfo)(unsafe.Pointer(&value[0]))
return out, err
}

// GetsockoptTCPCCDCTCPInfo returns algorithm specific congestion control information for a socket using the "dctp"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCDCTCPInfo(fd, level, opt int) (*TCPDCTCPInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPDCTCPInfo)(unsafe.Pointer(&value[0]))
return out, err
}

// GetsockoptTCPCCBBRInfo returns algorithm specific congestion control information for a socket using the "bbr"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCBBRInfo(fd, level, opt int) (*TCPBBRInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPBBRInfo)(unsafe.Pointer(&value[0]))
return out, err
}

// GetsockoptString returns the string value of the socket option opt for the
// socket associated with fd at the given socket level.
func GetsockoptString(fd, level, opt int) (string, error) {
Expand Down
24 changes: 24 additions & 0 deletions unix/ztypes_linux.go

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

0 comments on commit 48aad76

Please sign in to comment.