add DnsConfig and ZoneConfig with proto definitions

This commit is contained in:
Luna Yao
2026-02-05 18:30:09 +01:00
parent 7abdfd35e8
commit 3f3aec8edd
10 changed files with 319 additions and 15 deletions
+26
View File
@@ -0,0 +1,26 @@
syntax = "proto3";
import "common.proto";
package dns;
enum DnsConfigKind {
LOCAL = 0;
REMOTE = 1;
}
message DnsConfigPb {
DnsConfigKind kind = 1;
repeated ZoneConfigPb zones = 2;
string name = 3;
string domain = 4;
repeated common.SocketAddr addresses = 5;
repeated string listeners = 6;
}
message ZoneConfigPb {
string origin = 1;
uint32 ttl = 2;
repeated string records = 3;
repeated string forwarders = 4;
}
+34
View File
@@ -0,0 +1,34 @@
use std::fmt::Display;
include!(concat!(env!("OUT_DIR"), "/dns.rs"));
impl Display for ZoneConfigPb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "; EasyTier Magic DNS zone file")?;
writeln!(f, "; https://github.com/easytier/easytier")?;
if !self.forwarders.is_empty() {
writeln!(f, "; Forwarders:")?;
for forwarder in &self.forwarders {
writeln!(f, "; \t{}", forwarder)?;
}
}
writeln!(f)?;
write!(f, "$ORIGIN {}", self.origin)?;
if !self.origin.ends_with('.') {
write!(f, ".")?;
}
writeln!(f)?;
writeln!(f, "$TTL {}", self.ttl)?;
writeln!(f)?;
for record in &self.records {
writeln!(f, "{}", record)?;
}
Ok(())
}
}
+2
View File
@@ -4,6 +4,8 @@ pub mod rpc_types;
pub mod acl;
pub mod api;
pub mod common;
#[cfg(feature = "magic-dns")]
pub mod dns;
pub mod error;
#[cfg(feature = "magic-dns")]
pub mod magic_dns;