Skip to content

Commit e587491

Browse files
committed
linux: add tcp_cc_info and its related types
1 parent 30de352 commit e587491

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-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>
@@ -757,6 +758,14 @@ type Ucred C.struct_ucred
757758

758759
type TCPInfo C.struct_tcp_info
759760

761+
type tcpCCInfo C.union_tcp_cc_info // union of the three types below
762+
763+
type TCPVegasInfo C.struct_tcpvegas_info
764+
765+
type TCPDCTCPInfo C.struct_tcp_dctcp_info
766+
767+
type TCPBBRInfo C.struct_tcp_bbr_info
768+
760769
type CanFilter C.struct_can_filter
761770

762771
type ifreq C.struct_ifreq
@@ -798,6 +807,7 @@ const (
798807
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
799808
SizeofUcred = C.sizeof_struct_ucred
800809
SizeofTCPInfo = C.sizeof_struct_tcp_info
810+
SizeofTCPCCInfo = C.sizeof_union_tcp_cc_info
801811
SizeofCanFilter = C.sizeof_struct_can_filter
802812
SizeofTCPRepairOpt = C.sizeof_struct_tcp_repair_opt
803813
)

Diff for: unix/syscall_linux.go

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

1298+
// GetsockoptTCPCCVegasInfo returns algorithm specific congestion control information for a socket using the "vegas"
1299+
// algorithm.
1300+
//
1301+
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
1302+
//
1303+
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
1304+
func GetsockoptTCPCCVegasInfo(fd, level, opt int) (*TCPVegasInfo, error) {
1305+
var value tcpCCInfo
1306+
vallen := _Socklen(SizeofTCPCCInfo)
1307+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
1308+
out := (*TCPVegasInfo)(unsafe.Pointer(&value[0]))
1309+
return out, err
1310+
}
1311+
1312+
// GetsockoptTCPCCDCTCPInfo returns algorithm specific congestion control information for a socket using the "dctp"
1313+
// algorithm.
1314+
//
1315+
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
1316+
//
1317+
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
1318+
func GetsockoptTCPCCDCTCPInfo(fd, level, opt int) (*TCPDCTCPInfo, error) {
1319+
var value tcpCCInfo
1320+
vallen := _Socklen(SizeofTCPCCInfo)
1321+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
1322+
out := (*TCPDCTCPInfo)(unsafe.Pointer(&value[0]))
1323+
return out, err
1324+
}
1325+
1326+
// GetsockoptTCPCCBBRInfo returns algorithm specific congestion control information for a socket using the "bbr"
1327+
// algorithm.
1328+
//
1329+
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
1330+
//
1331+
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
1332+
func GetsockoptTCPCCBBRInfo(fd, level, opt int) (*TCPBBRInfo, error) {
1333+
var value tcpCCInfo
1334+
vallen := _Socklen(SizeofTCPCCInfo)
1335+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
1336+
out := (*TCPBBRInfo)(unsafe.Pointer(&value[0]))
1337+
return out, err
1338+
}
1339+
12981340
// GetsockoptString returns the string value of the socket option opt for the
12991341
// socket associated with fd at the given socket level.
13001342
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)