mirror of
https://github.com/slackhq/nebula.git
synced 2025-12-30 02:28:27 +01:00
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
//go:build linux && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64 || loong64) && !android && !e2e_testing
|
|
// +build linux
|
|
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x riscv64 loong64
|
|
// +build !android
|
|
// +build !e2e_testing
|
|
|
|
package udp
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
type iovec struct {
|
|
Base *byte
|
|
Len uint64
|
|
}
|
|
|
|
type msghdr struct {
|
|
Name *byte
|
|
Namelen uint32
|
|
Pad0 [4]byte
|
|
Iov *iovec
|
|
Iovlen uint64
|
|
Control *byte
|
|
Controllen uint64
|
|
Flags int32
|
|
Pad1 [4]byte
|
|
}
|
|
|
|
type rawMessage struct {
|
|
Hdr msghdr
|
|
Len uint32
|
|
Pad0 [4]byte
|
|
}
|
|
|
|
func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte, [][]byte) {
|
|
controlLen := int(u.controlLen.Load())
|
|
|
|
msgs := make([]rawMessage, n)
|
|
buffers := make([][]byte, n)
|
|
names := make([][]byte, n)
|
|
|
|
var controls [][]byte
|
|
if controlLen > 0 {
|
|
controls = make([][]byte, n)
|
|
}
|
|
|
|
for i := range msgs {
|
|
size := MTU
|
|
if defaultGROReadBufferSize > size {
|
|
size = defaultGROReadBufferSize
|
|
}
|
|
buffers[i] = make([]byte, size)
|
|
names[i] = make([]byte, unix.SizeofSockaddrInet6)
|
|
|
|
vs := []iovec{{Base: &buffers[i][0], Len: uint64(len(buffers[i]))}}
|
|
|
|
msgs[i].Hdr.Iov = &vs[0]
|
|
msgs[i].Hdr.Iovlen = uint64(len(vs))
|
|
|
|
msgs[i].Hdr.Name = &names[i][0]
|
|
msgs[i].Hdr.Namelen = uint32(len(names[i]))
|
|
|
|
if controlLen > 0 {
|
|
controls[i] = make([]byte, controlLen)
|
|
msgs[i].Hdr.Control = &controls[i][0]
|
|
msgs[i].Hdr.Controllen = controllen(len(controls[i]))
|
|
} else {
|
|
msgs[i].Hdr.Control = nil
|
|
msgs[i].Hdr.Controllen = controllen(0)
|
|
}
|
|
}
|
|
|
|
return msgs, buffers, names, controls
|
|
}
|