Skip to content

Commit

Permalink
unix: add SetsockoptTCPMD5Sig on linux
Browse files Browse the repository at this point in the history
This allows to set the TCP MD5 signature (see
https://www.rfc-editor.org/rfc/rfc2385) using TCPMD5Sig introduced in CL
106656.

Also export the storage data field in SockaddrStorage and convert it to
a byte array so the address in TCPMD5Sig.Addr can be set from an net.IP
without conversion.

Change-Id: I6bccfab57c188fcef857a6a3c514c943ca00b670
Reviewed-on: https://go-review.googlesource.com/c/sys/+/472835
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
  • Loading branch information
tklauser authored and gopherbot committed Mar 2, 2023
1 parent a6bfb89 commit 1470852
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 15 deletions.
9 changes: 9 additions & 0 deletions unix/mkpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func main() {
icmpV6Regex := regexp.MustCompile(`type (ICMPv6Filter) struct {(\s+)X__icmp6_filt(\s+\S+\s+)}`)
b = icmpV6Regex.ReplaceAll(b, []byte("type $1 struct {${2}Filt$3}"))

// Intentionally export address storage field in SockaddrStorage convert it to [N]byte.
convertSockaddrStorageData := regexp.MustCompile(`(X__ss_padding)\s+\[(\d+)\]u?int8`)
sockaddrStorageType := regexp.MustCompile(`type SockaddrStorage struct {[^}]*}`)
sockaddrStorageStructs := sockaddrStorageType.FindAll(b, -1)
for _, s := range sockaddrStorageStructs {
newNames := convertSockaddrStorageData.ReplaceAll(s, []byte("Data [$2]byte"))
b = bytes.Replace(b, s, newNames, 1)
}

// If we have empty Ptrace structs, we should delete them. Only s390x emits
// nonempty Ptrace structs.
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
Expand Down
4 changes: 4 additions & 0 deletions unix/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,10 @@ func SetsockoptTCPRepairOpt(fd, level, opt int, o []TCPRepairOpt) (err error) {
return setsockopt(fd, level, opt, unsafe.Pointer(&o[0]), uintptr(SizeofTCPRepairOpt*len(o)))
}

func SetsockoptTCPMD5Sig(fd, level, opt int, s *TCPMD5Sig) error {
return setsockopt(fd, level, opt, unsafe.Pointer(s), unsafe.Sizeof(*s))
}

// Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)

// KeyctlInt calls keyctl commands in which each argument is an int.
Expand Down
2 changes: 1 addition & 1 deletion unix/ztypes_linux_386.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_amd64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_arm.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_arm64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_loong64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_mips.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_mips64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_mips64le.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_mipsle.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_ppc.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_ppc64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_ppc64le.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_riscv64.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_s390x.go

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

2 changes: 1 addition & 1 deletion unix/ztypes_linux_sparc64.go

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

0 comments on commit 1470852

Please sign in to comment.