2017-12-26 21:23:47 +00:00
|
|
|
//! Types and constants for DNS TYPes
|
|
|
|
|
2017-12-26 16:30:08 +00:00
|
|
|
use bytes::Bytes;
|
|
|
|
use errors::*;
|
|
|
|
use records::registry::{lookup_type_to_name, lookup_type_name};
|
|
|
|
use ser::DnsPacketData;
|
2017-12-26 21:23:51 +00:00
|
|
|
use ser::text::{DnsTextData, DnsTextFormatter, DnsTextContext, next_field};
|
2017-12-26 16:30:08 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::fmt;
|
|
|
|
use std::io::Cursor;
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a host address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const A : Type = Type(KnownType::A as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an authoritative name server
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NS : Type = Type(KnownType::NS as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail destination (OBSOLETE - use MX)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MD : Type = Type(KnownType::MD as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail forwarder (OBSOLETE - use MX)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MF : Type = Type(KnownType::MF as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// the canonical name for an alias
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CNAME : Type = Type(KnownType::CNAME as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// marks the start of a zone of authority
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SOA : Type = Type(KnownType::SOA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mailbox domain name (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MB : Type = Type(KnownType::MB as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail group member (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MG : Type = Type(KnownType::MG as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail rename domain name (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MR : Type = Type(KnownType::MR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a null RR (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NULL : Type = Type(KnownType::NULL as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a well known service description
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const WKS : Type = Type(KnownType::WKS as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a domain name pointer
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const PTR : Type = Type(KnownType::PTR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// host information
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const HINFO : Type = Type(KnownType::HINFO as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mailbox or mail list information
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MINFO : Type = Type(KnownType::MINFO as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mail exchange
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const MX : Type = Type(KnownType::MX as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// text strings
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const TXT : Type = Type(KnownType::TXT as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for Responsible Person
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const RP : Type = Type(KnownType::RP as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for AFS Data Base location
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const AFSDB : Type = Type(KnownType::AFSDB as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for X.25 PSDN address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const X25 : Type = Type(KnownType::X25 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for ISDN address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const ISDN : Type = Type(KnownType::ISDN as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for Route Through
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const RT : Type = Type(KnownType::RT as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for NSAP address, NSAP style A record
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NSAP : Type = Type(KnownType::NSAP as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for domain name pointer, NSAP style
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NSAP_PTR : Type = Type(KnownType::NSAP_PTR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for security signature
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SIG : Type = Type(KnownType::SIG as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for security key
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const KEY : Type = Type(KnownType::KEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// X.400 mail mapping information
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const PX : Type = Type(KnownType::PX as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Geographical Position
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const GPOS : Type = Type(KnownType::GPOS as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// IP6 Address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const AAAA : Type = Type(KnownType::AAAA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Location Information
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const LOC : Type = Type(KnownType::LOC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Next Domain (OBSOLETE)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NXT : Type = Type(KnownType::NXT as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Endpoint Identifier
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const EID : Type = Type(KnownType::EID as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Nimrod Locator
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NIMLOC : Type = Type(KnownType::NIMLOC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Server Selection
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SRV : Type = Type(KnownType::SRV as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// ATM Address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const ATMA : Type = Type(KnownType::ATMA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Naming Authority Pointer
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NAPTR : Type = Type(KnownType::NAPTR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Key Exchanger
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const KX : Type = Type(KnownType::KX as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// CERT
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CERT : Type = Type(KnownType::CERT as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// A6 (OBSOLETE - use AAAA)
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const A6 : Type = Type(KnownType::A6 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNAME
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DNAME : Type = Type(KnownType::DNAME as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SINK
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SINK : Type = Type(KnownType::SINK as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// OPT
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const OPT : Type = Type(KnownMetaType::OPT as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// APL
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const APL : Type = Type(KnownType::APL as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Delegation Signer
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DS : Type = Type(KnownType::DS as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SSH Key Fingerprint
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SSHFP : Type = Type(KnownType::SSHFP as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// IPSECKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const IPSECKEY : Type = Type(KnownType::IPSECKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// RRSIG
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const RRSIG : Type = Type(KnownType::RRSIG as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NSEC : Type = Type(KnownType::NSEC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DNSKEY : Type = Type(KnownType::DNSKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DHCID
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DHCID : Type = Type(KnownType::DHCID as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC3
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NSEC3 : Type = Type(KnownType::NSEC3 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC3PARAM
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NSEC3PARAM : Type = Type(KnownType::NSEC3PARAM as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// TLSA
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const TLSA : Type = Type(KnownType::TLSA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// S/MIME cert association
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SMIMEA : Type = Type(KnownType::SMIMEA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Host Identity Protocol
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const HIP : Type = Type(KnownType::HIP as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NINFO
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NINFO : Type = Type(KnownType::NINFO as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// RKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const RKEY : Type = Type(KnownType::RKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Trust Anchor LINK
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const TALINK : Type = Type(KnownType::TALINK as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Child DS
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CDS : Type = Type(KnownType::CDS as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSKEY(s) the Child wants reflected in DS
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CDNSKEY : Type = Type(KnownType::CDNSKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// OpenPGP Key
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const OPENPGPKEY : Type = Type(KnownType::OPENPGPKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Child-To-Parent Synchronization
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CSYNC : Type = Type(KnownType::CSYNC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SPF
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const SPF : Type = Type(KnownType::SPF as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UINFO
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const UINFO : Type = Type(KnownType::UINFO as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UID
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const UID : Type = Type(KnownType::UID as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// GID
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const GID : Type = Type(KnownType::GID as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UNSPEC
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const UNSPEC : Type = Type(KnownType::UNSPEC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NID
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const NID : Type = Type(KnownType::NID as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// L32
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const L32 : Type = Type(KnownType::L32 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// L64
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const L64 : Type = Type(KnownType::L64 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// LP
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const LP : Type = Type(KnownType::LP as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an EUI-48 address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const EUI48 : Type = Type(KnownType::EUI48 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an EUI-64 address
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const EUI64 : Type = Type(KnownType::EUI64 as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Transaction Key
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const TKEY : Type = Type(KnownMetaType::TKEY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Transaction Signature
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const TSIG : Type = Type(KnownMetaType::TSIG as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// incremental transfer
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const IXFR : Type = Type(KnownQType::IXFR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// transfer of an entire zone
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const AXFR : Type = Type(KnownQType::AXFR as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mailbox-related RRs (MB, MG or MR)
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const MAILB : Type = Type(KnownQType::MAILB as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mail agent RRs (OBSOLETE - see MX)
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const MAILA : Type = Type(KnownQType::MAILA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// "*", a request for all records the server/cache has available
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const ANY : Type = Type(KnownQType::ANY as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// URI
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const URI : Type = Type(KnownType::URI as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Certification Authority Restriction
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const CAA : Type = Type(KnownType::CAA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Application Visibility and Control
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const AVC : Type = Type(KnownType::AVC as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Digital Object Architecture
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DOA : Type = Type(KnownType::DOA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSSEC Trust Authorities
|
2017-12-26 16:30:08 +00:00
|
|
|
pub const TA : Type = Type(KnownType::TA as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSSEC Lookaside Validation
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const DLV : Type = Type(KnownType::DLV as u16);
|
2017-12-26 21:23:47 +00:00
|
|
|
/// powerdns feature: authoritate should resolve to A and AAAA
|
2017-12-16 20:58:18 +00:00
|
|
|
pub const ALIAS : Type = Type(KnownType::ALIAS as u16);
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// known data TYPEs
|
2017-12-16 20:58:18 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
#[repr(u16)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum KnownType {
|
|
|
|
// try to list "original" rfc
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a host address
|
2017-12-16 20:58:18 +00:00
|
|
|
A = 0x0001, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an authoritative name server
|
2017-12-16 20:58:18 +00:00
|
|
|
NS = 0x0002, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail destination (OBSOLETE - use MX)
|
2017-12-16 20:58:18 +00:00
|
|
|
MD = 0x0003, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail forwarder (OBSOLETE - use MX)
|
2017-12-16 20:58:18 +00:00
|
|
|
MF = 0x0004, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// the canonical name for an alias
|
2017-12-16 20:58:18 +00:00
|
|
|
CNAME = 0x0005, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// marks the start of a zone of authority
|
2017-12-16 20:58:18 +00:00
|
|
|
SOA = 0x0006, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mailbox domain name (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
MB = 0x0007, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail group member (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
MG = 0x0008, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a mail rename domain name (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
MR = 0x0009, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a null RR (EXPERIMENTAL)
|
2017-12-16 20:58:18 +00:00
|
|
|
NULL = 0x000a, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a well known service description
|
2017-12-16 20:58:18 +00:00
|
|
|
WKS = 0x000b, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// a domain name pointer
|
2017-12-16 20:58:18 +00:00
|
|
|
PTR = 0x000c, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// host information
|
2017-12-16 20:58:18 +00:00
|
|
|
HINFO = 0x000d, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mailbox or mail list information
|
2017-12-16 20:58:18 +00:00
|
|
|
MINFO = 0x000e, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// mail exchange
|
2017-12-16 20:58:18 +00:00
|
|
|
MX = 0x000f, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// text strings
|
2017-12-16 20:58:18 +00:00
|
|
|
TXT = 0x0010, // RFC 1035
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for Responsible Person
|
2017-12-16 20:58:18 +00:00
|
|
|
RP = 0x0011, // RFC 1183
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for AFS Data Base location
|
2017-12-16 20:58:18 +00:00
|
|
|
AFSDB = 0x0012, // RFC 1183
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for X.25 PSDN address
|
2017-12-16 20:58:18 +00:00
|
|
|
X25 = 0x0013, // RFC 1183
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for ISDN address
|
2017-12-16 20:58:18 +00:00
|
|
|
ISDN = 0x0014, // RFC 1183
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for Route Through
|
2017-12-16 20:58:18 +00:00
|
|
|
RT = 0x0015, // RFC 1183
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for NSAP address, NSAP style A record
|
2017-12-16 20:58:18 +00:00
|
|
|
NSAP = 0x0016, // RFC 1706
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for domain name pointer, NSAP style
|
2017-12-16 20:58:18 +00:00
|
|
|
NSAP_PTR = 0x0017, // RFC 1348
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for security signature
|
2017-12-16 20:58:18 +00:00
|
|
|
SIG = 0x0018, // RFC 2535
|
2017-12-26 21:23:47 +00:00
|
|
|
/// for security key
|
2017-12-16 20:58:18 +00:00
|
|
|
KEY = 0x0019, // RFC 2535
|
2017-12-26 21:23:47 +00:00
|
|
|
/// X.400 mail mapping information
|
2017-12-16 20:58:18 +00:00
|
|
|
PX = 0x001a, // RFC 2163
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Geographical Position
|
2017-12-16 20:58:18 +00:00
|
|
|
GPOS = 0x001b, // RFC 1712
|
2017-12-26 21:23:47 +00:00
|
|
|
/// IP6 Address
|
2017-12-16 20:58:18 +00:00
|
|
|
AAAA = 0x001c, // RFC 3596
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Location Information
|
2017-12-16 20:58:18 +00:00
|
|
|
LOC = 0x001d, // RFC 1876
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Next Domain (OBSOLETE)
|
2017-12-16 20:58:18 +00:00
|
|
|
NXT = 0x001e, // RFC 2535
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Endpoint Identifier
|
2017-12-16 20:58:18 +00:00
|
|
|
EID = 0x001f, // Michael Patton: http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Nimrod Locator
|
2017-12-16 20:58:18 +00:00
|
|
|
NIMLOC = 0x0020, // Michael Patton: http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Server Selection
|
2017-12-16 20:58:18 +00:00
|
|
|
SRV = 0x0021, // RFC 2782
|
2017-12-26 21:23:47 +00:00
|
|
|
/// ATM Address
|
2017-12-16 20:58:18 +00:00
|
|
|
ATMA = 0x0022, // http://www.broadband-forum.org/ftp/pub/approved-specs/af-dans-0152.000.pdf
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Naming Authority Pointer
|
2017-12-16 20:58:18 +00:00
|
|
|
NAPTR = 0x0023, // RFC 2168
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Key Exchanger
|
2017-12-16 20:58:18 +00:00
|
|
|
KX = 0x0024, // RFC 2230
|
2017-12-26 21:23:47 +00:00
|
|
|
/// CERT
|
2017-12-16 20:58:18 +00:00
|
|
|
CERT = 0x0025, // RFC 4398
|
2017-12-26 21:23:47 +00:00
|
|
|
/// A6 (OBSOLETE - use AAAA)
|
2017-12-16 20:58:18 +00:00
|
|
|
A6 = 0x0026, // RFC 2874
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNAME
|
2017-12-16 20:58:18 +00:00
|
|
|
DNAME = 0x0027, // RFC 6672
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SINK
|
2017-12-16 20:58:18 +00:00
|
|
|
SINK = 0x0028, // Donald E Eastlake: http://tools.ietf.org/html/draft-eastlake-kitchen-sink
|
2017-12-26 16:30:08 +00:00
|
|
|
// OPT (0x0029) is a meta type
|
2017-12-26 21:23:47 +00:00
|
|
|
/// APL
|
2017-12-16 20:58:18 +00:00
|
|
|
APL = 0x002a, // RFC 3123
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Delegation Signer
|
2017-12-16 20:58:18 +00:00
|
|
|
DS = 0x002b, // RFC 3658
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SSH Key Fingerprint
|
2017-12-16 20:58:18 +00:00
|
|
|
SSHFP = 0x002c, // RFC 4255
|
2017-12-26 21:23:47 +00:00
|
|
|
/// IPSECKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
IPSECKEY = 0x002d, // RFC 4025
|
2017-12-26 21:23:47 +00:00
|
|
|
/// RRSIG
|
2017-12-16 20:58:18 +00:00
|
|
|
RRSIG = 0x002e, // RFC 4034
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC
|
2017-12-16 20:58:18 +00:00
|
|
|
NSEC = 0x002f, // RFC 4034
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
DNSKEY = 0x0030, // RFC 4034
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DHCID
|
2017-12-16 20:58:18 +00:00
|
|
|
DHCID = 0x0031, // RFC 4701
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC3
|
2017-12-16 20:58:18 +00:00
|
|
|
NSEC3 = 0x0032, // RFC 5155
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NSEC3PARAM
|
2017-12-16 20:58:18 +00:00
|
|
|
NSEC3PARAM = 0x0033, // RFC 5155
|
2017-12-26 21:23:47 +00:00
|
|
|
/// TLSA
|
2017-12-16 20:58:18 +00:00
|
|
|
TLSA = 0x0034, // RFC 6698
|
2017-12-26 21:23:47 +00:00
|
|
|
/// S/MIME cert association
|
2017-12-16 20:58:18 +00:00
|
|
|
SMIMEA = 0x0035, // RFC 8162
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Host Identity Protocol
|
2017-12-16 20:58:18 +00:00
|
|
|
HIP = 0x0037, // RFC 8005
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NINFO
|
2017-12-16 20:58:18 +00:00
|
|
|
NINFO = 0x0038, // Jim Reid
|
2017-12-26 21:23:47 +00:00
|
|
|
/// RKEY
|
2017-12-16 20:58:18 +00:00
|
|
|
RKEY = 0x0039, // Jim Reid
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Trust Anchor LINK
|
2017-12-16 20:58:18 +00:00
|
|
|
TALINK = 0x003a, // Wouter Wijngaards
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Child DS
|
2017-12-16 20:58:18 +00:00
|
|
|
CDS = 0x003b, // RFC 7344
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSKEY(s) the Child wants reflected in DS
|
2017-12-16 20:58:18 +00:00
|
|
|
CDNSKEY = 0x003c, // RFC 7344
|
2017-12-26 21:23:47 +00:00
|
|
|
/// OpenPGP Key
|
2017-12-16 20:58:18 +00:00
|
|
|
OPENPGPKEY = 0x003d, // RFC 7929
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Child-To-Parent Synchronization
|
2017-12-16 20:58:18 +00:00
|
|
|
CSYNC = 0x003e, // RFC 7477
|
2017-12-26 21:23:47 +00:00
|
|
|
/// SPF
|
2017-12-16 20:58:18 +00:00
|
|
|
SPF = 0x0063, // RFC 7208
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UINFO
|
2017-12-16 20:58:18 +00:00
|
|
|
UINFO = 0x0064, // IANA-Reserved
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UID
|
2017-12-16 20:58:18 +00:00
|
|
|
UID = 0x0065, // IANA-Reserved
|
2017-12-26 21:23:47 +00:00
|
|
|
/// GID
|
2017-12-16 20:58:18 +00:00
|
|
|
GID = 0x0066, // IANA-Reserved
|
2017-12-26 21:23:47 +00:00
|
|
|
/// UNSPEC
|
2017-12-16 20:58:18 +00:00
|
|
|
UNSPEC = 0x0067, // IANA-Reserved
|
2017-12-26 21:23:47 +00:00
|
|
|
/// NID
|
2017-12-16 20:58:18 +00:00
|
|
|
NID = 0x0068, // RFC 6742
|
2017-12-26 21:23:47 +00:00
|
|
|
/// L32
|
2017-12-16 20:58:18 +00:00
|
|
|
L32 = 0x0069, // RFC 6742
|
2017-12-26 21:23:47 +00:00
|
|
|
/// L64
|
2017-12-16 20:58:18 +00:00
|
|
|
L64 = 0x006a, // RFC 6742
|
2017-12-26 21:23:47 +00:00
|
|
|
/// LP
|
2017-12-16 20:58:18 +00:00
|
|
|
LP = 0x006b, // RFC 6742
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an EUI-48 address
|
2017-12-16 20:58:18 +00:00
|
|
|
EUI48 = 0x006c, // RFC 7043
|
2017-12-26 21:23:47 +00:00
|
|
|
/// an EUI-64 address
|
2017-12-16 20:58:18 +00:00
|
|
|
EUI64 = 0x006d, // RFC 7043
|
2017-12-26 16:30:08 +00:00
|
|
|
// 0x0080..0x00ff: meta and qtypes
|
2017-12-26 21:23:47 +00:00
|
|
|
/// URI
|
2017-12-26 16:30:08 +00:00
|
|
|
URI = 0x0100, // RFC 7553
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Certification Authority Restriction
|
2017-12-26 16:30:08 +00:00
|
|
|
CAA = 0x0101, // RFC 6844
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Application Visibility and Control
|
2017-12-26 16:30:08 +00:00
|
|
|
AVC = 0x0102, // Wolfgang Riedel
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Digital Object Architecture
|
2017-12-26 16:30:08 +00:00
|
|
|
DOA = 0x0103, // http://www.iana.org/go/draft-durand-doa-over-dns
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSSEC Trust Authorities
|
2017-12-26 16:30:08 +00:00
|
|
|
TA = 0x8000, //
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNSSEC Lookaside Validation
|
2017-12-26 16:30:08 +00:00
|
|
|
DLV = 0x8001, // RFC 4431
|
2017-12-26 21:23:47 +00:00
|
|
|
/// powerdns feature: authoritate should resolve to A and AAAA
|
2017-12-26 16:30:08 +00:00
|
|
|
ALIAS = 0xff79, // powerdns
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// known QTYPEs
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
#[repr(u16)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum KnownQType {
|
|
|
|
/// incremental transfer
|
|
|
|
IXFR = 0x00fb, // RFC 1995
|
|
|
|
/// transfer of an entire zone
|
|
|
|
AXFR = 0x00fc, // RFC 1035
|
|
|
|
/// mailbox-related RRs (MB, MG or MR)
|
|
|
|
MAILB = 0x00fd, // RFC 1035
|
|
|
|
/// mail agent RRs (OBSOLETE - see MX)
|
|
|
|
MAILA = 0x00fe, // RFC 1035
|
|
|
|
/// "*", a request for all records the server/cache has available
|
|
|
|
ANY = 0x00ff, // RFC 1035
|
|
|
|
}
|
|
|
|
|
|
|
|
/// known Meta-TYPEs
|
2017-12-26 16:30:08 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
#[repr(u16)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum KnownMetaType {
|
2017-12-26 21:23:47 +00:00
|
|
|
/// OPT
|
2017-12-26 16:30:08 +00:00
|
|
|
OPT = 0x0029, // RFC 6891
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Transaction Key
|
2017-12-16 20:58:18 +00:00
|
|
|
TKEY = 0x00f9, // RFC 2930
|
2017-12-26 21:23:47 +00:00
|
|
|
/// Transaction Signature
|
2017-12-16 20:58:18 +00:00
|
|
|
TSIG = 0x00fa, // RFC 2845
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// DNS (RR)TYPE
|
|
|
|
///
|
|
|
|
/// Originally QTYPE was a superset of TYPE; RFC 6895 now defines:
|
|
|
|
///
|
|
|
|
/// > There are three subcategories of RRTYPE numbers: data TYPEs,
|
|
|
|
/// > QTYPEs, and Meta-TYPEs.
|
|
|
|
///
|
|
|
|
/// ## `ANY`
|
|
|
|
///
|
|
|
|
/// QTYPE 255 ("*") doesn't seem to have an official mnemonic; `ANY` is
|
|
|
|
/// used in most tools though.
|
|
|
|
///
|
|
|
|
/// The `ANY` mnemonic conflicts with the QCLASS `ANY` though; the name
|
|
|
|
/// functions for `Class` have `_without_any` variants though.
|
2017-12-26 16:30:08 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
2017-12-26 21:23:47 +00:00
|
|
|
pub struct Type(pub u16);
|
2017-12-16 20:58:18 +00:00
|
|
|
|
2017-12-26 16:30:08 +00:00
|
|
|
impl Type {
|
2017-12-26 21:23:47 +00:00
|
|
|
/// whether TYPE is known or reserved to be a QTYPE or a Meta-TYPE.
|
|
|
|
///
|
|
|
|
/// 0x0080-0x00FF is reserved for QTYPEs and Meta-TYPEs; OPT is a
|
|
|
|
/// special Meta-TYPE.
|
2017-12-26 16:30:08 +00:00
|
|
|
pub fn is_q_or_meta_type(self) -> bool {
|
|
|
|
self == OPT || (self.0 >= 128 && self.0 < 256)
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// map to `KnownQType`
|
|
|
|
pub fn known_qtype(self) -> Option<KnownQType> {
|
|
|
|
Some(match self {
|
|
|
|
IXFR => KnownQType::IXFR,
|
|
|
|
AXFR => KnownQType::AXFR,
|
|
|
|
MAILB => KnownQType::MAILB,
|
|
|
|
MAILA => KnownQType::MAILA,
|
|
|
|
ANY => KnownQType::ANY,
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// whether TYPE is known to be a QTYPE
|
2017-12-26 16:30:08 +00:00
|
|
|
pub fn is_known_qtype(self) -> bool {
|
2017-12-26 21:23:47 +00:00
|
|
|
self.known_qtype().is_some()
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// map to `KnownMetaType`
|
|
|
|
pub fn known_meta_type(self) -> Option<KnownMetaType> {
|
|
|
|
Some(match self {
|
|
|
|
OPT => KnownMetaType::OPT,
|
|
|
|
TKEY => KnownMetaType::TKEY,
|
|
|
|
TSIG => KnownMetaType::TSIG,
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// whether TYPE is known to be a Meta-TYPE
|
2017-12-26 16:30:08 +00:00
|
|
|
pub fn is_known_meta_type(self) -> bool {
|
2017-12-26 21:23:47 +00:00
|
|
|
self.known_meta_type().is_some()
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// name for TYPE if known
|
|
|
|
///
|
|
|
|
/// Known TYPEs are represented using their known mnemonic, others
|
|
|
|
/// return None.
|
|
|
|
pub fn known_name(self) -> Option<&'static str> {
|
|
|
|
lookup_type_to_name(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// name for TYPE
|
|
|
|
///
|
|
|
|
/// Known TYPEes are represented using their known mnemonic, others
|
|
|
|
/// using the "TYPE..." syntax (RFC 3597).
|
|
|
|
pub fn name(self) -> Cow<'static, str> {
|
|
|
|
match self.known_name() {
|
|
|
|
Some(name) => Cow::Borrowed(name),
|
|
|
|
None => Cow::Owned(self.generic_name())
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// generic name "TYPE..."
|
2017-12-26 16:30:08 +00:00
|
|
|
pub fn generic_name(self) -> String {
|
2017-12-26 21:23:47 +00:00
|
|
|
let mut result = String::new();
|
|
|
|
self.write_generic_name(&mut result).unwrap();
|
|
|
|
result
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// directly write generic name "TYPE..." to some target
|
|
|
|
pub fn write_generic_name<W: fmt::Write>(self, w: &mut W) -> fmt::Result {
|
|
|
|
write!(w, "TYPE{}", self.0)
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// parses known names (mnemonics)
|
|
|
|
pub fn from_known_name(name: &str) -> Option<Self> {
|
|
|
|
lookup_type_name(name)
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// parses generic names of the form "TYPE..."
|
|
|
|
pub fn from_generic_name(name: &str) -> Option<Self> {
|
|
|
|
use std::ascii::AsciiExt;
|
2017-12-26 21:23:51 +00:00
|
|
|
if name.len() > 4 && name.as_bytes()[0..4].eq_ignore_ascii_case(b"TYPE") {
|
2017-12-26 21:23:47 +00:00
|
|
|
name[4..].parse::<u16>().ok().map(Type)
|
2017-12-26 16:30:08 +00:00
|
|
|
} else {
|
2017-12-26 21:23:47 +00:00
|
|
|
None
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// parses any name (mnemonics and "TYPE...")
|
|
|
|
pub fn from_name(name: &str) -> Option<Self> {
|
|
|
|
Self::from_generic_name(name).or_else(|| {
|
|
|
|
Self::from_known_name(name)
|
|
|
|
})
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// whether TYPE is defined in RFC 1035
|
|
|
|
pub fn is_well_known(self) -> bool {
|
2017-12-26 16:30:08 +00:00
|
|
|
// 0x0001 (A) ... 0x0010 (TXT) are defined in RFC 1035
|
|
|
|
self.0 >= 0x0001 && self.0 <= 0x0010
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
/// require converting to canonical form for DNSSEC (i.e. names must
|
|
|
|
/// be converted to (ASCII) lower case).
|
2017-12-26 16:30:08 +00:00
|
|
|
///
|
2017-12-26 21:23:47 +00:00
|
|
|
/// For DNSSEC name compression is forbidden too; all compressable
|
|
|
|
/// TYPEs are included in the list anyway.
|
|
|
|
///
|
|
|
|
/// See [RFC 4034 section 6.2][1] (obsoletes RFC 3597). Also
|
|
|
|
/// updated by [RFC 6840 section 5.1][2].
|
|
|
|
///
|
|
|
|
/// [1]: https://tools.ietf.org/html/rfc4034#section-6.2
|
|
|
|
/// [2]: https://tools.ietf.org/html/rfc6840#section-5.1
|
|
|
|
pub fn use_canonical_names(self) -> bool {
|
2017-12-26 16:30:08 +00:00
|
|
|
match self {
|
|
|
|
NS => true,
|
|
|
|
MD => true,
|
|
|
|
MF => true,
|
|
|
|
CNAME => true,
|
|
|
|
SOA => true,
|
|
|
|
MB => true,
|
|
|
|
MG => true,
|
|
|
|
MR => true,
|
|
|
|
PTR => true,
|
|
|
|
// HINFO => true, // removed by RFC 6840: doesn't have a name in data
|
|
|
|
MINFO => true,
|
|
|
|
MX => true,
|
|
|
|
// HINFO => true, // removed by RFC 6840: see above, also duplicate
|
|
|
|
RP => true,
|
|
|
|
AFSDB => true,
|
|
|
|
RT => true,
|
|
|
|
NSAP_PTR => true, // not listed in the RFCs, but probably should be.
|
|
|
|
SIG => true,
|
|
|
|
PX => true,
|
|
|
|
NXT => true,
|
|
|
|
SRV => true, // moved up to match numeric order
|
|
|
|
NAPTR => true,
|
|
|
|
KX => true,
|
|
|
|
// SRV => true, // moved up to match numeric order
|
|
|
|
A6 => true, // moved up to match numeric order
|
|
|
|
DNAME => true,
|
|
|
|
// A6 => true, // moved up to match numeric order
|
|
|
|
RRSIG => true,
|
|
|
|
// NSEC => true, // removed by RFC 6840
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<KnownType> for Type {
|
|
|
|
fn from(value: KnownType) -> Self {
|
|
|
|
Type(value as u16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
impl From<KnownQType> for Type {
|
|
|
|
fn from(value: KnownQType) -> Self {
|
2017-12-26 16:30:08 +00:00
|
|
|
Type(value as u16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
impl From<KnownMetaType> for Type {
|
|
|
|
fn from(value: KnownMetaType) -> Self {
|
2017-12-26 16:30:08 +00:00
|
|
|
Type(value as u16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Type {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-12-26 21:23:47 +00:00
|
|
|
match self.known_name() {
|
|
|
|
Some(name) => write!(f, "{}", name),
|
|
|
|
None => self.write_generic_name(f),
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DnsPacketData for Type {
|
|
|
|
fn deserialize(data: &mut Cursor<Bytes>) -> Result<Self> {
|
|
|
|
Ok(Type(DnsPacketData::deserialize(data)?))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DnsTextData for Type {
|
2017-12-26 21:23:51 +00:00
|
|
|
fn dns_parse(_context: &DnsTextContext, data: &mut &str) -> Result<Self> {
|
2017-12-26 16:30:08 +00:00
|
|
|
let field = next_field(data)?;
|
2017-12-26 21:23:47 +00:00
|
|
|
Type::from_name(field).ok_or_else(|| format_err!("unknown TYPE {:?}", field))
|
2017-12-26 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn dns_format(&self, f: &mut DnsTextFormatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 20:58:18 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
macro_rules! check_type {
|
|
|
|
($t:ident, $dec:expr) => {
|
|
|
|
{
|
|
|
|
use records::registry;
|
|
|
|
// compare decimal value
|
|
|
|
assert_eq!($t, Type($dec), "wrong decimal value for {}", stringify!($t));
|
|
|
|
// make sure it's registered
|
2017-12-26 16:30:08 +00:00
|
|
|
assert_eq!(registry::lookup_type_name(stringify!($t)), Some($t), "{} not registered", stringify!($t));
|
2017-12-16 20:58:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
($t:ident, $dec:expr, $name:expr) => {
|
|
|
|
{
|
|
|
|
use records::registry;
|
|
|
|
// compare decimal value
|
|
|
|
assert_eq!($t, Type($dec), "wrong decimal value for {}", stringify!($t));
|
|
|
|
// make sure it's registered
|
2017-12-26 16:30:08 +00:00
|
|
|
assert_eq!(registry::lookup_type_name($name), Some($t), "{} not registered as {:?}", stringify!($t), $name);
|
2017-12-16 20:58:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-26 21:23:47 +00:00
|
|
|
// the IANA registry uses decimal numbers; make sure there were no typos
|
|
|
|
// when converting them to hex in the constants above.
|
|
|
|
//
|
|
|
|
// also checks the registry has the name-to-number mapping.
|
2017-12-16 20:58:18 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
#[test]
|
|
|
|
fn check_types() {
|
|
|
|
check_type!(A , 1);
|
|
|
|
check_type!(NS , 2);
|
|
|
|
check_type!(MD , 3);
|
|
|
|
check_type!(MF , 4);
|
|
|
|
check_type!(CNAME , 5);
|
|
|
|
check_type!(SOA , 6);
|
|
|
|
check_type!(MB , 7);
|
|
|
|
check_type!(MG , 8);
|
|
|
|
check_type!(MR , 9);
|
|
|
|
check_type!(NULL , 10);
|
|
|
|
check_type!(WKS , 11);
|
|
|
|
check_type!(PTR , 12);
|
|
|
|
check_type!(HINFO , 13);
|
|
|
|
check_type!(MINFO , 14);
|
|
|
|
check_type!(MX , 15);
|
|
|
|
check_type!(TXT , 16);
|
|
|
|
check_type!(RP , 17);
|
|
|
|
check_type!(AFSDB , 18);
|
|
|
|
check_type!(X25 , 19);
|
|
|
|
check_type!(ISDN , 20);
|
|
|
|
check_type!(RT , 21);
|
|
|
|
check_type!(NSAP , 22);
|
|
|
|
check_type!(NSAP_PTR , 23, "NSAP-PTR");
|
|
|
|
check_type!(SIG , 24);
|
|
|
|
check_type!(KEY , 25);
|
|
|
|
check_type!(PX , 26);
|
|
|
|
check_type!(GPOS , 27);
|
|
|
|
check_type!(AAAA , 28);
|
|
|
|
check_type!(LOC , 29);
|
|
|
|
check_type!(NXT , 30);
|
|
|
|
check_type!(EID , 31);
|
|
|
|
check_type!(NIMLOC , 32);
|
|
|
|
check_type!(SRV , 33);
|
|
|
|
check_type!(ATMA , 34);
|
|
|
|
check_type!(NAPTR , 35);
|
|
|
|
check_type!(KX , 36);
|
|
|
|
check_type!(CERT , 37);
|
|
|
|
check_type!(A6 , 38);
|
|
|
|
check_type!(DNAME , 39);
|
|
|
|
check_type!(SINK , 40);
|
|
|
|
check_type!(OPT , 41);
|
|
|
|
check_type!(APL , 42);
|
|
|
|
check_type!(DS , 43);
|
|
|
|
check_type!(SSHFP , 44);
|
|
|
|
check_type!(IPSECKEY , 45);
|
|
|
|
check_type!(RRSIG , 46);
|
|
|
|
check_type!(NSEC , 47);
|
|
|
|
check_type!(DNSKEY , 48);
|
|
|
|
check_type!(DHCID , 49);
|
|
|
|
check_type!(NSEC3 , 50);
|
|
|
|
check_type!(NSEC3PARAM, 51);
|
|
|
|
check_type!(TLSA , 52);
|
|
|
|
check_type!(SMIMEA , 53);
|
|
|
|
check_type!(HIP , 55);
|
|
|
|
check_type!(NINFO , 56);
|
|
|
|
check_type!(RKEY , 57);
|
|
|
|
check_type!(TALINK , 58);
|
|
|
|
check_type!(CDS , 59);
|
|
|
|
check_type!(CDNSKEY , 60);
|
|
|
|
check_type!(OPENPGPKEY, 61);
|
|
|
|
check_type!(CSYNC , 62);
|
|
|
|
check_type!(SPF , 99);
|
|
|
|
check_type!(UINFO , 100);
|
|
|
|
check_type!(UID , 101);
|
|
|
|
check_type!(GID , 102);
|
|
|
|
check_type!(UNSPEC , 103);
|
|
|
|
check_type!(NID , 104);
|
|
|
|
check_type!(L32 , 105);
|
|
|
|
check_type!(L64 , 106);
|
|
|
|
check_type!(LP , 107);
|
|
|
|
check_type!(EUI48 , 108);
|
|
|
|
check_type!(EUI64 , 109);
|
|
|
|
check_type!(TKEY , 249);
|
|
|
|
check_type!(TSIG , 250);
|
|
|
|
check_type!(IXFR , 251);
|
|
|
|
check_type!(AXFR , 252);
|
|
|
|
check_type!(MAILB , 253);
|
|
|
|
check_type!(MAILA , 254);
|
|
|
|
check_type!(ANY , 255);
|
|
|
|
check_type!(URI , 256);
|
|
|
|
check_type!(CAA , 257);
|
|
|
|
check_type!(AVC , 258);
|
|
|
|
check_type!(DOA , 259);
|
2017-12-26 16:30:08 +00:00
|
|
|
check_type!(TA , 32768);
|
2017-12-16 20:58:18 +00:00
|
|
|
check_type!(DLV , 32769);
|
|
|
|
check_type!(ALIAS , 65401);
|
|
|
|
}
|