wgengine/filter: inline ip6InList into match.

matchIPsOnly gets 5% slower when inlining, despite significantly reduced
memory ops and slightly tighter code.

Part of #19.

Filter/tcp6_syn_in-8     45.5ns ± 1%    42.4ns ± 2%   -6.86%  (p=0.000 n=10+10)
Filter/udp6_in-8          107ns ± 2%      94ns ± 2%  -11.50%  (p=0.000 n=9+10)

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2020-11-12 20:21:16 -08:00
parent 3fdae12f0c
commit ce45f4f3ff
3 changed files with 47 additions and 18 deletions

View File

@@ -118,33 +118,43 @@ func newMatches6(ms []Match) (ret matches6) {
}
func (ms matches6) match(q *packet.Parsed) bool {
outer:
for i := range ms {
if !ip6InList(q.SrcIP6, ms[i].srcs) {
continue
}
dsts := ms[i].dsts
for i := range dsts {
if !dsts[i].net.Contains(q.DstIP6) {
continue
srcs := ms[i].srcs
for j := range srcs {
if srcs[j].Contains(q.SrcIP6) {
dsts := ms[i].dsts
for k := range dsts {
if dsts[k].net.Contains(q.DstIP6) && dsts[k].ports.contains(q.DstPort) {
return true
}
}
// We hit on src, but missed on all
// dsts. No need to try other srcs,
// they'll never fully match.
continue outer
}
if !dsts[i].ports.contains(q.DstPort) {
continue
}
return true
}
}
return false
}
func (ms matches6) matchIPsOnly(q *packet.Parsed) bool {
outer:
for i := range ms {
if !ip6InList(q.SrcIP6, ms[i].srcs) {
continue
}
dsts := ms[i].dsts
for i := range dsts {
if dsts[i].net.Contains(q.DstIP6) {
return true
srcs := ms[i].srcs
for j := range srcs {
if srcs[j].Contains(q.SrcIP6) {
dsts := ms[i].dsts
for k := range dsts {
if dsts[k].net.Contains(q.DstIP6) {
return true
}
}
// We hit on src, but missed on all
// dsts. No need to try other srcs,
// they'll never fully match.
continue outer
}
}
}