diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-12 14:47:59 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-12 15:01:12 +0900 |
commit | 95e7cc73083dfbc161b4ac6b0271c006d822d38d (patch) | |
tree | f76aeb30f19ee66aca066f366f105c0d0a5bf20c /server/server.go | |
parent | 180d68f88f457096ec92bcb6eabd915a64bb8858 (diff) |
mrt: support reset/rotate commands
$ gobgp mrt update reset
create a new file or reopen the existing file and continue to write
update messages to it.
$ gobgp mrt update <filename>
rename the current logging file to <filename> and truncate the logging
file and continue to write update messages to it.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index 8a5cabdf..46b9b44d 100644 --- a/server/server.go +++ b/server/server.go @@ -1691,6 +1691,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { server.broadcastReqs = append(server.broadcastReqs, grpcReq) case REQ_MRT_GLOBAL_RIB, REQ_MRT_LOCAL_RIB: server.handleMrt(grpcReq) + case REQ_MOD_MRT: + server.handleModMrt(grpcReq) case REQ_ROA, REQ_RPKI: server.roaClient.handleGRPC(grpcReq) case REQ_VRF, REQ_VRFS, REQ_VRF_MOD: @@ -2197,6 +2199,46 @@ 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) + } + arg := grpcReq.Data.(*api.ModMrtArguments) + w, y := server.watchers[WATCHER_MRT] + if arg.Operation == api.Operation_ADD { + if y { + done(fmt.Errorf("already enabled")) + return + } + } else { + if !y { + done(fmt.Errorf("not enabled yet")) + return + } + } + switch arg.Operation { + case api.Operation_ADD: + w, err := newMrtWatcher(arg.Filename) + if err == nil { + server.watchers[WATCHER_MRT] = w + } + done(err) + case api.Operation_DEL: + delete(server.watchers, WATCHER_MRT) + w.stop() + done(nil) + case api.Operation_REPLACE: + go func() { + err := w.restart(arg.Filename) + done(err) + }() + } +} + func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { now := uint32(time.Now().Unix()) view := "" |