summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go14
-rw-r--r--server/server.go70
2 files changed, 81 insertions, 3 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 348d11c7..c475f232 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -28,6 +28,8 @@ import (
const (
_ = iota
+ REQ_GLOBAL_CONFIG
+ REQ_MOD_GLOBAL_CONFIG
REQ_NEIGHBOR
REQ_NEIGHBORS
REQ_ADJ_RIB_IN
@@ -385,6 +387,18 @@ func (s *Server) ModPolicyAssignment(ctx context.Context, arg *api.ModPolicyAssi
return s.mod(REQ_MOD_POLICY_ASSIGNMENT, arg)
}
+func (s *Server) GetGlobalConfig(ctx context.Context, arg *api.Arguments) (*api.Global, error) {
+ d, err := s.get(REQ_GLOBAL_CONFIG, arg)
+ if err != nil {
+ return nil, err
+ }
+ return d.(*api.Global), nil
+}
+
+func (s *Server) ModGlobalConfig(ctx context.Context, arg *api.ModGlobalConfigArguments) (*api.Error, error) {
+ return s.mod(REQ_MOD_GLOBAL_CONFIG, arg)
+}
+
type GrpcRequest struct {
RequestType int
Name string
diff --git a/server/server.go b/server/server.go
index 49b584ca..67499076 100644
--- a/server/server.go
+++ b/server/server.go
@@ -18,6 +18,7 @@ package server
import (
"bytes"
"fmt"
+ "github.com/BurntSushi/toml"
log "github.com/Sirupsen/logrus"
"github.com/armon/go-radix"
api "github.com/osrg/gobgp/api"
@@ -142,8 +143,19 @@ func listenAndAccept(proto string, port int, ch chan *net.TCPConn) (*net.TCPList
}
func (server *BgpServer) Serve() {
- g := <-server.globalTypeCh
- server.bgpConfig.Global = g
+ var g config.Global
+ for {
+ select {
+ case grpcReq := <-server.GrpcReqCh:
+ server.handleGrpc(grpcReq)
+ case g = <-server.globalTypeCh:
+ server.bgpConfig.Global = g
+ server.globalTypeCh = nil
+ }
+ if server.globalTypeCh == nil {
+ break
+ }
+ }
server.roaClient, _ = newROAClient(g.GlobalConfig.As, config.RpkiServers{})
@@ -830,7 +842,9 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
}
func (server *BgpServer) SetGlobalType(g config.Global) {
- server.globalTypeCh <- g
+ if server.globalTypeCh != nil {
+ server.globalTypeCh <- g
+ }
}
func (server *BgpServer) SetRpkiConfig(c config.RpkiServers) {
@@ -1254,6 +1268,33 @@ END:
return msgs
}
+func (server *BgpServer) handleModGlobalConfig(grpcReq *GrpcRequest) error {
+ arg := grpcReq.Data.(*api.ModGlobalConfigArguments)
+ if arg.Operation != api.Operation_ADD {
+ return fmt.Errorf("invalid operation %s", arg.Operation)
+ }
+ if server.globalTypeCh == nil {
+ return fmt.Errorf("gobgp is already started")
+ }
+ g := arg.Global
+ c := config.Bgp{
+ Global: config.Global{
+ GlobalConfig: config.GlobalConfig{
+ As: g.As,
+ RouterId: net.ParseIP(g.RouterId),
+ },
+ },
+ }
+ err := config.SetDefaultConfigValues(toml.MetaData{}, &c)
+ if err != nil {
+ return err
+ }
+ go func() {
+ server.globalTypeCh <- c.Global
+ }()
+ return nil
+}
+
func sendMultipleResponses(grpcReq *GrpcRequest, results []*GrpcResponse) {
defer close(grpcReq.ResponseCh)
for _, r := range results {
@@ -1307,7 +1348,30 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
return results
}
+ if server.globalTypeCh != nil && grpcReq.RequestType != REQ_MOD_GLOBAL_CONFIG {
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: fmt.Errorf("bgpd main loop is not started yet"),
+ }
+ close(grpcReq.ResponseCh)
+ return nil
+ }
+
switch grpcReq.RequestType {
+ case REQ_GLOBAL_CONFIG:
+ result := &GrpcResponse{
+ Data: &api.Global{
+ As: server.bgpConfig.Global.GlobalConfig.As,
+ RouterId: server.bgpConfig.Global.GlobalConfig.RouterId.String(),
+ },
+ }
+ grpcReq.ResponseCh <- result
+ close(grpcReq.ResponseCh)
+ case REQ_MOD_GLOBAL_CONFIG:
+ err := server.handleModGlobalConfig(grpcReq)
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: err,
+ }
+ close(grpcReq.ResponseCh)
case REQ_GLOBAL_RIB:
var results []*GrpcResponse
if t, ok := server.globalRib.Tables[grpcReq.RouteFamily]; ok {