dns_parser_joe/
structs.rs

1use {QueryType, QueryClass, Name, Class, Header, RRData};
2
3
4/// Parsed DNS packet
5#[derive(Debug)]
6pub struct Packet<'a> {
7    pub header: Header,
8    pub questions: Vec<Question<'a>>,
9    pub answers: Vec<ResourceRecord<'a>>,
10    pub nameservers: Vec<ResourceRecord<'a>>,
11    pub additional: Vec<ResourceRecord<'a>>,
12    /// Optional Pseudo-RR
13    /// When present it is sent as an RR in the additional section. In this RR
14    /// the `class` and `ttl` fields store max udp packet size and flags
15    /// respectively. To keep `ResourceRecord` clean we store the OPT record
16    /// here.
17    pub opt: Option<OptRecord<'a>>,
18}
19
20/// A parsed chunk of data in the Query section of the packet
21#[derive(Debug)]
22pub struct Question<'a> {
23    pub qname: Name<'a>,
24    /// Whether or not we prefer unicast responses.
25    /// This is used in multicast DNS.
26    pub prefer_unicast: bool,
27    pub qtype: QueryType,
28    pub qclass: QueryClass,
29}
30
31/// A single DNS record
32///
33/// We aim to provide whole range of DNS records available. But as time is
34/// limited we have some types of packets which are parsed and other provided
35/// as unparsed slice of bytes.
36#[derive(Debug)]
37pub struct ResourceRecord<'a> {
38    pub name: Name<'a>,
39    /// Whether or not the set of resource records is fully contained in the
40    /// packet, or whether there will be more resource records in future
41    /// packets. Only used for multicast DNS.
42    pub multicast_unique: bool,
43    pub cls: Class,
44    pub ttl: u32,
45    pub data: RRData<'a>,
46}
47
48/// RFC 6891 OPT RR
49#[derive(Debug)]
50pub struct OptRecord<'a> {
51    pub udp: u16,
52    pub extrcode: u8,
53    pub version: u8,
54    pub flags: u16,
55    pub data: RRData<'a>,
56}
57
58#[derive(Debug)]
59pub struct SoaRecord<'a> {
60    pub primary_ns: Name<'a>,
61    pub mailbox: Name<'a>,
62    pub serial: u32,
63    pub refresh: u32,
64    pub retry: u32,
65    pub expire: u32,
66    pub minimum_ttl: u32,
67}