When subnetwork is deleted from table lookup/get still reports individual IPs as present.
Maybe I misunderstand how to use this module correctly, below is an example test:
package main
import (
"net/netip"
"testing"
"github.com/gaissmai/bart"
"github.com/stretchr/testify/assert"
)
func mustParsePrefix(s string) netip.Prefix {
pfx, err := netip.ParsePrefix(s)
if err != nil {
panic(err)
}
return pfx
}
func mustParseAddr(s string) netip.Addr {
addr, err := netip.ParseAddr(s)
if err != nil {
panic(err)
}
return addr
}
func TestBART(t *testing.T) {
var ok bool
tbl := new(bart.Table[struct{}])
{
// 192.168.40.1 - 192.168.43.254
tbl.Insert(mustParsePrefix("192.168.42.1/22"), struct{}{})
_, _, ok = tbl.Lookup(mustParseAddr("192.168.40.1"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.43.254"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.42.242"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("10.0.42.42"))
assert.False(t, ok)
}
{
tbl.Delete(mustParsePrefix("192.168.42.42/32"))
_, _, ok = tbl.Lookup(mustParseAddr("192.168.40.1"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.43.254"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.42.42"))
assert.False(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("10.0.42.42"))
assert.False(t, ok)
}
{
// 192.168.42.1 - 192.168.42.254
tbl.Delete(mustParsePrefix("192.168.42.1/24"))
_, _, ok = tbl.Lookup(mustParseAddr("192.168.40.1"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.43.254"))
assert.True(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("192.168.42.242"))
assert.False(t, ok)
_, _, ok = tbl.Lookup(mustParseAddr("10.0.42.42"))
assert.False(t, ok)
}
}