libwg-go: don't use submodule
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
c93e81c632
commit
49cc634678
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,6 +4,3 @@
|
|||||||
[submodule "app/tools/wireguard"]
|
[submodule "app/tools/wireguard"]
|
||||||
path = app/tools/wireguard
|
path = app/tools/wireguard
|
||||||
url = https://git.zx2c4.com/WireGuard
|
url = https://git.zx2c4.com/WireGuard
|
||||||
[submodule "app/tools/wireguard-go"]
|
|
||||||
path = app/tools/wireguard-go
|
|
||||||
url = https://git.zx2c4.com/wireguard-go
|
|
||||||
|
3
app/tools/libwg-go/.gitignore
vendored
3
app/tools/libwg-go/.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
build/
|
build/
|
||||||
.gobuildversion
|
|
@ -2,9 +2,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
|
# 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
|
BUILDDIR ?= $(CURDIR)/build
|
||||||
DESTDIR ?= $(CURDIR)/out
|
DESTDIR ?= $(CURDIR)/out
|
||||||
|
|
||||||
@ -43,23 +40,10 @@ $(GOROOT)/bin/go:
|
|||||||
curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || { rm -rf "$(GOROOT)"; exit 1; }
|
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; }
|
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
|
$(DESTDIR)/libwg-go.so: $(GOROOT)/bin/go
|
||||||
$(subst $(1),$(BUILDDIR)/,$(2)): $(2)
|
go get -tags linux || { chmod -fR +w "$(GOPATH)/pkg/mod"; rm -rf "$(GOPATH)/pkg/mod"; exit 1; }
|
||||||
@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; }
|
|
||||||
chmod -fR +w "$(GOPATH)/pkg/mod"
|
chmod -fR +w "$(GOPATH)/pkg/mod"
|
||||||
touch "$@"
|
go build -tags linux -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared
|
||||||
|
go version > $(BUILDDIR)/.gobuildversion
|
||||||
$(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
|
|
||||||
|
@ -12,6 +12,8 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
"golang.zx2c4.com/wireguard/device"
|
||||||
|
"golang.zx2c4.com/wireguard/ipc"
|
||||||
"golang.zx2c4.com/wireguard/tun"
|
"golang.zx2c4.com/wireguard/tun"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
@ -34,14 +36,14 @@ func (l AndroidLogger) Write(p []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TunnelHandle struct {
|
type TunnelHandle struct {
|
||||||
device *Device
|
device *device.Device
|
||||||
uapi net.Listener
|
uapi net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunnelHandles map[int32]TunnelHandle
|
var tunnelHandles map[int32]TunnelHandle
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
roamingDisabled = true
|
device.RoamingDisabled = true
|
||||||
tunnelHandles = make(map[int32]TunnelHandle)
|
tunnelHandles = make(map[int32]TunnelHandle)
|
||||||
signals := make(chan os.Signal)
|
signals := make(chan os.Signal)
|
||||||
signal.Notify(signals, unix.SIGUSR2)
|
signal.Notify(signals, unix.SIGUSR2)
|
||||||
@ -62,7 +64,7 @@ func init() {
|
|||||||
func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
|
func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
|
||||||
interfaceName := string([]byte(ifnameRef))
|
interfaceName := string([]byte(ifnameRef))
|
||||||
|
|
||||||
logger := &Logger{
|
logger := &device.Logger{
|
||||||
Debug: log.New(&AndroidLogger{level: C.ANDROID_LOG_DEBUG, interfaceName: interfaceName}, "", 0),
|
Debug: log.New(&AndroidLogger{level: C.ANDROID_LOG_DEBUG, interfaceName: interfaceName}, "", 0),
|
||||||
Info: log.New(&AndroidLogger{level: C.ANDROID_LOG_INFO, 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),
|
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")
|
logger.Debug.Println("Debug log enabled")
|
||||||
|
|
||||||
tun, name, err := tun.CreateTUNFromFD(int(tunFd))
|
tun, name, err := tun.CreateUnmonitoredTUNFromFD(int(tunFd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
unix.Close(int(tunFd))
|
unix.Close(int(tunFd))
|
||||||
logger.Error.Println(err)
|
logger.Error.Println(err)
|
||||||
@ -78,11 +80,9 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Attaching to interface", name)
|
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 := device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
|
||||||
|
|
||||||
setError := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
|
|
||||||
if setError != nil {
|
if setError != nil {
|
||||||
unix.Close(int(tunFd))
|
unix.Close(int(tunFd))
|
||||||
logger.Error.Println(setError)
|
logger.Error.Println(setError)
|
||||||
@ -91,11 +91,11 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
|
|||||||
|
|
||||||
var uapi net.Listener
|
var uapi net.Listener
|
||||||
|
|
||||||
uapiFile, err := UAPIOpen(name)
|
uapiFile, err := ipc.UAPIOpen(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error.Println(err)
|
logger.Error.Println(err)
|
||||||
} else {
|
} else {
|
||||||
uapi, err = UAPIListen(name, uapiFile)
|
uapi, err = ipc.UAPIListen(name, uapiFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
uapiFile.Close()
|
uapiFile.Close()
|
||||||
logger.Error.Println(err)
|
logger.Error.Println(err)
|
||||||
@ -106,7 +106,7 @@ func wgTurnOn(ifnameRef string, tunFd int32, settings string) int32 {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go ipcHandle(device, conn)
|
go device.IpcHandle(conn)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -148,22 +148,11 @@ func wgGetSocketV4(tunnelHandle int32) int32 {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
native, ok := handle.device.net.bind.(*NativeBind)
|
fd, err := handle.device.PeekLookAtSocketFd4()
|
||||||
if !ok {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
fd := int32(-1)
|
|
||||||
conn, err := native.ipv4.SyscallConn()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
err = conn.Control(func(f uintptr) {
|
return int32(fd)
|
||||||
fd = int32(f)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return fd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export wgGetSocketV6
|
//export wgGetSocketV6
|
||||||
@ -172,27 +161,16 @@ func wgGetSocketV6(tunnelHandle int32) int32 {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
native, ok := handle.device.net.bind.(*NativeBind)
|
fd, err := handle.device.PeekLookAtSocketFd6()
|
||||||
if !ok {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
fd := int32(-1)
|
|
||||||
conn, err := native.ipv6.SyscallConn()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
err = conn.Control(func(f uintptr) {
|
return int32(fd)
|
||||||
fd = int32(f)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return fd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export wgVersion
|
//export wgVersion
|
||||||
func wgVersion() *C.char {
|
func wgVersion() *C.char {
|
||||||
return C.CString(WireGuardGoVersion)
|
return C.CString(device.WireGuardGoVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {}
|
func main() {}
|
8
app/tools/libwg-go/go.mod
Normal file
8
app/tools/libwg-go/go.mod
Normal 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
11
app/tools/libwg-go/go.sum
Normal 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=
|
@ -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
|
|
||||||
)
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user