summaryrefslogtreecommitdiffhomepage
path: root/app/tools/libwg-go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-23 03:52:26 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-23 17:01:40 +0200
commit62dbeca7323e74d4e08a08a878f429ad0a050616 (patch)
tree75cd35a8fdd55f2890f02fd92c6b90c7e302f89d /app/tools/libwg-go
parenta533be82e8d889216bcc25b2aad35ca55f2822ff (diff)
libwg-go: use gopath
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/tools/libwg-go')
-rw-r--r--app/tools/libwg-go/.gitignore7
-rw-r--r--app/tools/libwg-go/Makefile11
-rw-r--r--app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go (renamed from app/tools/libwg-go/api-android.go)20
-rw-r--r--app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c (renamed from app/tools/libwg-go/jni.c)0
-rw-r--r--app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/tun/api-android.go31
5 files changed, 41 insertions, 28 deletions
diff --git a/app/tools/libwg-go/.gitignore b/app/tools/libwg-go/.gitignore
index 2a4c5348..c464c736 100644
--- a/app/tools/libwg-go/.gitignore
+++ b/app/tools/libwg-go/.gitignore
@@ -1,7 +1,2 @@
-go/
-*.go
-libwg-go.h
-jni.o
-gopath/
-goroot/
+src/
.gobuildversion
diff --git a/app/tools/libwg-go/Makefile b/app/tools/libwg-go/Makefile
index a7828e79..671ffa15 100644
--- a/app/tools/libwg-go/Makefile
+++ b/app/tools/libwg-go/Makefile
@@ -11,7 +11,6 @@ NDK_GO_ARCH_MAP_arm64 := arm64
NDK_GO_ARCH_MAP_mips := mipsx
NDK_GO_ARCH_MAP_mips64 := mips64x
-export GOPATH := $(CURDIR)/gopath
CLANG_FLAGS := --target=$(ANDROID_LLVM_TRIPLE) --gcc-toolchain=$(ANDROID_TOOLCHAIN_ROOT) --sysroot=$(ANDROID_SYSROOT)
export CGO_CFLAGS := $(CLANG_FLAGS) $(CFLAGS)
export CGO_LDFLAGS := $(CLANG_FLAGS) $(LDFLAGS)
@@ -48,12 +47,12 @@ endif
$(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
-$(DESTDIR)/libwg-go.so: $(FILES) api-android.go jni.c
+$(DESTDIR)/libwg-go.so: $(FILES) src/git.zx2c4.com/wireguard-go/api-android.go src/git.zx2c4.com/wireguard-go/tun/api-android.go src/git.zx2c4.com/wireguard-go/jni.c
find . -name '*.go' -type l -delete
find . -type d -empty -delete
- mkdir -p $(subst ../wireguard-go/,./,$(dir $(FILES)))
- $(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./,$(dir $(FILE))) $(FILE);)
+ mkdir -p $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILES)))
+ $(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILE))) $(FILE);)
patch -p1 -f -R -s --dry-run -d"$$(go env GOROOT)" < goruntime-boottime-over-monotonic.diff
- go get -v -d
- go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared
+ GOPATH=$(PWD) go get -v -d git.zx2c4.com/wireguard-go
+ GOPATH=$(PWD) go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared git.zx2c4.com/wireguard-go
go version > .gobuildversion
diff --git a/app/tools/libwg-go/api-android.go b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go
index faf718ab..24a0eaec 100644
--- a/app/tools/libwg-go/api-android.go
+++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go
@@ -10,8 +10,8 @@ package main
import "C"
import (
- "./rwcancel"
"bufio"
+ "git.zx2c4.com/wireguard-go/tun"
"golang.org/x/sys/unix"
"io/ioutil"
"log"
@@ -64,28 +64,16 @@ func wgTurnOn(ifnameRef string, tun_fd int32, settings string) int32 {
logger.Debug.Println("Debug log enabled")
- tun := &NativeTun{
- fd: os.NewFile(uintptr(tun_fd), "/dev/tun"),
- 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 {
- unix.Close(int(tun_fd))
- logger.Error.Println(err)
- return -1
- }
- name, err := tun.Name()
+ tun, name, err := tun.CreateTUNFromFD(int(tun_fd))
if err != nil {
unix.Close(int(tun_fd))
logger.Error.Println(err)
return -1
}
+
logger.Info.Println("Attaching to interface", name)
device := NewDevice(tun, logger)
+
logger.Debug.Println("Interface has MTU", device.tun.mtu)
bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard))
diff --git a/app/tools/libwg-go/jni.c b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c
index a0f3d0ba..a0f3d0ba 100644
--- a/app/tools/libwg-go/jni.c
+++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c
diff --git a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/tun/api-android.go b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/tun/api-android.go
new file mode 100644
index 00000000..3cb5753e
--- /dev/null
+++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/tun/api-android.go
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+package tun
+
+import (
+ "git.zx2c4.com/wireguard-go/rwcancel"
+ "os"
+)
+
+func CreateTUNFromFD(tun_fd int) (TUNDevice, string, error) {
+ tun := &nativeTun{
+ fd: os.NewFile(uintptr(tun_fd), "/dev/tun"),
+ events: make(chan TUNEvent, 5),
+ errors: make(chan error, 5),
+ nopi: true,
+ }
+ var err error
+ tun.fdCancel, err = rwcancel.NewRWCancel(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
+}