*: add global listen port configuration

if port < 0, gobgpd won't listen on tcp:179

Signed-off-by: ISHIDA Wataru <[email protected]>
This commit is contained in:
ISHIDA Wataru
2015-12-21 19:28:25 +09:00
parent e71fb3a3ae
commit 406efffa74
7 changed files with 46 additions and 19 deletions
+3 -2
View File
@@ -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{} }
+1
View File
@@ -467,4 +467,5 @@ message Vrf {
message Global {
uint32 as = 1;
string router_id = 2;
int32 listen_port = 3;
}
+8
View File
@@ -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
+4
View File
@@ -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
}
+1 -2
View File
@@ -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 {
+21 -15
View File
@@ -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 {
+8
View File
@@ -681,4 +681,12 @@ module bgp-gobgp {
}
}
}
augment "/bgp:bgp/bgp:global" {
container listen-config {
leaf port {
type int32;
}
}
}
}