Skip to content

Commit 7f62fa9

Browse files
tamihiroaauren
authored andcommitted
start peering connection to neighbors from node's advertise-ip
1 parent 61ed184 commit 7f62fa9

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
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

@@ -238,8 +243,8 @@ 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) (
242-
[]*gobgpapi.Peer, error) {
246+
func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []string, holdtime float64,
247+
localAddress string) ([]*gobgpapi.Peer, error) {
243248
peers := make([]*gobgpapi.Peer, 0)
244249

245250
// Validations
@@ -269,14 +274,19 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
269274
asns[i])
270275
}
271276

277+
// explicitly set neighbors.transport.config.local-address with nodeIP which is configured
278+
// as their neighbor address at the remote peers.
279+
// this prevents the controller from initiating connection to its peers with a different IP address
280+
// when multiple L3 interfaces are active.
272281
peer := &gobgpapi.Peer{
273282
Conf: &gobgpapi.PeerConf{
274283
NeighborAddress: ips[i].String(),
275284
PeerAs: asns[i],
276285
},
277286
Timers: &gobgpapi.Timers{Config: &gobgpapi.TimersConfig{HoldTime: uint64(holdtime)}},
278287
Transport: &gobgpapi.Transport{
279-
RemotePort: options.DefaultBgpPort,
288+
LocalAddress: localAddress,
289+
RemotePort: options.DefaultBgpPort,
280290
},
281291
}
282292

pkg/controllers/routing/network_routes_controller.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
10881088
}
10891089

10901090
// Create and set Global Peer Router complete configs
1091-
nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime)
1091+
nrc.globalPeerRouters, err = newGlobalPeers(peerIPs, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime,
1092+
nrc.nodeIP.String())
10921093
if err != nil {
10931094
err2 := nrc.bgpServer.StopBgp(context.Background(), &gobgpapi.StopBgpRequest{})
10941095
if err2 != nil {
@@ -1281,8 +1282,8 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
12811282
}
12821283
}
12831284

1284-
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, peerASNs,
1285-
peerPasswords, nrc.bgpHoldtime)
1285+
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts,
1286+
peerASNs, peerPasswords, nrc.bgpHoldtime, nrc.nodeIP.String())
12861287
if err != nil {
12871288
return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err)
12881289
}

0 commit comments

Comments
 (0)