aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2022-12-06 20:54:09 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2023-01-26 09:27:24 -0600
commit0fa3db229ce2036ae779de8ba03d336b7aa826bd (patch)
tree492c08a6aee8c726f3454e99d444dc9fec5dfb66
parentglobal: move go:build line to top (diff)
downloadwintun-go-0fa3db229ce2036ae779de8ba03d336b7aa826bd.tar.xz
wintun-go-0fa3db229ce2036ae779de8ba03d336b7aa826bd.zip
wintun: return errors instead of panicking where possibleHEADmaster
Apparently there are weird crashes related to this, and returning an err would help diagnose them. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--wintun.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/wintun.go b/wintun.go
index 254dc1e..1ffd62f 100644
--- a/wintun.go
+++ b/wintun.go
@@ -89,6 +89,9 @@ func CreateAdapter(name string, tunnelType string, requestedGUID *windows.GUID)
if err != nil {
return
}
+ if err := procWintunCreateAdapter.Find(); err != nil {
+ return nil, err
+ }
r0, _, e1 := syscall.Syscall(procWintunCreateAdapter.Addr(), 3, uintptr(unsafe.Pointer(name16)), uintptr(unsafe.Pointer(tunnelType16)), uintptr(unsafe.Pointer(requestedGUID)))
if r0 == 0 {
err = e1
@@ -106,6 +109,9 @@ func OpenAdapter(name string) (wintun *Adapter, err error) {
if err != nil {
return
}
+ if err := procWintunOpenAdapter.Find(); err != nil {
+ return nil, err
+ }
r0, _, e1 := syscall.Syscall(procWintunOpenAdapter.Addr(), 1, uintptr(unsafe.Pointer(name16)), 0, 0)
if r0 == 0 {
err = e1
@@ -118,6 +124,9 @@ func OpenAdapter(name string) (wintun *Adapter, err error) {
// Close closes a Wintun adapter.
func (wintun *Adapter) Close() (err error) {
+ if err := procWintunCloseAdapter.Find(); err != nil {
+ return err
+ }
runtime.SetFinalizer(wintun, nil)
r1, _, e1 := syscall.Syscall(procWintunCloseAdapter.Addr(), 1, wintun.handle, 0, 0)
if r1 == 0 {
@@ -128,6 +137,9 @@ func (wintun *Adapter) Close() (err error) {
// Uninstall removes the driver from the system if no drivers are currently in use.
func Uninstall() (err error) {
+ if err := procWintunDeleteDriver.Find(); err != nil {
+ return err
+ }
r1, _, e1 := syscall.Syscall(procWintunDeleteDriver.Addr(), 0, 0, 0, 0)
if r1 == 0 {
err = e1
@@ -137,6 +149,9 @@ func Uninstall() (err error) {
// RunningVersion returns the version of the loaded driver.
func RunningVersion() (version uint32, err error) {
+ if err := procWintunGetRunningDriverVersion.Find(); err != nil {
+ return 0, err
+ }
r0, _, e1 := syscall.Syscall(procWintunGetRunningDriverVersion.Addr(), 0, 0, 0, 0)
version = uint32(r0)
if version == 0 {