diff --git a/packages/dns-test/src/container.rs b/packages/dns-test/src/container.rs index 3c51c70e..006770b3 100644 --- a/packages/dns-test/src/container.rs +++ b/packages/dns-test/src/container.rs @@ -4,7 +4,7 @@ use std::net::Ipv4Addr; use std::process::{self, ExitStatus}; use std::process::{Command, Stdio}; use std::sync::atomic::AtomicUsize; -use std::sync::{atomic, Arc, Once}; +use std::sync::{atomic, Arc}; use tempfile::{NamedTempFile, TempDir}; @@ -19,8 +19,6 @@ const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME"); impl Container { /// Starts the container in a "parked" state pub fn run(implementation: Implementation) -> Result { - static ONCE: Once = Once::new(); - // TODO make this configurable and support hickory & bind let dockerfile = implementation.dockerfile(); let docker_build_dir = TempDir::new()?; @@ -35,7 +33,7 @@ impl Container { .arg(&image_tag) .arg(docker_build_dir); - ONCE.call_once(|| { + implementation.once().call_once(|| { let output = command.output().unwrap(); let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); diff --git a/packages/dns-test/src/docker/hickory.Dockerfile b/packages/dns-test/src/docker/hickory.Dockerfile index 0fe0137f..1f6efac9 100644 --- a/packages/dns-test/src/docker/hickory.Dockerfile +++ b/packages/dns-test/src/docker/hickory.Dockerfile @@ -4,4 +4,5 @@ RUN apt-get update && \ apt-get install -y \ tshark -RUN cargo install hickory-dns --version 0.24.0 +RUN cargo install hickory-dns --version 0.24.0 --features recursor +env RUST_LOG=debug diff --git a/packages/dns-test/src/lib.rs b/packages/dns-test/src/lib.rs index b6747262..aeccd5fe 100644 --- a/packages/dns-test/src/lib.rs +++ b/packages/dns-test/src/lib.rs @@ -1,6 +1,7 @@ //! A test framework for all things DNS use core::fmt; +use std::sync::Once; pub use crate::fqdn::FQDN; pub use crate::recursive_resolver::RecursiveResolver; @@ -31,6 +32,19 @@ impl Implementation { Implementation::Hickory => include_str!("docker/hickory.Dockerfile"), } } + + fn once(&self) -> &'static Once { + match self { + Implementation::Unbound => { + static UNBOUND_ONCE: Once = Once::new(); + &UNBOUND_ONCE + } + Implementation::Hickory => { + static HICKORY_ONCE: Once = Once::new(); + &HICKORY_ONCE + } + } + } } impl Default for Implementation { diff --git a/packages/dns-test/src/recursive_resolver.rs b/packages/dns-test/src/recursive_resolver.rs index 7393b1ca..f95ee696 100644 --- a/packages/dns-test/src/recursive_resolver.rs +++ b/packages/dns-test/src/recursive_resolver.rs @@ -26,16 +26,32 @@ impl RecursiveResolver { writeln!(hints, "{root}").unwrap(); } - container.cp("/etc/unbound/root.hints", &hints)?; - let use_dnssec = !trust_anchor.is_empty(); - container.cp("/etc/unbound/unbound.conf", &unbound_conf(use_dnssec))?; + match implementation { + Implementation::Unbound => { + container.cp("/etc/unbound/root.hints", &hints)?; + + container.cp("/etc/unbound/unbound.conf", &unbound_conf(use_dnssec))?; + } + + Implementation::Hickory => { + container.status_ok(&["mkdir", "-p", "/etc/hickory"])?; + + container.cp("/etc/hickory/root.hints", &hints)?; + + container.cp("/etc/named.toml", &hickory_conf(use_dnssec))?; + } + } if use_dnssec { container.cp(TRUST_ANCHOR_FILE, &trust_anchor.to_string())?; } - let child = container.spawn(&["unbound", "-d"])?; + let command: &[_] = match implementation { + Implementation::Unbound => &["unbound", "-d"], + Implementation::Hickory => &["hickory-dns", "-d"], + }; + let child = container.spawn(command)?; Ok(Self { child, container }) } @@ -70,6 +86,10 @@ fn unbound_conf(use_dnssec: bool) -> String { minijinja::render!(include_str!("templates/unbound.conf.jinja"), use_dnssec => use_dnssec) } +fn hickory_conf(use_dnssec: bool) -> String { + minijinja::render!(include_str!("templates/hickory.resolver.toml.jinja"), use_dnssec => use_dnssec) +} + #[cfg(test)] mod tests { use super::*; diff --git a/packages/dns-test/src/templates/hickory.resolver.toml.jinja b/packages/dns-test/src/templates/hickory.resolver.toml.jinja new file mode 100644 index 00000000..d3da6496 --- /dev/null +++ b/packages/dns-test/src/templates/hickory.resolver.toml.jinja @@ -0,0 +1,5 @@ +[[zones]] +zone = "." +zone_type = "Hint" +stores = { type = "recursor", roots = "/etc/hickory/root.hints", ns_cache_size = 1024, record_cache_size = 1048576 } +enable_dnssec = {{ use_dnssec }}