summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go/tun.go
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/tools/libwg-go/tun.go')
-rw-r--r--tunnel/tools/libwg-go/tun.go27
1 files changed, 14 insertions, 13 deletions
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,
}