Skip to content

Commit 51b383f

Browse files
committed
forgot these little guys
1 parent 71c849e commit 51b383f

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

udp/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package udp
2+
3+
import "sync/atomic"
4+
5+
var disableUDPCsum atomic.Bool
6+
7+
// SetDisableUDPCsum controls whether IPv4 UDP sockets opt out of kernel
8+
// checksum calculation via SO_NO_CHECK. Only applicable on platforms that
9+
// support the option (Linux). IPv6 always keeps the checksum enabled.
10+
func SetDisableUDPCsum(disable bool) {
11+
disableUDPCsum.Store(disable)
12+
}
13+
14+
func udpChecksumDisabled() bool {
15+
return disableUDPCsum.Load()
16+
}

udp/msghdr_helper_linux_32.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build linux && (386 || amd64p32 || arm || mips || mipsle) && !android && !e2e_testing
2+
// +build linux
3+
// +build 386 amd64p32 arm mips mipsle
4+
// +build !android
5+
// +build !e2e_testing
6+
7+
package udp
8+
9+
import "golang.org/x/sys/unix"
10+
11+
func controllen(n int) uint32 {
12+
return uint32(n)
13+
}
14+
15+
func setCmsgLen(h *unix.Cmsghdr, n int) {
16+
h.Len = uint32(unix.CmsgLen(n))
17+
}
18+
19+
func setIovecLen(v *unix.Iovec, n int) {
20+
v.Len = uint32(n)
21+
}
22+
23+
func setMsghdrIovlen(m *unix.Msghdr, n int) {
24+
m.Iovlen = uint32(n)
25+
}

udp/msghdr_helper_linux_64.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build linux && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64 || loong64) && !android && !e2e_testing
2+
// +build linux
3+
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x riscv64 loong64
4+
// +build !android
5+
// +build !e2e_testing
6+
7+
package udp
8+
9+
import "golang.org/x/sys/unix"
10+
11+
func controllen(n int) uint64 {
12+
return uint64(n)
13+
}
14+
15+
func setCmsgLen(h *unix.Cmsghdr, n int) {
16+
h.Len = uint64(unix.CmsgLen(n))
17+
}
18+
19+
func setIovecLen(v *unix.Iovec, n int) {
20+
v.Len = uint64(n)
21+
}
22+
23+
func setMsghdrIovlen(m *unix.Msghdr, n int) {
24+
m.Iovlen = uint64(n)
25+
}

udp/sendmmsg_linux_32.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build linux && (386 || amd64p32 || arm || mips || mipsle) && !android && !e2e_testing
2+
3+
package udp
4+
5+
import (
6+
"unsafe"
7+
8+
"golang.org/x/sys/unix"
9+
)
10+
11+
type linuxMmsgHdr struct {
12+
Hdr unix.Msghdr
13+
Len uint32
14+
}
15+
16+
func sendmmsg(fd int, hdrs []linuxMmsgHdr, flags int) (int, error) {
17+
if len(hdrs) == 0 {
18+
return 0, nil
19+
}
20+
n, _, errno := unix.Syscall6(unix.SYS_SENDMMSG, uintptr(fd), uintptr(unsafe.Pointer(&hdrs[0])), uintptr(len(hdrs)), uintptr(flags), 0, 0)
21+
if errno != 0 {
22+
return int(n), errno
23+
}
24+
return int(n), nil
25+
}

udp/sendmmsg_linux_64.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build linux && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64 || loong64) && !android && !e2e_testing
2+
3+
package udp
4+
5+
import (
6+
"unsafe"
7+
8+
"golang.org/x/sys/unix"
9+
)
10+
11+
type linuxMmsgHdr struct {
12+
Hdr unix.Msghdr
13+
Len uint32
14+
_ uint32
15+
}
16+
17+
func sendmmsg(fd int, hdrs []linuxMmsgHdr, flags int) (int, error) {
18+
if len(hdrs) == 0 {
19+
return 0, nil
20+
}
21+
n, _, errno := unix.Syscall6(unix.SYS_SENDMMSG, uintptr(fd), uintptr(unsafe.Pointer(&hdrs[0])), uintptr(len(hdrs)), uintptr(flags), 0, 0)
22+
if errno != 0 {
23+
return int(n), errno
24+
}
25+
return int(n), nil
26+
}

0 commit comments

Comments
 (0)