Implemented setting bind-host for DNS-resolver.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "alfis"
|
name = "alfis"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["Revertron <alfis@revertron.com>"]
|
authors = ["Revertron <alfis@revertron.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
"test-ip6.alfis.name:4244"
|
"test-ip6.alfis.name:4244"
|
||||||
],
|
],
|
||||||
"dns": {
|
"dns": {
|
||||||
"port": 53,
|
"host": "0.0.0.0",
|
||||||
|
"port": 5300,
|
||||||
"forwarders": [
|
"forwarders": [
|
||||||
"94.140.14.14:53",
|
"94.140.14.14:53",
|
||||||
"94.140.15.15:53"
|
"94.140.15.15:53"
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ pub struct ServerContext {
|
|||||||
pub cache: SynchronizedCache,
|
pub cache: SynchronizedCache,
|
||||||
pub filters: Vec<Box<dyn DnsFilter + Sync + Send>>,
|
pub filters: Vec<Box<dyn DnsFilter + Sync + Send>>,
|
||||||
pub client: Box<dyn DnsClient + Sync + Send>,
|
pub client: Box<dyn DnsClient + Sync + Send>,
|
||||||
|
pub dns_host: String,
|
||||||
pub dns_port: u16,
|
pub dns_port: u16,
|
||||||
pub api_port: u16,
|
pub api_port: u16,
|
||||||
pub resolve_strategy: ResolveStrategy,
|
pub resolve_strategy: ResolveStrategy,
|
||||||
@@ -70,6 +71,7 @@ impl ServerContext {
|
|||||||
cache: SynchronizedCache::new(),
|
cache: SynchronizedCache::new(),
|
||||||
filters: Vec::new(),
|
filters: Vec::new(),
|
||||||
client: Box::new(DnsNetworkClient::new(34255)),
|
client: Box::new(DnsNetworkClient::new(34255)),
|
||||||
|
dns_host: String::from("0.0.0.0"),
|
||||||
dns_port: 53,
|
dns_port: 53,
|
||||||
api_port: 5380,
|
api_port: 5380,
|
||||||
resolve_strategy: ResolveStrategy::Recursive,
|
resolve_strategy: ResolveStrategy::Recursive,
|
||||||
@@ -127,6 +129,7 @@ pub mod tests {
|
|||||||
cache: SynchronizedCache::new(),
|
cache: SynchronizedCache::new(),
|
||||||
filters: Vec::new(),
|
filters: Vec::new(),
|
||||||
client: Box::new(DnsStubClient::new(callback)),
|
client: Box::new(DnsStubClient::new(callback)),
|
||||||
|
dns_host: String::from("0.0.0.0"),
|
||||||
dns_port: 53,
|
dns_port: 53,
|
||||||
api_port: 5380,
|
api_port: 5380,
|
||||||
resolve_strategy: ResolveStrategy::Recursive,
|
resolve_strategy: ResolveStrategy::Recursive,
|
||||||
|
|||||||
+2
-2
@@ -175,7 +175,7 @@ impl DnsServer for DnsUdpServer {
|
|||||||
/// This method takes ownership of the server, preventing the method from being called multiple times.
|
/// This method takes ownership of the server, preventing the method from being called multiple times.
|
||||||
fn run_server(self) -> Result<()> {
|
fn run_server(self) -> Result<()> {
|
||||||
// Bind the socket
|
// 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
|
// Spawn threads for handling requests
|
||||||
for thread_id in 0..self.thread_count {
|
for thread_id in 0..self.thread_count {
|
||||||
@@ -290,7 +290,7 @@ impl DnsTcpServer {
|
|||||||
|
|
||||||
impl DnsServer for DnsTcpServer {
|
impl DnsServer for DnsTcpServer {
|
||||||
fn run_server(mut self) -> Result<()> {
|
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
|
// Spawn threads for handling requests, and create the channels
|
||||||
for thread_id in 0..self.thread_count {
|
for thread_id in 0..self.thread_count {
|
||||||
|
|||||||
+7
-1
@@ -49,12 +49,18 @@ impl Settings {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Dns {
|
pub struct Dns {
|
||||||
|
#[serde(default = "default_host")]
|
||||||
|
pub host: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub forwarders: Vec<String>
|
pub forwarders: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Dns {
|
impl Default for Dns {
|
||||||
fn default() -> Self {
|
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")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user