libwg-go: don't use submodule

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-03-03 04:47:11 +01:00
parent c93e81c632
commit 49cc634678
10 changed files with 41 additions and 114 deletions

3
.gitmodules vendored
View File

@ -4,6 +4,3 @@
[submodule "app/tools/wireguard"]
path = app/tools/wireguard
url = https://git.zx2c4.com/WireGuard
[submodule "app/tools/wireguard-go"]
path = app/tools/wireguard-go
url = https://git.zx2c4.com/wireguard-go

View File

@ -1,2 +1 @@
build/
.gobuildversion
build/

View File

@ -2,9 +2,6 @@
#
# Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
UPSTREAM_FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)) ../wireguard-go/go.mod ../wireguard-go/go.sum
DOWNSTREAM_FILES := $(wildcard src/*.go) $(wildcard src/*.c) $(wildcard src/*/*.go)
BUILDDIR ?= $(CURDIR)/build
DESTDIR ?= $(CURDIR)/out
@ -43,23 +40,10 @@ $(GOROOT)/bin/go:
curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || { rm -rf "$(GOROOT)"; exit 1; }
patch -p1 -f -N -r- -d "$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
$(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
$(shell test "$$(cat $(BUILDDIR)/.gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
define copy-src-to-build
$(subst $(1),$(BUILDDIR)/,$(2)): $(2)
@mkdir -vp "$$(dir $$@)"
@cp -vp "$$<" "$$@"
$(BUILDDIR)/.prepared: $(subst $(1),$(BUILDDIR)/,$(2))
endef
$(foreach FILE,$(UPSTREAM_FILES),$(eval $(call copy-src-to-build,../wireguard-go/,$(FILE))))
$(foreach FILE,$(DOWNSTREAM_FILES),$(eval $(call copy-src-to-build,src/,$(FILE))))
$(BUILDDIR)/.prepared: $(GOROOT)/bin/go
cd "$(BUILDDIR)" && go get || { chmod -fR +w "$(GOPATH)/pkg/mod"; rm -rf "$(GOPATH)/pkg/mod"; exit 1; }
$(DESTDIR)/libwg-go.so: $(GOROOT)/bin/go
go get -tags linux || { chmod -fR +w "$(GOPATH)/pkg/mod"; rm -rf "$(GOPATH)/pkg/mod"; exit 1; }
chmod -fR +w "$(GOPATH)/pkg/mod"
touch "$@"
$(DESTDIR)/libwg-go.so: $(BUILDDIR)/.prepared
cd "$(BUILDDIR)" && go build -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared
go version > .gobuildversion
go build -tags linux -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared
go version > $(BUILDDIR)/.gobuildversion

View File

@ -12,6 +12,8 @@ import "C"
import (
"bufio"
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
"golang.zx2c4.com/wireguard/tun"
"log"
"math"
@ -34,14 +36,14 @@ func (l AndroidLogger) Write(p []byte) (int, error) {
}
type TunnelHandle struct {
device *Device
device *device.Device
uapi net.Listener
}
var tunnelHandles map[int32]TunnelHandle
func init() {
roamingDisabled = true
device.RoamingDisabled = true
tunnelHandles = make(map[int32]TunnelHandle)
signals := make(chan os.Signal)
signal.Notify(signals, unix.SIGUSR2)
@ -62,7 +64,7 @@ func init() {
func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
interfaceName := string([]byte(ifnameRef))
logger := &Logger{
logger := &device.Logger{
Debug: log.New(&AndroidLogger{level: C.ANDROID_LOG_DEBUG, interfaceName: interfaceName}, "", 0),
Info: log.New(&AndroidLogger{level: C.ANDROID_LOG_INFO, interfaceName: interfaceName}, "", 0),
Error: log.New(&AndroidLogger{level: C.ANDROID_LOG_ERROR, interfaceName: interfaceName}, "", 0),
@ -70,7 +72,7 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
logger.Debug.Println("Debug log enabled")
tun, name, err := tun.CreateTUNFromFD(int(tunFd))
tun, name, err := tun.CreateUnmonitoredTUNFromFD(int(tunFd))
if err != nil {
unix.Close(int(tunFd))
logger.Error.Println(err)
@ -78,11 +80,9 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
}
logger.Info.Println("Attaching to interface", name)
device := NewDevice(tun, logger)
device := device.NewDevice(tun, logger)
logger.Debug.Println("Interface has MTU", device.tun.mtu)
setError := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
setError := device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
if setError != nil {
unix.Close(int(tunFd))
logger.Error.Println(setError)
@ -91,11 +91,11 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
var uapi net.Listener
uapiFile, err := UAPIOpen(name)
uapiFile, err := ipc.UAPIOpen(name)
if err != nil {
logger.Error.Println(err)
} else {
uapi, err = UAPIListen(name, uapiFile)
uapi, err = ipc.UAPIListen(name, uapiFile)
if err != nil {
uapiFile.Close()
logger.Error.Println(err)
@ -106,7 +106,7 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
if err != nil {
return
}
go ipcHandle(device, conn)
go device.IpcHandle(conn)
}
}()
}
@ -148,22 +148,11 @@ func wgGetSocketV4(tunnelHandle int32) int32 {
if !ok {
return -1
}
native, ok := handle.device.net.bind.(*NativeBind)
if !ok {
return -1
}
fd := int32(-1)
conn, err := native.ipv4.SyscallConn()
fd, err := handle.device.PeekLookAtSocketFd4()
if err != nil {
return -1
}
err = conn.Control(func(f uintptr) {
fd = int32(f)
})
if err != nil {
return -1
}
return fd
return int32(fd)
}
//export wgGetSocketV6
@ -172,27 +161,16 @@ func wgGetSocketV6(tunnelHandle int32) int32 {
if !ok {
return -1
}
native, ok := handle.device.net.bind.(*NativeBind)
if !ok {
return -1
}
fd := int32(-1)
conn, err := native.ipv6.SyscallConn()
fd, err := handle.device.PeekLookAtSocketFd6()
if err != nil {
return -1
}
err = conn.Control(func(f uintptr) {
fd = int32(f)
})
if err != nil {
return -1
}
return fd
return int32(fd)
}
//export wgVersion
func wgVersion() *C.char {
return C.CString(WireGuardGoVersion)
return C.CString(device.WireGuardGoVersion)
}
func main() {}

View File

@ -0,0 +1,8 @@
module golang.zx2c4.com/wireguard/android
go 1.12
require (
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10
golang.zx2c4.com/wireguard v0.0.0-20190303043202-244a98e380fa
)

11
app/tools/libwg-go/go.sum Normal file
View File

@ -0,0 +1,11 @@
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 h1:fY7Dsw114eJN4boqzVSbpVHO6rTdhq6/GnXeu+PKnzU=
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 h1:xQJI9OEiErEQ++DoXOHqEpzsGMrAv2Q2jyCpi7DmfpQ=
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.zx2c4.com/wireguard v0.0.0-20190303042013-27104279d88d/go.mod h1:Koyxt99ZAZcr8lJuisBNX9vnaqKVNGcITeWOI1Zkmsw=
golang.zx2c4.com/wireguard v0.0.0-20190303043202-244a98e380fa h1:t/IV/5G9uPXXDoaOrk+Lx2VsFhbqWGYFE+GEl160Yzc=
golang.zx2c4.com/wireguard v0.0.0-20190303043202-244a98e380fa/go.mod h1:Koyxt99ZAZcr8lJuisBNX9vnaqKVNGcITeWOI1Zkmsw=

View File

@ -1,16 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
*/
package main
/* Reduce memory consumption for Android */
const (
QueueOutboundSize = 1024
QueueInboundSize = 1024
QueueHandshakeSize = 1024
MaxSegmentSize = 2200
PreallocatedBuffersPerPool = 4096
)

View File

@ -1,33 +0,0 @@
/* SPDX-License-Identifier: Apache-2.0
*
* Copyright (C) 2017-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
package tun
import (
"golang.zx2c4.com/wireguard/rwcancel"
"os"
)
func CreateTUNFromFD(tunFd int) (TUNDevice, string, error) {
file := os.NewFile(uintptr(tunFd), "/dev/tun")
tun := &nativeTun{
tunFile: file,
fd: file.Fd(),
events: make(chan TUNEvent, 5),
errors: make(chan error, 5),
nopi: true,
}
var err error
tun.fdCancel, err = rwcancel.NewRWCancel(int(tun.fd))
if err != nil {
return nil, "", err
}
name, err := tun.Name()
if err != nil {
tun.fdCancel.Cancel()
return nil, "", err
}
return tun, name, nil
}

@ -1 +0,0 @@
Subproject commit 88ff67fb6f55456e46877b71aa5d33060468f95e