pub struct DnsServer { /* private fields */ }Expand description
DNS server for overlay networks
Implementations§
Source§impl DnsServer
impl DnsServer
Sourcepub fn new(listen_addr: SocketAddr, zone: &str) -> Result<Self, DnsError>
pub fn new(listen_addr: SocketAddr, zone: &str) -> Result<Self, DnsError>
Create a new DNS server for the given zone
§Errors
Returns DnsError::InvalidName if the zone name is invalid.
Sourcepub fn from_config(config: &DnsConfig) -> Result<Self, DnsError>
pub fn from_config(config: &DnsConfig) -> Result<Self, DnsError>
Sourcepub fn handle(&self) -> DnsHandle
pub fn handle(&self) -> DnsHandle
Get a handle for managing DNS records
The handle can be cloned and used to add/remove records even after the server has been started.
Sourcepub async fn add_record(
&self,
hostname: &str,
ip: IpAddr,
) -> Result<(), DnsError>
pub async fn add_record( &self, hostname: &str, ip: IpAddr, ) -> Result<(), DnsError>
Add a DNS record for a hostname to IP mapping
Creates an A record for IPv4 addresses and an AAAA record for IPv6 addresses.
§Errors
Returns DnsError::InvalidName if the hostname is invalid.
Sourcepub async fn remove_record(&self, hostname: &str) -> Result<bool, DnsError>
pub async fn remove_record(&self, hostname: &str) -> Result<bool, DnsError>
Remove DNS records for a hostname (both A and AAAA)
§Errors
Returns DnsError::InvalidName if the hostname is invalid.
Sourcepub async fn start(self) -> Result<DnsHandle, DnsError>
pub async fn start(self) -> Result<DnsHandle, DnsError>
Start the DNS server and return a handle for record management
This spawns the DNS server in a background task and returns a handle that can be used to add/remove records while the server is running.
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub async fn start_background(&self) -> Result<DnsHandle, DnsError>
pub async fn start_background(&self) -> Result<DnsHandle, DnsError>
Start the DNS server in a background task without consuming self.
Unlike start(self), this method borrows self, allowing the DnsServer
to be wrapped in an Arc and shared (e.g., with ServiceManager) while
the server runs in the background.
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub async fn bind_windows_fallback(
&self,
bind_ip: IpAddr,
) -> Result<DnsHandle, DnsError>
pub async fn bind_windows_fallback( &self, bind_ip: IpAddr, ) -> Result<DnsHandle, DnsError>
Bind a second DNS listener on port 53 of bind_ip, sharing this
server’s authority + zone so the same records answer both listeners.
Windows containers always query DNS on port 53 — HNS endpoints do not
support setting a non-standard DNS port in the schema. The canonical
overlay listener on DEFAULT_DNS_PORT (15353) is therefore
unreachable from a Windows container; this method adds a second
listener on port 53 of the overlay IP so containers that point at
<overlay_ip>:53 via Dns.ServerList can actually resolve.
bind_ip is typically the node’s overlay IP (e.g. 10.200.42.1).
Binding to 0.0.0.0:53 would collide with whatever resolver the host
already runs (systemd-resolved on Linux, DNS Client on Windows). The
method itself is cross-platform; callers decide whether to invoke it
based on their workload mix.
The bound UDP + TCP sockets live on a detached tokio task that shares
the same Arc<InMemoryAuthority> as the primary listener, so
DnsHandle::add_record / remove_record updates both responders
atomically. Returns a cloneable DnsHandle for convenience.
§Errors
Returns DnsError::Io when either port 53 socket (UDP or TCP) cannot
be bound — typically because another DNS resolver already owns the
address, or because the process lacks the privilege to bind below 1024
on platforms that require it. Callers should treat this as a warning
and fall back to the primary 15353 listener for non-Windows workloads.
Sourcepub fn listen_addr(&self) -> SocketAddr
pub fn listen_addr(&self) -> SocketAddr
Get the listen address
Sourcepub fn zone_origin(&self) -> &Name
pub fn zone_origin(&self) -> &Name
Get the zone origin