diff options
author | Toshiki Tsuchiya <taruta0811@gmail.com> | 2020-01-04 15:55:40 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2020-01-05 20:56:43 +0900 |
commit | 543f50ded98b7c6da29bdd70246d1c8e17ab93cd (patch) | |
tree | 8d2f72df8890a9211ee340fd2a4eddde1c44a0ec /pkg | |
parent | a4b688a25ffca6eca74db36876d107c104cfb147 (diff) |
gobgpd: use map for validation table
`Table.destinations` is a map, so the order changes.
This commit allows to get validate information from path by using map for validate table
Fix: https://github.com/osrg/gobgp/issues/2223
Signed-off-by: Toshiki Tsuchiya <taruta0811@gmail.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/server/grpc_server.go | 4 | ||||
-rw-r--r-- | pkg/server/server.go | 16 |
2 files changed, 9 insertions, 11 deletions
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 215a1866..69af445c 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -160,11 +160,11 @@ func toPathApi(path *table.Path, v *table.Validation) *api.Path { return toPathAPI(nil, nil, anyNlri, anyPattrs, path, v) } -func getValidation(v []*table.Validation, i int) *table.Validation { +func getValidation(v map[*table.Path]*table.Validation, p *table.Path) *table.Validation { if v == nil { return nil } else { - return v[i] + return v[p] } } diff --git a/pkg/server/server.go b/pkg/server/server.go index b8e29f6d..d9e14926 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2351,19 +2351,19 @@ func (s *BgpServer) sReset(addr string, family bgp.RouteFamily) error { return s.softResetOut(addr, family, false) } -func (s *BgpServer) validateTable(r *table.Table) (v []*table.Validation) { +func (s *BgpServer) validateTable(r *table.Table) (v map[*table.Path]*table.Validation) { if s.roaManager.enabled() { - v = make([]*table.Validation, 0, len(r.GetDestinations())) + v = make(map[*table.Path]*table.Validation, len(r.GetDestinations())) for _, d := range r.GetDestinations() { for _, p := range d.GetAllKnownPathList() { - v = append(v, s.roaTable.Validate(p)) + v[p] = s.roaTable.Validate(p) } } } return } -func (s *BgpServer) getRib(addr string, family bgp.RouteFamily, prefixes []*table.LookupPrefix) (rib *table.Table, v []*table.Validation, err error) { +func (s *BgpServer) getRib(addr string, family bgp.RouteFamily, prefixes []*table.LookupPrefix) (rib *table.Table, v map[*table.Path]*table.Validation, err error) { err = s.mgmtOperation(func() error { m := s.globalRib id := table.GLOBAL_RIB_NAME @@ -2422,7 +2422,7 @@ func (s *BgpServer) getVrfRib(name string, family bgp.RouteFamily, prefixes []*t return } -func (s *BgpServer) getAdjRib(addr string, family bgp.RouteFamily, in bool, enableFiltered bool, prefixes []*table.LookupPrefix) (rib *table.Table, filtered map[string]*table.Path, v []*table.Validation, err error) { +func (s *BgpServer) getAdjRib(addr string, family bgp.RouteFamily, in bool, enableFiltered bool, prefixes []*table.LookupPrefix) (rib *table.Table, filtered map[string]*table.Path, v map[*table.Path]*table.Validation, err error) { err = s.mgmtOperation(func() error { peer, ok := s.neighborMap[addr] if !ok { @@ -2474,7 +2474,7 @@ func (s *BgpServer) getAdjRib(addr string, family bgp.RouteFamily, in bool, enab func (s *BgpServer) ListPath(ctx context.Context, r *api.ListPathRequest, fn func(*api.Destination)) error { var tbl *table.Table - var v []*table.Validation + var v map[*table.Path]*table.Validation var filtered map[string]*table.Path f := func() []*table.LookupPrefix { @@ -2512,7 +2512,6 @@ func (s *BgpServer) ListPath(ctx context.Context, r *api.ListPathRequest, fn fun return err } - idx := 0 err = func() error { for _, dst := range tbl.GetDestinations() { d := api.Destination{ @@ -2521,8 +2520,7 @@ func (s *BgpServer) ListPath(ctx context.Context, r *api.ListPathRequest, fn fun } knownPathList := dst.GetAllKnownPathList() for i, path := range knownPathList { - p := toPathApi(path, getValidation(v, idx)) - idx++ + p := toPathApi(path, getValidation(v, path)) if !table.SelectionOptions.DisableBestPathSelection { if i == 0 { switch r.TableType { |