Skip to content

Commit b444e23

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

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

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
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
)

unix/syscall_linux.go

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

1298+
type TCPCCAlgo interface {
1299+
TCPVegasInfo | TCPDCTCPInfo | TCPBBRInfo
1300+
}
1301+
1302+
func GetsockoptTCPCCInfo[T TCPCCAlgo](fd, level, opt int) (*T, error) {
1303+
var value TCPCCInfo
1304+
vallen := _Socklen(SizeofTCPCCInfo)
1305+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
1306+
out := (*T)(unsafe.Pointer(&value[0]))
1307+
return out, err
1308+
}
1309+
12981310
// GetsockoptString returns the string value of the socket option opt for the
12991311
// socket associated with fd at the given socket level.
13001312
func GetsockoptString(fd, level, opt int) (string, error) {

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)