mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
wgengine/monitor: start moving interface state accessor into monitor
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
14dc790137
commit
34188d93d4
@ -11,6 +11,7 @@
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tailscale.com/net/interfaces"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,6 +73,16 @@ func New(logf logger.Logf) (*Mon, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InterfaceState returns the state of the machine's network interfaces,
|
||||||
|
// without any Tailscale ones.
|
||||||
|
func (m *Mon) InterfaceState() (*interfaces.State, error) {
|
||||||
|
s, err := interfaces.GetState()
|
||||||
|
if s != nil {
|
||||||
|
s.RemoveTailscaleInterfaces()
|
||||||
|
}
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterChangeCallback adds callback to the set of parties to be
|
// RegisterChangeCallback adds callback to the set of parties to be
|
||||||
// notified (in their own goroutine) when the network state changes.
|
// notified (in their own goroutine) when the network state changes.
|
||||||
// To remove this callback, call unregister (or close the monitor).
|
// To remove this callback, call unregister (or close the monitor).
|
||||||
|
@ -244,8 +244,6 @@ func newUserspaceEngine(logf logger.Logf, rawTUNDev tun.Device, conf Config) (_
|
|||||||
pingers: make(map[wgkey.Key]*pinger),
|
pingers: make(map[wgkey.Key]*pinger),
|
||||||
}
|
}
|
||||||
e.localAddrs.Store(map[netaddr.IP]bool{})
|
e.localAddrs.Store(map[netaddr.IP]bool{})
|
||||||
e.linkState, _ = getLinkState()
|
|
||||||
logf("link state: %+v", e.linkState)
|
|
||||||
|
|
||||||
if conf.LinkMonitor != nil {
|
if conf.LinkMonitor != nil {
|
||||||
e.linkMon = conf.LinkMonitor
|
e.linkMon = conf.LinkMonitor
|
||||||
@ -258,6 +256,10 @@ func newUserspaceEngine(logf logger.Logf, rawTUNDev tun.Device, conf Config) (_
|
|||||||
e.linkMon = mon
|
e.linkMon = mon
|
||||||
e.linkMonOwned = true
|
e.linkMonOwned = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.linkState, _ = e.linkMon.InterfaceState()
|
||||||
|
logf("link state: %+v", e.linkState)
|
||||||
|
|
||||||
unregisterMonWatch := e.linkMon.RegisterChangeCallback(func() {
|
unregisterMonWatch := e.linkMon.RegisterChangeCallback(func() {
|
||||||
e.LinkChange(false)
|
e.LinkChange(false)
|
||||||
tshttpproxy.InvalidateCache()
|
tshttpproxy.InvalidateCache()
|
||||||
@ -1280,7 +1282,7 @@ func (e *userspaceEngine) setLinkState(st *interfaces.State) (changed bool, cb f
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *userspaceEngine) LinkChange(isExpensive bool) {
|
func (e *userspaceEngine) LinkChange(isExpensive bool) {
|
||||||
cur, err := getLinkState()
|
cur, err := e.linkMon.InterfaceState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.logf("LinkChange: interfaces.GetState: %v", err)
|
e.logf("LinkChange: interfaces.GetState: %v", err)
|
||||||
return
|
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) {
|
func (e *userspaceEngine) SetNetInfoCallback(cb NetInfoCallback) {
|
||||||
e.magicConn.SetNetInfoCallback(cb)
|
e.magicConn.SetNetInfoCallback(cb)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user