summaryrefslogtreecommitdiffhomepage
path: root/table/table.go
diff options
context:
space:
mode:
authorBen Agricola <bagricola@squiz.co.uk>2016-07-01 16:33:33 +0100
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-11 18:52:33 +0900
commitdcdc6f7a05419d211590a6ac9fc60d41efea0dbe (patch)
tree6f21f78bdc9c630f9e1205dc360af05eba0c4e95 /table/table.go
parentc40f64c235fa9ed532cdcc98b61c14a72d17d298 (diff)
Fix longer-prefix search using radix trie walk
Bug-Url: #1006 Signed-off-by: Ben Agricola <bagricola@squiz.co.uk>
Diffstat (limited to 'table/table.go')
-rw-r--r--table/table.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/table/table.go b/table/table.go
index cbe5c4c9..33db8130 100644
--- a/table/table.go
+++ b/table/table.go
@@ -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
}