From 184976a5369920ec176da961e61de739726be5fb Mon Sep 17 00:00:00 2001 From: Tamihiro Lee Date: Thu, 5 Sep 2019 18:41:06 +0900 Subject: [PATCH] start peering connection to neighbors from node's advertise-ip --- pkg/controllers/routing/bgp_peers.go | 18 ++++++++++++++---- .../routing/network_routes_controller.go | 7 ++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pkg/controllers/routing/bgp_peers.go b/pkg/controllers/routing/bgp_peers.go index 879e0c8a..59fc2a6c 100644 --- a/pkg/controllers/routing/bgp_peers.go +++ b/pkg/controllers/routing/bgp_peers.go @@ -91,13 +91,18 @@ func (nrc *NetworkRoutingController) syncInternalPeers() { currentNodes = append(currentNodes, nodeIP.String()) 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{ Conf: &gobgpapi.PeerConf{ NeighborAddress: nodeIP.String(), PeerAs: nrc.nodeAsnNumber, }, 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 -func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64) ( - []*gobgpapi.Peer, error) { +func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64, + localAddress string) ([]*gobgpapi.Peer, error) { peers := make([]*gobgpapi.Peer, 0) // Validations @@ -269,6 +274,10 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str 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{ Conf: &gobgpapi.PeerConf{ 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)}}, Transport: &gobgpapi.Transport{ - RemotePort: options.DefaultBgpPort, + LocalAddress: localAddress, + RemotePort: options.DefaultBgpPort, }, } diff --git a/pkg/controllers/routing/network_routes_controller.go b/pkg/controllers/routing/network_routes_controller.go index 75227e08..894b024e 100644 --- a/pkg/controllers/routing/network_routes_controller.go +++ b/pkg/controllers/routing/network_routes_controller.go @@ -1088,7 +1088,8 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error { } // 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 { err2 := nrc.bgpServer.StopBgp(context.Background(), &gobgpapi.StopBgpRequest{}) if err2 != nil { @@ -1281,8 +1282,8 @@ func NewNetworkRoutingController(clientset kubernetes.Interface, } } - nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, peerASNs, - peerPasswords, nrc.bgpHoldtime) + nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, + peerASNs, peerPasswords, nrc.bgpHoldtime, nrc.nodeIP.String()) if err != nil { return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err) }