summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/server.go14
-rw-r--r--table/table.go15
2 files changed, 19 insertions, 10 deletions
diff --git a/server/server.go b/server/server.go
index d3f05853..049f3e46 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1483,20 +1483,22 @@ func (s *BgpServer) GetRib(addr string, family bgp.RouteFamily, prefixes []*Look
key := p.Prefix
switch p.LookupOption {
case LOOKUP_LONGER:
- _, prefix, err := net.ParseCIDR(key)
+ ds, e := rib.Tables[af].GetLongerPrefixDestinations(key)
if err != nil {
- return id, nil, err
+ err = e
+ return
}
- for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) {
+ for _, dst := range ds {
if paths := dst.GetKnownPathList(id); len(paths) > 0 {
dsts[dst.GetNlri().String()] = clonePathList(paths)
}
}
case LOOKUP_SHORTER:
- _, prefix, err := net.ParseCIDR(key)
- if err != nil {
- return id, nil, err
+ _, prefix, e := net.ParseCIDR(key)
+ if e != nil {
+ err = e
+ return
}
ones, bits := prefix.Mask.Size()
for i := ones; i > 0; i-- {
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) {