summaryrefslogtreecommitdiffhomepage
path: root/app/tools
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-03 04:47:11 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-03 05:43:42 +0100
commit49cc63467812ed9946f4a98eb73658f2ce0b2aac (patch)
treeb6e1f54465e57ae0161fcd61a701d41c18902b09 /app/tools
parentc93e81c632d2be7faa53ad2803a61444710ae962 (diff)
libwg-go: don't use submodule
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/tools')
-rw-r--r--app/tools/libwg-go/.gitignore3
-rw-r--r--app/tools/libwg-go/Makefile26
-rw-r--r--app/tools/libwg-go/api-android.go (renamed from app/tools/libwg-go/src/api-android.go)54
-rw-r--r--app/tools/libwg-go/go.mod8
-rw-r--r--app/tools/libwg-go/go.sum11
-rw-r--r--app/tools/libwg-go/jni.c (renamed from app/tools/libwg-go/src/jni.c)0
-rw-r--r--app/tools/libwg-go/src/queueconstants.go16
-rw-r--r--app/tools/libwg-go/src/tun/api-android.go33
m---------app/tools/wireguard-go0
9 files changed, 41 insertions, 110 deletions
diff --git a/app/tools/libwg-go/.gitignore b/app/tools/libwg-go/.gitignore
index 1454fe8b..d1638636 100644
--- a/app/tools/libwg-go/.gitignore
+++ b/app/tools/libwg-go/.gitignore
@@ -1,2 +1 @@
-build/
-.gobuildversion
+build/ \ No newline at end of file
diff --git a/app/tools/libwg-go/Makefile b/app/tools/libwg-go/Makefile
index d07b313f..a72be5be 100644
--- a/app/tools/libwg-go/Makefile
+++ b/app/tools/libwg-go/Makefile
@@ -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")
-
-define copy-src-to-build
-$(subst $(1),$(BUILDDIR)/,$(2)): $(2)
- @mkdir -vp "$$(dir $$@)"
- @cp -vp "$$<" "$$@"
-$(BUILDDIR)/.prepared: $(subst $(1),$(BUILDDIR)/,$(2))
-endef
+$(shell test "$$(cat $(BUILDDIR)/.gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
-$(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
diff --git a/app/tools/libwg-go/src/api-android.go b/app/tools/libwg-go/api-android.go
index ddf175ab..7e951b9c 100644
--- a/app/tools/libwg-go/src/api-android.go
+++ b/app/tools/libwg-go/api-android.go
@@ -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()
- if err != nil {
- return -1
- }
- err = conn.Control(func(f uintptr) {
- fd = int32(f)
- })
+ fd, err := handle.device.PeekLookAtSocketFd4()
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()
- if err != nil {
- return -1
- }
- err = conn.Control(func(f uintptr) {
- fd = int32(f)
- })
+ fd, err := handle.device.PeekLookAtSocketFd6()
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() {}
diff --git a/app/tools/libwg-go/go.mod b/app/tools/libwg-go/go.mod
new file mode 100644
index 00000000..691fdf02
--- /dev/null
+++ b/app/tools/libwg-go/go.mod
@@ -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
+)
diff --git a/app/tools/libwg-go/go.sum b/app/tools/libwg-go/go.sum
new file mode 100644
index 00000000..e7cec709
--- /dev/null
+++ b/app/tools/libwg-go/go.sum
@@ -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=
diff --git a/app/tools/libwg-go/src/jni.c b/app/tools/libwg-go/jni.c
index f6229a49..f6229a49 100644
--- a/app/tools/libwg-go/src/jni.c
+++ b/app/tools/libwg-go/jni.c
diff --git a/app/tools/libwg-go/src/queueconstants.go b/app/tools/libwg-go/src/queueconstants.go
deleted file mode 100644
index dd11bf10..00000000
--- a/app/tools/libwg-go/src/queueconstants.go
+++ /dev/null
@@ -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
-)
diff --git a/app/tools/libwg-go/src/tun/api-android.go b/app/tools/libwg-go/src/tun/api-android.go
deleted file mode 100644
index 75e80c5a..00000000
--- a/app/tools/libwg-go/src/tun/api-android.go
+++ /dev/null
@@ -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
-}
diff --git a/app/tools/wireguard-go b/app/tools/wireguard-go
deleted file mode 160000
-Subproject 88ff67fb6f55456e46877b71aa5d33060468f95