2021-10-21 23:24:11 +02:00
|
|
|
//go:build linux && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64) && !android && !e2e_testing
|
2019-12-11 19:38:45 +01:00
|
|
|
// +build linux
|
2021-10-13 16:55:32 +02:00
|
|
|
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x riscv64
|
2020-06-30 20:48:58 +02:00
|
|
|
// +build !android
|
2021-03-26 15:46:30 +01:00
|
|
|
// +build !e2e_testing
|
2019-12-11 19:38:45 +01:00
|
|
|
|
2019-11-19 18:00:20 +01:00
|
|
|
package nebula
|
|
|
|
|
2021-03-19 02:37:24 +01:00
|
|
|
import (
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
2019-11-19 18:00:20 +01:00
|
|
|
|
|
|
|
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 *udpConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
|
|
|
|
msgs := make([]rawMessage, n)
|
|
|
|
buffers := make([][]byte, n)
|
|
|
|
names := make([][]byte, n)
|
|
|
|
|
|
|
|
for i := range msgs {
|
|
|
|
buffers[i] = make([]byte, mtu)
|
2021-03-19 02:37:24 +01:00
|
|
|
names[i] = make([]byte, unix.SizeofSockaddrInet6)
|
2019-11-19 18:00:20 +01:00
|
|
|
|
|
|
|
//TODO: this is still silly, no need for an array
|
|
|
|
vs := []iovec{
|
2021-03-19 02:37:24 +01:00
|
|
|
{Base: &buffers[i][0], Len: uint64(len(buffers[i]))},
|
2019-11-19 18:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
msgs[i].Hdr.Iov = &vs[0]
|
|
|
|
msgs[i].Hdr.Iovlen = uint64(len(vs))
|
|
|
|
|
2021-03-19 02:37:24 +01:00
|
|
|
msgs[i].Hdr.Name = &names[i][0]
|
2019-11-19 18:00:20 +01:00
|
|
|
msgs[i].Hdr.Namelen = uint32(len(names[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs, buffers, names
|
|
|
|
}
|