all: use bart.Lite instead of bart.Table where appropriate
When we don't care about the payload value and are just checking whether a set contains an IP/prefix, we can use `bart.Lite` for the same lookup times but a lower memory footprint. Fixes #19075 Change-Id: Ia709e8b718666cc61ea56eac1066467ae0b6e86c Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
+5
-5
@@ -82,14 +82,14 @@ func main() {
|
||||
log.Fatalf("site-id must be in the range [0, 65535]")
|
||||
}
|
||||
|
||||
var ignoreDstTable *bart.Table[bool]
|
||||
var ignoreDstTable *bart.Lite
|
||||
for s := range strings.SplitSeq(*ignoreDstPfxStr, ",") {
|
||||
s := strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if ignoreDstTable == nil {
|
||||
ignoreDstTable = &bart.Table[bool]{}
|
||||
ignoreDstTable = &bart.Lite{}
|
||||
}
|
||||
pfx, err := netip.ParsePrefix(s)
|
||||
if err != nil {
|
||||
@@ -98,7 +98,7 @@ func main() {
|
||||
if pfx.Masked() != pfx {
|
||||
log.Fatalf("prefix %v is not normalized (bits are set outside the mask)", pfx)
|
||||
}
|
||||
ignoreDstTable.Insert(pfx, true)
|
||||
ignoreDstTable.Insert(pfx)
|
||||
}
|
||||
ts := &tsnet.Server{
|
||||
Hostname: *hostname,
|
||||
@@ -276,7 +276,7 @@ type connector struct {
|
||||
// and if any of the ip addresses in response to the lookup match any 'ignore destinations' prefix we will
|
||||
// return a dns response that contains the ip addresses we discovered with the lookup (ie not the
|
||||
// natc behavior, which would return a dummy ip address pointing at natc).
|
||||
ignoreDsts *bart.Table[bool]
|
||||
ignoreDsts *bart.Lite
|
||||
|
||||
// ipPool contains the per-peer IPv4 address assignments.
|
||||
ipPool ippool.IPPool
|
||||
@@ -538,7 +538,7 @@ func (c *connector) ignoreDestination(dstAddrs []netip.Addr) bool {
|
||||
return false
|
||||
}
|
||||
for _, a := range dstAddrs {
|
||||
if _, ok := c.ignoreDsts.Lookup(a); ok {
|
||||
if c.ignoreDsts.Contains(a) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user