libwg-go: use gopath
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
a533be82e8
commit
62dbeca732
7
app/tools/libwg-go/.gitignore
vendored
7
app/tools/libwg-go/.gitignore
vendored
@ -1,7 +1,2 @@
|
||||
go/
|
||||
*.go
|
||||
libwg-go.h
|
||||
jni.o
|
||||
gopath/
|
||||
goroot/
|
||||
src/
|
||||
.gobuildversion
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
tun, name, err := tun.CreateTUNFromFD(int(tun_fd))
|
||||
if err != nil {
|
||||
unix.Close(int(tun_fd))
|
||||
logger.Error.Println(err)
|
||||
return -1
|
||||
}
|
||||
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()
|
||||
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))
|
@ -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
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit d67d89c7f9d83d22d750452236b0e16510ab1368
|
||||
Subproject commit 6977826c2c9840f79dc2ac6b4206a5f393e9dfb4
|
@ -1 +1 @@
|
||||
Subproject commit 65a74f3175855dc41b49332103ada6bb27733291
|
||||
Subproject commit 0b647d1ca7e079f3bb2fe95c3ca7c05898315a6e
|
Loading…
Reference in New Issue
Block a user