remove fqdn from DnsConfig

l

l

plan: update

plan: update
This commit is contained in:
Luna Yao
2026-04-19 00:33:47 +02:00
parent cbb966d57c
commit 9feb548bc2
5 changed files with 23 additions and 54 deletions
+6 -4
View File
@@ -581,10 +581,12 @@ impl ConfigLoader for TomlConfigLoader {
self.set_hostname(hostname.clone());
hostname.unwrap_or_else(|| {
hostname::get()
.unwrap_or_default()
.to_string_lossy()
.into_owned()
sanitize(
hostname::get()
.unwrap_or_default()
.to_string_lossy()
.as_ref(),
)
})
}
+13 -9
View File
@@ -23,7 +23,7 @@ use super::{
};
#[cfg(feature = "magic-dns")]
use crate::dns::{
config::{DnsExportConfig, DnsGlobalCtxExt},
config::{DnsConfigLoaderExt, DnsExportConfig, DnsGlobalCtxExt},
server::DnsServer,
};
use crate::{
@@ -691,18 +691,22 @@ impl DnsGlobalCtxExt for GlobalCtx {
}
fn dns_self_zone(&self) -> crate::dns::config::zone::ZoneConfig {
let fqdn = self.config.get_dns().get_fqdn();
let dns = self.config.get_dns();
let mut hostname = dns.name.to_string();
if hostname.is_empty() {
hostname = self.get_hostname();
}
let fqdn = dns
.domain
.prepend_label(hostname)
.unwrap_or_default()
.into();
let ipv4 = self.get_ipv4().map(|ip| ip.address());
let ipv6 = self.get_ipv6().map(|ip| ip.address());
let ipv6 = ipv6.map(|a| vec![a]).unwrap_or_default();
crate::dns::config::zone::ZoneConfig::dedicated(
Some(self.get_id()),
fqdn.clone(),
ipv4,
ipv6,
)
.unwrap()
crate::dns::config::zone::ZoneConfig::dedicated(Some(self.get_id()), fqdn, ipv4, ipv6)
.unwrap()
}
fn dns_export_config(&self) -> DnsExportConfig {
+2 -39
View File
@@ -4,13 +4,11 @@ use crate::dns::config::{DNS_DEFAULT_ADDRESS, DNS_DEFAULT_DOMAIN};
use crate::dns::server::DnsServer;
use crate::dns::utils::addr::NameServerAddrGroup;
use crate::proto::dns::GetExportConfigResponse;
use crate::utils::dns::parse;
use derivative::Derivative;
use hickory_net::xfer::Protocol;
use hickory_proto::rr::{LowerName, Name};
use hickory_proto::rr::LowerName;
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;
use std::iter;
use std::sync::Arc;
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, PartialEq)]
@@ -21,7 +19,7 @@ pub struct DnsConfig {
pub zones: Vec<ZoneConfig>,
#[serde(flatten)]
pub policies: HashMap<LowerName, DnsPolicyConfig>,
name: LowerName,
pub name: LowerName,
#[derivative(Default(value = "DNS_DEFAULT_DOMAIN.clone()"))]
pub domain: LowerName,
#[derivative(Default(value = "vec![DNS_DEFAULT_ADDRESS].into()"))]
@@ -48,41 +46,6 @@ impl DnsConfig {
}
}
impl DnsConfig {
pub fn get_name(&self) -> LowerName {
if self.name.is_empty() {
parse(
hostname::get()
.unwrap_or_default()
.to_string_lossy()
.as_ref(),
)
} else {
self.name.clone()
}
}
pub fn set_name(&mut self, name: &str) {
self.name = parse(name);
}
pub fn get_fqdn(&self) -> LowerName {
Name::from(self.get_name())
.append_domain(&self.domain)
.unwrap()
.into()
}
pub fn set_fqdn(&mut self, fqdn: &str) {
let mut fqdn = Name::from(parse(fqdn));
fqdn.set_fqdn(true);
self.name = Name::from_labels(iter::once(fqdn.iter().next().unwrap_or_default()))
.unwrap_or_default()
.into();
self.domain = fqdn.base_name().into();
}
}
#[auto_impl::auto_impl(Box, &)]
pub trait DnsConfigLoaderExt {
fn get_dns(&self) -> DnsConfig;
+1 -1
View File
@@ -213,7 +213,7 @@ mod tests {
) -> Arc<PeerManager> {
let ctx = get_mock_global_ctx();
let mut dns = ctx.config.get_dns();
dns.set_name(host);
dns.name = host.parse().unwrap();
dns.zones.push(
ZoneConfig::dedicated(
Some(Uuid::new_v4()),
+1 -1
View File
@@ -47,7 +47,7 @@ pub async fn prepare_env_with_tld_dns_zone(
ctx.set_ipv4(Some(tun_ip));
let mut dns_config = ctx.config.get_dns();
dns_config.set_name(dns_name);
dns_config.name = dns_name.parse().unwrap();
if let Some(zone) = tld_dns_zone {
dns_config.domain = zone.parse().expect("invalid test dns zone");
}