From 36d14fc7806c0bbdfebf0b169dd1361b9e0bed47 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 9 Aug 2021 22:44:15 +0200 Subject: embeddable-dll-service: use wgnt always Signed-off-by: Jason A. Donenfeld --- embeddable-dll-service/README.md | 2 +- embeddable-dll-service/csharp/README.md | 8 +------- embeddable-dll-service/main.go | 1 + tunnel/service.go | 8 +++++++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/embeddable-dll-service/README.md b/embeddable-dll-service/README.md index aeb80eba..9e05ab56 100644 --- a/embeddable-dll-service/README.md +++ b/embeddable-dll-service/README.md @@ -1,6 +1,6 @@ ## Embeddable WireGuard Tunnel Library -This allows embedding WireGuard as a service inside of another application. Build `tunnel.dll` by running `./build.bat` in this folder. The first time you run it, it will invoke `..\build.bat` simply for downloading dependencies. After, you should have `amd64/tunnel.dll`, `x86/tunnel.dll`, and `arm64/tunnel.dll`. In addition, `tunnel.dll` requires `wintun.dll`, which can be downloaded from [wintun.net](https://www.wintun.net), and `wireguard.dll`, which can be downloaded from [the wireguard-nt download server](https://download.wireguard.com/wireguard-nt/). +This allows embedding WireGuard as a service inside of another application. Build `tunnel.dll` by running `./build.bat` in this folder. The first time you run it, it will invoke `..\build.bat` simply for downloading dependencies. After, you should have `amd64/tunnel.dll`, `x86/tunnel.dll`, and `arm64/tunnel.dll`. In addition, `tunnel.dll` requires `wireguard.dll`, which can be downloaded from [the wireguard-nt download server](https://download.wireguard.com/wireguard-nt/). The basic setup to use `tunnel.dll` is: diff --git a/embeddable-dll-service/csharp/README.md b/embeddable-dll-service/csharp/README.md index 39542f3d..24b36563 100644 --- a/embeddable-dll-service/csharp/README.md +++ b/embeddable-dll-service/csharp/README.md @@ -4,10 +4,4 @@ This is a simple client for demo.wireguard.com, which brings up WireGuard tunnel ## Building -The code in this repository can be built in Visual Studio 2019 by opening the .sln and pressing build. However, it requires [`tunnel.dll` and its dependencies](../README.md) to be present in the run directory. That can be built by: - -```batch -> git clone https://git.zx2c4.com/wireguard-windows -> cd wireguard-windows\embeddable-dll-service -> .\build.bat -``` +The code in this repository can be built in Visual Studio 2019 by opening the .sln and pressing build. However, it requires [`tunnel.dll` and `wireguard.dll`](../README.md). diff --git a/embeddable-dll-service/main.go b/embeddable-dll-service/main.go index df63034e..ee2f0ce1 100644 --- a/embeddable-dll-service/main.go +++ b/embeddable-dll-service/main.go @@ -25,6 +25,7 @@ func WireGuardTunnelService(confFile16 *uint16) bool { confFile := windows.UTF16PtrToString(confFile16) conf.PresetRootDirectory(filepath.Dir(confFile)) tunnel.UseFixedGUIDInsteadOfDeterministic = true + tunnel.ForceImplementation = 1 err := tunnel.Run(confFile) if err != nil { log.Printf("Service run error: %v", err) diff --git a/tunnel/service.go b/tunnel/service.go index 14264193..fc3c0f07 100644 --- a/tunnel/service.go +++ b/tunnel/service.go @@ -34,6 +34,12 @@ type tunnelService struct { Path string } +// Escape hatch to let the embeddable-dll-service force an implementation. +// 0 - use the registry key +// 1 - use the kernel driver +// 2 - use wireguard-go +var ForceImplementation = 0 + func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (svcSpecificEC bool, exitCode uint32) { changes <- svc.Status{State: svc.StartPending} @@ -163,7 +169,7 @@ func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest, } log.Println("Creating network adapter") - if conf.AdminBool("ExperimentalKernelDriver") { + if ForceImplementation == 1 || (ForceImplementation == 0 && conf.AdminBool("ExperimentalKernelDriver")) { // Does an adapter with this name already exist? adapter, err = driver.DefaultPool.OpenAdapter(config.Name) if err == nil { -- cgit v1.2.3-59-g8ed1b