summaryrefslogtreecommitdiffhomepage
path: root/tun/tun_windows.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-08-29 18:00:44 +0200
committerSimon Rozman <simon@rozman.si>2019-08-29 18:00:44 +0200
commit69c26dc258958be54513bb1d8d8e489d61690e82 (patch)
treee94378ccfca4b094292e2e8c61decec2b154813d /tun/tun_windows.go
parente862131d3cf56a5db53722648c04051c064b22a8 (diff)
wintun: introduce adapter pools
This makes wintun package reusable for non-WireGuard applications. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/tun_windows.go')
-rw-r--r--tun/tun_windows.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index aa54ad5..c34204c 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -71,6 +71,8 @@ type NativeTun struct {
rate rateJuggler
}
+const WintunPool = wintun.Pool("WireGuard")
+
//go:linkname procyield runtime.procyield
func procyield(cycles uint32)
@@ -98,22 +100,20 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Dev
var wt *wintun.Wintun
// Does an interface with this name already exist?
- wt, err = wintun.GetInterface(ifname)
+ wt, err = WintunPool.GetInterface(ifname)
if err == nil {
// If so, we delete it, in case it has weird residual configuration.
_, err = wt.DeleteInterface()
if err != nil {
return nil, fmt.Errorf("Unable to delete already existing Wintun interface: %v", err)
}
- } else if err == windows.ERROR_ALREADY_EXISTS {
- return nil, fmt.Errorf("Foreign network interface with the same name exists")
}
- wt, _, err = wintun.CreateInterface(requestedGUID)
+ wt, _, err = WintunPool.CreateInterface(requestedGUID)
if err != nil {
return nil, fmt.Errorf("Unable to create Wintun interface: %v", err)
}
- err = wt.SetInterfaceName(ifname)
+ err = wt.SetInterfaceName(ifname, WintunPool)
if err != nil {
wt.DeleteInterface()
return nil, fmt.Errorf("Unable to set name of Wintun interface: %v", err)