Remove magic numbers, support mips64le

This commit is contained in:
Nate Brown 2019-11-22 15:22:31 -08:00
parent e94caa9e58
commit ec63d0d285
3 changed files with 61 additions and 12 deletions

View File

@ -3,7 +3,7 @@ BUILD_NUMBER ?= dev+$(shell date -u '+%Y%m%d%H%M%S')
GO111MODULE = on GO111MODULE = on
export GO111MODULE export GO111MODULE
all: bin-linux bin-arm bin-arm6 bin-arm64 bin-darwin bin-windows bin-mips64 all: bin-linux bin-arm bin-arm6 bin-arm64 bin-darwin bin-windows bin-mips64 bin-mips64le
bin: bin:
go build -ldflags "-X main.Build=$(BUILD_NUMBER)" -o ./nebula ${NEBULA_CMD_PATH} go build -ldflags "-X main.Build=$(BUILD_NUMBER)" -o ./nebula ${NEBULA_CMD_PATH}
@ -52,6 +52,11 @@ bin-mips64:
GOARCH=mips64 GOOS=linux go build -o build/mips64/nebula -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula GOARCH=mips64 GOOS=linux go build -o build/mips64/nebula -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula
GOARCH=mips64 GOOS=linux go build -o build/mips64/nebula-cert -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula-cert GOARCH=mips64 GOOS=linux go build -o build/mips64/nebula-cert -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula-cert
bin-mips64le:
mkdir -p build/mips64le
GOARCH=mips64le GOOS=linux go build -o build/mips64le/nebula -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula
GOARCH=mips64le GOOS=linux go build -o build/mips64le/nebula-cert -ldflags "-X main.Build=$(BUILD_NUMBER)" ./cmd/nebula-cert
release: all release: all
tar -zcv -C build/arm/ -f nebula-linux-arm.tar.gz nebula nebula-cert tar -zcv -C build/arm/ -f nebula-linux-arm.tar.gz nebula nebula-cert
tar -zcv -C build/arm6/ -f nebula-linux-arm6.tar.gz nebula nebula-cert tar -zcv -C build/arm6/ -f nebula-linux-arm6.tar.gz nebula nebula-cert
@ -60,6 +65,7 @@ release: all
tar -zcv -C build/windows/ -f nebula-windows-amd64.tar.gz nebula.exe nebula-cert.exe tar -zcv -C build/windows/ -f nebula-windows-amd64.tar.gz nebula.exe nebula-cert.exe
tar -zcv -C build/linux/ -f nebula-linux-amd64.tar.gz nebula nebula-cert tar -zcv -C build/linux/ -f nebula-linux-amd64.tar.gz nebula nebula-cert
tar -zcv -C build/mips64/ -f nebula-linux-mips64.tar.gz nebula nebula-cert tar -zcv -C build/mips64/ -f nebula-linux-mips64.tar.gz nebula nebula-cert
tar -zcv -C build/mips64le/ -f nebula-linux-mips64le.tar.gz nebula nebula-cert
vet: vet:
go vet -v ./... go vet -v ./...

View File

@ -63,25 +63,18 @@ func NewListener(ip string, port int, multi bool) (*udpConn, error) {
if err != nil { if err != nil {
syscall.Close(fd) syscall.Close(fd)
return nil, err return nil, fmt.Errorf("unable to open socket: %s", err)
} }
var lip [4]byte var lip [4]byte
copy(lip[:], net.ParseIP(ip).To4()) copy(lip[:], net.ParseIP(ip).To4())
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, 0x0F, 1); err != nil { if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return nil, err return nil, fmt.Errorf("unable to set SO_REUSEPORT: %s", err)
} }
if err = syscall.Bind(fd, &syscall.SockaddrInet4{Port: port}); err != nil { if err = syscall.Bind(fd, &syscall.SockaddrInet4{Port: port}); err != nil {
return nil, err return nil, fmt.Errorf("unable to bind to socket: %s", err)
}
// SO_REUSEADDR does not load balance so we use PORT
if multi {
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return nil, err
}
} }
//TODO: this may be useful for forcing threads into specific cores //TODO: this may be useful for forcing threads into specific cores

50
udp_linux_mips64le.go Normal file
View File

@ -0,0 +1,50 @@
package nebula
import "unsafe"
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)
names[i] = make([]byte, 0x1c) //TODO = sizeofSockaddrInet6
//TODO: this is still silly, no need for an array
vs := []iovec{
{Base: (*byte)(unsafe.Pointer(&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 = (*byte)(unsafe.Pointer(&names[i][0]))
msgs[i].Hdr.Namelen = uint32(len(names[i]))
}
return msgs, buffers, names
}