resolver: check that the root servers list is not empty
This commit is contained in:
parent
77150bbca6
commit
36f93252a2
@ -12,6 +12,13 @@ pub struct Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Resolver {
|
impl Resolver {
|
||||||
|
/// Starts a DNS server in the recursive resolver role
|
||||||
|
///
|
||||||
|
/// This server is not an authoritative name server; it does not server a zone file to clients
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This constructor panics if `roots` is an empty slice
|
||||||
pub fn start(
|
pub fn start(
|
||||||
implementation: Implementation,
|
implementation: Implementation,
|
||||||
roots: &[Root],
|
roots: &[Root],
|
||||||
@ -19,6 +26,11 @@ impl Resolver {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
const TRUST_ANCHOR_FILE: &str = "/etc/trusted-key.key";
|
const TRUST_ANCHOR_FILE: &str = "/etc/trusted-key.key";
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!roots.is_empty(),
|
||||||
|
"must configure at least one local root server"
|
||||||
|
);
|
||||||
|
|
||||||
let container = Container::run(implementation)?;
|
let container = Container::run(implementation)?;
|
||||||
|
|
||||||
let mut hints = String::new();
|
let mut hints = String::new();
|
||||||
@ -92,11 +104,19 @@ fn hickory_conf(use_dnssec: bool) -> String {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::{name_server::NameServer, FQDN};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn terminate_works() -> Result<()> {
|
fn terminate_works() -> Result<()> {
|
||||||
let resolver = Resolver::start(Implementation::Unbound, &[], &TrustAnchor::empty())?;
|
let ns = NameServer::new(FQDN::ROOT)?.start()?;
|
||||||
|
|
||||||
|
let resolver = Resolver::start(
|
||||||
|
Implementation::Unbound,
|
||||||
|
&[Root::new(ns.fqdn().clone(), ns.ipv4_addr())],
|
||||||
|
&TrustAnchor::empty(),
|
||||||
|
)?;
|
||||||
let logs = resolver.terminate()?;
|
let logs = resolver.terminate()?;
|
||||||
|
|
||||||
eprintln!("{logs}");
|
eprintln!("{logs}");
|
||||||
|
Loading…
Reference in New Issue
Block a user