mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 20:49:46 +00:00
add ttl to ZoneData
This commit is contained in:
@@ -26,13 +26,13 @@ pub struct DnsConfig {
|
||||
#[derivative(Default(value = "DNS_DEFAULT_TLD.clone()"))]
|
||||
pub domain: LowerName,
|
||||
#[derivative(Default(value = "vec![DNS_DEFAULT_ADDRESS].into()"))]
|
||||
#[serde(deserialize_with = "DnsConfig::validate_addresses")]
|
||||
#[serde(deserialize_with = "DnsConfig::deserialize_addresses")]
|
||||
pub addresses: NameServerAddrGroup,
|
||||
pub listeners: NameServerAddrGroup,
|
||||
}
|
||||
|
||||
impl DnsConfig {
|
||||
pub fn validate_addresses<'de, D>(deserializer: D) -> Result<NameServerAddrGroup, D::Error>
|
||||
pub fn deserialize_addresses<'de, D>(deserializer: D) -> Result<NameServerAddrGroup, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
@@ -82,32 +82,37 @@ impl DnsConfig {
|
||||
pub type DnsExportConfig = GetExportConfigResponse;
|
||||
|
||||
pub trait DnsGlobalCtxExt {
|
||||
fn dns_self_zone(&self) -> Option<ZoneConfig>;
|
||||
fn dns_self_zone(&self) -> ZoneConfig;
|
||||
fn dns_export_config(&self) -> DnsExportConfig;
|
||||
fn dns_iter_zones(&self) -> impl Iterator<Item = ZoneConfig>;
|
||||
}
|
||||
|
||||
impl DnsGlobalCtxExt for GlobalCtx {
|
||||
fn dns_self_zone(&self) -> Option<ZoneConfig> {
|
||||
fn dns_self_zone(&self) -> ZoneConfig {
|
||||
let fqdn = self.config.get_dns().get_fqdn();
|
||||
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();
|
||||
|
||||
ZoneConfig::dedicated(Some(self.get_id()), fqdn.clone(), ipv4, ipv6)
|
||||
ZoneConfig::dedicated(Some(self.get_id()), fqdn.clone(), ipv4, ipv6).unwrap()
|
||||
}
|
||||
|
||||
fn dns_export_config(&self) -> DnsExportConfig {
|
||||
let config = self.config.get_dns();
|
||||
let zone = self.dns_self_zone();
|
||||
let zones = config.zones.iter().chain(zone.iter());
|
||||
|
||||
DnsExportConfig {
|
||||
zones: zones
|
||||
zones: self
|
||||
.dns_iter_zones()
|
||||
.filter(|z| z.policy.export.is_some()) // TODO: check policies of parent zones
|
||||
.cloned()
|
||||
.map_into()
|
||||
.collect(),
|
||||
fqdn: config.get_fqdn().to_string(),
|
||||
fqdn: self.config.get_dns().get_fqdn().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn dns_iter_zones(&self) -> impl Iterator<Item = ZoneConfig> {
|
||||
self.config
|
||||
.get_dns()
|
||||
.zones
|
||||
.into_iter()
|
||||
.chain(iter::once(self.dns_self_zone()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl ZoneConfig {
|
||||
origin: LowerName,
|
||||
ipv4: Option<Ipv4Addr>,
|
||||
ipv6: Vec<Ipv6Addr>,
|
||||
) -> Option<Self> {
|
||||
) -> anyhow::Result<Self> {
|
||||
let mut records = Vec::new();
|
||||
|
||||
if let Some(ipv4) = ipv4 {
|
||||
@@ -53,10 +53,6 @@ impl ZoneConfig {
|
||||
export: Some(DnsExportPolicy::default()),
|
||||
};
|
||||
|
||||
if records.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let config = ZoneConfigInner {
|
||||
id: id.unwrap_or_else(Uuid::new_v4),
|
||||
origin,
|
||||
@@ -65,7 +61,7 @@ impl ZoneConfig {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
config.try_into().ok()
|
||||
config.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +86,7 @@ impl From<ZoneConfigInner> for ZoneData {
|
||||
Self {
|
||||
id: Some(value.id.into()),
|
||||
origin: value.origin.to_string(),
|
||||
ttl: value.ttl,
|
||||
records: value.records,
|
||||
forwarders: value.forwarders.into(),
|
||||
}
|
||||
|
||||
@@ -58,13 +58,10 @@ impl DnsPeerMgr {
|
||||
|
||||
pub fn snapshot(&self) -> DnsSnapshot {
|
||||
let global_ctx = self.peer_mgr.get_global_ctx_ref();
|
||||
let config = global_ctx.config.get_dns();
|
||||
|
||||
let zones = config
|
||||
.zones
|
||||
.into_iter()
|
||||
let zones = global_ctx
|
||||
.dns_iter_zones()
|
||||
.map_into()
|
||||
.chain(global_ctx.dns_self_zone().into_iter().map_into())
|
||||
.chain(
|
||||
self.peers
|
||||
.iter()
|
||||
@@ -72,6 +69,7 @@ impl DnsPeerMgr {
|
||||
)
|
||||
.collect();
|
||||
|
||||
let config = global_ctx.config.get_dns();
|
||||
DnsSnapshot {
|
||||
zones,
|
||||
addresses: config.addresses.into(),
|
||||
|
||||
@@ -160,6 +160,7 @@ impl From<Zone> for proto::dns::ZoneData {
|
||||
Self {
|
||||
id: Some(value.id.into()),
|
||||
origin: value.origin.to_string(),
|
||||
ttl: 0,
|
||||
records,
|
||||
forwarders,
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ package dns;
|
||||
message ZoneData {
|
||||
common.UUID id = 1;
|
||||
string origin = 2;
|
||||
repeated string records = 3;
|
||||
repeated common.Url forwarders = 4;
|
||||
uint32 ttl = 3;
|
||||
repeated string records = 4;
|
||||
repeated common.Url forwarders = 5;
|
||||
}
|
||||
|
||||
message GetExportConfigRequest {}
|
||||
|
||||
@@ -30,6 +30,8 @@ impl Display for ZoneData {
|
||||
}
|
||||
writeln!(f)?;
|
||||
|
||||
writeln!(f, "$TTL {}", self.ttl)?;
|
||||
|
||||
for record in &self.records {
|
||||
writeln!(f, "{}", record)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user