fix incorrect config check (#1086)
Some checks failed
EasyTier Core / pre_job (push) Has been cancelled
EasyTier GUI / pre_job (push) Has been cancelled
EasyTier Mobile / pre_job (push) Has been cancelled
EasyTier OHOS / pre_job (push) Has been cancelled
EasyTier Test / pre_job (push) Has been cancelled
EasyTier Core / build_web (push) Has been cancelled
EasyTier Core / build (freebsd-13.2-x86_64, 13.2, ubuntu-22.04, x86_64-unknown-freebsd) (push) Has been cancelled
EasyTier Core / build (linux-aarch64, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-arm, ubuntu-22.04, arm-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armhf, ubuntu-22.04, arm-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-armv7, ubuntu-22.04, armv7-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armv7hf, ubuntu-22.04, armv7-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-mips, ubuntu-22.04, mips-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-mipsel, ubuntu-22.04, mipsel-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-x86_64, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (macos-aarch64, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (macos-x86_64, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (windows-arm64, windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / build (windows-i686, windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / build (windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / core-result (push) Has been cancelled
EasyTier Core / magisk_build (push) Has been cancelled
EasyTier GUI / build-gui (linux-aarch64, aarch64-unknown-linux-gnu, ubuntu-22.04, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (linux-x86_64, x86_64-unknown-linux-gnu, ubuntu-22.04, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (macos-aarch64, aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (macos-x86_64, x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (windows-arm64, aarch64-pc-windows-msvc, windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / build-gui (windows-i686, i686-pc-windows-msvc, windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / build-gui (windows-x86_64, x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / gui-result (push) Has been cancelled
EasyTier Mobile / build-mobile (android, ubuntu-22.04, android) (push) Has been cancelled
EasyTier Mobile / mobile-result (push) Has been cancelled
EasyTier OHOS / build-ohos (push) Has been cancelled
EasyTier Test / test (push) Has been cancelled

This commit is contained in:
Sijie.Sun
2025-07-06 14:20:49 +08:00
committed by GitHub
parent 3c65594030
commit 13c2e72871
6 changed files with 62 additions and 21 deletions

View File

@@ -70,7 +70,11 @@ pub trait ConfigLoader: Send + Sync {
fn get_dhcp(&self) -> bool; fn get_dhcp(&self) -> bool;
fn set_dhcp(&self, dhcp: bool); fn set_dhcp(&self, dhcp: bool);
fn add_proxy_cidr(&self, cidr: cidr::Ipv4Cidr, mapped_cidr: Option<cidr::Ipv4Cidr>); fn add_proxy_cidr(
&self,
cidr: cidr::Ipv4Cidr,
mapped_cidr: Option<cidr::Ipv4Cidr>,
) -> Result<(), anyhow::Error>;
fn remove_proxy_cidr(&self, cidr: cidr::Ipv4Cidr); fn remove_proxy_cidr(&self, cidr: cidr::Ipv4Cidr);
fn get_proxy_cidrs(&self) -> Vec<ProxyNetworkConfig>; fn get_proxy_cidrs(&self) -> Vec<ProxyNetworkConfig>;
@@ -445,17 +449,23 @@ impl ConfigLoader for TomlConfigLoader {
self.config.lock().unwrap().dhcp = Some(dhcp); self.config.lock().unwrap().dhcp = Some(dhcp);
} }
fn add_proxy_cidr(&self, cidr: cidr::Ipv4Cidr, mapped_cidr: Option<cidr::Ipv4Cidr>) { fn add_proxy_cidr(
&self,
cidr: cidr::Ipv4Cidr,
mapped_cidr: Option<cidr::Ipv4Cidr>,
) -> Result<(), anyhow::Error> {
let mut locked_config = self.config.lock().unwrap(); let mut locked_config = self.config.lock().unwrap();
if locked_config.proxy_network.is_none() { if locked_config.proxy_network.is_none() {
locked_config.proxy_network = Some(vec![]); locked_config.proxy_network = Some(vec![]);
} }
if let Some(mapped_cidr) = mapped_cidr.as_ref() { if let Some(mapped_cidr) = mapped_cidr.as_ref() {
assert_eq!( if cidr.network_length() != mapped_cidr.network_length() {
cidr.network_length(), return Err(anyhow::anyhow!(
mapped_cidr.network_length(), "Mapped CIDR must have the same network length as the original CIDR: {} != {}",
"Mapped CIDR must have the same network length as the original CIDR", cidr.network_length(),
); mapped_cidr.network_length()
));
}
} }
// insert if no duplicate // insert if no duplicate
if !locked_config if !locked_config
@@ -475,6 +485,7 @@ impl ConfigLoader for TomlConfigLoader {
allow: None, allow: None,
}); });
} }
Ok(())
} }
fn remove_proxy_cidr(&self, cidr: cidr::Ipv4Cidr) { fn remove_proxy_cidr(&self, cidr: cidr::Ipv4Cidr) {

View File

@@ -168,13 +168,23 @@ impl DNSTunnelConnector {
impl super::TunnelConnector for DNSTunnelConnector { impl super::TunnelConnector for DNSTunnelConnector {
async fn connect(&mut self) -> Result<Box<dyn Tunnel>, TunnelError> { async fn connect(&mut self) -> Result<Box<dyn Tunnel>, TunnelError> {
let mut conn = if self.addr.scheme() == "txt" { let mut conn = if self.addr.scheme() == "txt" {
self.handle_txt_record(self.addr.host_str().as_ref().unwrap()) self.handle_txt_record(
.await self.addr
.with_context(|| "get txt record url failed")? .host_str()
.as_ref()
.ok_or(anyhow::anyhow!("host should not be empty in txt url"))?,
)
.await
.with_context(|| "get txt record url failed")?
} else if self.addr.scheme() == "srv" { } else if self.addr.scheme() == "srv" {
self.handle_srv_record(self.addr.host_str().as_ref().unwrap()) self.handle_srv_record(
.await self.addr
.with_context(|| "get srv record url failed")? .host_str()
.as_ref()
.ok_or(anyhow::anyhow!("host should not be empty in srv url"))?,
)
.await
.with_context(|| "get srv record url failed")?
} else { } else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"unsupported dns scheme: {}, expecting txt or srv", "unsupported dns scheme: {}, expecting txt or srv",

View File

@@ -147,6 +147,12 @@ pub async fn create_connector_by_url(
Box::new(connector) Box::new(connector)
} }
"txt" | "srv" => { "txt" | "srv" => {
if url.host_str().is_none() {
return Err(Error::InvalidUrl(format!(
"host should not be empty in txt or srv url: {}",
url
)));
}
let connector = dns_connector::DNSTunnelConnector::new(url, global_ctx.clone()); let connector = dns_connector::DNSTunnelConnector::new(url, global_ctx.clone());
Box::new(connector) Box::new(connector)
} }

View File

@@ -658,6 +658,7 @@ impl NetworkOptions {
} }
if !self.mapped_listeners.is_empty() { if !self.mapped_listeners.is_empty() {
let mut errs = Vec::new();
cfg.set_mapped_listeners(Some( cfg.set_mapped_listeners(Some(
self.mapped_listeners self.mapped_listeners
.iter() .iter()
@@ -668,12 +669,21 @@ impl NetworkOptions {
}) })
.map(|s: url::Url| { .map(|s: url::Url| {
if s.port().is_none() { if s.port().is_none() {
panic!("mapped listener port is missing: {}", s); errs.push(anyhow::anyhow!("mapped listener port is missing: {}", s));
} }
s s
}) })
.collect(), .collect::<Vec<_>>(),
)); ));
if !errs.is_empty() {
return Err(anyhow::anyhow!(
"{}",
errs.iter()
.map(|x| format!("{}", x))
.collect::<Vec<_>>()
.join("\n")
));
}
} }
for n in self.proxy_networks.iter() { for n in self.proxy_networks.iter() {

View File

@@ -483,7 +483,7 @@ pub fn add_proxy_network_to_config(
} else { } else {
None None
}; };
cfg.add_proxy_cidr(real_cidr, mapped_cidr); cfg.add_proxy_cidr(real_cidr, mapped_cidr)?;
Ok(()) Ok(())
} }
@@ -1003,7 +1003,7 @@ mod tests {
} else { } else {
None None
}; };
config.add_proxy_cidr(network, mapped_network); config.add_proxy_cidr(network, mapped_network).unwrap();
} }
} }

View File

@@ -448,7 +448,8 @@ pub async fn quic_proxy() {
"udp", "udp",
|cfg| { |cfg| {
if cfg.get_inst_name() == "inst3" { if cfg.get_inst_name() == "inst3" {
cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None); cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None)
.unwrap();
} }
cfg cfg
}, },
@@ -498,11 +499,13 @@ pub async fn subnet_proxy_three_node_test(
flags.disable_quic_input = disable_quic_input; flags.disable_quic_input = disable_quic_input;
flags.enable_quic_proxy = dst_enable_quic_proxy; flags.enable_quic_proxy = dst_enable_quic_proxy;
cfg.set_flags(flags); cfg.set_flags(flags);
cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None); cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None)
.unwrap();
cfg.add_proxy_cidr( cfg.add_proxy_cidr(
"10.1.2.0/24".parse().unwrap(), "10.1.2.0/24".parse().unwrap(),
Some("10.1.3.0/24".parse().unwrap()), Some("10.1.3.0/24".parse().unwrap()),
); )
.unwrap();
} }
if cfg.get_inst_name() == "inst2" && relay_by_public_server { if cfg.get_inst_name() == "inst2" && relay_by_public_server {
@@ -1181,7 +1184,8 @@ pub async fn port_forward_test(
}, },
]); ]);
} else if cfg.get_inst_name() == "inst3" { } else if cfg.get_inst_name() == "inst3" {
cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None); cfg.add_proxy_cidr("10.1.2.0/24".parse().unwrap(), None)
.unwrap();
} }
let mut flags = cfg.get_flags(); let mut flags = cfg.get_flags();
flags.no_tun = no_tun; flags.no_tun = no_tun;