Skip to content

Commit 665cf83

Browse files
authored
Support a "mixed" mgs config (#7630)
Support both Simulated and SwitchZoneInterface ports for non-gimlet deployments.
1 parent 24913f0 commit 665cf83

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

gateway/src/management_switch.rs

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -183,60 +183,39 @@ impl ManagementSwitch {
183183
) -> Result<Self, StartupError> {
184184
let log = log.new(o!("component" => "ManagementSwitch"));
185185

186-
// Skim over our port configs - either all should be simulated or all
187-
// should be switch zone interfaces. Reject a mix.
188-
let mut shared_socket = None;
189-
for (i, port_desc) in config.port.iter().enumerate() {
190-
if i == 0 {
191-
// First item: either create a shared socket (if we're going to
192-
// share one socket among multiple switch zone VLAN interfaces)
193-
// or leave it as `None` (if we're going to be connecting to
194-
// simulated SPs by address).
195-
if let SwitchPortConfig::SwitchZoneInterface { .. } =
196-
&port_desc.config
197-
{
198-
shared_socket = Some(
199-
SharedSocket::bind(
200-
config.udp_listen_port,
201-
Arc::clone(&host_phase2_provider),
202-
log.clone(),
203-
)
204-
.await?,
205-
);
206-
}
207-
} else {
208-
match (&shared_socket, &port_desc.config) {
209-
// OK - config is consistent
210-
(Some(_), SwitchPortConfig::SwitchZoneInterface { .. })
211-
| (None, SwitchPortConfig::Simulated { .. }) => (),
212-
213-
// not OK - config is mixed
214-
(None, SwitchPortConfig::SwitchZoneInterface { .. })
215-
| (Some(_), SwitchPortConfig::Simulated { .. }) => {
216-
return Err(StartupError::InvalidConfig {
217-
reasons: vec![concat!(
218-
"switch port contains a mixture of `simulated`",
219-
" and `switch-zone-interface`"
220-
)
221-
.to_string()],
222-
});
223-
}
224-
}
225-
}
226-
}
227-
228186
// Convert our config into actual SP handles and sockets, keyed by
229187
// `SwitchPort` (newtype around an index into `config.port`).
188+
let mut shared_socket = None;
230189
let mut port_to_handle = Vec::with_capacity(config.port.len());
231190
let mut port_to_desc = Vec::with_capacity(config.port.len());
232191
let mut port_to_ignition_target = Vec::with_capacity(config.port.len());
233192
let mut interface_to_port = HashMap::with_capacity(config.port.len());
234193
let retry_config = config.rpc_retry_config.into();
194+
235195
for (i, port_desc) in config.port.into_iter().enumerate() {
236196
let single_sp = match &port_desc.config {
237197
SwitchPortConfig::SwitchZoneInterface { interface } => {
198+
// Create a shared socket if we're going to be sharing one
199+
// socket among mulitple switch zone VLAN interfaces
200+
let socket = match &mut shared_socket {
201+
None => {
202+
shared_socket = Some(
203+
SharedSocket::bind(
204+
config.udp_listen_port,
205+
Arc::clone(&host_phase2_provider),
206+
log.clone(),
207+
)
208+
.await?,
209+
);
210+
211+
shared_socket.as_ref().unwrap()
212+
}
213+
214+
Some(v) => v,
215+
};
216+
238217
SingleSp::new(
239-
shared_socket.as_ref().unwrap(),
218+
&socket,
240219
gateway_sp_comms::SwitchPortConfig {
241220
discovery_addr: default_discovery_addr(),
242221
interface: interface.clone(),
@@ -245,6 +224,7 @@ impl ManagementSwitch {
245224
)
246225
.await
247226
}
227+
248228
SwitchPortConfig::Simulated { addr, .. } => {
249229
// Bind a new socket for each simulated switch port.
250230
let bind_addr: SocketAddrV6 =

0 commit comments

Comments
 (0)