mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-08 23:49:56 +00:00
wgengine/netstack: optimize shouldProcessInbound, avoiding 4via6 lookups
All IPv6 packets for the self address were doing netip.Prefix.Contains lookups. If if we know they're for a self address (which we already previously computed and have sitting in a bool), then they can't be for a 4via6 range. Change-Id: Iaaaf1248cb3fecec229935a80548ead0eb4cb892 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
2daf0f146c
commit
79472a4a6e
@@ -259,6 +259,13 @@ func TestShouldHandlePing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// looksLikeATailscaleSelfAddress reports whether addr looks like
|
||||
// a Tailscale self address, for tests.
|
||||
func looksLikeATailscaleSelfAddress(addr netip.Addr) bool {
|
||||
return addr.Is4() && tsaddr.IsTailscaleIP(addr) ||
|
||||
addr.Is6() && tsaddr.Tailscale4To6Range().Contains(addr)
|
||||
}
|
||||
|
||||
func TestShouldProcessInbound(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
@@ -289,6 +296,7 @@ func TestShouldProcessInbound(t *testing.T) {
|
||||
StateKey: ipn.GlobalDaemonStateKey,
|
||||
UpdatePrefs: prefs,
|
||||
})
|
||||
i.atomicIsLocalIPFunc.Store(looksLikeATailscaleSelfAddress)
|
||||
|
||||
// This should be handled even if we're
|
||||
// otherwise not processing local IPs or
|
||||
@@ -400,7 +408,7 @@ func TestShouldProcessInbound(t *testing.T) {
|
||||
// For testing purposes, assume all Tailscale
|
||||
// IPs are local; the Dst above is something
|
||||
// not in that range.
|
||||
i.atomicIsLocalIPFunc.Store(tsaddr.IsTailscaleIP)
|
||||
i.atomicIsLocalIPFunc.Store(looksLikeATailscaleSelfAddress)
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
|
Reference in New Issue
Block a user