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 | |
parent | d62984352e4acc8c6091213f37a18d41dfe1c49d (diff) |
rpki: grpc support
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | api/gobgp.pb.go | 101 | ||||
-rw-r--r-- | api/gobgp.proto | 7 | ||||
-rw-r--r-- | gobgp/cmd/rpki.go | 21 | ||||
-rw-r--r-- | server/grpc_server.go | 5 | ||||
-rw-r--r-- | server/server.go | 61 |
5 files changed, 181 insertions, 14 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 04f6f9b0..7932ff57 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -15,6 +15,7 @@ It has these top-level messages: ModNeighborArguments MrtArguments ModMrtArguments + ModRpkiArguments ModVrfArguments ModDefinedSetArguments ModStatementArguments @@ -402,6 +403,16 @@ func (m *ModMrtArguments) Reset() { *m = ModMrtArguments{} } func (m *ModMrtArguments) String() string { return proto.CompactTextString(m) } func (*ModMrtArguments) ProtoMessage() {} +type ModRpkiArguments struct { + Operation Operation `protobuf:"varint,1,opt,name=operation,enum=gobgpapi.Operation" json:"operation,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"` + Port uint32 `protobuf:"varint,3,opt,name=port" json:"port,omitempty"` +} + +func (m *ModRpkiArguments) Reset() { *m = ModRpkiArguments{} } +func (m *ModRpkiArguments) String() string { return proto.CompactTextString(m) } +func (*ModRpkiArguments) ProtoMessage() {} + type ModVrfArguments struct { Operation Operation `protobuf:"varint,1,opt,name=operation,enum=gobgpapi.Operation" json:"operation,omitempty"` Vrf *Vrf `protobuf:"bytes,2,opt,name=vrf" json:"vrf,omitempty"` @@ -1492,6 +1503,69 @@ func (m *Global) String() string { return proto.CompactTextString(m) } func (*Global) ProtoMessage() {} func init() { + proto.RegisterType((*Error)(nil), "gobgpapi.Error") + proto.RegisterType((*Arguments)(nil), "gobgpapi.Arguments") + proto.RegisterType((*ModPathArguments)(nil), "gobgpapi.ModPathArguments") + proto.RegisterType((*ModNeighborArguments)(nil), "gobgpapi.ModNeighborArguments") + proto.RegisterType((*MrtArguments)(nil), "gobgpapi.MrtArguments") + proto.RegisterType((*ModMrtArguments)(nil), "gobgpapi.ModMrtArguments") + proto.RegisterType((*ModRpkiArguments)(nil), "gobgpapi.ModRpkiArguments") + proto.RegisterType((*ModVrfArguments)(nil), "gobgpapi.ModVrfArguments") + proto.RegisterType((*ModDefinedSetArguments)(nil), "gobgpapi.ModDefinedSetArguments") + proto.RegisterType((*ModStatementArguments)(nil), "gobgpapi.ModStatementArguments") + proto.RegisterType((*ModPolicyArguments)(nil), "gobgpapi.ModPolicyArguments") + proto.RegisterType((*ModPolicyAssignmentArguments)(nil), "gobgpapi.ModPolicyAssignmentArguments") + proto.RegisterType((*ModGlobalConfigArguments)(nil), "gobgpapi.ModGlobalConfigArguments") + proto.RegisterType((*Path)(nil), "gobgpapi.Path") + proto.RegisterType((*Destination)(nil), "gobgpapi.Destination") + proto.RegisterType((*Peer)(nil), "gobgpapi.Peer") + proto.RegisterType((*AddPaths)(nil), "gobgpapi.AddPaths") + proto.RegisterType((*AfiSafis)(nil), "gobgpapi.AfiSafis") + proto.RegisterType((*AfiSafi)(nil), "gobgpapi.AfiSafi") + proto.RegisterType((*ApplyPolicy)(nil), "gobgpapi.ApplyPolicy") + proto.RegisterType((*AfiSafiGracefulRestart)(nil), "gobgpapi.AfiSafiGracefulRestart") + proto.RegisterType((*LabelledUnicast)(nil), "gobgpapi.LabelledUnicast") + proto.RegisterType((*PrefixLimit)(nil), "gobgpapi.PrefixLimit") + proto.RegisterType((*Unicast)(nil), "gobgpapi.Unicast") + proto.RegisterType((*Vpn)(nil), "gobgpapi.Vpn") + proto.RegisterType((*Prefixes)(nil), "gobgpapi.Prefixes") + proto.RegisterType((*UseMultiplePaths)(nil), "gobgpapi.UseMultiplePaths") + proto.RegisterType((*Ebgp)(nil), "gobgpapi.Ebgp") + proto.RegisterType((*AsPathOptions)(nil), "gobgpapi.AsPathOptions") + proto.RegisterType((*PeerConf)(nil), "gobgpapi.PeerConf") + proto.RegisterType((*EbgpMultihop)(nil), "gobgpapi.EbgpMultihop") + proto.RegisterType((*ErrorHandling)(nil), "gobgpapi.ErrorHandling") + proto.RegisterType((*PeerGracefulRestart)(nil), "gobgpapi.PeerGracefulRestart") + proto.RegisterType((*LoggingOptions)(nil), "gobgpapi.LoggingOptions") + proto.RegisterType((*RouteReflector)(nil), "gobgpapi.RouteReflector") + proto.RegisterType((*PeerState)(nil), "gobgpapi.PeerState") + proto.RegisterType((*Messages)(nil), "gobgpapi.Messages") + proto.RegisterType((*Message)(nil), "gobgpapi.Message") + proto.RegisterType((*Queues)(nil), "gobgpapi.Queues") + proto.RegisterType((*Timers)(nil), "gobgpapi.Timers") + proto.RegisterType((*TimersConfig)(nil), "gobgpapi.TimersConfig") + proto.RegisterType((*TimersState)(nil), "gobgpapi.TimersState") + proto.RegisterType((*Transport)(nil), "gobgpapi.Transport") + proto.RegisterType((*RouteServer)(nil), "gobgpapi.RouteServer") + proto.RegisterType((*Prefix)(nil), "gobgpapi.Prefix") + proto.RegisterType((*DefinedSet)(nil), "gobgpapi.DefinedSet") + proto.RegisterType((*MatchSet)(nil), "gobgpapi.MatchSet") + proto.RegisterType((*AsPathLength)(nil), "gobgpapi.AsPathLength") + proto.RegisterType((*Conditions)(nil), "gobgpapi.Conditions") + proto.RegisterType((*CommunityAction)(nil), "gobgpapi.CommunityAction") + proto.RegisterType((*MedAction)(nil), "gobgpapi.MedAction") + proto.RegisterType((*AsPrependAction)(nil), "gobgpapi.AsPrependAction") + proto.RegisterType((*Actions)(nil), "gobgpapi.Actions") + proto.RegisterType((*Statement)(nil), "gobgpapi.Statement") + proto.RegisterType((*Policy)(nil), "gobgpapi.Policy") + proto.RegisterType((*PolicyAssignment)(nil), "gobgpapi.PolicyAssignment") + proto.RegisterType((*MrtMessage)(nil), "gobgpapi.MrtMessage") + proto.RegisterType((*RPKIConf)(nil), "gobgpapi.RPKIConf") + proto.RegisterType((*RPKIState)(nil), "gobgpapi.RPKIState") + proto.RegisterType((*RPKI)(nil), "gobgpapi.RPKI") + proto.RegisterType((*ROA)(nil), "gobgpapi.ROA") + proto.RegisterType((*Vrf)(nil), "gobgpapi.Vrf") + proto.RegisterType((*Global)(nil), "gobgpapi.Global") proto.RegisterEnum("gobgpapi.Resource", Resource_name, Resource_value) proto.RegisterEnum("gobgpapi.Operation", Operation_name, Operation_value) proto.RegisterEnum("gobgpapi.DefinedType", DefinedType_name, DefinedType_value) @@ -1530,6 +1604,7 @@ type GobgpApiClient interface { GetMrt(ctx context.Context, in *MrtArguments, opts ...grpc.CallOption) (GobgpApi_GetMrtClient, error) ModMrt(ctx context.Context, in *ModMrtArguments, opts ...grpc.CallOption) (*Error, error) GetRPKI(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (GobgpApi_GetRPKIClient, error) + ModRPKI(ctx context.Context, in *ModRpkiArguments, opts ...grpc.CallOption) (*Error, error) GetROA(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (GobgpApi_GetROAClient, error) GetVrfs(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (GobgpApi_GetVrfsClient, error) ModVrf(ctx context.Context, in *ModVrfArguments, opts ...grpc.CallOption) (*Error, error) @@ -1888,6 +1963,15 @@ func (x *gobgpApiGetRPKIClient) Recv() (*RPKI, error) { return m, nil } +func (c *gobgpApiClient) ModRPKI(ctx context.Context, in *ModRpkiArguments, opts ...grpc.CallOption) (*Error, error) { + out := new(Error) + err := grpc.Invoke(ctx, "/gobgpapi.GobgpApi/ModRPKI", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *gobgpApiClient) GetROA(ctx context.Context, in *Arguments, opts ...grpc.CallOption) (GobgpApi_GetROAClient, error) { stream, err := grpc.NewClientStream(ctx, &_GobgpApi_serviceDesc.Streams[7], c.cc, "/gobgpapi.GobgpApi/GetROA", opts...) if err != nil { @@ -2151,6 +2235,7 @@ type GobgpApiServer interface { GetMrt(*MrtArguments, GobgpApi_GetMrtServer) error ModMrt(context.Context, *ModMrtArguments) (*Error, error) GetRPKI(*Arguments, GobgpApi_GetRPKIServer) error + ModRPKI(context.Context, *ModRpkiArguments) (*Error, error) GetROA(*Arguments, GobgpApi_GetROAServer) error GetVrfs(*Arguments, GobgpApi_GetVrfsServer) error ModVrf(context.Context, *ModVrfArguments) (*Error, error) @@ -2467,6 +2552,18 @@ func (x *gobgpApiGetRPKIServer) Send(m *RPKI) error { return x.ServerStream.SendMsg(m) } +func _GobgpApi_ModRPKI_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { + in := new(ModRpkiArguments) + if err := dec(in); err != nil { + return nil, err + } + out, err := srv.(GobgpApiServer).ModRPKI(ctx, in) + if err != nil { + return nil, err + } + return out, nil +} + func _GobgpApi_GetROA_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(Arguments) if err := stream.RecvMsg(m); err != nil { @@ -2733,6 +2830,10 @@ var _GobgpApi_serviceDesc = grpc.ServiceDesc{ Handler: _GobgpApi_ModMrt_Handler, }, { + MethodName: "ModRPKI", + Handler: _GobgpApi_ModRPKI_Handler, + }, + { MethodName: "ModVrf", Handler: _GobgpApi_ModVrf_Handler, }, diff --git a/api/gobgp.proto b/api/gobgp.proto index fc6d8f69..2857cf45 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -39,6 +39,7 @@ service GobgpApi { rpc GetMrt(MrtArguments) returns (stream MrtMessage) {} rpc ModMrt(ModMrtArguments) returns (Error) {} rpc GetRPKI(Arguments) returns (stream RPKI) {} + rpc ModRPKI(ModRpkiArguments) returns (Error) {} rpc GetROA(Arguments) returns (stream ROA) {} rpc GetVrfs(Arguments) returns (stream Vrf) {} rpc ModVrf(ModVrfArguments) returns (Error) {} @@ -93,6 +94,12 @@ message ModMrtArguments { string filename = 2; } +message ModRpkiArguments { + Operation operation = 1; + string address = 2; + uint32 port = 3; +} + message ModVrfArguments { Operation operation = 1; Vrf vrf = 2; diff --git a/gobgp/cmd/rpki.go b/gobgp/cmd/rpki.go index 7d206b6e..484a990c 100644 --- a/gobgp/cmd/rpki.go +++ b/gobgp/cmd/rpki.go @@ -95,6 +95,27 @@ func NewRPKICmd() *cobra.Command { Use: CMD_RPKI, } + modRPKI := func(op api.Operation, address string) { + arg := &api.ModRpkiArguments{ + Operation: op, + Address: address, + Port: 323, + } + client.ModRPKI(context.Background(), arg) + } + + enableCmd := &cobra.Command{ + Use: CMD_ENABLE, + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 1 { + fmt.Println("usage: gobgp rpki enable <ip address>") + os.Exit(1) + } + modRPKI(api.Operation_ADD, args[0]) + }, + } + rpkiCmd.AddCommand(enableCmd) + serverCmd := &cobra.Command{ Use: CMD_RPKI_SERVER, Run: func(cmd *cobra.Command, args []string) { 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 := "" |