mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 04:06:35 +02:00
Create ifacewatcher
This commit is contained in:
parent
39f7a61e9c
commit
f96cf1892a
25
wgengine/ifacewatcher_other.go
Normal file
25
wgengine/ifacewatcher_other.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !windows
|
||||
|
||||
package wgengine
|
||||
|
||||
import (
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
// Dummy implementation that does nothing.
|
||||
type ifaceWatcher struct {
|
||||
}
|
||||
|
||||
func initWatcher(logf logger.Logf) (*ifaceWatcher, error) {
|
||||
return &ifaceWatcher{}, nil
|
||||
}
|
||||
|
||||
func (iw *ifaceWatcher) setTun(ifc interface{}) {
|
||||
}
|
||||
|
||||
func (iw *ifaceWatcher) Destroy() {
|
||||
}
|
||||
28
wgengine/ifacewatcher_windows.go
Normal file
28
wgengine/ifacewatcher_windows.go
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package wgengine
|
||||
|
||||
import (
|
||||
"github.com/tailscale/wireguard-go/tun"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
type ifaceWatcher struct {
|
||||
logf logger.Logf
|
||||
iface *tun.NativeTun
|
||||
}
|
||||
|
||||
func initWatcher(logf logger.Logf) (*ifaceWatcher, error) {
|
||||
return &ifaceWatcher{logf: logger.WithPrefix(logf, "ifaceWatcher: ")}, nil
|
||||
}
|
||||
|
||||
func (iw *ifaceWatcher) setTun(ifc interface{}) {
|
||||
iw.iface = ifc.(*tun.NativeTun)
|
||||
iw.logf("setTun LUID=%v", iw.iface.LUID())
|
||||
}
|
||||
|
||||
func (iw *ifaceWatcher) Destroy() {
|
||||
iw.logf("Destroy")
|
||||
}
|
||||
@ -179,14 +179,22 @@ func NewUserspaceEngine(logf logger.Logf, tunName string, listenPort uint16) (En
|
||||
|
||||
logf("Starting userspace wireguard engine with tun device %q", tunName)
|
||||
|
||||
iw, err := initWatcher(logf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tun, err := tun.CreateTUN(tunName, minimalMTU)
|
||||
if err != nil {
|
||||
iw.Destroy()
|
||||
diagnoseTUNFailure(tunName, logf)
|
||||
logf("CreateTUN: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
logf("CreateTUN ok.")
|
||||
|
||||
iw.setTun(tun)
|
||||
|
||||
conf := EngineConfig{
|
||||
Logf: logf,
|
||||
TUN: tun,
|
||||
@ -196,6 +204,7 @@ func NewUserspaceEngine(logf logger.Logf, tunName string, listenPort uint16) (En
|
||||
|
||||
e, err := NewUserspaceEngineAdvanced(conf)
|
||||
if err != nil {
|
||||
iw.Destroy()
|
||||
tun.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user