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