Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zeronsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trust-dns-resolver = { version = "^0.22", features = ["tokio-runtime", "dns-over
trust-dns-server = { version = "^0.22", features = ["dns-over-openssl"] }
trust-dns-proto = "^0.22"
tokio = { version = "1", features = ["full"] }
socket2 = { version = "0.5", features = ["all"] }
serde = "^1.0.210"
serde_json = "^1.0.128"
serde_yml = "^0.0.12"
Expand Down
29 changes: 27 additions & 2 deletions zeronsd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
net::{IpAddr, SocketAddr},
time::Duration,
};
use socket2::{Domain, Protocol, Socket, Type};
use tracing::info;

use openssl::{
Expand Down Expand Up @@ -33,8 +34,32 @@ impl Server {
key: Option<PKey<Private>>,
) -> Result<(), anyhow::Error> {
let sa = SocketAddr::new(ip, 53);
let tcp = TcpListener::bind(sa).await?;
let udp = UdpSocket::bind(sa).await?;

// macOS Sequoia (Darwin 25+): mDNSResponder permanently binds *:53 as a
// unicast DNS proxy and cannot be removed (SIP-protected). SO_REUSEPORT
// allows this specific-IP socket to coexist with the wildcard binding;
// BSD routing delivers packets destined for `ip` to this socket rather
// than the wildcard. SO_REUSEPORT is harmless on Linux and other platforms.
let domain = if ip.is_ipv4() { Domain::IPV4 } else { Domain::IPV6 };

let udp = {
let s = Socket::new(domain, Type::DGRAM, Some(Protocol::UDP))?;
s.set_reuse_port(true)?;
s.bind(&sa.into())?;
s.set_nonblocking(true)?;
let std_udp: std::net::UdpSocket = s.into();
UdpSocket::from_std(std_udp)?
};

let tcp = {
let s = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
s.set_reuse_port(true)?;
s.bind(&sa.into())?;
s.listen(128)?;
s.set_nonblocking(true)?;
let std_tcp: std::net::TcpListener = s.into();
TcpListener::from_std(std_tcp)?
};

let mut sf = ServerFuture::new(init_catalog(self.0).await?);

Expand Down