Skip to content

Commit ded7526

Browse files
authored
Fix BGP session flapping (#8213)
1 parent 37a2122 commit ded7526

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

nexus/src/app/background/tasks/sync_switch_configuration.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl BackgroundTask for SwitchPortSettingsManager {
491491
// build a list of desired settings for each switch
492492
let mut desired_bgp_configs: HashMap<
493493
SwitchLocation,
494-
Vec<ApplyRequest>,
494+
ApplyRequest,
495495
> = HashMap::new();
496496

497497
// we currently only support one bgp config per switch
@@ -785,48 +785,47 @@ impl BackgroundTask for SwitchPortSettingsManager {
785785
},
786786
};
787787

788-
let request = ApplyRequest {
789-
asn: *request_bgp_config.asn,
790-
peers,
791-
originate: request_prefixes.clone(),
792-
checker: request_bgp_config.checker.as_ref().map(|code| CheckerSource{
793-
asn: *request_bgp_config.asn,
794-
code: code.clone(),
795-
}),
796-
shaper: request_bgp_config.shaper.as_ref().map(|code| ShaperSource{
797-
asn: *request_bgp_config.asn,
798-
code: code.clone(),
799-
}),
800-
};
801-
802788
match desired_bgp_configs.entry(*location) {
803789
Entry::Occupied(mut occupied_entry) => {
804-
occupied_entry.get_mut().push(request);
790+
let config = occupied_entry.get_mut();
791+
// peers are the only per-port part of the config.
792+
config.peers.extend(peers);
805793
}
806794
Entry::Vacant(vacant_entry) => {
807-
vacant_entry.insert(vec![request]);
795+
vacant_entry.insert(
796+
ApplyRequest {
797+
asn: *request_bgp_config.asn,
798+
peers,
799+
originate: request_prefixes.clone(),
800+
checker: request_bgp_config.checker.as_ref().map(|code| CheckerSource{
801+
asn: *request_bgp_config.asn,
802+
code: code.clone(),
803+
}),
804+
shaper: request_bgp_config.shaper.as_ref().map(|code| ShaperSource{
805+
asn: *request_bgp_config.asn,
806+
code: code.clone(),
807+
}),
808+
});
808809
}
809810
}
810811
}
811812

812-
for (location, configs) in &desired_bgp_configs {
813+
for (location, config) in &desired_bgp_configs {
813814
let client = match mgd_clients.get(location) {
814815
Some(client) => client,
815816
None => {
816817
error!(log, "no mgd client found for switch"; "switch_location" => ?location);
817818
continue;
818819
},
819820
};
820-
for config in configs {
821-
info!(
822-
&log,
823-
"applying bgp config";
824-
"switch_location" => ?location,
825-
"config" => ?config,
826-
);
827-
if let Err(e) = client.bgp_apply(config).await {
828-
error!(log, "error while applying bgp configuration"; "error" => ?e);
829-
}
821+
info!(
822+
&log,
823+
"applying bgp config";
824+
"switch_location" => ?location,
825+
"config" => ?config,
826+
);
827+
if let Err(e) = client.bgp_apply(config).await {
828+
error!(log, "error while applying bgp configuration"; "error" => ?e);
830829
}
831830
}
832831

0 commit comments

Comments
 (0)