Codebase list golang-golang-x-sys / bce67f0
unix: add SetsockoptTCPRepairOpt on Linux There is currently no function to allow for setting repair options for sockets in repair mode. There are 4 options catered for in the linux implementation. TCPOPT_WINDOW TCPOPT_MAXSEG TCPOPT_SACK_PERMITTED TCPOPT_TIMESTAMP Details of the patch to the kernel and the thinking behind it is here https://lwn.net/Articles/495304 Work done in this commit Included the tcp options type and length for inclusion in the Docker build Added TCPOPT to the regular expression in mkerrors.sh. There was only TCP_ previously Add the new function to syscall_unix.go I have tested locally and verified each option with ss -i I am not sure whether to commit tests because I don't know if socket creation is possible on the test runs in the offical pipeline. I did check for existing tests but didn't see any that created sockets, only one that validated a string option. Fixes golang/go#46984 Change-Id: Iade0434c05cebf2fbdfb5f04b2a7b51c8b358423 Reviewed-on: https://go-review.googlesource.com/c/sys/+/332709 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Mark Jeffery authored 2 years ago Tobias Klauser committed 2 years ago
5 changed file(s) with 25 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
636636
637637 type ifreq C.struct_ifreq
638638
639 type TCPRepairOpt C.struct_tcp_repair_opt
640
639641 const (
640642 SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
641643 SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
672674 SizeofUcred = C.sizeof_struct_ucred
673675 SizeofTCPInfo = C.sizeof_struct_tcp_info
674676 SizeofCanFilter = C.sizeof_struct_can_filter
677 SizeofTCPRepairOpt = C.sizeof_struct_tcp_repair_opt
675678 )
676679
677680 // Netlink routing and interface messages
499499 $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
500500 $2 ~ /^LO_(KEY|NAME)_SIZE$/ ||
501501 $2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ ||
502 $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL)_/ ||
502 $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT)_/ ||
503503 $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ ||
504504 $2 ~ /^NFC_.*_(MAX)?SIZE$/ ||
505505 $2 ~ /^RAW_PAYLOAD_/ ||
13521352
13531353 func SetsockoptTpacketReq3(fd, level, opt int, tp *TpacketReq3) error {
13541354 return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp))
1355 }
1356
1357 func SetsockoptTCPRepairOpt(fd, level, opt int, o []TCPRepairOpt) (err error) {
1358 if len(o) == 0 {
1359 return EINVAL
1360 }
1361 return setsockopt(fd, level, opt, unsafe.Pointer(&o[0]), uintptr(SizeofTCPRepairOpt*len(o)))
13551362 }
13561363
13571364 // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
25472547 TCOFLUSH = 0x1
25482548 TCOOFF = 0x0
25492549 TCOON = 0x1
2550 TCPOPT_EOL = 0x0
2551 TCPOPT_MAXSEG = 0x2
2552 TCPOPT_NOP = 0x1
2553 TCPOPT_SACK = 0x5
2554 TCPOPT_SACK_PERMITTED = 0x4
2555 TCPOPT_TIMESTAMP = 0x8
2556 TCPOPT_TSTAMP_HDR = 0x101080a
2557 TCPOPT_WINDOW = 0x3
25502558 TCP_CC_INFO = 0x1a
25512559 TCP_CM_INQ = 0x24
25522560 TCP_CONGESTION = 0xd
451451 Mask uint32
452452 }
453453
454 type TCPRepairOpt struct {
455 Code uint32
456 Val uint32
457 }
458
454459 const (
455460 SizeofSockaddrInet4 = 0x10
456461 SizeofSockaddrInet6 = 0x1c
483488 SizeofUcred = 0xc
484489 SizeofTCPInfo = 0x68
485490 SizeofCanFilter = 0x8
491 SizeofTCPRepairOpt = 0x8
486492 )
487493
488494 const (