diff options
-rw-r--r-- | server/grpc_server.go | 6 | ||||
-rw-r--r-- | server/server.go | 38 |
2 files changed, 20 insertions, 24 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index cbe5bf55..fef1a21a 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -639,11 +639,7 @@ func (s *Server) DeleteBmp(ctx context.Context, arg *api.DeleteBmpRequest) (*api } func (s *Server) ValidateRib(ctx context.Context, arg *api.ValidateRibRequest) (*api.ValidateRibResponse, error) { - d, err := s.get(REQ_VALIDATE_RIB, arg) - if err != nil { - return nil, err - } - return d.(*api.ValidateRibResponse), err + return &api.ValidateRibResponse{}, s.bgpServer.ValidateRib(arg.Prefix) } func (s *Server) AddRpki(ctx context.Context, arg *api.AddRpkiRequest) (*api.AddRpkiResponse, error) { diff --git a/server/server.go b/server/server.go index 5d01ecfa..10ee11aa 100644 --- a/server/server.go +++ b/server/server.go @@ -1623,8 +1623,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { } grpcReq.ResponseCh <- &GrpcResponse{Data: &api.SoftResetNeighborResponse{}} close(grpcReq.ResponseCh) - case REQ_VALIDATE_RIB: - server.handleValidateRib(grpcReq) case REQ_INITIALIZE_RPKI: g := grpcReq.Data.(*config.Global) grpcDone(grpcReq, server.roaManager.SetAS(g.Config.As)) @@ -2622,27 +2620,29 @@ func (s *BgpServer) DisableMrt() (err error) { return err } -func (server *BgpServer) handleValidateRib(grpcReq *GrpcRequest) { - arg := grpcReq.Data.(*api.ValidateRibRequest) - for _, rf := range server.globalRib.GetRFlist() { - if t, ok := server.globalRib.Tables[rf]; ok { - dsts := t.GetDestinations() - if arg.Prefix != "" { - _, prefix, _ := net.ParseCIDR(arg.Prefix) - if dst := t.GetDestination(prefix.String()); dst != nil { - dsts = map[string]*table.Destination{prefix.String(): dst} +func (s *BgpServer) ValidateRib(prefix string) (err error) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + for _, rf := range s.globalRib.GetRFlist() { + if t, ok := s.globalRib.Tables[rf]; ok { + dsts := t.GetDestinations() + if prefix != "" { + _, p, _ := net.ParseCIDR(prefix) + if dst := t.GetDestination(p.String()); dst != nil { + dsts = map[string]*table.Destination{p.String(): dst} + } + } + for _, dst := range dsts { + s.roaManager.validate(dst.GetAllKnownPathList()) } - } - for _, dst := range dsts { - server.roaManager.validate(dst.GetAllKnownPathList()) } } } - result := &GrpcResponse{ - Data: &api.ValidateRibResponse{}, - } - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) + return err } func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) { |