diff --git a/dns.config.yaml b/dns.config.yaml index 4c066bf..b2254fb 100644 --- a/dns.config.yaml +++ b/dns.config.yaml @@ -1,5 +1,4 @@ listening-port: 53 -remote-lookup-port: 42069 thread-count: 1 use-udp: true use-tcp: false diff --git a/src/dns_resolver.rs b/src/dns_resolver.rs index a3ffadf..d285aad 100644 --- a/src/dns_resolver.rs +++ b/src/dns_resolver.rs @@ -6,14 +6,12 @@ use std::net::UdpSocket; pub struct DnsResolver { database: SimpleDatabase, - remote_lookup_port: u16, } impl DnsResolver { - pub fn new(database_file: String, remote_lookup_port: u16) -> DnsResolver { + pub fn new(database_file: String) -> DnsResolver { Self { database: SimpleDatabase::new(database_file), - remote_lookup_port, } } @@ -66,7 +64,7 @@ impl DnsResolver { fn do_remote_lookup(&self, question: &DnsQuestion, packet: &mut DnsPacket) -> Result<(), Box> { let server = (self.database.get_random_remote_lookup_server().unwrap(), 53); - let socket = UdpSocket::bind(("0.0.0.0", self.remote_lookup_port))?; + let socket = UdpSocket::bind(("0.0.0.0:0"))?; let mut remote_packet = DnsPacket::new(); remote_packet.header.recurse_desired = true; diff --git a/src/dns_server.rs b/src/dns_server.rs index 721dfb9..e02846f 100644 --- a/src/dns_server.rs +++ b/src/dns_server.rs @@ -66,7 +66,7 @@ impl DnsServer for DnsUdpServer { }; // process request - let resolver = DnsResolver::new(settings.database_file.clone(), settings.remote_lookup_port); + let resolver = DnsResolver::new(settings.database_file.clone()); match resolver.answer_question(request_packet) { Ok(result) => { @@ -155,7 +155,7 @@ impl DnsServer for DnsTcpServer { ignore_result_or_log_error_continue!(stream.read_to_end(&mut packet_buffer), "Failed to read the packet into a buffer"); let request = return_result_or_log_error_continue!(DnsPacket::from_bytes(packet_buffer.as_slice()), "Failed to parse packet from buffer"); - let resolver = DnsResolver::new(settings.database_file.clone(), settings.remote_lookup_port); + let resolver = DnsResolver::new(settings.database_file.clone()); match resolver.answer_question(request) { Ok(result) => { diff --git a/src/main.rs b/src/main.rs index e9e4cc2..b8d897f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -139,7 +139,6 @@ fn main() -> Result<(), Box> { }; let settings = settings.expect("Error reading settings!"); log_debug!("Settings: {:?}", settings); - let server_udp = DnsUdpServer::new(settings.clone()); let server_tcp = DnsTcpServer::new(settings.clone()); diff --git a/src/settings.rs b/src/settings.rs index 157d40d..8b50f77 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2,6 +2,9 @@ use std::error::Error; use std::fs; use std::io::ErrorKind; use yaml_rust::YamlLoader; +use std::path::Path; + +use crate::log_info; use crate::log_debug; @@ -10,7 +13,6 @@ extern crate shellexpand; #[derive(Clone, Debug)] pub struct DnsSettings { pub listening_port: u16, - pub remote_lookup_port: u16, pub database_file: String, pub thread_count: u32, pub use_udp: bool, @@ -34,10 +36,6 @@ impl DnsSettings { Some(x) => x as u16, None => 53, }; - let remote_lookup_port = match config_settings["remote-lookup-port"].as_i64() { - Some(x) => x as u16, - None => 42069, - }; let thread_count = match config_settings["thread-count"].as_i64() { Some(x) => x as u32, None => 1, // TODO is this the best default? @@ -61,7 +59,6 @@ impl DnsSettings { Ok(DnsSettings { listening_port, - remote_lookup_port, database_file, thread_count, use_udp,