summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-12-30 00:40:23 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2022-03-18 22:07:58 +0100
commitea7ee9554957ad6b7ad025ec57234f906180db76 (patch)
treeb7f70bc02d56c44b2306572090472c536326008a
parent8b2011a825b71247f1933cfe2402655855f65b9e (diff)
tunnel: use local tun.go in libwg
-rw-r--r--tunnel/tools/libwg-go/api-android.go3
-rw-r--r--tunnel/tools/libwg-go/tun.go27
2 files changed, 15 insertions, 15 deletions
diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go
index 01608923..457359b7 100644
--- a/tunnel/tools/libwg-go/api-android.go
+++ b/tunnel/tools/libwg-go/api-android.go
@@ -24,7 +24,6 @@ import (
"golang.zx2c4.com/wireguard/conn"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
- "golang.zx2c4.com/wireguard/tun"
)
type AndroidLogger struct {
@@ -81,7 +80,7 @@ func wgTurnOn(interfaceName string, tunFd int32, settings string) int32 {
Errorf: AndroidLogger{level: C.ANDROID_LOG_ERROR, tag: tag}.Printf,
}
- tun, name, err := tun.CreateUnmonitoredTUNFromFD(int(tunFd))
+ tun, name, err := CreateUnmonitoredTUNFromFD(int(tunFd))
if err != nil {
unix.Close(int(tunFd))
logger.Errorf("CreateUnmonitoredTUNFromFD: %v", err)
diff --git a/tunnel/tools/libwg-go/tun.go b/tunnel/tools/libwg-go/tun.go
index 89b716d9..ec4664a5 100644
--- a/tunnel/tools/libwg-go/tun.go
+++ b/tunnel/tools/libwg-go/tun.go
@@ -3,7 +3,7 @@
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
*/
-package tun
+package main
/* Implementation of the TUN device interface for linux
*/
@@ -22,6 +22,7 @@ import (
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/rwcancel"
+ wgtun "golang.zx2c4.com/wireguard/tun"
)
const (
@@ -33,7 +34,7 @@ type NativeTun struct {
tunFile *os.File
index int32 // if index
errors chan error // async error handling
- events chan Event // device related events
+ events chan wgtun.Event // device related events
nopi bool // the device was passed IFF_NO_PI
netlinkSock int
netlinkCancel *rwcancel.RWCancel
@@ -77,14 +78,14 @@ func (tun *NativeTun) routineHackListener() {
if last != up {
// If the tunnel is up, it reports that write() is
// allowed but we provided invalid data.
- tun.events <- EventUp
+ tun.events <- wgtun.EventUp
last = up
}
case unix.EIO:
if last != down {
// If the tunnel is down, it reports that no I/O
// is possible, without checking our provided data.
- tun.events <- EventDown
+ tun.events <- wgtun.EventDown
last = down
}
default:
@@ -170,7 +171,7 @@ func (tun *NativeTun) routineNetlinkListener() {
}
if info.Flags&unix.IFF_RUNNING != 0 {
- tun.events <- EventUp
+ tun.events <- wgtun.EventUp
wasEverUp = true
}
@@ -179,11 +180,11 @@ func (tun *NativeTun) routineNetlinkListener() {
// This avoids a startup race with HackListener, which
// might detect Up before we have finished reporting Down.
if wasEverUp {
- tun.events <- EventDown
+ tun.events <- wgtun.EventDown
}
}
- tun.events <- EventMTUUpdate
+ tun.events <- wgtun.EventMTUUpdate
default:
remain = remain[hdr.Len:]
@@ -381,7 +382,7 @@ func (tun *NativeTun) Read(buf []byte, offset int) (n int, err error) {
return
}
-func (tun *NativeTun) Events() chan Event {
+func (tun *NativeTun) Events() chan wgtun.Event {
return tun.events
}
@@ -404,7 +405,7 @@ func (tun *NativeTun) Close() error {
return err2
}
-func CreateTUN(name string, mtu int) (Device, error) {
+func CreateTUN(name string, mtu int) (wgtun.Device, error) {
nfd, err := unix.Open(cloneDevicePath, os.O_RDWR, 0)
if err != nil {
if os.IsNotExist(err) {
@@ -446,10 +447,10 @@ func CreateTUN(name string, mtu int) (Device, error) {
return CreateTUNFromFile(fd, mtu)
}
-func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
+func CreateTUNFromFile(file *os.File, mtu int) (wgtun.Device, error) {
tun := &NativeTun{
tunFile: file,
- events: make(chan Event, 5),
+ events: make(chan wgtun.Event, 5),
errors: make(chan error, 5),
statusListenersShutdown: make(chan struct{}),
nopi: false,
@@ -490,7 +491,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
return tun, nil
}
-func CreateUnmonitoredTUNFromFD(fd int) (Device, string, error) {
+func CreateUnmonitoredTUNFromFD(fd int) (wgtun.Device, string, error) {
err := unix.SetNonblock(fd, true)
if err != nil {
return nil, "", err
@@ -498,7 +499,7 @@ func CreateUnmonitoredTUNFromFD(fd int) (Device, string, error) {
file := os.NewFile(uintptr(fd), "/dev/tun")
tun := &NativeTun{
tunFile: file,
- events: make(chan Event, 5),
+ events: make(chan wgtun.Event, 5),
errors: make(chan error, 5),
nopi: true,
}