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 -2
View File
@@ -49,8 +49,8 @@ core_clap:
en: "manually specify the public IPv6 subnet to share, instead of auto-detecting from system routes"
zh-CN: "手动指定要共享的公网 IPv6 子网,不自动从系统路由检测"
dhcp:
en: "automatically determine and set IP address by Easytier, and the IP address starts from 10.0.0.1 by default. Warning, if there is an IP conflict in the network when using DHCP, the IP will be automatically changed. Optionally specify a CIDR subnet (e.g. -d 10.0.0.0/24) to fix the DHCP address range."
zh-CN: "由Easytier自动确定并设置IP地址,默认从10.0.0.1开始。警告:在使用DHCP时,如果网络中出现IP冲突,IP将自动更改。可选指定CIDR子网(如 -d 10.0.0.0/24)来固定DHCP地址范围。"
en: "automatically determine and set IP address by Easytier. The subnet is derived from a connected peer's IPv4 or defaults to 10.126.126.0/24. Warning, if there is an IP conflict in the network when using DHCP, the IP will be automatically changed. Optionally specify a CIDR subnet (e.g. -d 10.0.0.0/24, prefix <= /30) to pin the DHCP address range."
zh-CN: "由Easytier自动确定并设置IP地址。子网从已连接对等节点的IPv4派生,或默认使用10.126.126.0/24。警告:在使用DHCP时,如果网络中出现IP冲突,IP将自动更改。可选指定CIDR子网(如 -d 10.0.0.0/24,前缀 <= /30)来固定DHCP地址范围。"
peers:
en: "peers to connect initially"
zh-CN: "最初要连接的对等节点"
+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());