mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-10-10 12:46:14 -08:00
clippy all codes (#1214)
1. clippy code 2. add fmt and clippy check in ci
This commit is contained in:
1 parent
0087ac3ffc
commit
e43537939a
144 files changed
+1475
-1531
No files matched your search
@@ -70,6 +70,20 @@ pub(super) struct MagicDnsServerInstanceData {
|
||||
}
|
||||
|
||||
impl MagicDnsServerInstanceData {
|
||||
fn is_valid_subdomain_label(s: &str) -> bool {
|
||||
let s = s.trim();
|
||||
|
||||
// 长度检查:1-63 个字符
|
||||
if s.is_empty() || s.len() > 63 {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查每个字符是否合法,并确保不以 '-' 开头或结尾
|
||||
s.chars().all(|c| matches!(c, 'a'..='z' | '0'..='9' | '-'))
|
||||
&& !s.starts_with('-')
|
||||
&& !s.ends_with('-')
|
||||
}
|
||||
|
||||
pub async fn update_dns_records<'a, T: Iterator<Item = &'a Route>>(
|
||||
&self,
|
||||
routes: T,
|
||||
@@ -81,6 +95,11 @@ impl MagicDnsServerInstanceData {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check host name valid for dns
|
||||
if !Self::is_valid_subdomain_label(&route.hostname) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(ipv4_addr) = route.ipv4_addr.unwrap_or_default().address else {
|
||||
continue;
|
||||
};
|
||||
@@ -432,7 +451,7 @@ impl MagicDnsServerInstance {
|
||||
if !self.tun_inet.contains(&self.data.fake_ip) && self.data.tun_dev.is_some() {
|
||||
let ifcfg = IfConfiger {};
|
||||
let _ = ifcfg
|
||||
.remove_ipv4_route(&self.data.tun_dev.as_ref().unwrap(), self.data.fake_ip, 32)
|
||||
.remove_ipv4_route(self.data.tun_dev.as_ref().unwrap(), self.data.fake_ip, 32)
|
||||
.await;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user