summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-12-02 11:25:41 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-12-02 11:25:41 +0900
commitacad9314f0a607ca0b417b044a95150921a431c7 (patch)
treeca499a0a25773f4857bbc271754dbb650c2eabde /server
parent093945ee30f47555f28b389f14b62976586b8bac (diff)
server: fix show rib with host address
With this fix, the RPC API works like the following: $ gobgp global rib Network Next Hop AS_PATH Age Attrs *> 210.173.160.0/19 210.173.172.65 65001 00:00:41 [{Origin: i}] $ gobgp global rib 210.173.176.1 Network Next Hop AS_PATH Age Attrs *> 210.173.160.0/19 210.173.172.65 65001 00:01:17 [{Origin: i}] Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/server.go35
1 files changed, 22 insertions, 13 deletions
diff --git a/server/server.go b/server/server.go
index db92981a..3bd4b448 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1428,21 +1428,30 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
if len(arg.Destinations) > 0 {
dsts := []*api.Destination{}
+ f := func(cidr string) (bool, error) {
+ _, prefix, err := net.ParseCIDR(cidr)
+ if err != nil {
+ return false, err
+ }
+ if dst := rib.Tables[af].GetDestination(prefix.String()); dst != nil {
+ dsts = append(dsts, dst.ToApiStruct())
+ return true, nil
+ } else {
+ return false, nil
+ }
+ }
for _, dst := range arg.Destinations {
key := dst.Prefix
- if _, prefix, err := net.ParseCIDR(key); err == nil {
- if dst := rib.Tables[af].GetDestination(prefix.String()); dst != nil {
- dsts = append(dsts, dst.ToApiStruct())
- }
- } else if host := net.ParseIP(key); host != nil {
- masklen := 32
- if af == bgp.RF_IPv6_UC {
- masklen = 128
- }
- for i := masklen; i > 0; i-- {
- if dst := rib.Tables[af].GetDestination(fmt.Sprintf("%s/%d", key, i)); dst != nil {
- dsts = append(dsts, dst.ToApiStruct())
- break
+ if _, err := f(key); err != nil {
+ if host := net.ParseIP(key); host != nil {
+ masklen := 32
+ if af == bgp.RF_IPv6_UC {
+ masklen = 128
+ }
+ for i := masklen; i > 0; i-- {
+ if y, _ := f(fmt.Sprintf("%s/%d", key, i)); y {
+ break
+ }
}
}
}