start peering connection to neighbors from node's advertise-ip

This commit is contained in:
Tamihiro Lee 2019-09-05 18:41:06 +09:00 committed by Aaron U'Ren
parent 61ed1849a0
commit 184976a536
2 changed files with 18 additions and 7 deletions

View File

@ -91,13 +91,18 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
currentNodes = append(currentNodes, nodeIP.String()) currentNodes = append(currentNodes, nodeIP.String())
nrc.activeNodes[nodeIP.String()] = true nrc.activeNodes[nodeIP.String()] = true
// explicitly set neighbors.transport.config.local-address with nodeIP which is configured
// as their neighbor address at the remote peers.
// this prevents the controller from initiating connection to its peers with a different IP address
// when multiple L3 interfaces are active.
n := &gobgpapi.Peer{ n := &gobgpapi.Peer{
Conf: &gobgpapi.PeerConf{ Conf: &gobgpapi.PeerConf{
NeighborAddress: nodeIP.String(), NeighborAddress: nodeIP.String(),
PeerAs: nrc.nodeAsnNumber, PeerAs: nrc.nodeAsnNumber,
}, },
Transport: &gobgpapi.Transport{ Transport: &gobgpapi.Transport{
RemotePort: nrc.bgpPort, LocalAddress: nrc.nodeIP.String(),
RemotePort: nrc.bgpPort,
}, },
} }
@ -238,8 +243,8 @@ func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*gobgpap
} }
// Does validation and returns neighbor configs // Does validation and returns neighbor configs
func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64) ( func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64,
[]*gobgpapi.Peer, error) { localAddress string) ([]*gobgpapi.Peer, error) {
peers := make([]*gobgpapi.Peer, 0) peers := make([]*gobgpapi.Peer, 0)
// Validations // Validations
@ -269,6 +274,10 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
asns[i]) asns[i])
} }
// explicitly set neighbors.transport.config.local-address with nodeIP which is configured
// as their neighbor address at the remote peers.
// this prevents the controller from initiating connection to its peers with a different IP address
// when multiple L3 interfaces are active.
peer := &gobgpapi.Peer{ peer := &gobgpapi.Peer{
Conf: &gobgpapi.PeerConf{ Conf: &gobgpapi.PeerConf{
NeighborAddress: ips[i].String(), NeighborAddress: ips[i].String(),
@ -276,7 +285,8 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
}, },
Timers: &gobgpapi.Timers{Config: &gobgpapi.TimersConfig{HoldTime: uint64(holdtime)}}, Timers: &gobgpapi.Timers{Config: &gobgpapi.TimersConfig{HoldTime: uint64(holdtime)}},
Transport: &gobgpapi.Transport{ Transport: &gobgpapi.Transport{
RemotePort: options.DefaultBgpPort, LocalAddress: localAddress,
RemotePort: options.DefaultBgpPort,
}, },
} }

View File

@ -1088,7 +1088,8 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
} }
// Create and set Global Peer Router complete configs // Create and set Global Peer Router complete configs
nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime) nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime,
nrc.nodeIP.String())
if err != nil { if err != nil {
err2 := nrc.bgpServer.StopBgp(context.Background(), &gobgpapi.StopBgpRequest{}) err2 := nrc.bgpServer.StopBgp(context.Background(), &gobgpapi.StopBgpRequest{})
if err2 != nil { if err2 != nil {
@ -1281,8 +1282,8 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
} }
} }
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, peerASNs, nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts,
peerPasswords, nrc.bgpHoldtime) peerASNs, peerPasswords, nrc.bgpHoldtime, nrc.nodeIP.String())
if err != nil { if err != nil {
return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err) return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err)
} }