Skip to main content

domain_core/bits/
mod.rs

1//! Handling of DNS data.
2//!
3//! This module provides types and traits for working with DNS data. The types
4//! allow creating such data from scratch and processing it. Crucially, the
5//! module provides means to extract the data from wire-format DNS messages
6//! and assemble such messages. Tools for processing the textual master format
7//! representation of DNS data are not part of this module but can be found in
8//! [master].
9//!
10//! [master]: ../master/index.html
11//!
12//!
13//! # Representation of Variable-length Data and DNS Messages
14//!
15//! Various types have to deal with data of variable length. For instance, a
16//! domain name can be anywhere between one and 255 bytes long. Such types,
17//! all the way up to complete DNS messages, use the [`bytes::Bytes`] type
18//! for holding the actual octets. Values of this type provide a good
19//! compromise between the convenience of owned values and the performance
20//! gained by using slices wherever possible. (The prize for the latter would
21//! be excessive use of generic types and, worse yet, lifetime arguments all
22//! over the place.)
23//!
24//! In order to distinguish between the various possible representations of
25//! a sequence of bytes, the module attempts to use a consistent terminology.
26//! The term ‘bytes’ will always mean a [`Bytes`] value; a `slice` or `byte
27//! slice` is always a reference to a slice of `u8`; and a `vec` is always a
28//! `Vec<u8>`. Thus a method `as_bytes` on a type would return a [`Bytes`]
29//! reference of the types raw content, while `as_slice` will provide access
30//! to the even more raw `[u8]` of it.
31//!
32//! [`bytes::Bytes`]: ../../bytes/struct.Bytes.html
33//! [`Bytes`]: ../../bytes/struct.Bytes.html
34//!
35//!
36//! # Parsing and Composing Messages
37//!
38//! In order to easily distinguish the process of creating and disecting
39//! wire-format messages other forms of representation conversion such as
40//! reading from a master file, we use the term *parsing* for extracting data
41//! from a wire-format representation and *composing* for producing such a
42//! representation. 
43//!
44//! Both parsing and composing happen on buffers holding a complete DNS
45//! message. This seems to be a reasonably good choice given the limited 
46//! size of DNS messages and the complexities introduced by to compress
47//! domain names in message by referencing other parts of the message.
48//! The details are explained in the [parse] and [compose] sub-modules.
49//! Unless you are implementing your own resource record types, you are
50//! unlikely to ever having to deal with parsing and composing directly.
51//!
52//! Instead, the types [`Message`] and [`MessageBuilder`] are there to make
53//! parsing and constructing DNS messages easy. A [`Message`] takes the
54//! binary data of a DNS message and allows iterating over its four
55//! sections to look at the questions and resource records. Similarly,
56//! a [`MessageBuilder`] takes a bytes vector (or creates one for you) and
57//! has functionality to build the sections of the message step-by-step.//!
58//!
59//! [compose]: compose/index.html
60//! [parse]: parse/index.html
61//! [`Message`]: message/struct.Message.html
62//! [`MessageBuilder`]: message_builder/struct.MessageBuilder.html
63//!
64//!
65//! # Types for DNS Data
66//!
67//! The module contains a number of types for DNS data, both fundamental
68//! and composed. Because they often come with a number of support types,
69//! they are arranged in submodules. You will find detailed explanations for
70//! all of them in their module. These are:
71//!
72//! * [charstr](charstr/index.html) for DNS character strings,
73//! * [header](header/index.html) for the header of DNS messages,
74//! * [name](name/index.html) for domain names,
75//! * [opt](opt/index.html) for the record data of OPT records used in EDNS,
76//! * [question](question/index.html) for questions,
77//! * [serial](serial/index.html) for serial numbers of zones,
78//! * [rdata](rdata/index.html) for infrastructure around record data; the
79//!   actual implementations of the various record types are in the top-level
80//!   [rdata](../rdata/index.html) module, and
81//! * [record](record/index.html) for DNS resource records.
82//!
83//! The main types from each module are being reimported here.
84
85
86//--- Re-exports
87
88pub use self::charstr::{CharStr, CharStrMut};
89pub use self::compose::{Compose, Compress, Compressor};
90pub use self::header::{Header, HeaderCounts, HeaderSection};
91pub use self::message::{Message, RecordSection, Section};
92pub use self::message_builder::{MessageBuilder, SectionBuilder, RecordSectionBuilder};
93pub use self::name::{
94    Dname, ParsedDname, RelativeDname, ToDname, ToRelativeDname
95};
96pub use self::parse::{Parser, Parse, ParseAll, ShortBuf};
97pub use self::question::Question;
98pub use self::rdata::{ParseRecordData, RecordData, UnknownRecordData};
99pub use self::record::{Record, RecordHeader, ParsedRecord};
100
101
102//--- Modules
103
104pub mod charstr;
105pub mod compose;
106pub mod header;
107pub mod message;
108pub mod message_builder;
109pub mod name;
110pub mod opt;
111pub mod parse;
112pub mod query;
113pub mod question;
114pub mod rdata;
115pub mod record;
116pub mod serial;
117