diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-23 22:59:04 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-23 23:00:18 -0800 |
commit | a1602f3a256177d5d9474a403928cc6bc00bbc85 (patch) | |
tree | 71c22ea459b3868d7e037aa870389f4c5c9ce4a3 /server | |
parent | d62984352e4acc8c6091213f37a18d41dfe1c49d (diff) |
rpki: grpc support
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/grpc_server.go | 5 | ||||
-rw-r--r-- | server/server.go | 61 |
2 files changed, 52 insertions, 14 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 5ec5947b..68d0e72b 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -50,6 +50,7 @@ const ( REQ_MRT_LOCAL_RIB REQ_MOD_MRT REQ_RPKI + REQ_MOD_RPKI REQ_ROA REQ_VRF REQ_VRFS @@ -264,6 +265,10 @@ func (s *Server) ModMrt(ctx context.Context, arg *api.ModMrtArguments) (*api.Err return s.mod(REQ_MOD_MRT, arg) } +func (s *Server) ModRPKI(ctx context.Context, arg *api.ModRpkiArguments) (*api.Error, error) { + return s.mod(REQ_MOD_RPKI, arg) +} + func (s *Server) GetRPKI(arg *api.Arguments, stream api.GobgpApi_GetRPKIServer) error { req := NewGrpcRequest(REQ_RPKI, "", bgp.RouteFamily(arg.Rf), nil) s.bgpServerCh <- req diff --git a/server/server.go b/server/server.go index 3e7d4072..0b8faf76 100644 --- a/server/server.go +++ b/server/server.go @@ -119,6 +119,7 @@ func NewBgpServer(port int) *BgpServer { b.neighborMap = make(map[string]*Peer) b.listenPort = port b.watchers = make(map[watcherType]watcher) + b.roaClient, _ = newROAClient(0, config.RpkiServers{}) return &b } @@ -161,8 +162,6 @@ func (server *BgpServer) Serve() { } } - server.roaClient, _ = newROAClient(g.GlobalConfig.As, config.RpkiServers{}) - if g.Mrt.FileName != "" { w, err := newMrtWatcher(g.Mrt.FileName) if err != nil { @@ -1697,6 +1696,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { server.handleMrt(grpcReq) case REQ_MOD_MRT: server.handleModMrt(grpcReq) + case REQ_MOD_RPKI: + server.handleModRpki(grpcReq) case REQ_ROA, REQ_RPKI: server.roaClient.handleGRPC(grpcReq) case REQ_VRF, REQ_VRFS, REQ_VRF_MOD: @@ -2203,24 +2204,25 @@ func (server *BgpServer) handleGrpcModPolicyAssignment(grpcReq *GrpcRequest) err return err } -func (server *BgpServer) handleModMrt(grpcReq *GrpcRequest) { - done := func(e error) { - result := &GrpcResponse{ - ResponseErr: e, - } - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) +func grpcDone(grpcReq *GrpcRequest, e error) { + result := &GrpcResponse{ + ResponseErr: e, } + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) +} + +func (server *BgpServer) handleModMrt(grpcReq *GrpcRequest) { arg := grpcReq.Data.(*api.ModMrtArguments) w, y := server.watchers[WATCHER_MRT] if arg.Operation == api.Operation_ADD { if y { - done(fmt.Errorf("already enabled")) + grpcDone(grpcReq, fmt.Errorf("already enabled")) return } } else { if !y { - done(fmt.Errorf("not enabled yet")) + grpcDone(grpcReq, fmt.Errorf("not enabled yet")) return } } @@ -2230,19 +2232,50 @@ func (server *BgpServer) handleModMrt(grpcReq *GrpcRequest) { if err == nil { server.watchers[WATCHER_MRT] = w } - done(err) + grpcDone(grpcReq, err) case api.Operation_DEL: delete(server.watchers, WATCHER_MRT) w.stop() - done(nil) + grpcDone(grpcReq, nil) case api.Operation_REPLACE: go func() { err := w.restart(arg.Filename) - done(err) + grpcDone(grpcReq, err) }() } } +func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) { + arg := grpcReq.Data.(*api.ModRpkiArguments) + configured := false + if len(server.bgpConfig.RpkiServers.RpkiServerList) > 0 { + configured = true + } + + if arg.Operation == api.Operation_ADD { + if configured { + grpcDone(grpcReq, fmt.Errorf("already enabled")) + return + } + } else { + if !configured { + grpcDone(grpcReq, fmt.Errorf("not enabled yet")) + return + } + } + switch arg.Operation { + case api.Operation_ADD: + r := config.RpkiServer{} + r.RpkiServerConfig.Address = net.ParseIP(arg.Address) + r.RpkiServerConfig.Port = arg.Port + server.bgpConfig.RpkiServers.RpkiServerList = append(server.bgpConfig.RpkiServers.RpkiServerList, r) + server.roaClient, _ = newROAClient(server.bgpConfig.Global.GlobalConfig.As, server.bgpConfig.RpkiServers) + grpcDone(grpcReq, nil) + return + } + grpcDone(grpcReq, fmt.Errorf("not supported yet")) +} + func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { now := uint32(time.Now().Unix()) view := "" |