diff options
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) { |