summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-08-20 10:21:23 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-08-25 15:53:14 +0900
commita17ee18e5b1fe90a7c80d6cb1f0778b97f00235a (patch)
tree04b225dff85ae251d17aa0eaa3aed205762de19f /table
parent17331d161fae507424a9760a9dbca41b3669ed36 (diff)
server: fix RIB lookup with longer-prefixes option
the feature was somehow broken. Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/table.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/table/table.go b/table/table.go
index d5434005..b1ec94a1 100644
--- a/table/table.go
+++ b/table/table.go
@@ -16,10 +16,12 @@
package table
import (
+ "net"
+ "sort"
+
log "github.com/Sirupsen/logrus"
"github.com/armon/go-radix"
"github.com/osrg/gobgp/packet/bgp"
- "sort"
)
type Table struct {
@@ -234,15 +236,20 @@ func (t *Table) GetDestination(key string) *Destination {
}
}
-func (t *Table) GetLongerPrefixDestinations(key string) []*Destination {
+func (t *Table) GetLongerPrefixDestinations(key string) ([]*Destination, error) {
results := make([]*Destination, 0, len(t.GetDestinations()))
switch t.routeFamily {
case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
+ _, prefix, err := net.ParseCIDR(key)
+ if err != nil {
+ return nil, err
+ }
+ k := CidrToRadixkey(prefix.String())
r := radix.New()
for _, dst := range t.GetDestinations() {
r.Insert(dst.RadixKey, dst)
}
- r.WalkPrefix(key, func(s string, v interface{}) bool {
+ r.WalkPrefix(k, func(s string, v interface{}) bool {
results = append(results, v.(*Destination))
return false
})
@@ -251,7 +258,7 @@ func (t *Table) GetLongerPrefixDestinations(key string) []*Destination {
results = append(results, dst)
}
}
- return results
+ return results, nil
}
func (t *Table) setDestination(key string, dest *Destination) {