From 074a709f3ba1de1b15de13ee7bebb9ce000ed128 Mon Sep 17 00:00:00 2001 From: Revertron Date: Mon, 22 Feb 2021 22:02:01 +0100 Subject: [PATCH] Implemented setting bind-host for DNS-resolver. --- Cargo.toml | 2 +- alfis.cfg | 3 ++- src/dns/context.rs | 3 +++ src/dns/server.rs | 4 ++-- src/settings.rs | 8 +++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee45888..e2a905c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alfis" -version = "0.1.1" +version = "0.1.2" authors = ["Revertron "] edition = "2018" build = "build.rs" diff --git a/alfis.cfg b/alfis.cfg index 8b029d7..686aad0 100644 --- a/alfis.cfg +++ b/alfis.cfg @@ -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" diff --git a/src/dns/context.rs b/src/dns/context.rs index 9b95f0a..023f916 100644 --- a/src/dns/context.rs +++ b/src/dns/context.rs @@ -46,6 +46,7 @@ pub struct ServerContext { pub cache: SynchronizedCache, pub filters: Vec>, pub client: Box, + 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, diff --git a/src/dns/server.rs b/src/dns/server.rs index 818e169..6e35ea1 100644 --- a/src/dns/server.rs +++ b/src/dns/server.rs @@ -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 { diff --git a/src/settings.rs b/src/settings.rs index ec1d9c0..2f50aa1 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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 } 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") } \ No newline at end of file