mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
Fix longer-prefix search using radix trie walk
Bug-Url: #1006 Signed-off-by: Ben Agricola <[email protected]>
This commit is contained in:
committed by
FUJITA Tomonori
parent
c40f64c235
commit
dcdc6f7a05
+5
-4
@@ -1619,10 +1619,11 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
|
||||
}
|
||||
} else if dst.LongerPrefixes {
|
||||
_, prefix, _ := net.ParseCIDR(key)
|
||||
ones, bits := prefix.Mask.Size()
|
||||
for i := ones + 1; i <= bits; i++ {
|
||||
prefix.Mask = net.CIDRMask(i, bits)
|
||||
f(id, prefix.String())
|
||||
|
||||
for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) {
|
||||
if d := dst.ToApiStruct(id); d != nil {
|
||||
dsts = append(dsts, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,26 @@ func (t *Table) GetDestination(key string) *Destination {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Table) GetLongerPrefixDestinations(key string) []*Destination {
|
||||
results := make([]*Destination, 0, len(t.GetDestinations()))
|
||||
switch t.routeFamily {
|
||||
case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
|
||||
r := radix.New()
|
||||
for _, dst := range t.GetDestinations() {
|
||||
r.Insert(dst.RadixKey, dst)
|
||||
}
|
||||
r.WalkPrefix(key, func(s string, v interface{}) bool {
|
||||
results = append(results, v.(*Destination))
|
||||
return false
|
||||
})
|
||||
default:
|
||||
for _, dst := range t.GetDestinations() {
|
||||
results = append(results, dst)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
func (t *Table) setDestination(key string, dest *Destination) {
|
||||
t.destinations[key] = dest
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user