summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go12
-rw-r--r--server/server.go45
2 files changed, 57 insertions, 0 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index c3f004df..e768c4c8 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -75,6 +75,7 @@ const (
REQ_MOD_PATH
REQ_GLOBAL_POLICY
REQ_DEFINED_SET
+ REQ_MOD_DEFINED_SET
)
const GRPC_PORT = 8080
@@ -519,6 +520,17 @@ func (s *Server) GetDefinedSets(arg *api.DefinedSet, stream api.GobgpApi_GetDefi
})
}
+func (s *Server) ModDefinedSet(ctx context.Context, arg *api.ModDefinedSetArguments) (*api.Error, error) {
+ none := &api.Error{}
+ req := NewGrpcRequest(REQ_MOD_DEFINED_SET, "", bgp.RouteFamily(0), arg)
+ s.bgpServerCh <- req
+ res := <-req.ResponseCh
+ if err := res.Err(); err != nil {
+ return none, err
+ }
+ return none, nil
+}
+
type GrpcRequest struct {
RequestType int
Name string
diff --git a/server/server.go b/server/server.go
index f60d4d6e..8867186c 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1637,6 +1637,13 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
}
close(grpcReq.ResponseCh)
+ case REQ_MOD_DEFINED_SET:
+ if err := server.handleGrpcModDefinedSet(grpcReq); err != nil {
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: err,
+ }
+ }
+ close(grpcReq.ResponseCh)
case REQ_POLICY_ROUTEPOLICY, REQ_POLICY_ROUTEPOLICIES:
info := server.policy.PolicyMap
typ := grpcReq.RequestType
@@ -1705,6 +1712,44 @@ func (server *BgpServer) handleGrpcGetDefinedSet(grpcReq *GrpcRequest) error {
return nil
}
+func (server *BgpServer) handleGrpcModDefinedSet(grpcReq *GrpcRequest) error {
+ arg := grpcReq.Data.(*api.ModDefinedSetArguments)
+ set := arg.Set
+ typ := table.DefinedType(set.Type)
+ name := set.Name
+ var err error
+ m, ok := server.policy.DefinedSetMap[typ]
+ if !ok {
+ return fmt.Errorf("invalid defined-set type: %d", typ)
+ }
+ d, ok := m[name]
+ if arg.Operation != api.Operation_ADD && !ok {
+ return fmt.Errorf("not found defined-set: %s", name)
+ }
+ s, err := table.NewDefinedSetFromApiStruct(set)
+ if err != nil {
+ return err
+ }
+ switch arg.Operation {
+ case api.Operation_ADD:
+ if ok {
+ err = d.Append(s)
+ } else {
+ m[name] = s
+ }
+ case api.Operation_DEL:
+ err = d.Remove(s)
+ case api.Operation_DEL_ALL:
+ if server.policy.InUse(d) {
+ return fmt.Errorf("can't delete. defined-set %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 := ""