supporty hickory-based Resolver

This commit is contained in:
Jorge Aparicio 2024-02-09 15:37:58 +01:00
parent 3c95b85150
commit 04a7190e61
5 changed files with 47 additions and 9 deletions

View File

@ -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<Self> {
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);

View File

@ -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

View File

@ -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 {

View File

@ -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::*;

View File

@ -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 }}