Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
NameServer: fix generation of SOA record
Browse files Browse the repository at this point in the history
`unbound` requires that the MNAME lies underneath the zone. That is
`primaryNN.nameservers.com.` is not a valid MNAME for a nameserver
authoritative over `mydomain.com.`. For that zone,
`primaryNN.mydomain.com.` would be a valid MNAME.
  • Loading branch information
japaric committed May 23, 2024
1 parent 0ba63a1 commit ab2aa39
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/dns-test/src/name_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ impl NameServer<Stopped> {
/// the zone
pub fn new(implementation: &Implementation, zone: FQDN, network: &Network) -> Result<Self> {
let ns_count = ns_count();
let nameserver = primary_ns(ns_count);
let nameserver = primary_ns(ns_count, &zone);
let image = implementation.clone().into();
let container = Container::run(&image, network)?;

let soa = SOA {
zone: zone.clone(),
ttl: DEFAULT_TTL,
nameserver: nameserver.clone(),
admin: admin_ns(ns_count),
admin: admin_ns(ns_count, &zone),
settings: SoaSettings::default(),
};
let mut zone_file = ZoneFile::new(soa);
Expand Down Expand Up @@ -439,12 +439,22 @@ pub struct Running {
child: Child,
}

fn primary_ns(ns_count: usize) -> FQDN {
FQDN(format!("primary{ns_count}.nameservers.com.")).unwrap()
fn primary_ns(ns_count: usize, zone: &FQDN) -> FQDN {
FQDN(format!("primary{ns_count}.{}", expand_zone(zone))).unwrap()
}

fn admin_ns(ns_count: usize) -> FQDN {
FQDN(format!("admin{ns_count}.nameservers.com.")).unwrap()
fn admin_ns(ns_count: usize, zone: &FQDN) -> FQDN {
FQDN(format!("admin{ns_count}.{}", expand_zone(zone))).unwrap()
}

fn expand_zone(zone: &FQDN) -> String {
if zone == &FQDN::ROOT {
"nameservers.com.".to_string()
} else if zone.num_labels() == 1 {
format!("nameservers.{}", zone.as_str())
} else {
zone.to_string()
}
}

#[cfg(test)]
Expand Down

0 comments on commit ab2aa39

Please sign in to comment.