mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-08 05:29:47 +00:00
fix: address review comments - CIDR validation, dhcp_cidr implies DHCP, fmt fixes
This commit is contained in:
committed by
GitHub
parent
a25c411249
commit
003fdefc63
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user