diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-28 12:27:06 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 08:41:30 +0200 |
commit | e9682162ac908e9b9d81f3378faf8b38d1baa630 (patch) | |
tree | 1c3e6059569376c72336ba09f06e9a5ee5e1e833 /version | |
parent | go.mod: use forked winio with no thirdparty deps (diff) | |
download | wireguard-windows-e9682162ac908e9b9d81f3378faf8b38d1baa630.tar.xz wireguard-windows-e9682162ac908e9b9d81f3378faf8b38d1baa630.zip |
updater: add initial skeleton
Diffstat (limited to 'version')
-rw-r--r-- | version/mksyscall.go | 8 | ||||
-rw-r--r-- | version/os_linux.go | 30 | ||||
-rw-r--r-- | version/os_windows.go | 43 | ||||
-rw-r--r-- | version/version.go | 20 | ||||
-rw-r--r-- | version/zsyscall_windows.go | 49 |
5 files changed, 150 insertions, 0 deletions
diff --git a/version/mksyscall.go b/version/mksyscall.go new file mode 100644 index 00000000..abd538e5 --- /dev/null +++ b/version/mksyscall.go @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package version + +//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go os_windows.go diff --git a/version/os_linux.go b/version/os_linux.go new file mode 100644 index 00000000..7e5c4f1c --- /dev/null +++ b/version/os_linux.go @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package version + +import ( + "bytes" + "fmt" + "golang.org/x/sys/unix" +) + +// This isn't a Linux program, yes, but having the updater package work across platforms is quite helpful for testing. + +func utsToStr(u [65]byte) string { + i := bytes.IndexByte(u[:], 0) + if i < 0 { + return string(u[:]) + } + return string(u[:i]) +} + +func OsName() string { + var utsname unix.Utsname + if unix.Uname(&utsname) != nil { + return "Unix Unknown" + } + return fmt.Sprintf("%s %s %s", utsToStr(utsname.Sysname), utsToStr(utsname.Release), utsToStr(utsname.Version)) +} diff --git a/version/os_windows.go b/version/os_windows.go new file mode 100644 index 00000000..ac4e8957 --- /dev/null +++ b/version/os_windows.go @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package version + +import ( + "fmt" + "unsafe" +) + +type osVersionInfo struct { + osVersionInfoSize uint32 + majorVersion uint32 + minorVersion uint32 + buildNumber uint32 + platformId uint32 + csdVersion [128]uint16 + servicePackMajor uint16 + servicePackMinor uint16 + suiteMask uint16 + productType byte + reserved byte +} + +//sys rtlGetVersion(versionInfo *osVersionInfo) (nterr uint32) = ntdll.RtlGetVersion + +func OsName() string { + windowsVersion := "Windows Unknown" + versionInfo := &osVersionInfo{osVersionInfoSize: uint32(unsafe.Sizeof(osVersionInfo{}))} + if rtlGetVersion(versionInfo) == 0 { + winType := "" + switch versionInfo.productType { + case 3: + winType = " Server" + case 2: + winType = " Controller" + } + windowsVersion = fmt.Sprintf("Windows%s %d.%d.%d", winType, versionInfo.majorVersion, versionInfo.minorVersion, versionInfo.buildNumber) + } + return windowsVersion +} diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..951d2731 --- /dev/null +++ b/version/version.go @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package version + +// #include "../version.h" +import "C" +import ( + "fmt" + "golang.zx2c4.com/wireguard/device" + "runtime" +) + +const WireGuardWindowsVersion = C.WIREGUARD_WINDOWS_VERSION + +func UserAgent() string { + return fmt.Sprintf("WireGuard/%s (wireguard-go %s; %s; %s; %s)", WireGuardWindowsVersion, device.WireGuardGoVersion, OsName(), runtime.Version(), runtime.GOARCH) +} diff --git a/version/zsyscall_windows.go b/version/zsyscall_windows.go new file mode 100644 index 00000000..9f11ce70 --- /dev/null +++ b/version/zsyscall_windows.go @@ -0,0 +1,49 @@ +// Code generated by 'go generate'; DO NOT EDIT. + +package version + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + +var ( + modntdll = windows.NewLazySystemDLL("ntdll.dll") + + procRtlGetVersion = modntdll.NewProc("RtlGetVersion") +) + +func rtlGetVersion(versionInfo *osVersionInfo) (nterr uint32) { + r0, _, _ := syscall.Syscall(procRtlGetVersion.Addr(), 1, uintptr(unsafe.Pointer(versionInfo)), 0, 0) + nterr = uint32(r0) + return +} |