dns_message_parser/rr/edns/
rfc_6891.rs1use super::{Cookie, ExtendedDNSErrors, Padding, ECS};
2use std::fmt::{Display, Formatter, Result as FmtResult};
3
4pub const EDNS_DNSSEC_MASK: u8 = 0x80;
5
6try_from_enum_to_integer! {
7 #[repr(u16)]
8 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9 pub enum EDNSOptionCode {
10 ECS = 0x00008,
11 Cookie = 0x000a,
12 Padding = 0x000c,
13 ExtendedDnsError = 0x000f,
14 }
15}
16
17#[derive(Debug, PartialEq, Clone, Eq, Hash)]
18pub enum EDNSOption {
19 ECS(ECS),
20 Cookie(Cookie),
21 Padding(Padding),
22 ExtendedDNSErrors(ExtendedDNSErrors),
23}
24
25impl Display for EDNSOption {
26 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
27 match self {
28 EDNSOption::ECS(ecs) => ecs.fmt(f),
29 EDNSOption::Cookie(cookie) => cookie.fmt(f),
30 EDNSOption::Padding(padding) => padding.fmt(f),
31 EDNSOption::ExtendedDNSErrors(extended_dns_errors) => extended_dns_errors.fmt(f),
32 }
33 }
34}
35
36#[derive(Debug, PartialEq, Clone, Eq, Hash)]
37pub struct OPT {
38 pub requestor_payload_size: u16,
39 pub extend_rcode: u8,
40 pub version: u8,
41 pub dnssec: bool,
42 pub edns_options: Vec<EDNSOption>,
43}
44
45impl_to_type!(OPT);
46
47impl Display for OPT {
48 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
49 write!(
51 f,
52 ". OPT {} {} {} {}",
53 self.requestor_payload_size, self.extend_rcode, self.version, self.dnssec,
54 )?;
55 for edns_option in &self.edns_options {
56 write!(f, " {}", edns_option)?;
57 }
58 Ok(())
59 }
60}