]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
wintun: expose version
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 8 Oct 2019 07:58:58 +0000 (09:58 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 8 Oct 2019 07:58:58 +0000 (09:58 +0200)
tun/tun_windows.go
tun/wintun/wintun_windows.go

index 6a603a30d10bb51268ad5b4dbdc4bddaac7d759a..4b5da02050499b1a7f7846ad7be9bbe217666c8f 100644 (file)
@@ -244,6 +244,11 @@ 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()
+}
+
 func (rate *rateJuggler) update(packetLen uint64) {
        now := nanotime()
        total := atomic.AddUint64(&rate.nextByteCount, packetLen)
index e2348c0a9ef50073d950a79e8020f65fe38b1d02..e6dc141c9409caf6507f9b9133897b16893eb659 100644 (file)
@@ -671,11 +671,39 @@ func (wintun *Interface) tcpipAdapterRegKeyName() string {
        return fmt.Sprintf("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters\\%v", wintun.cfgInstanceID)
 }
 
-// deviceRegKeyName returns the device-level registry key name
+// deviceRegKeyName returns the device-level registry key name.
 func (wintun *Interface) deviceRegKeyName() string {
        return fmt.Sprintf("SYSTEM\\CurrentControlSet\\Enum\\%v", wintun.devInstanceID)
 }
 
+// Version returns the version of the Wintun driver and NDIS system currently loaded.
+func (wintun *Interface) Version() (driverVersion string, ndisVersion string, err error) {
+       key, err := registry.OpenKey(registry.LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Wintun", registry.QUERY_VALUE)
+       if err != nil {
+               return
+       }
+       defer key.Close()
+       driverMajor, _, err := key.GetIntegerValue("DriverMajorVersion")
+       if err != nil {
+               return
+       }
+       driverMinor, _, err := key.GetIntegerValue("DriverMinorVersion")
+       if err != nil {
+               return
+       }
+       ndisMajor, _, err := key.GetIntegerValue("NdisMajorVersion")
+       if err != nil {
+               return
+       }
+       ndisMinor, _, err := key.GetIntegerValue("NdisMinorVersion")
+       if err != nil {
+               return
+       }
+       driverVersion = fmt.Sprintf("%d.%d", driverMajor, driverMinor)
+       ndisVersion = fmt.Sprintf("%d.%d", ndisMajor, ndisMinor)
+       return
+}
+
 // tcpipInterfaceRegKeyName returns the interface-specific TCP/IP network registry key name.
 func (wintun *Interface) tcpipInterfaceRegKeyName() (path string, err error) {
        key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.tcpipAdapterRegKeyName(), registry.QUERY_VALUE)