zone
ModuleZones: the records a server is authoritative for, looking names up in them, and zone files.
Contents
2 submodules, and what the module defines itself.
use utopia_dns::Zone;pub struct ZoneAn administrative unit: the records of a domain and its subdomains, and
the SOA record that heads it.
zone::file
Own pageZone files (RFC 1035 §5, the master file format).
use utopia_dns::zone::file::export;pub fn export(zone: &Zone, include_comments: bool) -> Vec<u8>Exports a zone as a zone file: $ORIGIN, $TTL (the SOA's), the
SOA over several lines, then the records grouped by type (NS, A,
AAAA, MX, CNAME, TXT, then the others in order of appearance),
with names relative to the zone. Comments, when included, head the file
(with the time, from std::time::SystemTime, in UTC) and each group.
use utopia_dns::zone::file::export_at;pub fn export_at(zone: &Zone, include_comments: bool, generated: &str) -> Vec<u8>export with the time written in the header comment (Y-m-d H:i:s).
use utopia_dns::zone::file::import;pub fn import(content: &[u8], default_origin: Option<&[u8]>, default_ttl: i64) -> Result<Zone, Error>Imports a zone from a zone file.
Supports $ORIGIN and $TTL (other $ directives are skipped,
$INCLUDE is refused), @, relative names, omitted owners (the
previous one), omitted TTLs and classes (the previous ones, in any
order), ; comments outside quotes, and records spanning lines in
parentheses. TXT strings are joined and \DDD escapes decoded. The zone
is named by the first $ORIGIN, else default_origin; it needs exactly
one SOA record.
Fails with Error::Import, carrying the file.
use utopia_dns::zone;
let zone = zone::import(b"$ORIGIN example.com.
$TTL 1800
@ IN SOA ns1.example.com. admin.example.com. 2025011801 7200 3600 1209600 1800
www IN A 192.168.1.10
mail 300 IN MX 10 mail", None, 3600)?;
assert_eq!(zone.name(), b"example.com");
assert_eq!(zone.records()[1].rdata(), b"mail.example.com");
assert_eq!(zone.records()[1].priority(), Some(10));zone::resolver
Own pageLooking a query up in a zone: exact names, wildcards, CNAMEs,
delegations and negative answers.
use utopia_dns::zone::resolver::lookup;pub fn lookup(query: &Message, zone: &Zone) -> Result<Message, Error>Answers query from zone, shuffling multi-record answers with a
generator seeded from the operating system.
See lookup_with.
use utopia_dns::zone::resolver::lookup_with;pub fn lookup_with(query: &Message, zone: &Zone, rng: &mut Mt19937) -> Result<Message, Error>Answers query from zone (the algorithm of
https://www.usenix.org/sites/default/files/styles/article_embedded/public/tree.png):
- no question:
FORMERR; - records named exactly like the question: the records of its type
(shuffled, RFC 2181 §5), else its
CNAMEs, else no data with theSOA; a name withNSrecords below the apex is a referral to them; - otherwise the closest enclosing wildcard's records, renamed to the question's name, chosen the same way;
- otherwise
NXDOMAINwith theSOA(anSOAquestion at the apex is answered with it).