mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-03 02:21:58 +00:00
wgengine/monitor: don't call LinkChange when interfaces look unchanged
Basically, don't trust the OS-level link monitor to only tell you interesting things. Sanity check it. Also, move the interfaces package into the net directory now that we have it.
This commit is contained in:
@@ -7,9 +7,14 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"tailscale.com/net/interfaces"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
@@ -99,6 +104,7 @@ func (m *Mon) Close() error {
|
||||
// the change channel of changes, and stopping when a stop is issued.
|
||||
func (m *Mon) pump() {
|
||||
defer m.goroutines.Done()
|
||||
last := interfaceSummary()
|
||||
for {
|
||||
_, err := m.om.Receive()
|
||||
if err != nil {
|
||||
@@ -113,9 +119,17 @@ func (m *Mon) pump() {
|
||||
continue
|
||||
}
|
||||
|
||||
cur := interfaceSummary()
|
||||
if cur == last {
|
||||
continue
|
||||
}
|
||||
m.logf("wgengine/monitor: now %v (was %v)", cur, last)
|
||||
last = cur
|
||||
|
||||
select {
|
||||
case m.change <- struct{}{}:
|
||||
default:
|
||||
case <-m.stop:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,3 +154,17 @@ func (m *Mon) debounce() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func interfaceSummary() string {
|
||||
var sb strings.Builder
|
||||
_ = interfaces.ForeachInterfaceAddress(func(ni interfaces.Interface, addr net.IP) {
|
||||
if runtime.GOOS == "linux" && strings.HasPrefix(ni.Name, "tailscale") {
|
||||
// Skip tailscale0, etc on Linux.
|
||||
return
|
||||
}
|
||||
if ni.IsUp() {
|
||||
fmt.Fprintf(&sb, "%s=%s ", ni.Name, addr)
|
||||
}
|
||||
})
|
||||
return strings.TrimSpace(sb.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user