summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go5
-rw-r--r--server/server.go36
2 files changed, 41 insertions, 0 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 6753417b..d68ecd96 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -62,6 +62,7 @@ const (
REQ_DEFINED_SET
REQ_MOD_DEFINED_SET
REQ_STATEMENT
+ REQ_MOD_STATEMENT
)
const GRPC_PORT = 8080
@@ -481,6 +482,10 @@ func (s *Server) GetStatements(arg *api.Statement, stream api.GobgpApi_GetStatem
})
}
+func (s *Server) ModStatement(ctx context.Context, arg *api.ModStatementArguments) (*api.Error, error) {
+ return s.mod(REQ_MOD_STATEMENT, arg)
+}
+
type GrpcRequest struct {
RequestType int
Name string
diff --git a/server/server.go b/server/server.go
index e25d314f..69c27f14 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1650,6 +1650,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
}
close(grpcReq.ResponseCh)
+ case REQ_MOD_STATEMENT:
+ err := server.handleGrpcModStatement(grpcReq)
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: err,
+ }
+ close(grpcReq.ResponseCh)
case REQ_POLICY_ROUTEPOLICY, REQ_POLICY_ROUTEPOLICIES:
info := server.policy.PolicyMap
typ := grpcReq.RequestType
@@ -1783,6 +1789,36 @@ func (server *BgpServer) handleGrpcGetStatement(grpcReq *GrpcRequest) error {
return nil
}
+func (server *BgpServer) handleGrpcModStatement(grpcReq *GrpcRequest) error {
+ arg := grpcReq.Data.(*api.ModStatementArguments)
+ s, err := table.NewStatementFromApiStruct(arg.Statement, server.policy.DefinedSetMap)
+ if err != nil {
+ return err
+ }
+ m := server.policy.StatementMap
+ name := s.Name
+ d, ok := m[name]
+ switch arg.Operation {
+ case api.Operation_ADD:
+ if ok {
+ err = d.Add(s)
+ } else {
+ m[name] = s
+ }
+ case api.Operation_DEL:
+ err = d.Remove(s)
+ case api.Operation_DEL_ALL:
+ if server.policy.StatementInUse(d) {
+ return fmt.Errorf("can't delete. statement %s is in use", name)
+ }
+ delete(m, name)
+ case api.Operation_REPLACE:
+ err = d.Replace(s)
+ }
+ return err
+
+}
+
func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) {
now := uint32(time.Now().Unix())
view := ""