mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +00:00
move sanitize and parse
fmt dns dns utils fmt unit test unit test
This commit is contained in:
@@ -3,8 +3,8 @@ use crate::dns::config::zone::ZoneConfig;
|
||||
use crate::dns::config::{DNS_DEFAULT_ADDRESS, DNS_DEFAULT_DOMAIN};
|
||||
use crate::dns::server::DnsServer;
|
||||
use crate::dns::utils::addr::NameServerAddrGroup;
|
||||
use crate::dns::utils::parse;
|
||||
use crate::proto::dns::GetExportConfigResponse;
|
||||
use crate::utils::dns::parse;
|
||||
use derivative::Derivative;
|
||||
use hickory_net::xfer::Protocol;
|
||||
use hickory_proto::rr::{LowerName, Name};
|
||||
|
||||
@@ -1,42 +1,3 @@
|
||||
use hickory_proto::rr::LowerName;
|
||||
use idna::AsciiDenyList;
|
||||
|
||||
pub mod addr;
|
||||
pub mod response;
|
||||
pub mod zone_handler;
|
||||
|
||||
pub fn sanitize(name: &str) -> String {
|
||||
let dot = name.ends_with('.');
|
||||
let mut name = idna::domain_to_ascii_cow(name.as_ref(), AsciiDenyList::EMPTY)
|
||||
.unwrap_or_default()
|
||||
.into_owned()
|
||||
.to_lowercase()
|
||||
.split('.')
|
||||
.map(|label| {
|
||||
label
|
||||
.chars()
|
||||
.map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
|
||||
.take(63)
|
||||
.collect::<String>()
|
||||
.trim_matches('-')
|
||||
.to_string()
|
||||
})
|
||||
.filter(|label| !label.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join(".");
|
||||
name.truncate(253);
|
||||
if dot {
|
||||
name.push('.');
|
||||
}
|
||||
name
|
||||
}
|
||||
|
||||
pub fn parse(name: &str) -> LowerName {
|
||||
if let Ok(name) = name.parse() {
|
||||
name
|
||||
} else {
|
||||
let sanitized = sanitize(name);
|
||||
tracing::debug!("invalid name: {}, sanitized to: {}", name, sanitized);
|
||||
sanitized.parse().unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user