ipn/ipnlocal, net/netmon: address code review comments

updates tailscale/corp#33891

Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
pull/17823/head
Jonathan Nobels 6 days ago
parent 403011dc9d
commit b451878c9a

@ -27,7 +27,7 @@ func LinkChangeLogLimiter(ctx context.Context, logf logger.Logf, nm *Monitor) lo
// Any link changes that are flagged as likely require a rebind are // Any link changes that are flagged as likely require a rebind are
// interesting enough that we should log them. // interesting enough that we should log them.
if cd.RebindLikelyRequired { if cd.RebindLikelyRequired {
formatLastSeen = sync.Map{} formatLastSeen.Clear()
} }
}) })
context.AfterFunc(ctx, sub.Close) context.AfterFunc(ctx, sub.Close)
@ -36,7 +36,7 @@ func LinkChangeLogLimiter(ctx context.Context, logf logger.Logf, nm *Monitor) lo
now := time.Now().Unix() now := time.Now().Unix()
lastSeen, ok := formatLastSeen.Load(format) lastSeen, ok := formatLastSeen.Load(format)
if ok { if ok {
// if we've seen this format string within the last hour, skip logging // if we've seen this format string within the last cooldownSeconds, skip logging
if now-lastSeen.(int64) < cooldownSeconds { if now-lastSeen.(int64) < cooldownSeconds {
return return
} }

@ -156,15 +156,13 @@ func NewChangeDelta(old, new *State, timeJumped bool, tsIfName string, forceViab
cd.DefaultInterfaceChanged = cd.old.DefaultRouteInterface != cd.new.DefaultRouteInterface cd.DefaultInterfaceChanged = cd.old.DefaultRouteInterface != cd.new.DefaultRouteInterface
cd.IsLessExpensive = cd.old.IsExpensive && !cd.new.IsExpensive cd.IsLessExpensive = cd.old.IsExpensive && !cd.new.IsExpensive
cd.HasPACOrProxyConfigChanged = (cd.old.PAC != cd.new.PAC) || (cd.old.HTTPProxy != cd.new.HTTPProxy) cd.HasPACOrProxyConfigChanged = (cd.old.PAC != cd.new.PAC) || (cd.old.HTTPProxy != cd.new.HTTPProxy)
cd.InterfaceIPsChanged = cd.isInterestingIntefaceChange() cd.InterfaceIPsChanged = cd.isInterestingInterfaceChange()
} }
// If the default route interface is populated, but it's not up this event signifies that we're in
// the process of tearing it down. Rebinds are going to fail so it's flappy to try.
cd.DefaultRouteInterface = new.DefaultRouteInterface cd.DefaultRouteInterface = new.DefaultRouteInterface
defIf := new.Interface[cd.DefaultRouteInterface] defIf := new.Interface[cd.DefaultRouteInterface]
// The default interface is not viable if is down or is the Tailscale interface itself. // The default interface is not viable if it is down or it is the Tailscale interface itself.
if !forceViability && (!defIf.IsUp() || cd.DefaultRouteInterface == tsIfName) { if !forceViability && (!defIf.IsUp() || cd.DefaultRouteInterface == tsIfName) {
cd.DefaultInterfaceMaybeViable = false cd.DefaultInterfaceMaybeViable = false
} else { } else {
@ -185,14 +183,14 @@ func NewChangeDelta(old, new *State, timeJumped bool, tsIfName string, forceViab
return &cd, nil return &cd, nil
} }
// StateDesc returns a description of the old and new states for logging // StateDesc returns a description of the old and new states for logging.
func (cd *ChangeDelta) StateDesc() string { func (cd *ChangeDelta) StateDesc() string {
return fmt.Sprintf("old: %v new: %v", cd.old, cd.new) return fmt.Sprintf("old: %v new: %v", cd.old, cd.new)
} }
// InterfaceIPAppeared reports whether the given IP address exists on any interface // InterfaceIPDisappeared reports whether the given IP address exists on any interface
// in the old state, but not in the new state. // in the old state, but not in the new state.
func (cd *ChangeDelta) InterfaceIPDisppeared(ip netip.Addr) bool { func (cd *ChangeDelta) InterfaceIPDisappeared(ip netip.Addr) bool {
if cd.old == nil { if cd.old == nil {
return false return false
} }
@ -202,12 +200,6 @@ func (cd *ChangeDelta) InterfaceIPDisppeared(ip netip.Addr) bool {
return cd.new.HasIP(ip) && !cd.old.HasIP(ip) return cd.new.HasIP(ip) && !cd.old.HasIP(ip)
} }
// InterfaceIPDisappeared reports whether the given IP address existed on any interface
// in the old state, but not in the new state.
func (cd *ChangeDelta) InterfaceIPDisappeared(ip netip.Addr) bool {
return !cd.new.HasIP(ip) && cd.old.HasIP(ip)
}
// AnyInterfaceUp reports whether any interfaces are up in the new state. // AnyInterfaceUp reports whether any interfaces are up in the new state.
func (cd *ChangeDelta) AnyInterfaceUp() bool { func (cd *ChangeDelta) AnyInterfaceUp() bool {
if cd.new == nil { if cd.new == nil {
@ -221,16 +213,12 @@ func (cd *ChangeDelta) AnyInterfaceUp() bool {
return false return false
} }
// isInterestingIntefaceChange reports whether any interfaces have changed in a meaninful way. // isInterestingInterfaceChange reports whether any interfaces have changed in a meaningful way.
// This excludes interfaces that are not interesting per IsInterestingInterface and // This excludes interfaces that are not interesting per IsInterestingInterface and
// filters out changes to interface IPs that that are uninteresting (e.g. link-local addresses). // filters out changes to interface IPs that that are uninteresting (e.g. link-local addresses).
func (cd *ChangeDelta) isInterestingIntefaceChange() bool { func (cd *ChangeDelta) isInterestingInterfaceChange() bool {
if cd.old == nil && cd.new == nil { // If there is no old state, everything is considered changed.
return false if cd.old == nil {
}
// If either side is nil treat as changed.
if cd.old == nil || cd.new == nil {
return true return true
} }
@ -253,7 +241,7 @@ func (cd *ChangeDelta) isInterestingIntefaceChange() bool {
// The old interface doesn't exist in the new interface set and it has // The old interface doesn't exist in the new interface set and it has
// a global unicast IP. That's considered a change from the perspective // a global unicast IP. That's considered a change from the perspective
// of anything that may have been bound to it. If it didn't have a global // of anything that may have been bound to it. If it didn't have a global
// unicast IP, it's not interesting. // unicast IP, it's not interesting.
newInterface, ok := cd.new.Interface[iname] newInterface, ok := cd.new.Interface[iname]
if !ok { if !ok {
@ -559,7 +547,7 @@ func (m *Monitor) pump() {
} }
} }
// / debounce calls the callback function with a delay between events // debounce calls the callback function with a delay between events
// and exits when a stop is issued. // and exits when a stop is issued.
func (m *Monitor) debounce() { func (m *Monitor) debounce() {
defer m.goroutines.Done() defer m.goroutines.Done()

Loading…
Cancel
Save