unix: add SetsockoptTCPMD5Sig on linux

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>
This commit is contained in:
Tobias Klauser
2023-03-02 17:30:46 +00:00
committed by Gopher Robot
parent a6bfb89d2f
commit 147085206c
17 changed files with 28 additions and 15 deletions
+9
View File
@@ -110,6 +110,15 @@ func main() {
icmpV6Regex := regexp.MustCompile(`type (ICMPv6Filter) struct {(\s+)X__icmp6_filt(\s+\S+\s+)}`) icmpV6Regex := regexp.MustCompile(`type (ICMPv6Filter) struct {(\s+)X__icmp6_filt(\s+\S+\s+)}`)
b = icmpV6Regex.ReplaceAll(b, []byte("type $1 struct {${2}Filt$3}")) 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 // If we have empty Ptrace structs, we should delete them. Only s390x emits
// nonempty Ptrace structs. // nonempty Ptrace structs.
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
+4
View File
@@ -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))) 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) // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
// KeyctlInt calls keyctl commands in which each argument is an int. // KeyctlInt calls keyctl commands in which each argument is an int.
+1 -1
View File
@@ -414,7 +414,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [122]int8 Data [122]byte
_ uint32 _ uint32
} }
+1 -1
View File
@@ -427,7 +427,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -405,7 +405,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [122]uint8 Data [122]byte
_ uint32 _ uint32
} }
+1 -1
View File
@@ -406,7 +406,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -407,7 +407,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -410,7 +410,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [122]int8 Data [122]byte
_ uint32 _ uint32
} }
+1 -1
View File
@@ -409,7 +409,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -409,7 +409,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -410,7 +410,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [122]int8 Data [122]byte
_ uint32 _ uint32
} }
+1 -1
View File
@@ -417,7 +417,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [122]uint8 Data [122]byte
_ uint32 _ uint32
} }
+1 -1
View File
@@ -416,7 +416,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]uint8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -416,7 +416,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]uint8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -434,7 +434,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]uint8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -429,7 +429,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }
+1 -1
View File
@@ -411,7 +411,7 @@ const (
type SockaddrStorage struct { type SockaddrStorage struct {
Family uint16 Family uint16
_ [118]int8 Data [118]byte
_ uint64 _ uint64
} }