diff options
Diffstat (limited to 'src/dns/packet/query.rs')
-rw-r--r-- | src/dns/packet/query.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/dns/packet/query.rs b/src/dns/packet/query.rs new file mode 100644 index 0000000..732b9b2 --- /dev/null +++ b/src/dns/packet/query.rs @@ -0,0 +1,78 @@ +#[derive(PartialEq, Eq, Debug, Clone, Hash, Copy)] +pub enum QueryType { + UNKNOWN(u16), + A, // 1 + NS, // 2 + CNAME, // 5 + SOA, // 6 + PTR, // 12 + MX, // 15 + TXT, // 16 + AAAA, // 28 + SRV, // 33 + OPT, // 41 + CAA, // 257 + AR, // 1000 + AAAAR, // 1001 +} + +impl QueryType { + pub fn to_num(&self) -> u16 { + match *self { + Self::UNKNOWN(x) => x, + Self::A => 1, + Self::NS => 2, + Self::CNAME => 5, + Self::SOA => 6, + Self::PTR => 12, + Self::MX => 15, + Self::TXT => 16, + Self::AAAA => 28, + Self::SRV => 33, + Self::OPT => 41, + Self::CAA => 257, + Self::AR => 1000, + Self::AAAAR => 1001, + } + } + + pub fn from_num(num: u16) -> Self { + match num { + 1 => Self::A, + 2 => Self::NS, + 5 => Self::CNAME, + 6 => Self::SOA, + 12 => Self::PTR, + 15 => Self::MX, + 16 => Self::TXT, + 28 => Self::AAAA, + 33 => Self::SRV, + 41 => Self::OPT, + 257 => Self::CAA, + 1000 => Self::AR, + 1001 => Self::AAAAR, + _ => Self::UNKNOWN(num), + } + } + + pub fn allowed_actions(&self) -> (bool, bool) { + // 0. duplicates allowed + // 1. allowed to be created by database + match self { + QueryType::UNKNOWN(_) => (false, false), + QueryType::A => (true, true), + QueryType::NS => (false, true), + QueryType::CNAME => (false, true), + QueryType::SOA => (false, false), + QueryType::PTR => (false, true), + QueryType::MX => (false, true), + QueryType::TXT => (true, true), + QueryType::AAAA => (true, true), + QueryType::SRV => (false, true), + QueryType::OPT => (false, false), + QueryType::CAA => (false, true), + QueryType::AR => (false, true), + QueryType::AAAAR => (false, true), + } + } +} |