mirror of https://github.com/tailscale/tailscale/
query for connectivity
Signed-off-by: Aaron Klotz <aaron@tailscale.com>aaron/oss_17111
parent
b7658a4ad2
commit
7a76b22972
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package netmon
|
||||||
|
|
||||||
|
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go mksyscall.go
|
||||||
|
//go:generate go run golang.org/x/tools/cmd/goimports -w zsyscall_windows.go
|
||||||
|
|
||||||
|
type _MIB_IF_ENTRY_LEVEL int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
_MibIfEntryNormal _MIB_IF_ENTRY_LEVEL = 0
|
||||||
|
_MibIfEntryNormalWithoutStatistics _MIB_IF_ENTRY_LEVEL = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
//sys getIfEntry2(row *winipcfg.MibIfRow2) (ret error) = iphlpapi.GetIfEntry2
|
||||||
|
//sys getIfEntry2Ex(level _MIB_IF_ENTRY_LEVEL, row *winipcfg.MibIfRow2) (ret error) = iphlpapi.GetIfEntry2Ex
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
// Code generated by 'go generate'; DO NOT EDIT.
|
||||||
|
|
||||||
|
package netmon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
errERROR_EINVAL error = syscall.EINVAL
|
||||||
|
)
|
||||||
|
|
||||||
|
// errnoErr returns common boxed Errno values, to prevent
|
||||||
|
// allocations at runtime.
|
||||||
|
func errnoErr(e syscall.Errno) error {
|
||||||
|
switch e {
|
||||||
|
case 0:
|
||||||
|
return errERROR_EINVAL
|
||||||
|
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 (
|
||||||
|
modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
|
||||||
|
|
||||||
|
procGetIfEntry2 = modiphlpapi.NewProc("GetIfEntry2")
|
||||||
|
procGetIfEntry2Ex = modiphlpapi.NewProc("GetIfEntry2Ex")
|
||||||
|
)
|
||||||
|
|
||||||
|
func getIfEntry2(row *winipcfg.MibIfRow2) (ret error) {
|
||||||
|
r0, _, _ := syscall.Syscall(procGetIfEntry2.Addr(), 1, uintptr(unsafe.Pointer(row)), 0, 0)
|
||||||
|
if r0 != 0 {
|
||||||
|
ret = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIfEntry2Ex(level _MIB_IF_ENTRY_LEVEL, row *winipcfg.MibIfRow2) (ret error) {
|
||||||
|
r0, _, _ := syscall.Syscall(procGetIfEntry2Ex.Addr(), 2, uintptr(level), uintptr(unsafe.Pointer(row)), 0)
|
||||||
|
if r0 != 0 {
|
||||||
|
ret = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package winnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
ole "github.com/go-ole/go-ole"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *INetworkListManager) GetNetwork(networkID windows.GUID) (*INetwork, error) {
|
||||||
|
words := (*[4]uintptr)(unsafe.Pointer(&networkID))
|
||||||
|
var result *INetwork
|
||||||
|
r, _, _ := syscall.SyscallN(
|
||||||
|
i.VTable().GetNetwork,
|
||||||
|
uintptr(unsafe.Pointer(i)),
|
||||||
|
words[0],
|
||||||
|
words[1],
|
||||||
|
words[2],
|
||||||
|
words[3],
|
||||||
|
uintptr(unsafe.Pointer(&result)),
|
||||||
|
)
|
||||||
|
|
||||||
|
if int32(r) < 0 {
|
||||||
|
return nil, ole.NewError(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
//go:build windows && !386
|
||||||
|
|
||||||
|
package winnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
ole "github.com/go-ole/go-ole"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *INetworkListManager) GetNetwork(networkID windows.GUID) (*INetwork, error) {
|
||||||
|
var result *INetwork
|
||||||
|
r, _, _ := syscall.SyscallN(
|
||||||
|
i.VTable().GetNetwork,
|
||||||
|
uintptr(unsafe.Pointer(i)),
|
||||||
|
uintptr(unsafe.Pointer(&networkID)),
|
||||||
|
uintptr(unsafe.Pointer(&result)),
|
||||||
|
)
|
||||||
|
|
||||||
|
if int32(r) < 0 {
|
||||||
|
return nil, ole.NewError(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -1,26 +0,0 @@
|
|||||||
// Copyright (c) Tailscale Inc & AUTHORS
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
package winnet
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/go-ole/go-ole"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (v *INetworkConnection) GetAdapterId() (string, error) {
|
|
||||||
buf := ole.GUID{}
|
|
||||||
hr, _, _ := syscall.Syscall(
|
|
||||||
v.VTable().GetAdapterId,
|
|
||||||
2,
|
|
||||||
uintptr(unsafe.Pointer(v)),
|
|
||||||
uintptr(unsafe.Pointer(&buf)),
|
|
||||||
0)
|
|
||||||
if hr != 0 {
|
|
||||||
return "", fmt.Errorf("GetAdapterId failed: %08x", hr)
|
|
||||||
}
|
|
||||||
return buf.String(), nil
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue