mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-20 18:07:34 +00:00
wgengine/monitor: start moving interface state accessor into monitor
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
@@ -244,8 +244,6 @@ func newUserspaceEngine(logf logger.Logf, rawTUNDev tun.Device, conf Config) (_
|
||||
pingers: make(map[wgkey.Key]*pinger),
|
||||
}
|
||||
e.localAddrs.Store(map[netaddr.IP]bool{})
|
||||
e.linkState, _ = getLinkState()
|
||||
logf("link state: %+v", e.linkState)
|
||||
|
||||
if conf.LinkMonitor != nil {
|
||||
e.linkMon = conf.LinkMonitor
|
||||
@@ -258,6 +256,10 @@ func newUserspaceEngine(logf logger.Logf, rawTUNDev tun.Device, conf Config) (_
|
||||
e.linkMon = mon
|
||||
e.linkMonOwned = true
|
||||
}
|
||||
|
||||
e.linkState, _ = e.linkMon.InterfaceState()
|
||||
logf("link state: %+v", e.linkState)
|
||||
|
||||
unregisterMonWatch := e.linkMon.RegisterChangeCallback(func() {
|
||||
e.LinkChange(false)
|
||||
tshttpproxy.InvalidateCache()
|
||||
@@ -1280,7 +1282,7 @@ func (e *userspaceEngine) setLinkState(st *interfaces.State) (changed bool, cb f
|
||||
}
|
||||
|
||||
func (e *userspaceEngine) LinkChange(isExpensive bool) {
|
||||
cur, err := getLinkState()
|
||||
cur, err := e.linkMon.InterfaceState()
|
||||
if err != nil {
|
||||
e.logf("LinkChange: interfaces.GetState: %v", err)
|
||||
return
|
||||
@@ -1334,14 +1336,6 @@ func (e *userspaceEngine) AddNetworkMapCallback(cb NetworkMapCallback) func() {
|
||||
}
|
||||
}
|
||||
|
||||
func getLinkState() (*interfaces.State, error) {
|
||||
s, err := interfaces.GetState()
|
||||
if s != nil {
|
||||
s.RemoveTailscaleInterfaces()
|
||||
}
|
||||
return s, err
|
||||
}
|
||||
|
||||
func (e *userspaceEngine) SetNetInfoCallback(cb NetInfoCallback) {
|
||||
e.magicConn.SetNetInfoCallback(cb)
|
||||
}
|
||||
|
Reference in New Issue
Block a user