diff options
-rw-r--r-- | api/gobgp.pb.go | 5 | ||||
-rw-r--r-- | api/gobgp.proto | 1 | ||||
-rw-r--r-- | config/bgp_configs.go | 8 | ||||
-rw-r--r-- | config/default.go | 4 | ||||
-rw-r--r-- | gobgpd/main.go | 3 | ||||
-rw-r--r-- | server/server.go | 36 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 8 |
7 files changed, 46 insertions, 19 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 30b925aa..17da4c6b 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -1178,8 +1178,9 @@ func (m *Vrf) String() string { return proto.CompactTextString(m) } func (*Vrf) ProtoMessage() {} type Global struct { - As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` - RouterId string `protobuf:"bytes,2,opt,name=router_id" json:"router_id,omitempty"` + As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` + RouterId string `protobuf:"bytes,2,opt,name=router_id" json:"router_id,omitempty"` + ListenPort int32 `protobuf:"varint,3,opt,name=listen_port" json:"listen_port,omitempty"` } func (m *Global) Reset() { *m = Global{} } diff --git a/api/gobgp.proto b/api/gobgp.proto index df52a93e..ca3b3020 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -467,4 +467,5 @@ message Vrf { message Global { uint32 as = 1; string router_id = 2; + int32 listen_port = 3; } diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 5611124d..6302d867 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -802,6 +802,12 @@ type Neighbors struct { NeighborList []Neighbor } +//struct for container gobgp:listen-config +type ListenConfig struct { + // original -> gobgp:port + Port int32 +} + //struct for container gobgp:mpls-label-range type MplsLabelRange struct { // original -> gobgp:min-label @@ -1376,6 +1382,8 @@ type Global struct { Zebra Zebra // original -> gobgp:mpls-label-range MplsLabelRange MplsLabelRange + // original -> gobgp:listen-config + ListenConfig ListenConfig } //struct for container bgp:bgp diff --git a/config/default.go b/config/default.go index 2170e0dd..9f58a9b8 100644 --- a/config/default.go +++ b/config/default.go @@ -47,6 +47,10 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error { } } + if bt.Global.ListenConfig.Port == 0 { + bt.Global.ListenConfig.Port = bgp.BGP_PORT + } + if _, ok := global["Global.MplsLabelRange.MinLabel"]; !ok { bt.Global.MplsLabelRange.MinLabel = DEFAULT_MPLS_LABEL_MIN } diff --git a/gobgpd/main.go b/gobgpd/main.go index de348021..f8632771 100644 --- a/gobgpd/main.go +++ b/gobgpd/main.go @@ -21,7 +21,6 @@ import ( "github.com/jessevdk/go-flags" "github.com/osrg/gobgp/config" ops "github.com/osrg/gobgp/openswitch" - "github.com/osrg/gobgp/packet" "github.com/osrg/gobgp/server" "io/ioutil" "log/syslog" @@ -152,7 +151,7 @@ func main() { configCh := make(chan config.BgpConfigSet) reloadCh := make(chan bool) - bgpServer := server.NewBgpServer(bgp.BGP_PORT) + bgpServer := server.NewBgpServer() if opts.Ops { m, err := ops.NewOpsConfigManager(bgpServer.GrpcReqCh) if err != nil { 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 { diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index 1f0f7474..c849127e 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -681,4 +681,12 @@ module bgp-gobgp { } } } + + augment "/bgp:bgp/bgp:global" { + container listen-config { + leaf port { + type int32; + } + } + } } |