summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-11-11 22:54:21 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-12-21 19:28:25 +0900
commit406efffa74eadb44826e4b464dc2fbabdddf72c4 (patch)
tree78ba4c1b69ed3272e76175c70b26b2839b93130d /server
parente71fb3a3ae6129573f50848f7af8e83eb8a4d7e2 (diff)
*: add global listen port configuration
if port < 0, gobgpd won't listen on tcp:179 Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/server.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/server/server.go b/server/server.go
index 70886b34..e97fec41 100644
--- a/server/server.go
+++ b/server/server.go
@@ -85,7 +85,6 @@ type BgpServer struct {
bmpConfigCh chan config.BmpServers
GrpcReqCh chan *GrpcRequest
- listenPort int
policyUpdateCh chan config.RoutingPolicy
policy *table.RoutingPolicy
broadcastReqs []*GrpcRequest
@@ -101,7 +100,7 @@ type BgpServer struct {
watchers map[watcherType]watcher
}
-func NewBgpServer(port int) *BgpServer {
+func NewBgpServer() *BgpServer {
b := BgpServer{}
b.globalTypeCh = make(chan config.Global, 1)
b.addedPeerCh = make(chan config.Neighbor)
@@ -113,7 +112,6 @@ func NewBgpServer(port int) *BgpServer {
b.GrpcReqCh = make(chan *GrpcRequest, 1)
b.policyUpdateCh = make(chan config.RoutingPolicy)
b.neighborMap = make(map[string]*Peer)
- b.listenPort = port
b.watchers = make(map[watcherType]watcher)
b.roaManager, _ = newROAManager(0, config.RpkiServers{})
b.policy = table.NewRoutingPolicy()
@@ -121,8 +119,8 @@ func NewBgpServer(port int) *BgpServer {
}
// avoid mapped IPv6 address
-func listenAndAccept(proto string, port int, ch chan *net.TCPConn) (*net.TCPListener, error) {
- service := ":" + strconv.Itoa(port)
+func listenAndAccept(proto string, port uint32, ch chan *net.TCPConn) (*net.TCPListener, error) {
+ service := ":" + strconv.Itoa(int(port))
addr, _ := net.ResolveTCPAddr(proto, service)
l, err := net.ListenTCP(proto, addr)
@@ -230,13 +228,15 @@ func (server *BgpServer) Serve() {
server.globalRib = table.NewTableManager(rfs, g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel)
server.listenerMap = make(map[string]*net.TCPListener)
acceptCh := make(chan *net.TCPConn, 4096)
- l4, err1 := listenAndAccept("tcp4", server.listenPort, acceptCh)
- server.listenerMap["tcp4"] = l4
- l6, err2 := listenAndAccept("tcp6", server.listenPort, acceptCh)
- server.listenerMap["tcp6"] = l6
- if err1 != nil && err2 != nil {
- log.Fatal("can't listen either v4 and v6")
- os.Exit(1)
+ if g.ListenConfig.Port > 0 {
+ l4, err1 := listenAndAccept("tcp4", uint32(g.ListenConfig.Port), acceptCh)
+ server.listenerMap["tcp4"] = l4
+ l6, err2 := listenAndAccept("tcp6", uint32(g.ListenConfig.Port), acceptCh)
+ server.listenerMap["tcp6"] = l6
+ if err1 != nil && err2 != nil {
+ log.Fatal("can't listen either v4 and v6")
+ os.Exit(1)
+ }
}
listener := func(addr net.IP) *net.TCPListener {
@@ -365,8 +365,9 @@ func (server *BgpServer) Serve() {
log.Warn("Can't overwrite the exising peer ", addr)
continue
}
-
- SetTcpMD5SigSockopts(listener(config.NeighborConfig.NeighborAddress), addr, config.NeighborConfig.AuthPassword)
+ if g.ListenConfig.Port > 0 {
+ SetTcpMD5SigSockopts(listener(config.NeighborConfig.NeighborAddress), addr, config.NeighborConfig.AuthPassword)
+ }
peer := NewPeer(g, config, server.globalRib, server.policy)
server.setPolicyByConfig(peer.ID(), config.ApplyPolicy)
if peer.isRouteServerClient() {
@@ -1358,6 +1359,9 @@ func (server *BgpServer) handleModGlobalConfig(grpcReq *GrpcRequest) error {
As: g.As,
RouterId: net.ParseIP(g.RouterId),
},
+ ListenConfig: config.ListenConfig{
+ Port: g.ListenPort,
+ },
},
}
err := config.SetDefaultConfigValues(toml.MetaData{}, &c)
@@ -1895,7 +1899,9 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
} else {
log.Infof("Peer %s is added", addr)
}
- SetTcpMD5SigSockopts(listener(net.ParseIP(addr)), addr, arg.Peer.Conf.AuthPassword)
+ if server.bgpConfig.Global.ListenConfig.Port > 0 {
+ SetTcpMD5SigSockopts(listener(net.ParseIP(addr)), addr, arg.Peer.Conf.AuthPassword)
+ }
apitoConfig := func(a *api.Peer) (config.Neighbor, error) {
var pconf config.Neighbor
if a.Conf != nil {