diff --git a/packages/dns-test/src/client.rs b/packages/dns-test/src/client.rs index 069f2562..484fb2c7 100644 --- a/packages/dns-test/src/client.rs +++ b/packages/dns-test/src/client.rs @@ -29,7 +29,7 @@ impl Client { &self, server: Ipv4Addr, record_type: RecordType, - fqdn: &FQDN<'_>, + fqdn: &FQDN, trust_anchor: &TrustAnchor, ) -> Result { const TRUST_ANCHOR_PATH: &str = "/etc/bind.keys"; @@ -57,7 +57,7 @@ impl Client { dnssec: Dnssec, server: Ipv4Addr, record_type: RecordType, - fqdn: &FQDN<'_>, + fqdn: &FQDN, ) -> Result { let output = self.inner.stdout(&[ "dig", diff --git a/packages/dns-test/src/fqdn.rs b/packages/dns-test/src/fqdn.rs index 18e08a8b..5c3d8678 100644 --- a/packages/dns-test/src/fqdn.rs +++ b/packages/dns-test/src/fqdn.rs @@ -5,13 +5,13 @@ use std::borrow::Cow; use crate::{Error, Result}; #[derive(Clone, PartialEq)] -pub struct FQDN<'a> { - inner: Cow<'a, str>, +pub struct FQDN { + inner: Cow<'static, str>, } // TODO likely needs further validation #[allow(non_snake_case)] -pub fn FQDN<'a>(input: impl Into>) -> Result> { +pub fn FQDN(input: impl Into>) -> Result { let input = input.into(); if !input.ends_with('.') { return Err("FQDN must end with a `.`".into()); @@ -24,12 +24,12 @@ pub fn FQDN<'a>(input: impl Into>) -> Result> { Ok(FQDN { inner: input }) } -impl<'a> FQDN<'a> { - pub const ROOT: FQDN<'static> = FQDN { +impl FQDN { + pub const ROOT: FQDN = FQDN { inner: Cow::Borrowed("."), }; - pub const COM: FQDN<'static> = FQDN { + pub const COM: FQDN = FQDN { inner: Cow::Borrowed("com."), }; @@ -41,7 +41,7 @@ impl<'a> FQDN<'a> { &self.inner } - pub fn into_owned(self) -> FQDN<'static> { + pub fn into_owned(self) -> FQDN { let owned = match self.inner { Cow::Borrowed(borrowed) => borrowed.to_string(), Cow::Owned(owned) => owned, @@ -53,21 +53,21 @@ impl<'a> FQDN<'a> { } } -impl FromStr for FQDN<'static> { +impl FromStr for FQDN { type Err = Error; fn from_str(input: &str) -> Result { - Ok(FQDN(input)?.into_owned()) + FQDN(input.to_string()) } } -impl fmt::Debug for FQDN<'_> { +impl fmt::Debug for FQDN { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } } -impl fmt::Display for FQDN<'_> { +impl fmt::Display for FQDN { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.inner) } diff --git a/packages/dns-test/src/name_server.rs b/packages/dns-test/src/name_server.rs index db9aab0a..f907c8b6 100644 --- a/packages/dns-test/src/name_server.rs +++ b/packages/dns-test/src/name_server.rs @@ -6,13 +6,13 @@ use crate::tshark::Tshark; use crate::zone_file::{self, SoaSettings, ZoneFile, DNSKEY, DS}; use crate::{Implementation, Result, FQDN}; -pub struct NameServer<'a, State> { +pub struct NameServer { container: Container, - zone_file: ZoneFile<'a>, + zone_file: ZoneFile, state: State, } -impl<'a> NameServer<'a, Stopped> { +impl NameServer { /// Spins up a primary name server that has authority over the given `zone` /// /// The initial state of the server is the "Stopped" state where it won't answer any query. @@ -25,7 +25,7 @@ impl<'a> NameServer<'a, Stopped> { /// - one SOA record, with the primary name server field set to this name server's FQDN /// - one NS record, with this name server's FQDN set as the only available name server for /// the zone - pub fn new(implementation: Implementation, zone: FQDN<'a>, network: &Network) -> Result { + pub fn new(implementation: Implementation, zone: FQDN, network: &Network) -> Result { assert!( matches!(implementation, Implementation::Unbound), "currently only `unbound` (`nsd`) can be used as a `NameServer`" @@ -56,18 +56,13 @@ impl<'a> NameServer<'a, Stopped> { } /// Adds a NS + A record pair to the zone file - pub fn referral( - &mut self, - zone: FQDN<'a>, - nameserver: FQDN<'a>, - ipv4_addr: Ipv4Addr, - ) -> &mut Self { + pub fn referral(&mut self, zone: FQDN, nameserver: FQDN, ipv4_addr: Ipv4Addr) -> &mut Self { self.zone_file.referral(zone, nameserver, ipv4_addr); self } /// Adds an A record pair to the zone file - pub fn a(&mut self, fqdn: FQDN<'a>, ipv4_addr: Ipv4Addr) -> &mut Self { + pub fn a(&mut self, fqdn: FQDN, ipv4_addr: Ipv4Addr) -> &mut Self { self.zone_file.entry(zone_file::A { fqdn, ipv4_addr }); self } @@ -79,7 +74,7 @@ impl<'a> NameServer<'a, Stopped> { } /// Freezes and signs the name server's zone file - pub fn sign(self) -> Result> { + pub fn sign(self) -> Result> { // TODO do we want to make these settings configurable? const ZSK_BITS: usize = 1024; const KSK_BITS: usize = 2048; @@ -139,7 +134,7 @@ impl<'a> NameServer<'a, Stopped> { } /// Moves the server to the "Start" state where it can answer client queries - pub fn start(self) -> Result> { + pub fn start(self) -> Result> { let Self { container, zone_file, @@ -176,9 +171,9 @@ fn ns_count() -> usize { COUNT.fetch_add(1, atomic::Ordering::Relaxed) } -impl<'a> NameServer<'a, Signed> { +impl NameServer { /// Moves the server to the "Start" state where it can answer client queries - pub fn start(self) -> Result> { + pub fn start(self) -> Result> { let Self { container, zone_file, @@ -216,7 +211,7 @@ impl<'a> NameServer<'a, Signed> { } } -impl<'a> NameServer<'a, Running> { +impl NameServer { /// Starts a `tshark` instance that captures DNS messages flowing through this network node pub fn eavesdrop(&self) -> Result { self.container.eavesdrop() @@ -246,7 +241,7 @@ kill -TERM $(cat {pidfile})" } } -impl<'a, S> NameServer<'a, S> { +impl NameServer { pub fn container_id(&self) -> &str { self.container.id() } @@ -256,15 +251,15 @@ impl<'a, S> NameServer<'a, S> { } /// Zone file BEFORE signing - pub fn zone_file(&self) -> &ZoneFile<'a> { + pub fn zone_file(&self) -> &ZoneFile { &self.zone_file } - pub fn zone(&self) -> &FQDN<'a> { + pub fn zone(&self) -> &FQDN { &self.zone_file.origin } - pub fn fqdn(&self) -> &FQDN<'a> { + pub fn fqdn(&self) -> &FQDN { &self.zone_file.soa.nameserver } } @@ -282,11 +277,11 @@ pub struct Running { child: Child, } -fn primary_ns(ns_count: usize) -> FQDN<'static> { +fn primary_ns(ns_count: usize) -> FQDN { FQDN(format!("primary{ns_count}.nameservers.com.")).unwrap() } -fn admin_ns(ns_count: usize) -> FQDN<'static> { +fn admin_ns(ns_count: usize) -> FQDN { FQDN(format!("admin{ns_count}.nameservers.com.")).unwrap() } diff --git a/packages/dns-test/src/record.rs b/packages/dns-test/src/record.rs index 0f6885ac..e8086916 100644 --- a/packages/dns-test/src/record.rs +++ b/packages/dns-test/src/record.rs @@ -93,7 +93,7 @@ impl FromStr for Record { #[derive(Debug)] pub struct A { - pub fqdn: FQDN<'static>, + pub fqdn: FQDN, pub ttl: u32, pub ipv4_addr: Ipv4Addr, } @@ -132,7 +132,7 @@ impl FromStr for A { #[allow(clippy::upper_case_acronyms)] #[derive(Debug)] pub struct RRSIG { - pub fqdn: FQDN<'static>, + pub fqdn: FQDN, pub ttl: u32, pub type_covered: RecordType, pub algorithm: u32, @@ -141,7 +141,7 @@ pub struct RRSIG { pub signature_expiration: u64, pub signature_inception: u64, pub key_tag: u32, - pub signer_name: FQDN<'static>, + pub signer_name: FQDN, /// base64 encoded pub signature: String, } @@ -193,10 +193,10 @@ impl FromStr for RRSIG { #[allow(clippy::upper_case_acronyms)] #[derive(Debug)] pub struct SOA { - pub zone: FQDN<'static>, + pub zone: FQDN, pub ttl: u32, - pub nameserver: FQDN<'static>, - pub admin: FQDN<'static>, + pub nameserver: FQDN, + pub admin: FQDN, pub serial: u32, pub refresh: u32, pub retry: u32, diff --git a/packages/dns-test/src/zone_file.rs b/packages/dns-test/src/zone_file.rs index 8dc153c9..53c498df 100644 --- a/packages/dns-test/src/zone_file.rs +++ b/packages/dns-test/src/zone_file.rs @@ -10,16 +10,16 @@ use std::str::FromStr; use crate::{Error, FQDN}; -pub struct ZoneFile<'a> { - pub origin: FQDN<'a>, +pub struct ZoneFile { + pub origin: FQDN, pub ttl: u32, - pub soa: SOA<'a>, - pub entries: Vec>, + pub soa: SOA, + pub entries: Vec, } -impl<'a> ZoneFile<'a> { +impl ZoneFile { /// Convenience constructor that uses "reasonable" defaults - pub fn new(origin: FQDN<'a>, soa: SOA<'a>) -> Self { + pub fn new(origin: FQDN, soa: SOA) -> Self { Self { origin, ttl: 1800, @@ -29,12 +29,12 @@ impl<'a> ZoneFile<'a> { } /// Appends an entry - pub fn entry(&mut self, entry: impl Into>) { + pub fn entry(&mut self, entry: impl Into) { self.entries.push(entry.into()) } /// Appends a NS + A entry pair - pub fn referral(&mut self, zone: FQDN<'a>, nameserver: FQDN<'a>, ipv4_addr: Ipv4Addr) { + pub fn referral(&mut self, zone: FQDN, nameserver: FQDN, ipv4_addr: Ipv4Addr) { self.entry(NS { zone: zone.clone(), nameserver: nameserver.clone(), @@ -46,7 +46,7 @@ impl<'a> ZoneFile<'a> { } } -impl fmt::Display for ZoneFile<'_> { +impl fmt::Display for ZoneFile { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { origin, @@ -67,15 +67,15 @@ impl fmt::Display for ZoneFile<'_> { } } -pub struct Root<'a> { +pub struct Root { pub ipv4_addr: Ipv4Addr, - pub ns: FQDN<'a>, + pub ns: FQDN, pub ttl: u32, } -impl<'a> Root<'a> { +impl Root { /// Convenience constructor that uses "reasonable" defaults - pub fn new(ns: FQDN<'a>, ipv4_addr: Ipv4Addr) -> Self { + pub fn new(ns: FQDN, ipv4_addr: Ipv4Addr) -> Self { Self { ipv4_addr, ns, @@ -84,7 +84,7 @@ impl<'a> Root<'a> { } } -impl fmt::Display for Root<'_> { +impl fmt::Display for Root { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { ipv4_addr, ns, ttl } = self; @@ -93,32 +93,32 @@ impl fmt::Display for Root<'_> { } } -pub enum Entry<'a> { - A(A<'a>), +pub enum Entry { + A(A), DNSKEY(DNSKEY), DS(DS), - NS(NS<'a>), + NS(NS), } -impl<'a> From for Entry<'a> { +impl From for Entry { fn from(v: DS) -> Self { Self::DS(v) } } -impl<'a> From> for Entry<'a> { - fn from(v: A<'a>) -> Self { +impl From for Entry { + fn from(v: A) -> Self { Self::A(v) } } -impl<'a> From> for Entry<'a> { - fn from(v: NS<'a>) -> Self { +impl From for Entry { + fn from(v: NS) -> Self { Self::NS(v) } } -impl fmt::Display for Entry<'_> { +impl fmt::Display for Entry { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Entry::A(a) => a.fmt(f), @@ -130,12 +130,12 @@ impl fmt::Display for Entry<'_> { } #[derive(Clone)] -pub struct A<'a> { - pub fqdn: FQDN<'a>, +pub struct A { + pub fqdn: FQDN, pub ipv4_addr: Ipv4Addr, } -impl fmt::Display for A<'_> { +impl fmt::Display for A { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { fqdn, ipv4_addr } = self; @@ -146,7 +146,7 @@ impl fmt::Display for A<'_> { // integer types chosen based on bit sizes in section 2.1 of RFC4034 #[derive(Clone, Debug)] pub struct DNSKEY { - zone: FQDN<'static>, + zone: FQDN, flags: u16, protocol: u8, algorithm: u8, @@ -256,7 +256,7 @@ impl fmt::Display for DNSKEY { #[derive(Clone)] pub struct DS { - zone: FQDN<'static>, + zone: FQDN, _ttl: u32, key_tag: u16, algorithm: u8, @@ -317,12 +317,12 @@ impl fmt::Display for DS { } } -pub struct NS<'a> { - pub zone: FQDN<'a>, - pub nameserver: FQDN<'a>, +pub struct NS { + pub zone: FQDN, + pub nameserver: FQDN, } -impl fmt::Display for NS<'_> { +impl fmt::Display for NS { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { zone, @@ -333,14 +333,14 @@ impl fmt::Display for NS<'_> { } } -pub struct SOA<'a> { - pub zone: FQDN<'a>, - pub nameserver: FQDN<'a>, - pub admin: FQDN<'a>, +pub struct SOA { + pub zone: FQDN, + pub nameserver: FQDN, + pub admin: FQDN, pub settings: SoaSettings, } -impl fmt::Display for SOA<'_> { +impl fmt::Display for SOA { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { zone, @@ -482,21 +482,21 @@ e.gtld-servers.net. IN A 192.12.94.30 Ok(()) } - fn example_a() -> Result> { + fn example_a() -> Result { Ok(A { fqdn: FQDN("e.gtld-servers.net.")?, ipv4_addr: Ipv4Addr::new(192, 12, 94, 30), }) } - fn example_ns() -> Result> { + fn example_ns() -> Result { Ok(NS { zone: FQDN::COM, nameserver: FQDN("e.gtld-servers.net.")?, }) } - fn example_soa() -> Result> { + fn example_soa() -> Result { Ok(SOA { zone: FQDN::ROOT, nameserver: FQDN("a.root-servers.net.")?,