diff --git a/Makefile b/Makefile index 91e6fce..aca5e54 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BUILD_NUMBER ?= dev+$(shell date -u '+%Y%m%d%H%M%S') GO111MODULE = on 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: 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-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 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 @@ -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/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/mips64le/ -f nebula-linux-mips64le.tar.gz nebula nebula-cert vet: go vet -v ./... diff --git a/udp_linux.go b/udp_linux.go index 593b896..2a1b0d0 100644 --- a/udp_linux.go +++ b/udp_linux.go @@ -63,25 +63,18 @@ func NewListener(ip string, port int, multi bool) (*udpConn, error) { if err != nil { syscall.Close(fd) - return nil, err + return nil, fmt.Errorf("unable to open socket: %s", err) } var lip [4]byte copy(lip[:], net.ParseIP(ip).To4()) - if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, 0x0F, 1); err != nil { - return nil, err + if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil { + return nil, fmt.Errorf("unable to set SO_REUSEPORT: %s", err) } if err = syscall.Bind(fd, &syscall.SockaddrInet4{Port: port}); err != nil { - return nil, 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 - } + return nil, fmt.Errorf("unable to bind to socket: %s", err) } //TODO: this may be useful for forcing threads into specific cores diff --git a/udp_linux_mips64le.go b/udp_linux_mips64le.go new file mode 100644 index 0000000..a61e0c8 --- /dev/null +++ b/udp_linux_mips64le.go @@ -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 +}