Skip to content

Commit 8864c4e

Browse files
committed
start peering connection to neighbors from node's advertise-ip
1 parent 011b7aa commit 8864c4e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

pkg/controllers/routing/bgp_peers.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
9191

9292
currentNodes = append(currentNodes, nodeIP.String())
9393
nrc.activeNodes[nodeIP.String()] = true
94+
// explicitly set neighbors.transport.config.local-address with nodeIP which is configured
95+
// as their neighbor address at the remote peers.
96+
// this prevents the controller from initiating connection to its peers with a different IP address
97+
// when multiple L3 interfaces are active.
9498
n := &gobgpapi.Peer{
9599
Conf: &gobgpapi.PeerConf{
96100
NeighborAddress: nodeIP.String(),
97101
PeerAs: nrc.nodeAsnNumber,
98102
},
99103
Transport: &gobgpapi.Transport{
100-
RemotePort: nrc.bgpPort,
104+
LocalAddress: nrc.nodeIP.String(),
105+
RemotePort: nrc.bgpPort,
101106
},
102107
}
103108

@@ -182,7 +187,7 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
182187
}
183188
}
184189

185-
// connectToExternalBGPPeers adds all the configured eBGP peers (global or node specific) as neighbours// connectToExternalBGPPeers adds all the configured eBGP peers (global or node specific) as neighbours
190+
// connectToExternalBGPPeers adds all the configured eBGP peers (global or node specific) as neighbours
186191
func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*gobgpapi.Peer, bgpGracefulRestart bool, bgpGracefulRestartDeferralTime time.Duration,
187192
bgpGracefulRestartTime time.Duration, peerMultihopTTL uint8) error {
188193
for _, n := range peerNeighbors {
@@ -238,7 +243,7 @@ func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*gobgpap
238243
}
239244

240245
// Does validation and returns neighbor configs
241-
func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64) (
246+
func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64, localAddress string) (
242247
[]*gobgpapi.Peer, error) {
243248
peers := make([]*gobgpapi.Peer, 0)
244249

@@ -272,14 +277,19 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
272277
asns[i])
273278
}
274279

280+
// explicitly set neighbors.transport.config.local-address with nodeIP which is configured
281+
// as their neighbor address at the remote peers.
282+
// this prevents the controller from initiating connection to its peers with a different IP address
283+
// when multiple L3 interfaces are active.
275284
peer := &gobgpapi.Peer{
276285
Conf: &gobgpapi.PeerConf{
277286
NeighborAddress: ips[i].String(),
278287
PeerAs: asns[i],
279288
},
280289
Timers: &gobgpapi.Timers{Config: &gobgpapi.TimersConfig{HoldTime: uint64(holdtime)}},
281290
Transport: &gobgpapi.Transport{
282-
RemotePort: options.DefaultBgpPort,
291+
LocalAddress: localAddress,
292+
RemotePort: options.DefaultBgpPort,
283293
},
284294
}
285295

pkg/controllers/routing/network_routes_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
996996
}
997997

998998
// Create and set Global Peer Router complete configs
999-
nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime)
999+
nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime, nrc.nodeIP.String())
10001000
if err != nil {
10011001
err2 := nrc.bgpServer.StopBgp(context.Background(), &gobgpapi.StopBgpRequest{})
10021002
if err2 != nil {
@@ -1187,7 +1187,8 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
11871187
}
11881188
}
11891189

1190-
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime)
1190+
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts,
1191+
peerASNs, peerPasswords, nrc.bgpHoldtime, nrc.nodeIP.String())
11911192
if err != nil {
11921193
return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err)
11931194
}

0 commit comments

Comments
 (0)