diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-12-04 10:54:00 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-12-04 11:01:07 +0900 |
commit | 7ff862f3eefceb3a58ca8be09ead21336d5cb504 (patch) | |
tree | 83f99e8d3af9e7ca170d0d5d934bfd0e4dd50315 /server | |
parent | a36c84c510bd7cde344e6cbabd043153e4a0196c (diff) |
api/cli: support showing longer-prefix
$ gobgp global rib
Network Next Hop AS_PATH Age Attrs
*> 10.0.0.0/24 0.0.0.0 00:00:01 [{Origin: ?}]
$ gobgp global rib 10.0.0.0/20
Network not in table
$ gobgp global rib 10.0.0.0/20 longer-prefix
Network Next Hop AS_PATH Age Attrs
*> 10.0.0.0/24 0.0.0.0 00:00:01 [{Origin: ?}]
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/server.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/server.go b/server/server.go index a09b7d02..089d8e0a 100644 --- a/server/server.go +++ b/server/server.go @@ -1441,18 +1441,28 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } for _, dst := range arg.Destinations { key := dst.Prefix - if _, err := f(key); err != nil { + y, err := f(key) + if 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 { + if y, _ = f(fmt.Sprintf("%s/%d", key, i)); y { break } } } + } else if !y && dst.LongerPrefix { + _, prefix, _ := net.ParseCIDR(key) + ones, bits := prefix.Mask.Size() + for i := ones + 1; i <= bits; i++ { + prefix.Mask = net.CIDRMask(i, bits) + if y, _ = f(prefix.String()); y { + break + } + } } } d.Destinations = dsts |