Skip to content

Commit 9bee0b8

Browse files
committed
linux: add tcp_cc_info and its related types
1 parent daa2394 commit 9bee0b8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Diff for: unix/linux/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct termios2 {
112112
#include <linux/if_pppox.h>
113113
#include <linux/if_tun.h>
114114
#include <linux/if_xdp.h>
115+
#include <linux/inet_diag.h>
115116
#include <linux/ipc.h>
116117
#include <linux/kcm.h>
117118
#include <linux/keyctl.h>
@@ -724,6 +725,14 @@ type Ucred C.struct_ucred
724725

725726
type TCPInfo C.struct_tcp_info
726727

728+
type tcpCCInfo C.union_tcp_cc_info // union of the three types below
729+
730+
type TCPVegasInfo C.struct_tcpvegas_info
731+
732+
type TCPDCTCPInfo C.struct_tcp_dctcp_info
733+
734+
type TCPBBRInfo C.struct_tcp_bbr_info
735+
727736
type CanFilter C.struct_can_filter
728737

729738
type ifreq C.struct_ifreq
@@ -765,6 +774,7 @@ const (
765774
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
766775
SizeofUcred = C.sizeof_struct_ucred
767776
SizeofTCPInfo = C.sizeof_struct_tcp_info
777+
SizeofTCPCCInfo = C.sizeof_union_tcp_cc_info
768778
SizeofCanFilter = C.sizeof_struct_can_filter
769779
SizeofTCPRepairOpt = C.sizeof_struct_tcp_repair_opt
770780
)

Diff for: unix/syscall_linux.go

+14
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,20 @@ func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) {
12951295
return &value, err
12961296
}
12971297

1298+
// GetsockoptTCPCCInfo returns algorithm specific congestion control information for the socket.
1299+
// It requires a type parameter to specify the type of congestion control algorithm being used. E.g. for BBR:
1300+
//
1301+
// info, err := unix.GetsockoptTCPCCInfo[TCPBBRInfo](fd, unix.IPPROTO_TCP, unix.TCP_CC_INFO)
1302+
//
1303+
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option.
1304+
func GetsockoptTCPCCInfo[T TCPVegasInfo | TCPDCTCPInfo | TCPBBRInfo](fd, level, opt int) (*T, error) {
1305+
var value tcpCCInfo
1306+
vallen := _Socklen(SizeofTCPCCInfo)
1307+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
1308+
out := (*T)(unsafe.Pointer(&value[0]))
1309+
return out, err
1310+
}
1311+
12981312
// GetsockoptString returns the string value of the socket option opt for the
12991313
// socket associated with fd at the given socket level.
13001314
func GetsockoptString(fd, level, opt int) (string, error) {

Diff for: unix/ztypes_linux.go

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)