]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: make customization of WintunPool and WintunGUID more obvious
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 22 Dec 2020 13:09:16 +0000 (14:09 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 22 Dec 2020 13:16:06 +0000 (14:16 +0100)
Persnickety consumers can now do:

    func init() {
        tun.WintunPool, _ = wintun.Pool("Flurp")
        tun.WintunStaticRequestedGUID, _ = windows.GUIDFromString("{5ae2716f-0b3e-4dc4-a8b5-48eba11a6e16}")
    }

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tun/tun_windows.go

index 238bee0545f373958647d11ee86bca08602e51f9..e66ae8eea4330b52f4af85a456a04679d8754751 100644 (file)
@@ -44,15 +44,8 @@ type NativeTun struct {
        readWait  windows.Handle
 }
 
-var WintunPool *wintun.Pool
-
-func init() {
-       var err error
-       WintunPool, err = wintun.MakePool("WireGuard")
-       if err != nil {
-               panic(fmt.Errorf("Failed to make pool: %w", err))
-       }
-}
+var WintunPool, _ = wintun.MakePool("WireGuard")
+var WintunStaticRequestedGUID *windows.GUID
 
 //go:linkname procyield runtime.procyield
 func procyield(cycles uint32)
@@ -65,7 +58,7 @@ func nanotime() int64
 // interface with the same name exist, it is reused.
 //
 func CreateTUN(ifname string, mtu int) (Device, error) {
-       return CreateTUNWithRequestedGUID(ifname, nil, mtu)
+       return CreateTUNWithRequestedGUID(ifname, WintunStaticRequestedGUID, mtu)
 }
 
 //