diff options
author | Simon Rozman <simon@rozman.si> | 2020-07-22 09:15:49 +0200 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2020-11-07 12:46:35 +0100 |
commit | 3e08b8aee0f6ae038f6316ca1bb84e5214db318f (patch) | |
tree | 34681cb00b6b22bded95e0df6ed271de18983646 /tun/tun_windows.go | |
parent | 5ca1218a5c16fb9b5e99b61c0b5758f66087e2e4 (diff) |
wintun: migrate to wintun.dll API
Rather than having every application using Wintun driver reinvent the
wheel, the Wintun device/adapter/interface management has been moved
from wireguard-go to wintun.dll deployed with Wintun itself.
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/tun_windows.go')
-rw-r--r-- | tun/tun_windows.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 5a52c56..684d6f0 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -33,7 +33,7 @@ type rateJuggler struct { } type NativeTun struct { - wt *wintun.Interface + wt *wintun.Adapter handle windows.Handle close bool events chan Event @@ -44,7 +44,15 @@ type NativeTun struct { writeLock sync.Mutex } -const WintunPool = wintun.Pool("WireGuard") +var WintunPool *wintun.Pool + +func init() { + var err error + WintunPool, err = wintun.MakePool("WireGuard") + if err != nil { + panic(fmt.Errorf("Failed to make pool: %v", err)) + } +} //go:linkname procyield runtime.procyield func procyield(cycles uint32) @@ -66,18 +74,18 @@ func CreateTUN(ifname string, mtu int) (Device, error) { // func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID, mtu int) (Device, error) { var err error - var wt *wintun.Interface + var wt *wintun.Adapter // Does an interface with this name already exist? - wt, err = WintunPool.GetInterface(ifname) + wt, err = WintunPool.OpenAdapter(ifname) if err == nil { // If so, we delete it, in case it has weird residual configuration. - _, err = wt.DeleteInterface() + _, err = wt.Delete(true) if err != nil { return nil, fmt.Errorf("Error deleting already existing interface: %v", err) } } - wt, _, err = WintunPool.CreateInterface(ifname, requestedGUID) + wt, _, err = WintunPool.CreateAdapter(ifname, requestedGUID) if err != nil { return nil, fmt.Errorf("Error creating interface: %v", err) } @@ -132,7 +140,7 @@ func (tun *NativeTun) Close() error { tun.rings.Close() var err error if tun.wt != nil { - _, err = tun.wt.DeleteInterface() + _, err = tun.wt.Delete(false) } close(tun.events) return err @@ -254,9 +262,9 @@ func (tun *NativeTun) LUID() uint64 { return tun.wt.LUID() } -// Version returns the version of the Wintun driver and NDIS system currently loaded. -func (tun *NativeTun) Version() (driverVersion string, ndisVersion string, err error) { - return tun.wt.Version() +// RunningVersion returns the running version of the Wintun driver. +func (tun *NativeTun) RunningVersion() (version uint32, err error) { + return wintun.RunningVersion() } func (rate *rateJuggler) update(packetLen uint64) { |