summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gobgpd/main.go4
-rw-r--r--server/grpc_server.go24
2 files changed, 19 insertions, 9 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go
index b41b72d9..f6788cab 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -49,7 +49,7 @@ func main() {
DisableStdlog bool `long:"disable-stdlog" description:"disable standard logging"`
CPUs int `long:"cpus" description:"specify the number of CPUs to be used"`
Ops bool `long:"openswitch" description:"openswitch mode"`
- GrpcPort int `short:"g" long:"grpc-port" description:"grpc port" default:"50051"`
+ GrpcHosts string `long:"api-hosts" description:"specify the hosts that gobgpd listens on" default:":50051"`
GracefulRestart bool `short:"r" long:"graceful-restart" description:"flag restart-state in graceful-restart capability"`
Dry bool `short:"d" long:"dry-run" description:"check configuration"`
}
@@ -174,7 +174,7 @@ func main() {
go bgpServer.Serve()
// start grpc Server
- grpcServer := server.NewGrpcServer(opts.GrpcPort, bgpServer.GrpcReqCh)
+ grpcServer := server.NewGrpcServer(opts.GrpcHosts, bgpServer.GrpcReqCh)
go func() {
if err := grpcServer.Serve(); err != nil {
log.Fatalf("failed to listen grpc port: %s", err)
diff --git a/server/grpc_server.go b/server/grpc_server.go
index cff759ff..cf0a883d 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -24,6 +24,7 @@ import (
"google.golang.org/grpc"
"io"
"net"
+ "strings"
)
const (
@@ -79,15 +80,24 @@ const (
type Server struct {
grpcServer *grpc.Server
bgpServerCh chan *GrpcRequest
- port int
+ hosts string
}
func (s *Server) Serve() error {
- lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.port))
- if err != nil {
- return fmt.Errorf("failed to listen: %v", err)
+ l := strings.Split(s.hosts, ",")
+ for i, host := range l {
+ lis, err := net.Listen("tcp", fmt.Sprintf(host))
+ if err != nil {
+ return fmt.Errorf("failed to listen: %v", err)
+ }
+ if i == len(l)-1 {
+ s.grpcServer.Serve(lis)
+ } else {
+ go func() {
+ s.grpcServer.Serve(lis)
+ }()
+ }
}
- s.grpcServer.Serve(lis)
return nil
}
@@ -482,13 +492,13 @@ func (r *GrpcResponse) Err() error {
return r.ResponseErr
}
-func NewGrpcServer(port int, bgpServerCh chan *GrpcRequest) *Server {
+func NewGrpcServer(hosts string, bgpServerCh chan *GrpcRequest) *Server {
grpc.EnableTracing = false
grpcServer := grpc.NewServer()
server := &Server{
grpcServer: grpcServer,
bgpServerCh: bgpServerCh,
- port: port,
+ hosts: hosts,
}
api.RegisterGobgpApiServer(grpcServer, server)
return server