diff options
author | Ben Agricola <bagricola@squiz.co.uk> | 2016-07-11 21:41:01 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-11 21:41:01 +0900 |
commit | ed62f3f3d91e378c53d4f6faea4fad4280c3079e (patch) | |
tree | 72bca446b4310618ae5a109f99f312c211bce49b /server | |
parent | dcdc6f7a05419d211590a6ac9fc60d41efea0dbe (diff) |
Add shorter prefix search
Adds a shorter-prefixes search mode that finds any identical-or-less-specific routes
than the input values.
Bug-Url: #1006
Signed-off-by: Ben Agricola bagricola@squiz.co.uk
Diffstat (limited to 'server')
-rw-r--r-- | server/server.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/server/server.go b/server/server.go index 6a766261..286ff85b 100644 --- a/server/server.go +++ b/server/server.go @@ -1605,7 +1605,21 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { } for _, dst := range arg.Table.Destinations { key := dst.Prefix - if _, err := f(id, key); err != nil { + if dst.LongerPrefixes { + _, prefix, _ := net.ParseCIDR(key) + for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) { + if d := dst.ToApiStruct(id); d != nil { + dsts = append(dsts, d) + } + } + } else if dst.ShorterPrefixes { + _, prefix, _ := net.ParseCIDR(key) + ones, bits := prefix.Mask.Size() + for i := ones; i > 0; i-- { + prefix.Mask = net.CIDRMask(i, bits) + f(id, prefix.String()) + } + } else if _, err := f(id, key); err != nil { if host := net.ParseIP(key); host != nil { masklen := 32 if af == bgp.RF_IPv6_UC { @@ -1617,14 +1631,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { } } } - } else if dst.LongerPrefixes { - _, prefix, _ := net.ParseCIDR(key) - - for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) { - if d := dst.ToApiStruct(id); d != nil { - dsts = append(dsts, d) - } - } } } } else { |