fix: address review comments - CIDR validation, dhcp_cidr implies DHCP, fmt fixes

This commit is contained in:
copilot-swe-agent[bot]
2026-06-11 16:54:40 +00:00
committed by GitHub
parent a25c411249
commit 003fdefc63
4 changed files with 23 additions and 9 deletions
+2 -1
View File
@@ -765,7 +765,8 @@ impl ConfigLoader for TomlConfigLoader {
}
fn get_dhcp(&self) -> bool {
self.config.lock().unwrap().dhcp.unwrap_or_default()
let config = self.config.lock().unwrap();
config.dhcp.unwrap_or_default() || config.dhcp_cidr.is_some()
}
fn set_dhcp(&self, dhcp: bool) {
+9 -3
View File
@@ -915,9 +915,15 @@ impl NetworkOptions {
} else {
// Treat as CIDR, e.g. "10.0.0.0/24"
cfg.set_dhcp(true);
let cidr: cidr::Ipv4Cidr = dhcp.parse().with_context(|| {
format!("failed to parse dhcp cidr: {}", dhcp)
})?;
let cidr: cidr::Ipv4Cidr = dhcp
.parse()
.with_context(|| format!("failed to parse dhcp cidr: {}", dhcp))?;
if cidr.network_length() > 30 {
anyhow::bail!(
"dhcp cidr prefix length must be <= 30, got /{}",
cidr.network_length()
);
}
cfg.set_dhcp_cidr(Some(cidr));
}
}
+10 -3
View File
@@ -638,9 +638,16 @@ impl NetworkConfig {
cfg.set_hostname(self.hostname.clone());
cfg.set_dhcp(self.dhcp.unwrap_or_default());
if let Some(ref dhcp_cidr) = self.dhcp_cidr {
let cidr = dhcp_cidr.parse::<cidr::Ipv4Cidr>().with_context(|| {
format!("failed to parse dhcp_cidr: {}", dhcp_cidr)
})?;
let cidr = dhcp_cidr
.parse::<cidr::Ipv4Cidr>()
.with_context(|| format!("failed to parse dhcp_cidr: {}", dhcp_cidr))?;
if cidr.network_length() > 30 {
anyhow::bail!(
"dhcp_cidr prefix length must be <= 30, got /{}",
cidr.network_length()
);
}
cfg.set_dhcp(true);
cfg.set_dhcp_cidr(Some(cidr));
}
cfg.set_inst_name(self.network_name.clone().unwrap_or_default());