Implemented setting bind-host for DNS-resolver.

pull/3/head
Revertron 3 years ago
parent d7911dfe04
commit 074a709f3b

@ -1,6 +1,6 @@
[package]
name = "alfis"
version = "0.1.1"
version = "0.1.2"
authors = ["Revertron <alfis@revertron.com>"]
edition = "2018"
build = "build.rs"

@ -10,7 +10,8 @@
"test-ip6.alfis.name:4244"
],
"dns": {
"port": 53,
"host": "0.0.0.0",
"port": 5300,
"forwarders": [
"94.140.14.14:53",
"94.140.15.15:53"

@ -46,6 +46,7 @@ pub struct ServerContext {
pub cache: SynchronizedCache,
pub filters: Vec<Box<dyn DnsFilter + Sync + Send>>,
pub client: Box<dyn DnsClient + Sync + Send>,
pub dns_host: String,
pub dns_port: u16,
pub api_port: u16,
pub resolve_strategy: ResolveStrategy,
@ -70,6 +71,7 @@ impl ServerContext {
cache: SynchronizedCache::new(),
filters: Vec::new(),
client: Box::new(DnsNetworkClient::new(34255)),
dns_host: String::from("0.0.0.0"),
dns_port: 53,
api_port: 5380,
resolve_strategy: ResolveStrategy::Recursive,
@ -127,6 +129,7 @@ pub mod tests {
cache: SynchronizedCache::new(),
filters: Vec::new(),
client: Box::new(DnsStubClient::new(callback)),
dns_host: String::from("0.0.0.0"),
dns_port: 53,
api_port: 5380,
resolve_strategy: ResolveStrategy::Recursive,

@ -175,7 +175,7 @@ impl DnsServer for DnsUdpServer {
/// This method takes ownership of the server, preventing the method from being called multiple times.
fn run_server(self) -> Result<()> {
// Bind the socket
let socket = UdpSocket::bind(("::", self.context.dns_port))?;
let socket = UdpSocket::bind((self.context.dns_host.as_str(), self.context.dns_port))?;
// Spawn threads for handling requests
for thread_id in 0..self.thread_count {
@ -290,7 +290,7 @@ impl DnsTcpServer {
impl DnsServer for DnsTcpServer {
fn run_server(mut self) -> Result<()> {
let socket = TcpListener::bind(("::", self.context.dns_port))?;
let socket = TcpListener::bind((self.context.dns_host.as_str(), self.context.dns_port))?;
// Spawn threads for handling requests, and create the channels
for thread_id in 0..self.thread_count {

@ -49,12 +49,18 @@ impl Settings {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Dns {
#[serde(default = "default_host")]
pub host: String,
pub port: u16,
pub forwarders: Vec<String>
}
impl Default for Dns {
fn default() -> Self {
Dns { port: 53, forwarders: Vec::new() }
Dns { host: String::from("0.0.0.0"), port: 53, forwarders: Vec::new() }
}
}
fn default_host() -> String {
String::from("0.0.0.0")
}
Loading…
Cancel
Save