summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-08-08 16:40:18 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-08-31 13:25:23 +0200
commit310126b10547f89f5b2ebea0fce07d59ec84d207 (patch)
tree612397c98f39c958d22b72b7e03603b103a7aa54
parent12f513d3267633b9e84a5a7add1405912fe40da6 (diff)
downloadmullvadvpn-310126b10547f89f5b2ebea0fce07d59ec84d207.tar.xz
mullvadvpn-310126b10547f89f5b2ebea0fce07d59ec84d207.zip
Remove Windows support from libwg
-rw-r--r--wireguard/libwg/README.md3
-rw-r--r--wireguard/libwg/go.mod2
-rw-r--r--wireguard/libwg/go.sum4
-rw-r--r--wireguard/libwg/interfacewatcher/interfacewatcher_windows.go123
-rw-r--r--wireguard/libwg/libwg_windows.go132
5 files changed, 0 insertions, 264 deletions
diff --git a/wireguard/libwg/README.md b/wireguard/libwg/README.md
index e5b96928f7..39ad48e3e0 100644
--- a/wireguard/libwg/README.md
+++ b/wireguard/libwg/README.md
@@ -7,7 +7,6 @@ It currently offers support for the following platforms:
- Linux
- macOS
- Android
-- Windows
# Organization
@@ -17,8 +16,6 @@ It currently offers support for the following platforms:
`libwg_android.go` has code specifically for Android.
-`libwg_windows.go` has code specifically for Windows.
-
# Usage
Call `wgTurnOn` to create and activate a tunnel. The prototype is different on different platforms, see the code for details.
diff --git a/wireguard/libwg/go.mod b/wireguard/libwg/go.mod
index 27f48a3d06..fb74c9beb8 100644
--- a/wireguard/libwg/go.mod
+++ b/wireguard/libwg/go.mod
@@ -5,11 +5,9 @@ go 1.18
require (
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478
- golang.zx2c4.com/wireguard/windows v0.5.3
)
require (
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
- golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
)
diff --git a/wireguard/libwg/go.sum b/wireguard/libwg/go.sum
index d1f125b01c..3907746df4 100644
--- a/wireguard/libwg/go.sum
+++ b/wireguard/libwg/go.sum
@@ -4,9 +4,5 @@ golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 h1:Ug9qvr1myri/zFN6xL17LSCBGFDnphBBhzmILHsM5TY=
-golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 h1:vDy//hdR+GnROE3OdYbQKt9rdtNdHkDtONvpRwmls/0=
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478/go.mod h1:bVQfyl2sCM/QIIGHpWbFGfHPuDvqnCNkT6MQLTCjO/U=
-golang.zx2c4.com/wireguard/windows v0.5.3 h1:On6j2Rpn3OEMXqBq00QEDC7bWSZrPIHKIus8eIuExIE=
-golang.zx2c4.com/wireguard/windows v0.5.3/go.mod h1:9TEe8TJmtwyQebdFwAkEWOPr3prrtqm+REGFifP60hI=
diff --git a/wireguard/libwg/interfacewatcher/interfacewatcher_windows.go b/wireguard/libwg/interfacewatcher/interfacewatcher_windows.go
deleted file mode 100644
index fcb53b8584..0000000000
--- a/wireguard/libwg/interfacewatcher/interfacewatcher_windows.go
+++ /dev/null
@@ -1,123 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- * Copyright (C) 2021 Mullvad VPN AB. All Rights Reserved.
- */
-
-package interfacewatcher
-
-import (
- "sync"
- "time"
-
- "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
-)
-
-type Event struct {
- Luid winipcfg.LUID
- Family winipcfg.AddressFamily
-}
-
-type interfaceWatcher struct {
- ready chan bool
- processingMutex sync.Mutex
- interfaceChangeCallback *winipcfg.InterfaceChangeCallback
- seenEvents []Event
- wantedEvents []Event
- expired bool
-}
-
-func NewWatcher() (*interfaceWatcher, error) {
- iw := &interfaceWatcher{
- ready: make(chan bool, 1),
- expired: false,
- }
- var err error
- iw.interfaceChangeCallback, err = winipcfg.RegisterInterfaceChangeCallback(func(notificationType winipcfg.MibNotificationType, iface *winipcfg.MibIPInterfaceRow) {
- if notificationType != winipcfg.MibAddInstance {
- return
- }
-
- iw.processingMutex.Lock()
- defer iw.processingMutex.Unlock()
-
- if iw.expired {
- return
- }
-
- iw.seenEvents = append(iw.seenEvents, Event{iface.InterfaceLUID, iface.Family})
-
- if len(iw.wantedEvents) != 0 {
- iw.evaluateEvents()
- }
- })
- if err != nil {
- return nil, err
- }
- return iw, nil
-}
-
-func (iw *interfaceWatcher) evaluateEvents() {
- matched := 0
-
- // This is n*n, but typically very few items in both slices :-)
- for _, wanted := range iw.wantedEvents {
- for _, seen := range iw.seenEvents {
- if seen == wanted {
- matched += 1
- break
- }
- }
- }
-
- if len(iw.wantedEvents) != matched {
- return
- }
-
- iw.expired = true
- iw.ready <- true
-}
-
-// You can only join() once after which the watcher becomes expired.
-func (iw *interfaceWatcher) Join(wantedEvents []Event, timeoutSeconds int) bool {
- {
- iw.processingMutex.Lock()
-
- if iw.expired || len(wantedEvents) == 0 {
- iw.processingMutex.Unlock()
- return false
- }
-
- iw.wantedEvents = wantedEvents
- iw.evaluateEvents()
-
- iw.processingMutex.Unlock()
- }
-
- result := false
-
- select {
- case <- iw.ready:
- result = true
- case <- time.After(time.Duration(timeoutSeconds) * time.Second):
- result = false
- }
-
- {
- iw.processingMutex.Lock()
-
- iw.wantedEvents = nil
- iw.expired = true
-
- iw.processingMutex.Unlock()
- }
-
- return result
-}
-
-func (iw *interfaceWatcher) Destroy() {
- if iw.interfaceChangeCallback != nil {
- iw.interfaceChangeCallback.Unregister()
- iw.interfaceChangeCallback = nil
- }
-}
diff --git a/wireguard/libwg/libwg_windows.go b/wireguard/libwg/libwg_windows.go
deleted file mode 100644
index a1dc4fd265..0000000000
--- a/wireguard/libwg/libwg_windows.go
+++ /dev/null
@@ -1,132 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0
- *
- * Copyright (C) 2017-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
- * Copyright (C) 2021 Mullvad VPN AB. All Rights Reserved.
- */
-
-package main
-
-// #include <stdlib.h>
-import "C"
-
-import (
- "bufio"
- "strings"
- "unsafe"
-
- "golang.org/x/sys/windows"
-
- "golang.zx2c4.com/wireguard/conn"
- "golang.zx2c4.com/wireguard/device"
- "golang.zx2c4.com/wireguard/tun"
-
- "github.com/mullvad/mullvadvpn-app/wireguard/libwg/logging"
- "github.com/mullvad/mullvadvpn-app/wireguard/libwg/tunnelcontainer"
-)
-
-// Redefined here because otherwise the compiler doesn't realize it's a type alias for a type that's safe to export.
-// Taken from the contained logging package.
-type LogSink = unsafe.Pointer
-type LogContext = unsafe.Pointer
-
-//export wgTurnOn
-func wgTurnOn(cIfaceName *C.char, mtu int, cSettings *C.char, cIfaceNameOut **C.char, cLuidOut *uint64, logSink LogSink, logContext LogContext) int32 {
- logger := logging.NewLogger(logSink, logContext)
- if cIfaceNameOut != nil {
- *cIfaceNameOut = nil
- }
-
- if cIfaceName == nil {
- logger.Errorf("cIfaceName is null\n")
- return ERROR_GENERAL_FAILURE
- }
-
- if cSettings == nil {
- logger.Errorf("cSettings is null\n")
- return ERROR_GENERAL_FAILURE
- }
-
- settings := C.GoString(cSettings)
- ifaceName := C.GoString(cIfaceName)
-
- // {AFE43773-E1F8-4EBB-8536-576AB86AFE9A}
- networkId := windows.GUID{0xafe43773, 0xe1f8, 0x4ebb, [8]byte{0x85, 0x36, 0x57, 0x6a, 0xb8, 0x6a, 0xfe, 0x9a}}
-
- tun.WintunTunnelType = "Mullvad"
-
- wintun, err := tun.CreateTUNWithRequestedGUID(ifaceName, &networkId, mtu)
- if err != nil {
- logger.Errorf("Failed to create tunnel\n")
- logger.Errorf("%s\n", err)
- return ERROR_INTERMITTENT_FAILURE
- }
-
- nativeTun := wintun.(*tun.NativeTun)
-
- actualInterfaceName, err := nativeTun.Name()
- if err != nil {
- nativeTun.Close()
- logger.Errorf("Failed to determine name of wintun adapter\n")
- return ERROR_GENERAL_FAILURE
- }
- if actualInterfaceName != ifaceName {
- // WireGuard picked a different name for the adapter than the one we expected.
- // This indicates there is already an adapter with the name we intended to use.
- logger.Verbosef("Failed to create adapter with specific name\n")
- }
-
- device := device.NewDevice(wintun, conn.NewDefaultBind(), logger)
-
- setError := device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
- if setError != nil {
- logger.Errorf("Failed to set device configuration\n")
- logger.Errorf("%s\n", setError)
- device.Close()
- return ERROR_GENERAL_FAILURE
- }
-
- device.Up()
-
- context := tunnelcontainer.Context{
- Device: device,
- Logger: logger,
- }
-
- handle, err := tunnels.Insert(context)
- if err != nil {
- logger.Errorf("%s\n", err)
- device.Close()
- return ERROR_GENERAL_FAILURE
- }
-
- if cIfaceNameOut != nil {
- *cIfaceNameOut = C.CString(actualInterfaceName)
- }
- if cLuidOut != nil {
- *cLuidOut = nativeTun.LUID()
- }
-
- return handle
-}
-
-//export wgRebindTunnelSocket
-func wgRebindTunnelSocket(family uint16, interfaceIndex uint32) {
- tunnels.ForEach(func(tunnel tunnelcontainer.Context) {
- blackhole := (interfaceIndex == 0)
- bind := tunnel.Device.Bind().(conn.BindSocketToInterface)
-
- if family == windows.AF_INET {
- tunnel.Logger.Verbosef("Binding v4 socket to interface %d (blackhole=%v)\n", interfaceIndex, blackhole)
- err := bind.BindSocketToInterface4(interfaceIndex, blackhole)
- if err != nil {
- tunnel.Logger.Verbosef("%s\n", err)
- }
- } else if family == windows.AF_INET6 {
- tunnel.Logger.Verbosef("Binding v6 socket to interface %d (blackhole=%v)\n", interfaceIndex, blackhole)
- err := bind.BindSocketToInterface6(interfaceIndex, blackhole)
- if err != nil {
- tunnel.Logger.Verbosef("%s\n", err)
- }
- }
- })
-}